/** * Recupera uma sequencia para um campo * * @author Hugo Ferreira da Silva * @link http://www.hufersil.com.br/ * @param array $field * @return string */ public function getSequence($field) { $st = null; $con_st = $this->obj->_getConnection()->getOption('sequence_type'); if (empty($field['sequence_type'])) { $st = $con_st; } else { $st = $field['sequence_type']; } $dialect = $this->obj->_getConfiguration()->getProperty('dialect'); switch ($st) { case self::SEQUENCE: $class = $dialect . "_Sequence"; Lumine::load('Sequence_' . $class); $this->seq_obj = new $class($obj, $field); break; case self::COUNT_TABLE: $class = $dialect . "_Count"; Lumine::load('Sequence_' . $class); $this->seq_obj = new $class($obj, $field); break; case self::NATURAL: default: $class = $dialect . "_Natural"; Lumine::load('Sequence_' . $class); $this->seq_obj = new $class($obj, $field); } $this->seq_obj->createSequence(); return $this->seq_obj; }
/** * Recupera o dialeto para o objeto * * @author Hugo Ferreira da Silva * @link http://www.hufersil.com.br/ * @param Lumine_Base $obj * @return ILumine_Dialect */ public static function get(Lumine_Base $obj) { $dialect = $obj->_getConfiguration()->getProperty('dialect'); $id = $obj->_getObjectPart('_objectID'); if (!array_key_exists($dialect, self::$createdItems)) { Lumine::load('Lumine_Dialect_' . $dialect); $ref = new ReflectionClass('Lumine_Dialect_' . $dialect); self::$createdItems[$dialect] = $ref->newInstance(); } self::$createdItems[$dialect]->setConnection($obj->_getConnection()); self::$createdItems[$dialect]->setObjectId($id); self::$createdItems[$dialect]->setTablename($obj->tablename()); return self::$createdItems[$dialect]; }
private function validateByClass($val, $fieldname, $classname, $method) { if (empty($classname)) { Lumine_Log::warning('Classe para validacao nao informada no XML. Use "classname" para informar o nome da classe'); return false; } $ds = DIRECTORY_SEPARATOR; $cfg = $this->obj->_getConfiguration(); $classpath = $cfg->getProperty('class_path'); $classespath = $classpath . $ds . str_replace('.', '/', $cfg->getProperty('package')) . $ds . 'validators' . $ds; $classfile = str_replace('.', '/', $classname) . '.php'; $classdef = array_pop(explode('.', $classname)); $php_validator_path = $cfg->getOption('php_validator_path'); $possibilidades = array(); if (!empty($php_validator_path)) { $possibilidades[] = $php_validator_path . $ds . $classfile; } $possibilidades[] = LUMINE_INCLUDE_PATH . $ds . 'lib' . $ds . 'Validator' . $ds . 'Custom' . $ds . $classfile; $possibilidades[] = $classpath . $ds . $classfile; $possibilidades[] = $classespath . $classfile; $use = ''; foreach ($possibilidades as $file) { if (file_exists($file)) { $use = $file; } } if (empty($use)) { Lumine_Log::error('Classe para validacao "' . $classname . '" nao encontrada'); return false; } require_once $use; if (!class_exists($classdef)) { Lumine_Log::error('Definicao para a classe de validacao "' . $classdef . '" nao encontrada'); return false; } $tester = new $classdef(); if (method_exists($tester, $method) && $method != '') { return $tester->{$method}($val); } else { if (method_exists($tester, 'execute')) { return $tester->execute($val); } else { Lumine_Log::error('Metodo "' . $method . '" nao encontrado na classe "' . $classdef . '" e a classe nao possui o metodo "execute"'); return false; } } }
/** * * @see Lumine_Form_IForm::getInputFor() */ public function getInputFor($nome) { $def = $this->obj->metadata()->getField($nome); if (empty($def['options']['foreign'])) { switch ($def['type']) { case 'int': case 'float': case 'decimal': case 'integer': if (!empty($def['options']['autoincrement'])) { $field = $this->autoincrement_string; $field .= '<input type="hidden" name="' . $def['name'] . '" value="' . @$_POST[$def['name']] . '" />'; return $field; } else { $field = '<input type="text" name="' . $def['name'] . '" value="' . @$_POST[$def['name']] . '" />'; return $field; } break; case 'text': case 'mediumtext': case 'longtext': $field = '<textarea name="' . $def['name'] . '" cols="30" rows="4">' . @$_POST[$def['name']] . '</textarea>'; return $field; break; case 'boolean': $field = '<input type="radio" name="' . $def['name'] . '" value="1"'; if (!empty($_POST[$def['name']])) { $field .= ' checked="checked"'; } $field .= ' /> Sim '; $field .= '<input type="radio" name="' . $def['name'] . '" value="0"'; if (isset($_POST[$def['name']]) && $_POST[$def['name']] == '0') { $field .= ' checked="checked"'; } $field .= ' /> N�o '; return $field; break; case 'date': case 'datetime': $field = '<input id="' . $def['name'] . '" type="text" name="' . $def['name'] . '" value="' . @$_POST[$def['name']] . '"'; $field .= ' size="10"'; $field .= ' /> '; $field .= $this->getCalendarFor($nome); return $field; break; case 'varchar': case 'char': default: $field = '<input type="text" name="' . $def['name'] . '" value="' . @$_POST[$def['name']] . '"'; if (!empty($def['length'])) { $length = $def['length']; if ($length > 50) { $length = 50; } $field .= ' size="' . $length . '" maxlength="' . $def['length'] . '"'; } $field .= ' />'; return $field; break; } } else { $this->obj->_getConfiguration()->import($def['options']['class']); $cls = new $def['options']['class'](); $cls->alias('cls'); $pklist = $cls->metadata()->getPrimaryKeys(); $first = array_shift($pklist); $label = $first['name']; if (!empty($def['options']['displayField'])) { $label = $def['options']['displayField']; } $cls->order('cls.' . $label . ' ASC'); $cls->find(); $combo = '<select name="' . $def['name'] . '" id="' . $def['name'] . '">'; $combo .= '<option value=""></option>'; while ($cls->fetch()) { $combo .= '<option value="' . $cls->fieldValue($first['name']) . '"'; if (@$_POST[$def['name']] == $cls->fieldValue($first['name'])) { $combo .= ' selected="selected"'; } $combo .= '>' . $cls->{$label}; $combo .= '</option>' . PHP_EOL; } $combo .= '</select>'; return $combo; } }
/** * Faz o parse do joins * * @author Hugo Ferreira da Silva * @link http://www.hufersil.com.br/ * @param Lumine_Base $obj * @param array $list * @return string */ public static function parseJoinValues(Lumine_Base $obj, $list) { $joinStr = implode("\r\n", $obj->_getObjectPart('_join')); preg_match_all('@(\\{(\\w+)\\.(\\w+)\\})@', $joinStr, $reg); $total = count($reg[0]); $schema = $obj->_getConfiguration()->getOption('schema_name'); if (!empty($schema)) { $schema .= '.'; } for ($i = 0; $i < $total; $i++) { if (!empty($reg[2][$i]) && !empty($reg[3][$i])) { // alterado em 28/08/2007 foreach ($list as $ent) { if ($ent->metadata()->getClassname() == $reg[2][$i]) { // $ent = $list[ $reg[2][$i] ]; $field = $ent->metadata()->getField($reg[3][$i]); $name = $ent->metadata()->getTablename(); $a = $ent->alias(); if (!empty($a)) { $name = $a; } $joinStr = str_replace($reg[0][$i], $name . '.' . $field['column'], $joinStr); } } /* if( !empty( $list[ $reg[2][$i] ])) { $ent = $list[ $reg[2][$i] ]; $field = $ent->metadata()->getField( $reg[3][$i] ); $name = $ent->metadata()->getTablename(); $a = $ent->alias(); if( !empty($a) ) { $name = $a; } $joinStr = str_replace($reg[0][$i], $name . '.' .$field['column'], $joinStr); } */ } } preg_match_all('@JOIN (\\{(\\w+)\\})@i', $joinStr, $reg); $total = count($reg[0]); for ($i = 0; $i < $total; $i++) { if (!empty($reg[2][$i])) { reset($list); foreach ($list as $ent) { if ($ent->metadata()->getClassname() == $reg[2][$i]) { break; } } // $ent = $list[ $reg[2][$i] ]; $joinStr = str_replace($reg[0][$i], 'JOIN ' . $schema . $ent->metadata()->getTablename() . ' ' . $ent->alias(), $joinStr); } } return "\r\n" . $joinStr; }
/** * Realiza os joins informados em uma model * * Quando chamar o metodo find, o usuario podera informar que uma * classe une com a outra, em varios niveis. * * Este metodo auxilia para poder fazer as unioes de forma recursiva, * para nao ter limite de unioes de classe. * * @author Hugo Ferreira da silva * @link http://www.hufersil.com.br * @param Lumine_Base $base Arquivo que tera as unioes incluidas * @param array $config Configuracoes de preferencia do find * @return void */ protected function makeJoins(Lumine_Base $base, array $config) { // se informou o nome da classe if (isset($config['class'])) { // importamos a classe $base->_getConfiguration()->import($config['class']); // reflexao $ref = new ReflectionClass($config['class']); $target = $ref->newInstance(); // se indicou um alias if (isset($config['alias'])) { $target->alias($config['alias']); } // se tiver join dentro dele if (!empty($config['join'])) { foreach ($config['join'] as $join) { // faz os join's aninhados $this->makeJoins($target, $join); } } // tipo de uniao $joinType = isset($config['type']) ? $config['type'] : 'INNER'; // se indicou os campos de uniao if (isset($config['fieldFrom']) && isset($config['fieldTo'])) { // se indicou um extra if (isset($config['extra'])) { // unimos as classes $base->join($target, $joinType, $target->_getAlias(), $config['fieldFrom'], $config['fieldTo'], $config['extra'], isset($config['extraArgs']) ? $config['extraArgs'] : ''); // se nao indicou extra } else { // une as classes sem extra $base->join($target, $joinType, $target->_getAlias(), $config['fieldFrom'], $config['fieldTo']); } // se nao indicou os campos mas indicou extra } else { if (isset($config['extra'])) { // une as classes sem indicar os campos, mas indica os argumentos extras $base->join($target, $joinType, $target->_getAlias(), null, null, $config['extra'], isset($config['extraArgs']) ? $config['extraArgs'] : ''); // une as classes } else { $base->join($target, $joinType, $target->_getAlias()); } } // se indicou alias if (isset($config['alias'])) { // muda o selectAs $base->selectAs($target, $config['alias'] . '%s'); } } }