Example #1
0
 public static function getUsers()
 {
     $userModel = new self();
     $select = $userModel->select();
     $select->order(array('last_name', 'first_name'));
     return $userModel->fetchAll($select);
 }
Example #2
0
 /**
  * Begins search for directories matching mask.
  * @param  mixed
  * @return Finder
  */
 public static function findDirectories($mask)
 {
     if (!is_array($mask)) {
         $mask = func_get_args();
     }
     $finder = new self();
     return $finder->select($mask, 'isDir');
 }
Example #3
0
 public function getCountryName($code = NULL)
 {
     $table = new self();
     $rName = $table->info('name');
     $select = $table->select()->from($rName);
     $select->where('iso_code_3 = ?', $code);
     $item = $table->fetchRow($select);
     return $item->name;
 }
Example #4
0
 public static function getLatestCommentByUserId($userId)
 {
     $status = new self();
     $status->setProjection(array("comment"));
     $status->setCondition("user_id", $userId);
     $status->setOrderBy("created_at", "desc");
     $status->setLimit(1);
     $statuses = $status->select();
     return isset($statuses[0]) ? $statuses[0]->comment : "";
 }
 public static function getConversation($IDMessage)
 {
     $TheMessage = new self();
     $Select = $TheMessage->select()->join(array('mm' => 'message'), 'message.IDParent = mm.IDParent', array())->where("mm.IDMessage = '{$IDMessage}'")->order("mm.Date");
     $Messages = $TheMessage->fetchAll($Select);
     $Ret = array();
     if ($Messages) {
         foreach ($Messages as $Message) {
             $TheMessage = new self();
             $Ret[] = $TheMessage->copyFromDb($Message);
         }
     }
     return $Ret;
 }
Example #6
0
 /**
  * 删除回复
  */
 public static final function remove()
 {
     $online = front::online();
     //if(!parent::init('in_manager') || $online->grade!=1) die('Permission Denied!');
     // 获取数据
     $doc_remark = new self();
     $doc_remark->doc_remark_id = isset($_GET['doc_remark_id']) ? $_GET['doc_remark_id'] : null;
     if (!is_numeric($doc_remark->doc_remark_id) || !$doc_remark->select()) {
         $error = '该回复不存在';
         return;
     }
     // 删除数据
     $doc_remark->delete();
     header('Location: ?' . $_GET['query']);
 }
Example #7
0
 /**
  * 删除用户
  */
 public static final function remove()
 {
     // 获取数据
     $user = new self();
     $user->user_id = isset($_GET['user_id']) ? $_GET['user_id'] : null;
     if (!is_numeric($user->user_id) || !$user->select()) {
         $error = '该用户不存在';
         self::view(__CLASS__ . '/error.tpl', compact('error'));
         return;
     }
     // 删除数据
     $user->delete();
     header('Location: ?' . $_GET['query']);
 }
Example #8
0
 /**
  * 删除日志
  */
 public static final function remove()
 {
     // 获取数据
     $book = new self();
     $book->book_id = isset($_GET['book_id']) ? $_GET['book_id'] : null;
     if (!is_numeric($book->book_id) || !$book->select()) {
         $error = '该日志不存在';
         front::view2('error.tpl', compact('error'));
         return;
     }
     // 删除数据
     $book->delete();
     header('Location: ?' . $_GET['query']);
 }
Example #9
0
 /**
  * Return an array of all groups.
  *
  * @return array
  */
 public static function fetchAllGroups()
 {
     $model = new self();
     $result = [];
     try {
         foreach ($model->select('group')->distinct()->get() as $row) {
             $result[] = $row->group;
         }
     } catch (\Exception $e) {
         // Do nothing.
     }
     return $result;
 }
Example #10
0
 /**
  * 删除分类
  */
 public static final function remove()
 {
     // 获取数据
     $channel = new self();
     $channel->channel_id = isset($_GET['channel_id']) ? $_GET['channel_id'] : null;
     if (!is_numeric($channel->channel_id) || !$channel->select()) {
         $error = '该分类不存在';
         front::view2('error.tpl', compact('error'));
         return;
     }
     //分类下不能有数据
     $count = self::selects('COUNT(*)', null, array('typeid' => $channel->channel_id), null, array('column|table=doc' => 'COUNT(*)'));
     if ($count > 0) {
         $error = '分类下还有数据不能删除';
         front::view2('error.tpl', compact('error'));
         return;
     } else {
         $count = self::selects('COUNT(*)', null, array('parent_id' => $channel->channel_id), null, array('column|table=channel' => 'COUNT(*)'));
         if ($count > 0) {
             $error = '分类下还有分类不能删除';
             front::view2('error.tpl', compact('error'));
             return;
         }
     }
     // 删除数据
     $channel->delete();
     header('Location: ?' . $_GET['query']);
 }
 /**
  * @since 1.3
  *
  * @return string
  */
 public static function init($value, $inputName, $isMandatory, $isDisabled, $otherArgs)
 {
     $instance = new self($GLOBALS['wgParser']);
     return $instance->select($value, $inputName, $isMandatory, $isDisabled, $otherArgs);
 }
 public static function compact($collection = null)
 {
     $collection = self::_collection($collection);
     $__ = new self();
     return $__->select($collection, function ($val) {
         return (bool) $val;
     });
 }
 /**
  *
  * @return mixed
  */
 public static function getUniqUsers()
 {
     $obj = new self();
     return $obj->select('user_id')->distinct()->get()->all_to_array('user_id');
 }
Example #14
0
 /**
  * 删除用户
  */
 public static final function remove()
 {
     if (!self::user_level(2, __CLASS__, __FUNCTION__)) {
         return;
     }
     $online = front::online();
     // 获取数据
     $user = new self();
     $user->user_id = isset($_GET['user_id']) ? $_GET['user_id'] : null;
     if (!is_numeric($user->user_id) || !$user->select()) {
         $error = '该用户不存在';
         front::view2('common/error.tpl', compact('error'));
         return;
     }
     if ($online->user_id == $user->user_id || $user->grade == 1) {
         $error = '此用户不能删除';
         front::view2('common/error.tpl', compact('error'));
         return;
     }
     // 删除数据
     $user->delete();
     header('Location: ?' . $_GET['query']);
 }
Example #15
0
 /**
  * Return a new collection where each element is a subselection of the original element.
  * (Known as "collect" in Ruby or "pluck" in underscore.js).
  *
  * @param string|array      $selector  Path to the variable to select. Examples: "->id", "[message]", "customer.name", array('id' => 'message_id', 'message' => 'message_text')
  * @param string|null|false $selectKey (optional) The path that will be used as key. false: Keep the current key, null:  create linear keys.
  *
  * @return Collection
  */
 public function select($selector, $selectKey = false)
 {
     if ($this->data !== null || is_string($this->sql) || is_object($selector) && is_callable($selector)) {
         return parent::select($selector, $selectKey);
     }
     if (is_int($selector)) {
         $selector = (string) $selector;
     }
     $selectorPaths = is_string($selector) ? array($selector => $selector) : $selector;
     $hasKeySelector = $selectKey !== false && $selectKey !== null;
     if ($hasKeySelector) {
         \Sledgehammer\array_key_unshift($selectorPaths, $selectKey, $selectKey);
     }
     if (count($selectorPaths) === 0) {
         // empty selector?
         return parent::select($selector, $selectKey);
     }
     $isWildcardSelector = $this->sql->columns === '*' || $this->sql->columns == array('*' => '*');
     if ($isWildcardSelector === false && (is_string($this->sql->columns) || count($selectorPaths) >= count($this->sql->columns))) {
         // The selector can't be a subsection of current columns.
         return parent::select($selector, $selectKey);
     }
     $columns = [];
     foreach ($selectorPaths as $to => $from) {
         $column = $this->convertPathToColumn($from);
         $alias = $this->convertPathToColumn($to);
         if ($column === false || $alias === false) {
             // Path can't be mapped to column
             return parent::select($selector, $selectKey);
         }
         if ($isWildcardSelector === false) {
             if (isset($this->sql->columns[$column])) {
                 $column = $this->sql->columns[$column];
                 // Use the original column/calculation (just change the alias)
             } else {
                 // @todo Use array_search() for support of indexed array of columns.
                 return parent::select($selector, $selectKey);
             }
         }
         if ($hasKeySelector) {
             $alias = $column;
             // Don't alias in SQL, but (re)use the $selector.
         }
         $columns[$alias] = $column;
     }
     $collection = new self($this->sql->select($columns), $this->dbLink);
     if ($hasKeySelector || is_string($selector)) {
         // Does the $collection requires additional selecting?
         return $collection->select($selector, $selectKey);
     }
     return $collection;
 }
Example #16
0
 public function compact($collection = null)
 {
     list($collection) = self::_wrapArgs(func_get_args(), 1);
     $collection = self::_collection($collection);
     $__ = new self();
     return self::_wrap($__->select($collection, function ($val) {
         return (bool) $val;
     }));
 }
Example #17
0
 public function select($lazy = true)
 {
     $class = new $this->className();
     $typeFields = $class->getTypeFields();
     $customFields = isset($class->getMapping()['customFields']) ? $class->getMapping()['customFields'] : false;
     $fields = array();
     foreach ($this->fields as $field) {
         $oldField = $field;
         /*
          * verifica se não há algum campo com a consulta personalizada
          *
          */
         if ($customFields) {
             if (in_array($field, array_keys(MasterSQLUteis::decodeProperties($customFields)))) {
                 $field = MasterSQLUteis::decodeProperties($customFields)[$field];
             }
         }
         /*
          * faz o tratamento para buscar os dados de acordo com o tipo correto date, number...
          *
          */
         if (array_key_exists($field, $typeFields)) {
             if ($typeFields[$field]->dataType == 'DATE') {
                 $field = "TO_CHAR(" . $field . ",'RRRR-MM-DD HH24:MI')";
             } elseif ($typeFields[$field]->dataType == 'NUMBER') {
                 if ($typeFields[$field]->dataScale > 0) {
                     $field = "(" . $field . " * (1 * Power(10,''||" . $typeFields[$field]->dataScale . "))) ";
                 }
             }
             $field = MasterSQLUteis::tableField($field, $oldField, $this->table);
         }
         array_push($fields, $field);
     }
     $this->db->select($fields, false);
     $this->db->from($this->table);
     if ($this->join) {
         $this->db->join($this->join, $this->joinCondition);
     }
     $this->query = $this->db->get();
     $this->error = MasterSQLUteis::exception($this->db->error());
     MasterSQLUteis::exception($this->db->error(), false);
     if ($this->query->num_rows() > 0) {
         $return = $this->query->result();
     } else {
         return false;
     }
     $arrayObject = array();
     $array = (array) $class;
     $fks = isset($class->getMapping()['foreignKeys']) && !$lazy ? $class->getMapping()['foreignKeys'] : false;
     foreach ($return as $object) {
         $object = (array) $object;
         foreach ($object as $key => $value) {
             if (array_key_exists($key, $typeFields)) {
                 if ($typeFields[$key]->dataType == 'NUMBER') {
                     if ($typeFields[$key]->dataScale > 0) {
                         $object[$key] = (double) ($value / (1 * pow(10, $typeFields[$key]->dataScale)));
                     } else {
                         $object[$key] = (int) $value;
                     }
                 }
             }
         }
         $object = (object) $object;
         $i = 0;
         foreach ($array as $campo => $valor) {
             $o = (array) $object;
             $returnFk = false;
             if ($fks) {
                 if (in_array($campo, array_keys($fks))) {
                     $query = new self(new $fks[$campo]['class']());
                     $query->setWhere($fks[$campo]['pk'], $o[MasterSQLUteis::decodeProperties($campo)]);
                     $query->setOrderBy($fks[$campo]['orderBy'], isset($fks[$campo]['orderByOrder']) ? $fks[$campo]['orderByOrder'] : 'asc');
                     $query->select($lazy);
                     if ($fks[$campo]['method'] == 'oneToOne') {
                         $returnFk = $query->row;
                     } else {
                         $returnFk = $query->result;
                     }
                 }
             }
             if ($returnFk) {
                 $array[$campo] = $returnFk;
             } else {
                 $array[$campo] = $o[MasterSQLUteis::decodeProperties($campo)];
             }
         }
         array_push($arrayObject, MasterSQLUteis::cast(new $this->className(), (object) $array));
     }
     $this->result = $arrayObject;
     $this->row = $arrayObject[0];
     $this->count = count($this->result) == null ? 0 : count($this->result);
     $this->exists = $this->count == 0 ? false : true;
 }