Exemplo n.º 1
0
 public function init()
 {
     $options = $this->_initialOption;
     if ($this->getAttrib('multiple')) {
         $options = array();
     }
     $table = new La_Db_Table($this->_tableName);
     $options += $table->fetchPairs($this->_keyColumn, $this->_valueColumn, $this->_where);
     $this->setMultiOptions($options);
 }
Exemplo n.º 2
0
Arquivo: Table.php Projeto: abdala/la
 protected function addAutoJoin(Zend_Db_Table_Select $select)
 {
     $tables = array();
     $columns = array();
     $references = $this->getDefaultAdapter()->getReferences(null, $this->_name);
     if ($references) {
         foreach ($references as $key => $reference) {
             $tableName = $reference['table'];
             $table = new La_Db_Table($tableName);
             $columnName = $table->getNameForOptionField();
             $comments = $this->getComments();
             $column = $reference['columns'];
             $columnAlias = $comments[$column];
             $tableAlias = $tableName . $key;
             $columns[$columnAlias] = $tableAlias . '.' . $columnName;
             $tables[$tableName] = $tableName;
             $joinTable = array($tableAlias => $tableName);
             $condition = sprintf('`%s`.`id` = `%s`.`%s`', $tableAlias, $this->_name, $column);
             $select->joinLeft($joinTable, $condition, array());
         }
         $select->setIntegrityCheck(false)->columns($columns);
     }
     return $select;
 }
Exemplo n.º 3
0
Arquivo: Form.php Projeto: abdala/la
 /**
  * Create elements array
  *
  * @return void
  */
 protected function _setupElements()
 {
     $info = $this->_table->info();
     $references = $this->_table->getDefaultAdapter()->getReferences(null, $this->_table->getName());
     $dynamicElements = $this->getFields();
     foreach ($this->_orderMetada($info["metadata"], $dynamicElements) as $key => $value) {
         $isDefaultTypes = true;
         if ($dynamicElements == '*' || in_array($key, (array) $dynamicElements)) {
             if ($key == "created" || $key == "updated" || $key == "deleted") {
                 continue;
             }
             $foreignTableName = $this->_getForeignTable($references, $key);
             $options = array('label' => $this->_table->getColumnComment($key), 'class' => 'form-control');
             if ($value['LENGTH'] > -1) {
                 $options['maxlength'] = $value['LENGTH'];
             }
             if (!$value['NULLABLE'] && !$value['PRIMARY']) {
                 $options['required'] = true;
             }
             switch ($value['DATA_TYPE']) {
                 case 'bpchar':
                 case 'varchar':
                 case 'char':
                     $this->_tableElements[$key] = array('text', $options);
                     break;
                 case 'text':
                     $options['rows'] = '8';
                     //$options['cols'] = '15';
                     //$options['class'] = 'input-xxlarge';
                     $this->_tableElements[$key] = array('textarea', $options);
                     break;
                 case 'int':
                 case 'int8':
                 case 'int4':
                 case 'int2':
                 case 'bigint':
                 case 'tinyint':
                 case 'smallint':
                 case 'bigint':
                 case 'integer':
                     $options['class'] .= ' digits';
                     $this->_tableElements[$key] = array('digits', $options);
                     break;
                 case 'numeric':
                 case 'decimal':
                     $options['class'] .= ' number';
                     $this->_tableElements[$key] = array('number', $options);
                     break;
                 case 'timestamp':
                 case 'date':
                 case 'datetime':
                     $this->_tableElements[$key] = array('date', $options);
                     break;
                 default:
                     $isDefaultTypes = false;
                     $this->_tableElements[$key] = array('text', $options);
                     break;
             }
             if ($value['PRIMARY']) {
                 $this->_tableElements[$key] = 'hidden';
                 continue;
             }
             if (strstr($value['COLUMN_NAME'], 'cnpj')) {
                 $options['class'] .= ' cnpj';
                 $options['filters'] = array('Digits');
                 $options['validators'] = array('Cnpj');
                 $options['maxlength'] = 18;
                 $this->_tableElements[$key] = array('Cnpj', $options);
                 continue;
             }
             if (strstr($value['COLUMN_NAME'], 'cpf')) {
                 $options['class'] .= ' cpf';
                 $options['filters'] = array('Digits');
                 $options['validators'] = array('Cpf');
                 $options['maxlength'] = 14;
                 $this->_tableElements[$key] = array('Cpf', $options);
                 continue;
             }
             if (strstr($value['COLUMN_NAME'], 'phone')) {
                 $options['class'] .= ' telefone';
                 $options['filters'] = array('Digits');
                 $options['maxlength'] = 16;
                 $this->_tableElements[$key] = array('Telefone', $options);
                 continue;
             }
             if (strstr($value['COLUMN_NAME'], 'cep')) {
                 $options['class'] .= ' cep';
                 $options['filters'] = array('Digits');
                 $options['validators'] = array('Cep');
                 $options['maxlength'] = 9;
                 $this->_tableElements[$key] = array('Cep', $options);
                 continue;
             }
             if ($value['COLUMN_NAME'] == 'password') {
                 $options['class'] .= ' password';
                 $options['validators'] = array('PasswordConfirmation');
                 $this->_tableElements[$key] = array('Password', $options);
                 unset($options['validators']);
                 $options['label'] = 'Confirmação de senha';
                 $this->_tableElements['password_confirmacao'] = array('Password', $options);
                 continue;
             }
             if ($foreignTableName) {
                 $foreignTable = new La_Db_Table($foreignTableName);
                 $valueColumn = $foreignTable->getNameForOptionField();
                 $options['tableName'] = $foreignTableName;
                 $options['keyColumn'] = 'id';
                 $options['valueColumn'] = $valueColumn;
                 $this->_tableElements[$key] = array('TableSelect', $options);
                 continue;
             }
             if (!$isDefaultTypes) {
                 if ($this->_table->isDomain($key, $value['DATA_TYPE'])) {
                     $domainValues = $this->_table->getDomainValues($key);
                     if ($domainValues) {
                         $options['multioptions'] = array('' => '[selecione]') + $domainValues;
                         $options['validators'] = array(array('InArray', false, array('haystack' => $domainValues)));
                         $this->_tableElements[$key] = array('Select', $options);
                     }
                 }
             }
         }
     }
 }