[ 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/ -> customfieldvaluefactory.class.php (source)

   1  <?php
   2  
   3      
   4      lt_include( PLOG_CLASS_PATH."class/dao/customfields/customfieldvalue.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/dao/customfields/customfielddatevalue.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/dao/customfields/customfieldcheckboxvalue.class.php" );    
   7      lt_include( PLOG_CLASS_PATH."class/dao/customfields/customfieldlistvalue.class.php" );    
   8          
   9      /**
  10       * Generates the right CustomFieldValue (or subclass of it)
  11       *
  12       * \ingroup DAO
  13       */
  14      class CustomFieldValueFactory 
  15      {
  16      
  17         /**
  18          * returns the right class depending on the field type
  19          * @private
  20          * @static
  21          * @param fieldType The field type
  22          */
  23  	   function _findConstructorClass( $fieldType )
  24         {
  25              /**
  26                * this array maps field types to class constructors, see _fillCustomFieldValueInformation
  27                */           
  28              $__fieldTypesConstructors = Array( CUSTOM_FIELD_TEXTBOX => "CustomFieldValue",
  29                                                 CUSTOM_FIELD_TEXTAREA => "CustomFieldValue",
  30                                                 CUSTOM_FIELD_CHECKBOX => "CustomFieldCheckboxValue",
  31                                                 CUSTOM_FIELD_DATE => "CustomFieldDateValue",
  32                                                 CUSTOM_FIELD_LIST => "CustomFieldListValue",
  33                                                 CUSTOM_FIELD_MULTILIST => "CustomFieldValue",
  34                                                 "default" => "CustomFieldValue" );
  35             
  36             // if the key is incorrect, use the default one
  37             if( array_key_exists( $fieldType,  $__fieldTypesConstructors ))
  38                 $fieldType == "default";
  39             
  40             // return whatever it is...
  41             return $__fieldTypesConstructors[$fieldType];
  42         }
  43      
  44         /**
  45          * creates and returns the right CustomFieldValuexxx object, or a 
  46          * CustomFieldValue object if there is no specific object defined for that type
  47          *
  48          * @param row
  49          * @return A CustomFieldValue object, or a subclass
  50          */
  51  	   function getCustomFieldValueObject( $row )
  52         {
  53              // depending on the type, we should return a different object... Just to
  54              // make things easier for clients of the class! But we can use the array with the
  55              // mappins to easily figure out the right$ class for the job
  56              $constructor = CustomFieldValueFactory::_findConstructorClass( (int)$row["field_type"] );
  57  
  58              $value = new $constructor( $row["field_id"],
  59                                         $row["field_value"],
  60                                         $row["article_id"],
  61                                            $row["blog_id"],
  62                                          $row["id"] );
  63  
  64              return $value;       
  65         }
  66         
  67         /**
  68          * returns the right CustomFieldValuexxx object but this method can be used
  69          * in those occasions when we know the fieldId but we do not know its type so what we need to do
  70          * is first load the field definition and then work on creating the right object type
  71          *
  72          * @param fieldId
  73          * @param row An array
  74          * @see getCustomFieldValueObject
  75          */
  76  	   function getCustomFieldValueByFieldId( $fieldId, $row )
  77         {
  78             // load the field definition first
  79              lt_include( PLOG_CLASS_PATH."class/dao/customfields/customfields.class.php" );
  80              $customFields = new CustomFields();
  81              $customField = $customFields->getCustomField( $fieldId );
  82              if( !$customField )
  83                  return false;
  84                  
  85              // if everything went fine, then continue   
  86              $row["field_id"] = $fieldId;
  87              $row["field_type"] = $customField->getType();
  88              $row["field_description"] = $customField->getDescription();
  89              $row["field_name"] = $customField->getName();
  90              
  91              $fieldValueObject = CustomFieldValueFactory::getCustomFieldValueObject( $row );
  92              
  93              return( $fieldValueObject );
  94         }
  95      }
  96  ?>


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