/** * Constructs the field * * @param string $column Field column name * @param string $label Field label * @throws \InvalidArgumentException */ public function __construct($label, $targetTable, $fixedField, $fixedFieldValue, \TotalFlex\DBSource $dbSource) { $this->_targetTable = $targetTable; $this->_fixedField = $fixedField; $this->_fixedFieldValue = $fixedFieldValue; $this->_source = $dbSource; $this->_instanceId = ++self::$instanceCount; $this->_elementId = str_replace("\\", "_", get_class($this)) . $this->_instanceId; $this->_sourceLinkField = $dbSource->getFieldKey(); $this->_sourceLabel = $dbSource->getFieldLabel(); if (empty(self::$defaultTemplate)) { self::$defaultTemplate = Select::getDefaultTemplate(); } // parent::__construct ( $column , $label ); if (empty($this->_encloseStart)) { $this->_encloseStart = static::$defaultEncloseStart; } if (empty($this->_encloseEnd)) { $this->_encloseEnd = static::$defaultEncloseEnd; } if (empty($this->_template)) { $this->_template = static::$defaultTemplate; } if (empty($this->_labelTemplate)) { $this->_labelTemplate = static::$defaultLabelTemplate; } $this->setLabel($label)->setType('text')->setPrimaryKey(false)->setRules([]); if (\TotalFlex\TotalFlex::getDefaultDB() === null) { throw new DefaultDBNotSet("You have to set default db with TotalFlex::setDefaultDB() or give it as an argument in constructor method"); } $this->db = \TotalFlex\TotalFlex::getDefaultDB(); $this->_options = $dbSource->getFieldAsKeyLabelAsValue(); }
/** * Constructs the field * * @param string $column Field column name * @param string $label Field label * @param mixed $dbSourceOrLabelField it can be an string with field name if you want to pass field label name and field value (key) name and query * but you can make it passing a DBSource instance to $dbSourceOrLabelField param and ignoring another paramether in sequence * @throws \InvalidArgumentException */ public function __construct($column, $label, $dbSourceOrLabelField, $valueField = "", $query = "", $db = null) { if (empty(self::$defaultTemplate)) { self::$defaultTemplate = Select::getDefaultTemplate(); } parent::__construct($column, $label); $dbSource = $dbSourceOrLabelField; if (!is_a($dbSource, 'DBSource')) { $dbSource = new \TotalFlex\DBSource($dbSourceOrLabelField, $valueField, $query, $db); } $this->_options = $dbSource->getLabelAsKeyFieldAsValue(); }