Example #1
0
 public static function isValid(Attributes $object)
 {
     if (array_key_exists('Required', $object->_allOptions)) {
         if (!Validation::Email($object->_value)) {
             ModelState::addError("O campo " . $object->_displayName . " deve ser um e-mail.");
         }
     } else {
         if (!Validation::Email($object->_value) && $object->_value != '') {
             ModelState::addError("O campo " . $object->_displayName . " deve ser um e-mail.");
         }
     }
 }
Example #2
0
 static function ValidateSummary()
 {
     $erros = ModelState::getErrors();
     if (count($erros) > 0) {
         $html = '<ul class="validate-summary">';
         foreach ($erros as $erro) {
             $html .= '<li>' . $erro . '</li>';
         }
         $html .= '</ul>';
         echo $html;
     }
 }
Example #3
0
 public static function isValid(Attributes $object)
 {
     $explode = explode(',', $object->_arg);
     if (count($explode) == 2) {
         $min = $explode[0];
         $max = $explode[1];
     } else {
         $max = $object->_arg;
         $min = 0;
     }
     if (!Validation::Lenght($object->_value, $max, $min) && ($object->_required || Validation::Required($object->_value))) {
         ModelState::addError("O campo " . $object->_displayName . " deve conter " . ($min > 0 ? "no mínimo " . $min . " e " : "") . "no máximo " . $max . " caracteres.");
     }
 }
Example #4
0
 public static function isValid(Attributes $object)
 {
     $explode = explode(',', $object->_arg);
     if (count($explode) == 2) {
         $min = $explode[0];
         $max = $explode[1];
     } else {
         $max = $object->_arg;
         $min = 0;
     }
     if (!Validation::Number($object->_value)) {
         return ModelState::addError("O campo " . $object->_displayName . " deve ser um número.");
     }
     if (!Validation::Range($object->_value, $max, $min)) {
         ModelState::addError("O campo " . $object->_displayName . " deve estar dentro do intervalo de " . $min . " e " . $max . ".");
     }
 }
Example #5
0
 public function ExecuteUpdate($table, $data, $where)
 {
     if (is_object($data)) {
         ModelState::ModelTreatment($data);
     }
     $data = (array) $data;
     // Ordena
     ksort($data);
     // Define os dados que ser�o atualizados
     $novosDados = NULL;
     foreach ($data as $key => $value) {
         $novosDados .= "`{$key}`=:{$key},";
     }
     $novosDados = rtrim($novosDados, ',');
     // Prepara a Query
     $sth = $this->prepare("UPDATE {$table} SET {$novosDados} WHERE {$where}");
     // Define os dados
     foreach ($data as $key => $value) {
         // Se o tipo do dado for inteiro, usa PDO::PARAM_INT, caso contr�rio, PDO::PARAM_STR
         $tipo = is_int($value) ? PDO::PARAM_INT : PDO::PARAM_STR;
         // Define o dado
         $sth->bindValue(":{$key}", $value, $tipo);
     }
     // Sucesso ou falha?
     return $sth->execute();
 }
Example #6
0
 /**
  * Caso exista algum post na pagina, ele é tranformado em um objeto $model
  * e colocado como o primeiro argumento para receber no metodo do controller
  */
 private static function getPost(&$parameters)
 {
     if (isset($_POST) and count($_POST) > 0) {
         $post = $_POST;
         $classe = Controller::getTypeModel();
         $model = new $classe();
         foreach ($post as $key => $valor) {
             $ex = explode("_", $key);
             $count = count($ex);
             $result = '$model->';
             for ($i = 0; $i < $count; $i++) {
                 $result .= '$ex[' . $i . ']' . ($i == $count - 1 ? '= $valor == "" ? null : $valor;' : '->');
             }
             eval($result);
         }
         $arrayMerge = array("model" => $model);
         if (isset($_FILES)) {
             foreach ($_FILES as $file => $args) {
                 if (property_exists($model, $file)) {
                     $model->{$file} = $args;
                 } else {
                     $arrayMerge[$file] = $args;
                 }
             }
         }
         ModelState::TryValidationModel($model);
         $parameters = array_merge($arrayMerge, $parameters);
     }
     return $parameters;
 }
Example #7
0
 /**
  * Deleta os dados no banco atraves de uma model mapeada
  * @param $model
  * @return int
  */
 public function Delete($model)
 {
     $this->OpenTransaction();
     $primaryKey = ModelState::GetPrimary($model);
     $table = $this->getTableName($model);
     if ($primaryKey != null) {
         $exec = $this->prepare("DELETE FROM " . $table . " WHERE " . $primaryKey . " = " . $model->{$primaryKey} . " LIMIT 1");
         $exec->execute();
         if ($exec->rowCount() > 0) {
             return true;
         }
         throw new UnitOfWorkException("A execução atingiu um numero 0 de linhas");
     }
     return false;
 }
Example #8
0
 public static function isValid(Attributes $object)
 {
     if (!Validation::Required($object->_value)) {
         ModelState::addError("O campo " . $object->_displayName . " é obrigatório.");
     }
 }
Example #9
0
 public static function isValid(Attributes $object)
 {
     if (!Validation::Date($object->_value)) {
         ModelState::addError("O campo " . $object->_displayName . " deve ser uma data.");
     }
 }
Example #10
0
 private function ExecutePersist($result, $all)
 {
     if ($this->persist == null || $result == null) {
         return $result;
     }
     $persist = explode(",", $this->persist);
     $obj = NAMESPACE_ENTITIES . $this->type;
     $obj = new $obj();
     $virtuals = ModelState::GetVirtuals($obj);
     foreach ($persist as $key => $value) {
         $ex = explode(".", $value);
         $value = $ex[0];
         if (!array_key_exists("_" . $value, $virtuals)) {
             unset($persist[$key]);
         }
     }
     if (is_object($result)) {
         $result = array($result);
     }
     $count = count($result);
     for ($i = 0; $i < $count; $i++) {
         foreach ($persist as $k => $p) {
             $p = "_" . $p;
             $novoPersist = explode(".", $p);
             if (count($novoPersist) == 2) {
                 $p = $novoPersist[0];
                 $novoPersist = $novoPersist[1];
             } else {
                 $novoPersist = null;
             }
             $table = $virtuals[$p]["Type"];
             $fk = $virtuals[$p]["Fk"];
             $unitofwork = new UnitOfWork();
             $result[$i]->{$p} = $unitofwork->Get($table, $fk . " = " . $result[$i]->{$fk}, $novoPersist)->ToList();
         }
     }
     if ($count == 1 && $all == false) {
         return $result[0];
     }
     return $result;
 }