[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/dao/customfields/ -> customfieldsvalues.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/dao/model.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/dao/customfields/customfields.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/dao/customfields/customfieldvaluefactory.class.php" );        
   6      lt_include( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );    
   7  
   8      /**
   9       * Model for the values given to certain custom fields
  10       *
  11       * \ingroup DAO
  12       */
  13      class CustomFieldsValues extends Model 
  14      {
  15      
  16          function CustomFieldsValues()
  17          {
  18              $this->Model();
  19              $this->table = $this->getPrefix()."custom_fields_values";
  20          }
  21          
  22          /**
  23           * @param id
  24           * @return A CustomFieldValue object
  25           */
  26          function getCustomFieldValue( $id )
  27          {
  28              return( $this->get( "id", $id, CACHE_CUSTOMFIELDVALUES ));
  29          }
  30          
  31          /**
  32           * returns an array of CustomFieldValue objects with information about all
  33           * the custom fields available for an article
  34           *
  35           * @param articleId The id of the article
  36           * @param includeHidden Whether to return hidden fields or not
  37           * @return An array of CustomFieldValue objects, or false if error
  38           */
  39          function getArticleCustomFieldsValues( $articleId, $includeHidden = true )
  40          {                   
  41              $prefix = $this->getPrefix();
  42              $query = "SELECT v.id AS id, d.id AS field_id, v.field_value AS field_value, 
  43                               d.field_name AS field_name, d.field_type AS field_type, 
  44                               d.field_description AS field_description,
  45                               v.article_id AS article_id, v.blog_id AS blog_id
  46                               FROM {$prefix}custom_fields_values v 
  47                               RIGHT OUTER JOIN {$prefix}custom_fields_definition d 
  48                               ON v.field_id = d.id
  49                               WHERE v.article_id = '".Db::qstr($articleId)."'";
  50                        
  51              $result = $this->Execute( $query );
  52              
  53              $fields = Array();
  54                          
  55              // return empty array if no fields
  56              if( !$result )
  57                  return $fields;
  58              
  59              while( $row = $result->FetchRow()) {
  60                  $field = $this->mapRow( $row );
  61                  $fields[$field->getName()] = $field;
  62              }
  63              $result->Close();
  64  
  65              return $fields;
  66          }
  67  
  68          /**
  69           * adds a custom field value to the given article
  70           *
  71           * @param fieldId
  72           * @param fieldValue
  73           * @param articleId
  74           * @param blogId
  75           * @return True if successful or false otherwise
  76           */
  77          function addCustomFieldValue( $fieldId, $fieldValue, $articleId, $blogId )
  78          {
  79              // create a bogus object, we don't really need a full CustomFieldValue object
  80              // but it makes it easier for us if we'd like to use Model::add()
  81              $value = new CustomFieldValue( $fieldId, 
  82                                             $fieldValue,
  83                                             $articleId,
  84                                             $blogId );
  85              if( $result = $this->add( $value )) {
  86                  $this->_cache->removeData( $articleId, CACHE_CUSTOMFIELDVALUES_ARTICLE );
  87              }
  88              
  89              return( $result );
  90          }
  91          
  92          
  93          /**
  94           * removes a value of a custom field, given its id.
  95           *
  96           * @param id
  97           * @return True if deleted successfully or false otherwise.
  98           */
  99          function removeCustomFieldValue( $id )
 100          {
 101              $field = $this->getCustomFieldValue( $id );
 102              if( !$field )
 103                  return false;
 104                  
 105              if( $result = $this->delete( "id", $id )) {
 106                  $this->_cache->removeData( $field->getArticleId(), CACHE_CUSTOMFIELDVALUES_ARTICLE );
 107              }
 108              return( $result );
 109          }
 110          
 111          /**
 112           * Removes all the values associated to a certain custom field
 113           *
 114           * @param fieldId
 115           * @return True if successful or false otherwise.
 116           */
 117          function removeCustomFieldValues( $fieldId )
 118          {
 119              $result = $this->delete( "field_id", $fieldId );
 120  
 121              return( true );
 122          }
 123          
 124          /**
 125           * Removes all the values associated to an article
 126           *
 127           * @param articleId
 128           * @return True if deleted successfully or false otherwise.
 129           */
 130          function removeArticleCustomFields( $articleId )
 131          {
 132              if( $result = $this->delete( "article_id", $articleId )) {
 133                  $this->_cache->removeData( $articleId, CACHE_CUSTOMFIELDVALUES_ARTICLE );
 134                  $result = true;
 135              }
 136              
 137              return( $result );
 138          }
 139  
 140          /**
 141           * Returns the search string needed to find custom fields based on their values
 142           *
 143           * @param
 144           * @return
 145           */
 146  		function getSearchConditions( $searchTerms )
 147          {
 148              lt_include( PLOG_CLASS_PATH."class/dao/searchengine.class.php" );
 149              
 150              $query = SearchEngine::adaptSearchString($searchTerms);
 151  
 152              $query_array = explode(' ',$query);    
 153              
 154              $db =& Db::getDb();
 155              if( $db->isFullTextSupported()) {            
 156                  // fast path used when FULLTEXT searches are supported
 157                  $where_string = "(MATCH(c.normalized_value) AGAINST ('{$query}' IN BOOLEAN MODE))";                
 158              }
 159              else {
 160                  $where_string = "(";
 161                  $where_string .= "(v.normalized_value LIKE '%{$query_array[0]}%')";
 162                  for ( $i = 1; $i < count($query_array); $i = $i + 1) {
 163                      $where_string .= " AND ((v.normalized_value LIKE '%{$query_array[$i]}%'))";
 164                  }
 165                  $where_string .= " OR (v.normalized_value LIKE '%{$query}%')";
 166                  $where_string .= ")";
 167              }
 168  
 169              return( $where_string );
 170          }
 171          
 172          /**
 173           * @private
 174           */
 175          function mapRow( $row )
 176          {
 177              return CustomFieldValueFactory::getCustomFieldValueObject( $row );
 178          }
 179      }
 180  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics