Beispiel #1
0
 public function beforeSave()
 {
     if (strlen($this->name) < 3) {
         $this->errors['name'] = 'Слишком короткий заголовок';
     }
     return parent::beforeSave();
 }
Beispiel #2
0
 /**
  * Returns a list of an field.
  * @param type $fieldName
  * @return EntityArray 
  */
 public function getList($fieldName)
 {
     $list = new EntityArray();
     if ($this->modelTable != null) {
         $helper = $this->modelTable->getFieldDefinitionHelper();
         if ($helper->isTypeForeignObject($fieldName) || $helper->isTypeManyForeignObjects($fieldName)) {
             $list->setModelTable($helper->getModelTable($fieldName));
         }
     }
     foreach ($this as $object) {
         $list->append($object->{$fieldName});
     }
     return $list;
 }
 private function criarMatrizCampos($tabela)
 {
     $campos = ModelTable::getDescTabela($tabela);
     foreach ($campos as $describle) {
         if (empty($describle['Key']) || $describle['Key'] == "PRI") {
             // se não for uma FK
             $p = strpos($describle['Field'], '_');
             $campo = substr($describle['Field'], $p + 1);
             // copia depois do primeiro "_"
         } else {
             $campo = $describle['Field'];
         }
         $campo = strtolower($campo);
         if (strpos($campo, "_") > 0) {
             $p = Strpos($campo, '_');
             $aux = ucwords(str_replace("_", " ", substr($campo, $p + 1)));
             $campo = substr($campo, 0, $p) . str_replace(" ", "", $aux);
         }
         $camposSaida[$describle['Field']] = array("campo" => "_" . $campo, "obs" => $describle['Key']);
     }
     return $camposSaida;
 }
Beispiel #4
0
 public function query()
 {
     global $redirectedPackage;
     global $packageSchema;
     $object = unserialize(base64_decode($_REQUEST["object"]));
     $redirectedPackage = $object['redirected_package'];
     $packageSchema = $object['package_schema'];
     $model = Model::load($object["model"]);
     if (isset($_REQUEST["conditions"])) {
         $conditions = explode(",", $_REQUEST["conditions"]);
         array_pop($conditions);
         //array_shift($conditions);
         foreach ($conditions as $i => $condition) {
             if (substr_count($condition, "==")) {
                 $parts = explode("==", $condition);
                 $conditions[$i] = $parts[0] . "=" . $parts[1];
             } else {
                 $parts = explode("=", $condition);
                 $conditions[$i] = $model->getSearch($parts[1], $parts[0]);
                 //"instr(lower({$parts[0]}),lower('".$model->escape($parts[1])."'))>0";//$parts[0] ." in '".$model->escape($parts[1])."'";
             }
         }
         $condition_opr = isset($_REQUEST["conditions_opr"]) ? $_REQUEST["conditions_opr"] : "AND";
         $conditions = implode(" {$condition_opr} ", $conditions);
     }
     $params = array("fields" => $object["fields"], "sort_field" => isset($_REQUEST["sort"]) ? $_REQUEST["sort"] : $object["sortField"], "sort_type" => isset($_REQUEST["sort_type"]) ? $_REQUEST["sort_type"] : "ASC", "limit" => $object["limit"], "offset" => $_REQUEST["offset"], "conditions" => "({$conditions}) " . ($object['and_conditions'] != '' ? " AND ({$object['and_conditions']})" : '') . ($_REQUEST['and_conditions'] != '' ? " AND ({$_REQUEST['and_conditions']})" : ''));
     //$data = $model->formatData();
     switch ($_REQUEST["action"]) {
         case "delete":
             $ids = json_decode($_REQUEST["params"]);
             foreach ($ids as $id) {
                 $data = $model->getWithField($model->getKeyField(), $id);
                 $model->delete($model->getKeyField("primary"), $id);
                 User::log("Deleted " . $model->name, $data[0]);
             }
             break;
     }
     switch ($object["format"]) {
         case "tbody":
             include "lib/tapi/Table.php";
             include "lib/tapi/ModelTable.php";
             $table = new ModelTable($prefix . "/" . str_replace(".", "/", $object["model"]) . "/");
             print json_encode(array("tbody" => $table->render(false), "footer" => $table->renderFooter()));
             break;
         case "json":
             $data = $model->get($params);
             print json_encode($data);
             break;
     }
 }
Beispiel #5
0
            $conditions[$i] = $model->getSearch($parts[1], $parts[0]);
            //"instr(lower({$parts[0]}),lower('".$model->escape($parts[1])."'))>0";//$parts[0] ." in '".$model->escape($parts[1])."'";
        }
    }
    $condition_opr = isset($_REQUEST["conditions_opr"]) ? $_REQUEST["conditions_opr"] : "AND";
    $conditions = implode(" {$condition_opr} ", $conditions);
}
$params = array("fields" => $object["fields"], "sort_field" => isset($_REQUEST["sort"]) ? $_REQUEST["sort"] : $object["sortField"], "sort_type" => isset($_REQUEST["sort_type"]) ? $_REQUEST["sort_type"] : "ASC", "limit" => $object["limit"], "offset" => $_REQUEST["offset"], "conditions" => "({$conditions}) " . ($object['and_conditions'] != '' ? " AND ({$object['and_conditions']})" : '') . ($_REQUEST['and_conditions'] != '' ? " AND ({$_REQUEST['and_conditions']})" : ''));
//$data = $model->formatData();
switch ($_REQUEST["action"]) {
    case "delete":
        $ids = json_decode($_REQUEST["params"]);
        foreach ($ids as $id) {
            $data = $model->getWithField($model->getKeyField(), $id);
            $model->delete($model->getKeyField("primary"), $id);
            User::log("Deleted " . $model->name, $data[0]);
        }
        break;
}
switch ($object["format"]) {
    case "tbody":
        include "lib/tapi/Table.php";
        include "lib/tapi/ModelTable.php";
        $table = new ModelTable($prefix . "/" . str_replace(".", "/", $object["model"]) . "/");
        print json_encode(array("tbody" => $table->render(false), "footer" => $table->renderFooter()));
        break;
    case "json":
        $data = $model->get($params);
        print json_encode($data);
        break;
}
Beispiel #6
0
 /**
  * Returns the model table for this entity
  * @return ModelTable
  */
 public function getModelTable()
 {
     return ModelTable::get($this->modelTableName);
 }
 public function gerar_models()
 {
     $tabelas = $_POST['tabela'];
     $model = new ModelTable($tabelas);
     $this->view("morgana/lista_gerada", " - Projeto via MorganaFramework", $resposta = $model->gerarModels());
 }