Beispiel #1
0
 private static function parseFilter($table, $f)
 {
     $flt = "";
     if (isset($f['raw'])) {
         $flt .= ($flt == "" ? "" : " AND ") . $f['raw'];
     } else {
         if (is_array($f['field']) != is_array($f['value'])) {
             \Sheldon::error("Error to parse where structure!");
         } else {
             if (is_array($f['field'])) {
                 $flt .= self::parseFilter($table, $f['field']) . " " . $f["modificator"] . " " . self::parseFilter($table, $f['value']);
             } else {
                 if ($f['operator'] == 'in') {
                     if (isset($f['value'])) {
                         $arr = "";
                         foreach ($f['value'] as $v) {
                             $arr .= ($arr == '' ? '' : ', ') . "'" . $v . "'";
                         }
                         $flt .= ($flt == "" ? "" : " " . $f["modificator"] . " ") . "" . $table . "." . $f['field'] . " IN (" . $arr . ")";
                     } else {
                         return "";
                     }
                 } elseif ($f['operator'] == 'notin') {
                     if (isset($f['value'])) {
                         $arr = "";
                         foreach ($f['value'] as $v) {
                             $arr .= ($arr == '' ? '' : ', ') . "'" . $v . "'";
                         }
                         $flt .= ($flt == "" ? "" : " " . $f["modificator"] . " ") . "" . $table . "." . $f['field'] . " NOT IN (" . $arr . ")";
                     } else {
                         return "";
                     }
                 } else {
                     $flt .= ($flt == "" ? "" : " " . $f["modificator"] . " ") . "" . $table . "." . $f['field'] . " " . $f['operator'] . " " . (trim($f['value']) == "" ? "" : "'" . $f['value'] . "'");
                 }
             }
         }
     }
     return "(" . $flt . ")";
 }
Beispiel #2
0
 protected function queryInsert($data = [], $beforeSilense = false, $afterSilense = false)
 {
     $modelName = $this->modelName;
     if (method_exists($modelName, "beforeInsert") and !$beforeSilense) {
         //   $data = $modelName::beforeInsert($data);
     }
     $q = self::constructInsert($this->table, $data);
     $result = $this->query($q);
     if ($result) {
         if ($this->gettingId) {
             $id = $this->pdo->lastInsertId();
             $result = Sheldon::table($this->table)->where("id", $id)->get();
             if (count($result) > 0) {
                 //$modelName::afterInsert($result[0]);
             }
             return $id;
         } else {
             $result = Sheldon::table($this->table)->where("id", $this->pdo->lastInsertId())->get();
             if (count($result) > 0) {
                 $record = $result[0];
                 if (method_exists($modelName, "afterInsert") and !$afterSilense) {
                     $record = $modelName::afterInsert($record);
                 }
                 return $record;
             } else {
                 return false;
             }
         }
     } else {
         return false;
     }
 }
Beispiel #3
0
 public static function __callStatic($method, $parameters)
 {
     $result = Sheldon::getCashe(get_called_class(), $method, $parameters[0]);
     if ($result != -1) {
         return $result;
     }
     $instance = new SheldonModel();
     $instance->table = isset(static::$tableName) ? static::$tableName : mb_strtolower(get_called_class());
     $instance->scheme = isset(static::$scheme) ? static::$scheme : [];
     $instance->modelName = get_called_class();
     return call_user_func_array(array($instance, $method), $parameters);
 }