Example #1
0
 /**
  * Ajoute un element de formulaire pour une propriété dynamique
  *
  * @param  $type string: type du chps de formulaire: text, select, ...
  * @param  $name string: nom du chps de formulaire
  * @param  $caption string: intitule du chps de formulaire: text, select...
  * @param  $attributes array: attributs optionnels,
  *            cf documentation de QuickForm
  * @param  $searchOptions array: Options relatives a la recherche:
  *             'PropertyType' => 'IntValue', // cf PropertyValue
  *           'Operator' => 'Like'
  *             'Value' => 'toto'
  *             'Disable' => true (false par defaut): si on ne veut pas que le
  *                         chps de form genere automatiquemt un
  *                         FilterComponent, pour le gerer differemment
  * @access public
  * @return void
  */
 public function addDynamicElement($type, $name, $caption = '', $attributes = array(), $searchOptions = array())
 {
     require_once MODELS_DIR . '/Product.php';
     // on appelle addElement sauf pour la partie recherche
     $this->addElement($type, $name, $caption, $attributes, false);
     // on gère la recherche ici
     if (!(isset($searchOptions['Disable']) && true === $searchOptions['Disable']) && strpos($name, 'DateOrder') === false) {
         // Si propertyType non precise, et si cette Property n'est pas
         // stockee ds la table Product
         if (!isset($searchOptions['PropertyType']) && !in_array($name, array_keys(Product::getProperties()))) {
             $PropertyMapper = Mapper::singleton('Property');
             $Property = $PropertyMapper->load(array('Name' => $name));
             $searchOptions['PropertyType'] = Tools::isEmptyObject($Property) ? 'StringProperty' : getPropertyTypeColumn($Property->getType());
         }
         if (!isset($searchOptions['Operator'])) {
             $searchOptions['Operator'] = $type == 'text' ? 'Like' : 'Equals';
         }
         if (!isset($searchOptions['Value'])) {
             $searchOptions['Value'] = "";
         }
         if (!isset($searchOptions['Disable'])) {
             $searchOptions['Disable'] = false;
         }
         $paramsArray = array('Name' => $name, 'Operator' => $searchOptions['Operator'], 'Value' => $searchOptions['Value'], 'Disable' => $searchOptions['Disable']);
         if (isset($searchOptions['PropertyType'])) {
             $paramsArray['PropertyType'] = $searchOptions['PropertyType'];
         } else {
             $paramsArray['Path'] = $name;
         }
         $this->_elementsForSearch[] = $paramsArray;
     }
     // todo
 }