Esempio n. 1
0
 function setValue($path)
 {
     if (!file_exists($this->imgDir . $path)) {
         $path = $this->default;
     }
     parent::setValue($path);
 }
Esempio n. 2
0
 public function add(Field $field)
 {
     $attr = $field->name();
     $field->setValue($this->entity->{$attr}());
     $this->fields[] = $field;
     return $this;
 }
Esempio n. 3
0
 public function add(Field $field)
 {
     $attr = $field->name();
     // On récupère le nom du champ.
     $field->setValue($this->entity->{$attr}());
     // On assigne la valeur correspondante au champ.
     $this->fields[] = $field;
     // On ajoute le champ passé en argument à la liste des champs.
     return $this;
 }
Esempio n. 4
0
 /**
  * Méthode permettant d'ajouter un champ à la liste
  * 
  * @param \OCFram\Field $field
  * @return \OCFram\Form
  */
 public function add(Field $field)
 {
     $attr = $field->name();
     // Récupérer le nom du champ
     $field->setValue($this->entity->{$attr}());
     // Assigner la valeur correspondante au champ
     $this->fields[] = $field;
     // Ajouter le champ passé en argument à la liste des champs
     return $this;
 }
Esempio n. 5
0
 public function testSettersAndGettersDoWhatTheyShould()
 {
     $field = new Field('type', 'element', 'label', 'description');
     $field->setOptions(['options' => 'options']);
     $field->setValidationRules('rules');
     $field->setValue('foo');
     $expectations = ['getOptions' => ['options' => 'options'], 'getValidationRules' => 'rules', 'getValue' => 'foo'];
     foreach ($expectations as $method => $value) {
         static::assertEquals($field->{$method}(), $value);
     }
 }
Esempio n. 6
0
 public function setValue($value)
 {
     if ($value === false) {
         return parent::setValue('0');
     } else {
         if ($value === true) {
             return parent::setValue('1');
         } else {
             return parent::setValue($value);
         }
     }
 }
Esempio n. 7
0
 public function setValue($value)
 {
     parent::setValue($value);
     if ($value == "") {
         return;
     }
     $mainValue = $this->subModel->get(array("fields" => array($this->mainModel->getKeyField()), "conditions" => "{$this->subModel->getKeyField()}={$value}"), Model::MODE_ARRAY, false, false);
     $this->mainSelectionList->setValue($mainValue[0][0]);
     $subValues = $this->subModel->get(array("fields" => array($this->subModel->getKeyField(), $this->subModelPathInfo["field"]), "conditions" => "{$this->subModel->getKeyField()}={$value}"), Model::MODE_ARRAY, false, false);
     foreach ($subValues as $subValue) {
         $this->subSelectionList->addOption($subValue[1], $subValue[0]);
     }
     $this->subSelectionList->setValue($value);
 }
Esempio n. 8
0
 public function setValue($value, $default = false)
 {
     if ($this->multiple) {
         if (is_array($value)) {
             foreach ($value as &$v) {
                 $v = (string) $v;
             }
             $this->value = $value;
         } else {
             $this->value = null;
         }
     } else {
         parent::setValue($value, $default);
     }
 }
Esempio n. 9
0
 public function setWithDisplayValue($value)
 {
     $parts = explode("//", $value);
     $mainId = $this->mainModel->getKeyField();
     $mainField = Model::resolvePath($this->mainModelField);
     $mainField = $mainField['field'];
     $subField = Model::resolvePath($this->subModelField);
     $subField = $subField['field'];
     $possibleMainItem = reset($this->mainModel->getWithField2("trim({$mainField})", trim($parts[0])));
     if ($possibleMainItem === false) {
         parent::setValue(null);
         return;
     }
     $possibleSubItem = reset($this->subModel->get(array('conditions' => "{$mainId} = {$possibleMainItem[$mainId]} and trim({$subField}) = '" . trim($this->mainModel->escape($parts[1])) . "'"), Model::MODE_ASSOC, false, false));
     parent::setValue($possibleSubItem[$this->getName()]);
 }
Esempio n. 10
0
 public function setValue($value, $default = false)
 {
     $set = false;
     if (!is_string($value) && !is_float($value) && !is_int($value)) {
         return;
     }
     foreach ($this->radios as $radio) {
         if ($radio->getValue() == $value) {
             $radio->setChecked(true);
             $set = true;
         } else {
             $radio->setChecked(false);
         }
     }
     parent::setValue($set ? $value : null);
 }
Esempio n. 11
0
 public static function parse($conf, $inputs)
 {
     $confPath = \Path::instance()->currentProject('etc.conf.@' . $conf . '.conf.xml');
     if (!file_exists($confPath)) {
         return false;
     }
     $dom = new \DOMDocument("1.0", "utf-8");
     $dom->load($confPath);
     $xpath = new \DOMXPath($dom);
     $xpath->registerNamespace('bong', 'http://lab.zigmoyd.net/xmlns/bong');
     $fieldNodes = $xpath->query("//bong:form/bong:field");
     $form = new Form();
     foreach ($fieldNodes as $fieldNode) {
         $field = null;
         $name = self::__attrValue($fieldNode, "name");
         $default = self::__attrValue($fieldNode, "default");
         if ($name) {
             $field = new Field($name);
             $required = self::__attrValue($fieldNode, "required", 'false');
             if ($required == 'true') {
                 $field->setRequiredFlag(true);
             }
             if (isset($inputs[$name])) {
                 $field->setValue(strlen($inputs[$name]) > 0 ? $inputs[$name] : ($default ? $default : ''));
             }
             $ruleNodes = $xpath->query("bong:criteria", $fieldNode);
             foreach ($ruleNodes as $ruleNode) {
                 $ruleName = self::__attrValue($ruleNode, 'name');
                 if ($ruleName) {
                     $arg = self::__attrValue($ruleNode, 'value');
                     $error = self::__attrValue($ruleNode, 'msg');
                     $rule = new RuleSet($ruleName, $error, $arg);
                     $field->addRuleSet($rule);
                 }
             }
         }
         $form->addField($field);
     }
     return $form;
 }
Esempio n. 12
0
 /**
  * This function gets the description of a table from the RDBMS and then constructs
  * an array of Fields and returns them as required
  */
 public function setupFields()
 {
     /*if(!$fields = Session::getRegistered($this->table_name.'_field_array'))
       {*/
     try {
         $fields = FieldDefinitions::current()->definitionsForTable($this->table_name);
     } catch (Exception $exc) {
         if (!file_exists($this->fieldCachePath())) {
             $query = SimpleQuery::create('describe ' . $this->table_name);
             $fields = array();
             while ($row = $query->next()) {
                 $type_array = preg_split('/\\(/', $row['Type']);
                 if ($row['Extra'] == 'auto_increment') {
                     $type = 'Field::T_AUTO';
                 } else {
                     if ($row['Key'] == 'PRI') {
                         $type = 'Field::T_PRIMARY_KEY_' . strtoupper($type_array[0]) . '';
                     } else {
                         $type = 'Field::T_' . strtoupper($type_array[0]) . '';
                     }
                 }
                 eval('$field_type = ' . $type . ';');
                 $field = new Field($this->table_name, $row['Field'], $field_type);
                 $fields[$row['Field']] = $field;
                 if ($row['Default'] || !$row['Default'] && is_numeric($row['Default'])) {
                     $field->setValue($row['Default']);
                 }
             }
             @unlink($this->fieldCachePath());
             file_put_contents($this->fieldCachePath(), serialize($fields));
             @chmod($this->fieldCachePath(), 0664);
         } else {
             if (file_exists($this->fieldCachePath())) {
                 $fields = unserialize(file_get_contents($this->fieldCachePath()));
             }
         }
         //Session::register($this->table_name.'_field_array',$fields);
         FieldDefinitions::current()->addDefinitionsForTable($this->table_name, $fields);
     }
     return $fields;
 }
 public function set($instance, Field $f, $value)
 {
     $f->setValue($instance, $value);
 }
Esempio n. 14
0
 public function setValue($value)
 {
     if ($value == 't') {
         $value = '1';
     }
     parent::setValue($value);
     return $this;
 }
Esempio n. 15
0
 /**
  * Must be a ISO 8601 date string or a \DateTime object
  * @param string|\DateTime $value
  * @return $this
  */
 public function setValue($value)
 {
     if ($value instanceof \DateTime) {
         $value = $value->format('c');
     }
     return parent::setValue($value);
 }
Esempio n. 16
0
    function setValue($v) {
	parent::setValue((boolean)$v);
    }
Esempio n. 17
0
 public function resolve($value)
 {
     $option = $this->getOptions();
     $key = array_keys($option);
     for ($i = 0; $i < count($option); $i++) {
         //print $option[$key[$i]];
         if (strtoupper($option[$key[$i]]) == strtoupper($value)) {
             Field::setValue($key[$i]);
             return;
         }
     }
     //Check the list of values
     for ($i = 0; $i < count($option); $i++) {
         if (strtoupper($key[$i]) == strtoupper($value)) {
             Field::setValue($key[$i]);
             return;
         }
     }
     //array_shift($this->options);
     $error = "Could not resolve value <b>{$value}</b> for the <b>" . $this->getLabel() . "</b> field.";
     if (count($option) > 1) {
         $error .= "Possible values can include";
     } else {
         $error .= "There are no possible values for this field";
     }
     $error .= "<ul>";
     //print_r($options);
     foreach ($option as $opt) {
         if ($opt != "") {
             $error .= "<li>{$opt}</li>";
         }
     }
     $error .= "</ul>";
     return $error;
 }
Esempio n. 18
0
 public function testSetValue()
 {
     $field = new Field();
     $this->assertInstanceOf(Field::class, $field->setValue('Test'));
 }