public function __construct($fieldLabel, $fieldKey, $query, $db = null) { $this->_fieldKey = $fieldKey; $this->_fieldLabel = $fieldLabel; if ($db !== null) { $this->_db = $db; } else { if (\TotalFlex\TotalFlex::getDefaultDB() !== null) { $this->_db = \TotalFlex\TotalFlex::getDefaultDB(); } else { throw new DefaultDBNotSet("You have to set default db with TotalFlex::setDefaultDB() or give it as an argument in constructor method"); } } $statement = $this->_db->prepare($query); if (!$statement->execute()) { throw new Exception($statement->errorInfo()); } $this->_arrayResult = $statement->fetchAll(\PDO::FETCH_ASSOC); }
/** * 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(); }
// imac // $pdo = new PDO("mysql:dbname=test", "root", ""); /************************************************************ * Bootstraping TotalFlex * --------------------------------------------------------- * This code is needed every initialization of the * application. There is, in te future, ideas to make this * part of one simple SQLite database that will only need * one line to bootstrap it all. *************************************************************/ // Initializing Total Flex with callback url/method and the target database connection info // 'index.php?callback=1', 'POST', 'sqlite:business.db3' // 10*40* // $result = $pdo->query("SELECT * FROM business_entity"); TotalFlex::setDefaultDB($pdo); $TotalFlex = new TotalFlex(); // tambem pode-se passar o $pdo como parametro para o construtor do TF // $TotalFlex = new TotalFlex ( $pdo ); // DEFAULT TEMPLATE TO BE COMPATIBLE WITH BOOTSTRAP ################################################################# \TotalFlex\Field\Field::setDefaultEncloseStart("<div class=\"col-md-6 form-group\">\n"); \TotalFlex\Field\Field::setDefaultEncloseEnd("</div>\n"); \TotalFlex\Field\Field::setDefaultTemplate("\t<input class=\"form-control\" type=\"__type__\" name=\"__name__\" id=\"__id__\" value=\"__value__\"/><br>\n\n"); \TotalFlex\Field\Select::setDefaultTemplate("\t<select class=\"form-control\" name=\"__name__\" id=\"__id__\" >\n__options__\n</select>\n\n"); // ################################################################################## ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <!-- <link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet" /> -->
$conn->query("CREATE TABLE IF NOT EXISTS business_entity (id_be INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)"); $conn = null; /************************************************************ * Bootstraping TotalFlex * --------------------------------------------------------- * This code is needed every initialization of the * application. There is, in te future, ideas to make this * part of one simple SQLite database that will only need * one line to bootstrap it all. *************************************************************/ // Initializing Total Flex with callback url/method and the target database connection info // 'index.php?callback=1', 'POST', 'sqlite:business.db3' // 10*40* // $pdo = new FluentPDOPDO("mysql:dbname=fazerbrasil", "root", ""); $pdo = new PDO("mysql:dbname=fazerbrasil", "root", ""); $TotalFlex = new TotalFlex($pdo); // DEFAULT TEMPLATE ################################################################# \TotalFlex\View\Formatter\Html::$templateCollection['start'] = "<div class=\"col-md-6 form-group\">\n"; \TotalFlex\View\Formatter\Html::$templateCollection['end'] = "</div>\n"; \TotalFlex\View\Formatter\Html::$templateCollection['input']['text'] = "\t<input class=\"form-control\" type=\"__type__\" name=\"__name__\" id=\"__id__\" value=\"__value__\"/><br>\n\n"; // ################################################################################## ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet" /> <style> *,html,body{font-size: 1em;}
/** * call functino callback * @param [type] $post [description] * @return [type] [description] */ public function preFilter($context) { $filterAction = $this->_filterAction; if (gettype($filterAction) === "object") { return $filterAction($context, $this, TotalFlex::getDefaultDB()); } else { return true; } }