public static function make() { $itemFactory = new itemFactory(); $collectionFactory = new ItemCollectionFactory(); $fields = new Field(); return $fields->setItemFactory($itemFactory)->setFactory($collectionFactory)->setFormatter(new FieldFormatter()); }
public function add(Field $field) { $attr = $field->name(); $field->setValue($this->entity->{$attr}()); $this->fields[] = $field; return $this; }
/** * Конструктор, нужен для реализации паттерна Observer * * @param \REXFramework\forms\Field $field * @param mixed $criterion Критерий для валидатора, например, регулярное выражение * @param string $message Сообщение об ошибке */ public function __construct(Field $field, $criterion = null, $message = '') { $this->field = $field; $this->criterion = $criterion; $this->message = $message; $field->attach($this); }
/** * @return mixed */ protected function getKeyKey() { $n = get_called_class(); if (!isset(self::$k_cache[$n])) { $key = null; $r = $this->getReflection(); //Parse the annotations in a class $reader = new \Phalcon\Annotations\Reader(); $parsing = $reader->parse($r->getName()); //Create the reflection $annotations = new \Phalcon\Annotations\Reflection($parsing); if ($annotations->getClassAnnotations()->has('key')) { $key = $annotations->getClassAnnotations()->get('key'); } else { foreach ($r->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { if (!$property->isPublic() || $property->isStatic()) { continue; } $f = new Field($r, $property); if ($f->isKey()) { $key = $property->getName(); break; } } } self::$k_cache[$n] = $key; } return self::$k_cache[$n]; }
public function removeField(Field $field) { if (isset($this->fields[$field->getName()])) { unset($this->fields[$field->getName()]); } return $this; }
/** * @param Field $field * @throws DuplicateFieldException */ public function addField(Field $field) { if (isset($this->fields[$field->getName()])) { throw new DuplicateFieldException('Field `' . $field->getName() . '` already exists'); } $this->fields[$field->getName()] = $field; }
/** * @param Field $field * * @return array */ public function resolve(Field $field) { $defaults = ['required' => false, 'label' => $field->getLabel()]; $definition = $this->registry->findDefinitionFor($field->getDocument()); $attributes = $definition->getAttributes($field); return array_merge($defaults, $this->trim($attributes)); }
public function process($input) { $id = 0; $minesAll = array(); while(count($input)>0) { $line = array_shift($input); if($this->isNewField($line)) { $dim = $this->getFieldDimensions($line); $m = $dim[0]; $n = $dim[1]; if(!$this->IsTheEnd($m, $n)) { if(!$this->isValidDim($m, $n)){ throw new Exception ("Error: Invalid field dimensions! $m, $n"); } ++$id; $lineNum = 0; $field = new Field($id, $m, $n); $field->setDebug($this->debug); $this->fields[$id] = $field; } } else { if( count($this->fields)<=0 ){ throw new Exception ("Error something wrong\n"); } $field = $this->getField($id); $id = $field->getFieldId(); /* line data process */ foreach(str_split($line) as $x=>$cellvalue) { $field->addCell($x, $lineNum); /* detecting mines */ if($this->isMinedCell($cellvalue)){ $minesAll[$id][] = array($x, $lineNum); } } $this->fields[$id] = $field; $lineNum++; } } if(count($minesAll)>0) { foreach($minesAll as $id=>$mines) { $field = $this->getField($id); $field = $this->MineField($field, $mines); } } return $this->getOutput(); }
function alterField(\Field $field, $add = false) { $q = $this->db->dsql()->expr('alter table [al_table] add [field_name] [type_expr]'); $q->setCustom('al_table', $this->table); $q->setCustom('field_name', $x = $field->actual_field ?: $field->short_name); $q->setCustom('type_expr', $this->db->dsql()->expr($this->resolveFieldType($field->type()))); $q->execute(); }
public function testCanOverrideInvalidRelation() { $args = array('type' => 'taxonomy', 'taxonomy' => 'category', 'relation' => 'IN'); $f = new Field($args); $defaults = $f->getDefaults(); $default_relation = $defaults['relation']; $this->assertTrue($f->getRelation() == $default_relation); }
/** * @param Field $field * @return void */ protected function DoAddField($field) { $sourceTable = $field->GetSourceTable(); if (!isset($sourceTable) || $sourceTable == '') { $sourceTable = $this->tableName; } $this->GetSelectCommand()->AddField($sourceTable, $field->GetName(), $field->GetEngFieldType(), $field->GetAlias()); }
/** * Add field * * @param Field $field * @throws \LogicException */ public function addField(Field $field) { $name = $field->getName(); if (isset($this->fields[$name])) { throw new \LogicException(sprintf('Field "%s" already exists', $name)); } $this->fields[$name] = $field; }
/** * Create CRON object from a crontab string * * @param $string */ public function fromString($string) { list($minute, $hour, $dayOfMonth, $month, $dayOfWeek) = preg_split('/\\s+/', $string); $this->minute->fromCronValue($minute); $this->hour->fromCronValue($hour); $this->dayOfMonth->fromCronValue($dayOfMonth); $this->month->fromCronValue($month); $this->dayOfWeek->fromCronValue($dayOfWeek); }
/** * 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; }
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; }
public function update() { $f = new Field(); $f->name = $this->getFieldName(); $f->type = $this->getFieldType(); $f->save(); $this->fieldSetup($f); $f->save(); return $f; }
/** * Validates the given data against this constraint. If the constraint was * already triggered before, then it will return the last result. * * @param mixed $data The data * * @return boolean */ public function validate(Field $field, $data) { if (true === $this->checked) { return; } $this->checked = true; if (true === $this->check($data)) { return; } $field->addError(new Error($field->getInternalName(), $this->getMessage())); }
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); } }
private function _parseFields($results) { $response = array(); foreach ($results as $result) { $field = new Field(); $field->setName($result["Field"]); $field->setType($result["Type"]); $field->setPk($result["Key"] == 'PRI'); $response[] = $field; } return $response; }
private function _parseFields($results, $pk) { $response = array(); foreach ($results as $result) { $field = new Field(); $field->setName($result["field"]); $field->setType($result["type"]); $field->setPk($result["field"] == $pk["col"]); $response[] = $field; } return $response; }
/** * @dataProvider outputProvider */ public function testPrintField($id, $m, $n, $mines, $r, $msg) { $field = new Field($id,$m,$n); $field->fillClean(); foreach($mines as $mine) { $x = $mine[0]; $y = $mine[1]; $field->mineCell($x,$y); } $this->assertEquals($r, $field->printField(),$msg); }
/** * Render the ajax request output directly and halt execution * * @param Page $page * @param Field $field * */ protected function renderAjax(Page $page, Field $field) { $inputfield = $field->getInputfield($page); if (!$inputfield) { return; } echo $inputfield->render(); if ($this->notes) { echo "<p class='notes'>" . $this->wire('sanitizer')->entities($this->notes) . "</p>"; $this->notes = ''; } exit; }
/** * Check that the file matches the validator as specified by the field * * @param Field $field * @param string $destination * @return boolean */ public function isValid(Field $field, $destination = NULL) { $this->valid = true; // Check if file name length will not exceed maximum allowed by Upload field's database column. // Upload field does not check that, so we have to do that here. if (!empty($destination)) { $this->valid = strlen($destination) < 255 ? true : false; if (!$this->valid) { $this->errors[] = __("Length of file name chosen in '%s' exceeds maximum allowed for that field.", array($field->get('label'))); } } return $this->valid; }
/** * Generate random table fields to test **/ private function getTableFields() { require_once APPPATH . "libraries/scaffolder/drivers/field.php"; $id = new Field(); $id->setName("id"); $id->setPk(true); $nome = new Field(); $nome->setName("nome"); $alias = new Field(); $alias->setName("alias"); $estado = new Field(); $estado->setName("estado_id"); return array($id, $nome, $alias, $estado); }
public function __construct($name = 'Email', array $config = []) { parent::__construct($name, $config); $this->validators[] = function ($value) { return filter_var($value, FILTER_VALIDATE_EMAIL) ? true : "Invalid email address: {$value}"; }; }
/** * TextField::TextField() * * Constructor: Create a new textfield object * * @param object &$oForm: The form where this field is located on * @param string $sName: The name of the field * @return TextField * @author Teye Heimans * @access public */ function TextField(&$oForm, $sName) { // call the constructor of the Field class parent::Field($oForm, $sName); $this->setSize(20); $this->setMaxlength(0); }
/** * @inheritdoc */ public function rules() { $rules = parent::rules(); $rules[] = [$this->attr, 'date', 'format' => $this->dateFormat]; $rules[] = [$this->attr, 'filter', 'filter' => 'trim']; return $rules; }
public function init() { parent::init(); if ($this->action == 'edit') { $this->addJS(); } }
/** * @brief setteur de tous le parametres de champs * @param fieldname Nom du champ * @papam params Tous le parametres comme decrits dans fields.php * @return this */ public function setAllFieldsParams($fieldname, $params) { parent::setAllFieldsParams($fieldname, $params); $this->setJoinToModule($params['join']['table']); $this->setVisibleField($params['join']['field']); return $this; }
public function getData() { $nameLenght = strlen($this->name); if ($this->isFormSent()) { $this->data = array(); foreach ($_POST as $field => $value) { if (is_array($value)) { foreach ($this->columnNames as $i => $columnName) { if ($field == $columnName) { $field = substr($field, $nameLenght - strlen($field) + 1); foreach ($value as $j => $data) { $this->data[$j][$field] = $data; } } } } } foreach ($this->data as $i => $data) { $pass = false; foreach ($data as $field => $value) { if ($value != "") { $pass = true; break; } } if (!$pass) { unset($this->data[$i]); } } return array($this->getName() => $this->data); } else { return parent::getData(); } }