[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/datatypes/ezkeyword/ -> ezkeywordtype.php (source)

   1  <?php
   2  //
   3  // Definition of eZKeywordType class
   4  //
   5  // Created on: <29-Apr-2003 14:59:12 bf>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*!
  30    \class eZKeywordType ezkeywordtype.php
  31    \ingroup eZDatatype
  32    \brief A content datatype which handles keyword indexes
  33  
  34  */
  35  
  36  include_once ( 'kernel/classes/ezdatatype.php' );
  37  include_once ( 'kernel/common/i18n.php' );
  38  
  39  include_once ( 'kernel/classes/datatypes/ezkeyword/ezkeyword.php' );
  40  
  41  define( 'EZ_DATATYPESTRING_KEYWORD', 'ezkeyword' );
  42  
  43  class eZKeywordType extends eZDataType
  44  {
  45      /*!
  46       Initializes with a keyword id and a description.
  47      */
  48      function eZKeywordType()
  49      {
  50          $this->eZDataType( EZ_DATATYPESTRING_KEYWORD, ezi18n( 'kernel/classes/datatypes', 'Keywords', 'Datatype name' ),
  51                             array( 'serialize_supported' => true ) );
  52      }
  53  
  54      /*!
  55       Sets the default value.
  56      */
  57      function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
  58      {
  59          if ( $currentVersion != false )
  60          {
  61              $originalContentObjectAttributeID = $originalContentObjectAttribute->attribute( 'id' );
  62              $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
  63  
  64              // if translating or copying an object
  65              if ( $originalContentObjectAttributeID != $contentObjectAttributeID )
  66              {
  67                  // copy keywords links as well
  68                  $keyword =& $originalContentObjectAttribute->content();
  69                  if ( is_object( $keyword ) )
  70                  {
  71                      $keyword->store( $contentObjectAttribute );
  72                  }
  73              }
  74          }
  75      }
  76  
  77      /*!
  78       Validates the input and returns true if the input was
  79       valid for this datatype.
  80      */
  81      function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
  82      {
  83          if ( $http->hasPostVariable( $base . '_ezkeyword_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
  84          {
  85              $data = $http->postVariable( $base . '_ezkeyword_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
  86              $classAttribute =& $contentObjectAttribute->contentClassAttribute();
  87  
  88              if ( $data == "" )
  89              {
  90                  if ( !$classAttribute->attribute( 'is_information_collector' ) and
  91                       $contentObjectAttribute->validateIsRequired() )
  92                  {
  93                      $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
  94                                                                           'Input required.' ) );
  95                      return EZ_INPUT_VALIDATOR_STATE_INVALID;
  96                  }
  97              }
  98          }
  99          return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
 100      }
 101  
 102      /*!
 103       Fetches the http post var keyword input and stores it in the data instance.
 104      */
 105      function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
 106      {
 107          if ( $http->hasPostVariable( $base . '_ezkeyword_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
 108          {
 109              $data = $http->postVariable( $base . '_ezkeyword_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
 110              $keyword = new eZKeyword();
 111              $keyword->initializeKeyword( $data );
 112              $contentObjectAttribute->setContent( $keyword );
 113              return true;
 114          }
 115          return false;
 116      }
 117  
 118      /*!
 119       Does nothing since it uses the data_text field in the content object attribute.
 120       See fetchObjectAttributeHTTPInput for the actual storing.
 121      */
 122      function storeObjectAttribute( &$attribute )
 123      {
 124          // create keyword index
 125          $keyword =& $attribute->content();
 126          if ( is_object( $keyword ) )
 127          {
 128              $keyword->store( $attribute );
 129          }
 130      }
 131  
 132      function storeClassAttribute( &$attribute, $version )
 133      {
 134      }
 135  
 136      function storeDefinedClassAttribute( &$attribute )
 137      {
 138      }
 139  
 140      /*!
 141       \reimp
 142      */
 143      function validateClassAttributeHTTPInput( &$http, $base, &$attribute )
 144      {
 145          return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
 146      }
 147  
 148      /*!
 149       \reimp
 150      */
 151      function fixupClassAttributeHTTPInput( &$http, $base, &$attribute )
 152      {
 153      }
 154  
 155      /*!
 156       \reimp
 157      */
 158      function fetchClassAttributeHTTPInput( &$http, $base, &$attribute )
 159      {
 160          return true;
 161      }
 162  
 163      /*!
 164       Returns the content.
 165      */
 166      function &objectAttributeContent( &$attribute )
 167      {
 168          $keyword = new eZKeyword();
 169          $keyword->fetch( $attribute );
 170  
 171          return $keyword;
 172      }
 173  
 174      /*!
 175       Returns the meta data used for storing search indeces.
 176      */
 177      function metaData( &$attribute )
 178      {
 179          $keyword = new eZKeyword();
 180          $keyword->fetch( $attribute );
 181          $return = $keyword->keywordString();
 182  
 183          return $return;
 184      }
 185  
 186      /*!
 187       \reuturn the collect information action if enabled
 188      */
 189      function contentActionList( &$classAttribute )
 190      {
 191          return array();
 192      }
 193  
 194      /*!
 195       Delete stored object attribute
 196      */
 197      function deleteStoredObjectAttribute( &$contentObjectAttribute, $version = null )
 198      {
 199          if ( $version != null ) // Do not delete if discarding draft
 200          {
 201              return;
 202          }
 203  
 204          $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
 205  
 206          $db =& eZDB::instance();
 207  
 208          /* First we retrieve all the keyword ID related to this object attribute */
 209          $res = $db->arrayQuery( "SELECT keyword_id
 210                                   FROM ezkeyword_attribute_link
 211                                   WHERE objectattribute_id='$contentObjectAttributeID'" );
 212          if ( !count ( $res ) )
 213          {
 214              /* If there are no keywords at all, we abort the function as there
 215               * is nothing more to do */
 216              return;
 217          }
 218          $keywordIDs = array();
 219          foreach ( $res as $record )
 220              $keywordIDs[] = $record['keyword_id'];
 221          $keywordIDString = implode( ', ', $keywordIDs );
 222  
 223          /* Then we see which ones only have a count of 1 */
 224          $res = $db->arrayQuery( "SELECT keyword_id
 225                                   FROM ezkeyword, ezkeyword_attribute_link
 226                                   WHERE ezkeyword.id = ezkeyword_attribute_link.keyword_id
 227                                       AND ezkeyword.id IN ($keywordIDString)
 228                                   GROUP BY keyword_id
 229                                   HAVING COUNT(*) = 1" );
 230          $unusedKeywordIDs = array();
 231          foreach ( $res as $record )
 232              $unusedKeywordIDs[] = $record['keyword_id'];
 233          $unusedKeywordIDString = implode( ', ', $unusedKeywordIDs );
 234  
 235          /* Then we delete those unused keywords */
 236          if ( $unusedKeywordIDString )
 237              $db->query( "DELETE FROM ezkeyword WHERE id IN ($unusedKeywordIDString)" );
 238  
 239          /* And as last we remove the link between the keyword and the object
 240           * attribute to be removed */
 241          $db->query( "DELETE FROM ezkeyword_attribute_link
 242                       WHERE objectattribute_id='$contentObjectAttributeID'" );
 243      }
 244  
 245      /*!
 246       Returns the content of the keyword for use as a title
 247      */
 248      function title( &$attribute )
 249      {
 250          $keyword = new eZKeyword();
 251          $keyword->fetch( $attribute );
 252          $return = $keyword->keywordString();
 253  
 254          return $return;
 255      }
 256  
 257      function hasObjectAttributeContent( &$contentObjectAttribute )
 258      {
 259          $keyword = new eZKeyword();
 260          $keyword->fetch( $contentObjectAttribute );
 261          $array =& $keyword->keywordArray();
 262  
 263          return count( $array ) > 0;
 264      }
 265  
 266      /*!
 267       \reimp
 268      */
 269      function isIndexable()
 270      {
 271          return true;
 272      }
 273  
 274      /*!
 275       \return string representation of an contentobjectattribute data for simplified export
 276  
 277      */
 278      function toString( $contentObjectAttribute )
 279      {
 280          $keyword = new eZKeyword();
 281          $keyword->fetch( $contentObjectAttribute  );
 282          return  $keyword->keywordString();
 283      }
 284  
 285      function fromString( &$contentObjectAttribute, $string )
 286      {
 287          if ( $string != '' )
 288          {
 289              $keyword = new eZKeyword();
 290              $keyword->initializeKeyword( $string );
 291              $contentObjectAttribute ->setContent( $keyword );
 292          }
 293          return true;
 294      }
 295  
 296      /*!
 297       \reimp
 298       \param package
 299       \param content attribute
 300  
 301       \return a DOM representation of the content object attribute
 302      */
 303      function serializeContentObjectAttribute( &$package, &$objectAttribute )
 304      {
 305          $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
 306  
 307          $keyword = new eZKeyword();
 308          $keyword->fetch( $objectAttribute );
 309          $keyWordString = $keyword->keywordString();
 310          $node->appendChild( eZDOMDocument::createElementTextNode( 'keyword-string', $keyWordString ) );
 311  
 312          return $node;
 313      }
 314  
 315      /*!
 316       \reimp
 317       Unserailize contentobject attribute
 318  
 319       \param package
 320       \param contentobject attribute object
 321       \param ezdomnode object
 322      */
 323      function unserializeContentObjectAttribute( &$package, &$objectAttribute, $attributeNode )
 324      {
 325          $keyWordString = $attributeNode->elementTextContentByName( 'keyword-string' );
 326          $keyword = new eZKeyword();
 327          $keyword->initializeKeyword( $keyWordString );
 328          $objectAttribute->setContent( $keyword );
 329      }
 330  }
 331  
 332  eZDataType::register( EZ_DATATYPESTRING_KEYWORD, 'ezkeywordtype' );
 333  
 334  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7