public static function search(TableCtl $controller, $term, $filter = false) { $object = call_user_func(array(get_class($controller), 'getObject')); if (!$object) { return false; } $terms = preg_split('/[ ,]/', $term); if (!count($terms)) { return false; } //Check for results containing the word $search = array(); foreach ($terms as $oneTerm) { $search[] = '`word` LIKE CONCAT("%", ?, "%")'; } //Check for results with the exact word $search[] = '`word` IN (' . implode(', ', array_fill(0, count($terms), '?')) . ')'; $search = '(' . implode(') OR (', $search) . ')'; $params = array_merge(array($object->getSource()), $terms, $terms); $query = new SelectQuery(get_called_class()); $query->field('DISTINCT `' . $object->getMeta('table') . '`.*')->leftJoin(get_class($controller), '`' . $object->getMeta('table') . '`.`' . $object->getMeta('id_field') . '` = `table_id`')->filter('`table` = ?')->filter($search)->order('`count` DESC, `sequence`'); if ($filter) { if (is_array($filter)) { foreach ($filter as $one_fil) { $query->filter($one_fil); } } else { $query->filter($filter); } } $result = $query->fetchAll($params); return $result; }
public function action_check_defines() { if (!Component::isActive('BackendError')) { return false; } $query = new SelectQuery('BackendError'); $query->distinct()->field('query')->filter("`string` LIKE 'Undefined index: %'")->filter("`file` LIKE '%\\\\Render.obj.php(%) : eval()\\'d code'")->filter("`query` LIKE 'a_p_i/define/%'"); return $query->fetchAll(array(), array('column' => 0)); }
public function action_display($id) { $query = new SelectQuery('ContentRevision'); $query->filter('`content_id` = :id')->order('`added` DESC'); $revisions = $query->fetchAll(array(':id' => $id)); $content = new ContentObj($id); if ($content->object) { $content->object->revisions = $revisions; } else { $content = false; } return $content; }
public function read($options = array()) { $result = parent::read($options); if ($result) { $query = new SelectQuery('Assignment'); $query->distinct()->field('`roles`.`name`')->leftJoin('Role', '`roles`.`id` = `assignments`.`role_id`')->filter("`assignments`.`access_type` = 'users'")->filter('`assignments`.`access_id` = :user_id OR `assignments`.`access_id` = 0')->order('`roles`.`name`'); $roles = $query->fetchAll(array(':user_id' => $this->getMeta('id')), array('column' => 0)); $roles = empty($roles) ? array() : $roles; if ($this->object) { $this->object->roles = $roles; } if ($this->array) { $this->array['roles'] = $roles; } } return $result; }
public static function getComments($table = false, $table_id = false, $limit = false) { $query = new SelectQuery('Comment'); $query->field(array('`comments`.*, `backend_users`.`username`, `backend_users`.`email`'))->leftJoin('BackendUser', '`comments`.`user_id` = `backend_users`.`id`')->filter('`comments`.`active` = 1')->order('IF(`comments`.`in_reply_to` = 0, `comments`.`id`, `comments`.`in_reply_to`) DESC'); $params = array(); if ($table) { $query->filter('`comments`.`foreign_table` = :table'); $params[':table'] = $table; } if ($table_id) { $query->filter('`comments`.`foreign_id` = :table_id'); $params[':table_id'] = $table_id; } if ($limit) { $query->limit($limit); } return $query->fetchAll($params); }
public static function get($hook, $type = 'pre') { if (!BACKEND_WITH_DATABASE) { return false; } $params = array(':type' => $type, ':hook' => $hook); $query = new SelectQuery('Hook'); $query->leftJoin('Component', array('`hooks`.`class` = `components`.`name`'))->filter('`hooks`.`hook` = :hook')->filter('`hooks`.`type` = :type')->filter('`hooks`.`active` = 1')->filter('`components`.`active` = 1'); if (Controller::$area) { $query->filter('`global` = 1 OR `class` = :area'); $params[':area'] = Controller::$area; } if (Controller::$view && Controller::$view->mode) { $query->filter('`mode` IN (:mode, \'*\')'); $params[':mode'] = Controller::$view->mode; } $query->order('`sequence`'); return $query->fetchAll($params); }
public static function getTagNames($table, $table_id = null) { if (is_null($table_id)) { if (!$table instanceof DBObject) { return false; } $table_id = $table->getMeta('id'); $table = $table->getMeta('table'); } $query = new SelectQuery('Tag'); $query->field('`tags`.`id`, `tags`.`name`')->leftJoin('TagLink', array('`tags`.`id` = `tag_links`.`tag_id`'))->filter('`tags`.`foreign_table` = :table')->filter('`tag_links`.`foreign_id` = :id'); $result = $query->fetchAll(array(':table' => $table, ':id' => $table_id), array('with_key' => true)); if (!$result) { return $result; } foreach ($result as $key => $value) { $result[$key] = current($value); } return $result; }
public function action_filter($pageId = 1) { $query = new SelectQuery('BackendRequest'); $query->setFields(array('user_id', 'ip', 'user_agent', 'mode', 'request', 'query', 'COUNT(id) AS `occured`', 'MAX(`added`) AS `last_occured`')); $query->setGroup(array('user_id', 'ip', 'user_agent', 'mode', 'request', 'query')); $params = $queryFilter = array(); $parameters = Controller::getVar('params'); $sort = Controller::getVar('sort'); if (!empty($parameters['userId'])) { $queryFilter[] = 'user_id = :userId'; $params[':userId'] = $parameters['userId']; } if (!empty($parameters['query'])) { $queryFilter[] = "query LIKE('%{$parameters['query']}%')"; } if (!empty($parameters['ip'])) { $queryFilter[] = "ip LIKE('%{$parameters['ip']}%')"; } if (!empty($parameters['user_agent'])) { $queryFilter[] = "user_agent LIKE('%{$parameters['user_agent']}%')"; } $query->filter($queryFilter); $count = 10; if (!empty($sort['field'])) { $query->setOrder(array($sort['field'] . ' ' . $sort['order'])); } if ($pageId == 1) { $start = 0; } elseif ($pageId == 0) { $start = false; $count = false; } else { $start = floor(($pageId - 1) * $count); } $pager = array(); if ($start === 'all') { $limit = 'all'; } else { if ($start || $count) { $limit = "{$start}, {$count}"; } else { $limit = false; } } $query->limit($limit); $items = $query->fetchAll($params); $totalItems = $query->getCount($params); $pager = ''; if ($start || $count) { $pager = array('currentPage' => $pageId, 'itemCount' => count($items), 'itemTotal' => $totalItems, 'totalPages' => round(($totalItems - 1) / $count, 0)); } $retArray['pager'] = $pager; $retArray['data'] = $items; $retArray['params'] = $parameters; $retArray['sort'] = $sort; return $retArray; }
private static function permissionHolders($action = '*', $subject = '*', $subject_id = 0) { $result = false; $query = new SelectQuery('Permission'); $params = array(); if ($action != '*') { $query->filter("(`action` = :action OR `action` = '*')"); $params[':action'] = $action; } if ($subject != '*') { $query->filter("(`subject` = :subject OR `subject` = '*')"); $params[':subject'] = $subject; } if ($subject_id != '0') { $query->filter("(`subject_id` = :subject_id OR `subject_id` = 0)"); $params[':subject_id'] = $subject_id; } $result = $query->fetchAll($params); return $result; }
public static function getSitemap() { $query = new SelectQuery('Content'); $query->filter('`active` = 1'); $list = $query->fetchAll(); return array('list' => $list, 'options' => array()); }
public function get_permissions($component = false) { $toret = new stdClass(); //Base Permissions $parameters = array(); $query = new SelectQuery('Permission'); $query->distinct()->field(array('action', 'subject'))->filter('`active` = 1')->filter('`subject_id` = 0')->group('`subject`, `action` WITH ROLLUP'); if ($component) { $query->filter('`subject` = :component'); $parameters[':component'] = class_for_url($component); } $toret->base_perms = $query->fetchAll($parameters); //Roles $query = new SelectQuery('Role'); $query->filter('`active` = 1'); $toret->roles = $query->fetchAll(); //Activated Permissions $parameters = array(); $query = new SelectQuery('Permission', array('fields' => "CONCAT(`subject`, '::', `action`), GROUP_CONCAT(DISTINCT `role` ORDER BY `role`) AS `roles`")); $query->filter('`active` = 1')->filter('`subject_id` = 0')->filter("`role` != 'nobody'")->group('`subject`, `action`'); if ($component) { $query->filter('`subject` = :component'); $parameters[':component'] = class_for_url($component); } $permissions = $query->fetchAll($parameters, array('with_key' => 1)); $toret->permissions = array(); foreach ($permissions as $key => $value) { $toret->permissions[$key] = explode(',', current($value)); } return $toret; }