public function get_language_texts_list($lang_id = 1) { $this->fields_text = array_merge($this->fields_text, array("value_{$lang_id}")); $this->DB->select(implode(", ", $this->fields_text)); $this->DB->from(LANG_TEXTS_TABLE); $results = $this->DB->get()->result_array(); if (!empty($results) && is_array($results)) { $return = array(); foreach ($results as $lang) { $return[$lang['gid']] = $lang['value_' . $lang_id]; } return $return; } return array(); }
/** * Return alerts as array * @param array $params * @return integer */ private function _get_alerts_count($params = null) { $this->DB->select("COUNT(*) AS cnt"); $this->DB->from(SPAM_ALERTS_TABLE); if (isset($params["where"]) && is_array($params["where"]) && count($params["where"])) { foreach ($params["where"] as $field => $value) { $this->DB->where($field, $value); } } if (isset($params["where_in"]) && is_array($params["where_in"]) && count($params["where_in"])) { foreach ($params["where_in"] as $field => $value) { $this->DB->where_in($field, $value); } } if (isset($params["where_sql"]) && is_array($params["where_sql"]) && count($params["where_sql"])) { foreach ($params["where_sql"] as $value) { $this->DB->where($value); } } $results = $this->DB->get()->result_array(); if (!empty($results) && is_array($results)) { return intval($results[0]["cnt"]); } return 0; }
/** * Return count of administrators by criteria * * Available where clauses: where, where_in, where_sql etc. * * @param array $params where clauses * @param array $filter_object_ids filter by identificators * @return array */ public function get_users_count($params = array(), $filter_object_ids = null) { $this->DB->select("COUNT(*) AS cnt"); $this->DB->from(AUSERS_TABLE); if (isset($params["where"]) && is_array($params["where"]) && count($params["where"])) { foreach ($params["where"] as $field => $value) { $this->DB->where($field, $value); } } if (isset($params["where_in"]) && is_array($params["where_in"]) && count($params["where_in"])) { foreach ($params["where_in"] as $field => $value) { $this->DB->where_in($field, $value); } } if (isset($params["where_sql"]) && is_array($params["where_sql"]) && count($params["where_sql"])) { foreach ($params["where_sql"] as $value) { $this->DB->where($value); } } if (isset($filter_object_ids) && is_array($filter_object_ids) && count($filter_object_ids)) { $this->DB->where_in("id", $filter_object_ids); } $result = $this->DB->get()->result(); if (!empty($result)) { return intval($result[0]->cnt); } else { return 0; } }
/** * Return number of information pages * * @param array $params filters data * @return integer */ public function get_pages_count($params = array()) { $this->DB->select("COUNT(*) AS cnt"); $this->DB->from(CONTENT_TABLE); if (isset($params["where"]) && is_array($params["where"]) && count($params["where"])) { foreach ($params["where"] as $field => $value) { $this->DB->where($field, $value); } } if (isset($params["where_in"]) && is_array($params["where_in"]) && count($params["where_in"])) { foreach ($params["where_in"] as $field => $value) { $this->DB->where_in($field, $value); } } if (isset($params["where_sql"]) && is_array($params["where_sql"]) && count($params["where_sql"])) { foreach ($params["where_sql"] as $value) { $this->DB->where($value); } } $result = $this->DB->get()->result(); if (!empty($result)) { return intval($result[0]->cnt); } else { return 0; } }
/** * Return number of filtered reason objects * @param array $params filters parameters * @param array $filter_object_ids filters identifiers * @return integer */ public function get_product_count($params = array(), $filter_object_ids = null) { $this->DB->select("COUNT(*) AS cnt"); $this->DB->from(PG_PRODUCTS_TABLE); if (isset($params["where"]) && is_array($params["where"]) && count($params["where"])) { foreach ($params["where"] as $field => $value) { $this->DB->where($field, $value); } } if (isset($params["where_in"]) && is_array($params["where_in"]) && count($params["where_in"])) { foreach ($params["where_in"] as $field => $value) { $this->DB->where_in($field, $value); } } if (isset($params["where_sql"]) && is_array($params["where_sql"]) && count($params["where_sql"])) { foreach ($params["where_sql"] as $value) { $this->DB->where($value); } } if (isset($filter_object_ids) && is_array($filter_object_ids) && count($filter_object_ids)) { $this->DB->where_in("id", $filter_object_ids); } $results = $this->DB->get()->result_array(); if (!empty($results) && is_array($results)) { return intval($results[0]["cnt"]); } return 0; }
/** * Return all types as array * @param boolean $status * @param array $filter_object_ids * @param boolean $formatted * @return array */ public function get_types($status = false, $filter_object_ids = null, $formatted = true) { $this->DB->select(implode(", ", $this->fields)); $this->DB->from(SPAM_TYPES_TABLE); if ($status) { $this->DB->where("status", "1"); } if (is_array($filter_object_ids)) { foreach ($filter_object_ids as $value) { $this->DB->where_in("id", $value); } } $results = $this->DB->get()->result_array(); if (!empty($results) && is_array($results)) { foreach ($results as $r) { $this->type_cache[$r['id']] = $this->type_cache[$r['gid']] = $data[$r['id']] = $r; } if ($formatted) { return $this->format_type($data); } else { return $data; } } return array(); }
/** * Set the from table. * * @param string $table * @access public * @return object the dao object self. */ public function from($table) { $this->setTable($table); if ($this->mode == 'raw') { $this->sqlobj->from($table); } return $this; }
/** * Get link type by GID * @param string $type_gid * @return mixed */ public function get_type_by_gid($type_gid) { $type_gid = preg_replace("/[^a-z_]/", "", strtolower($type_gid)); if (!$type_gid) { return false; } $this->DB->select('id, gid, separated, lifetime, unique_type'); $this->DB->from(LINKER_TYPES_TABLE); $this->DB->where('gid', $type_gid); //_compile_select; $result = $this->DB->get()->result(); if (!empty($result)) { $rt = get_object_vars($result[0]); $rt["table_name"] = $rt["separated"] ? LINKER_SEPARATED_PREFIX . $rt["gid"] : LINKER_TABLE; return $rt; } else { return false; } }
/** * Get user groups * Get groups a user is in * @param int|bool $user_id User id to get or FALSE for current user * @return array Groups */ public function get_user_groups($user_id = FALSE) { if ($user_id == FALSE) { $user_id = $this->CI->session->userdata('id'); } $this->aauth_db->select('*'); $this->aauth_db->from($this->config_vars['user_to_group']); $this->aauth_db->join($this->config_vars['groups'], "id = group_id"); $this->aauth_db->where('user_id', $user_id); return $query = $this->aauth_db->get()->result(); }
/** * Return attachements list * @param integer $message_id message identifier * @return array */ private function _get_attaches_count($message_ids) { $this->DB->select('COUNT(*) AS cnt'); $this->DB->from(MAILBOX_ATTACHES_TABLE); $this->DB->where_in('id_message', (array) $message_ids); $results = $this->DB->get()->result_array(); if (!empty($results) && is_array($results)) { return $results[0]['cnt']; } return array(); }
/** * Return preset object by guid * * @param string $gid area guid * @return array */ public function get_preset_by_gid($gid) { $data = array(); $this->DB->select(implode(",", $this->fields_preset)); $this->DB->from(DYNBLOCKS_PRESETS_TABLE); $this->DB->where("gid", $gid); $result = $this->DB->get()->result_array(); if (!empty($result)) { $data = array_shift($this->format_preset(array($result[0]))); } return $data; }
/** * Method to build the query * * @access private * @return string query */ protected function _buildQuery() { static $instance; if (!empty($instance)) { return $instance; } $this->_query->select('a.*'); $this->_query->from($this->_default_table . ' AS a'); $this->_buildContentWhere(); $this->_buildContentOrderBy(); $instance = $this->_query->__toString(); return $instance; }
/** * Return mailbox services as array * @param array $params criteria * @param integer $page page of results * @param integer $limits rows per page * @param array $order_by sorting * @return array */ private function _get($params = array(), $page = null, $limits = null, $order_by = null) { $this->DB->select(implode(", ", $this->fields)); $this->DB->from(MAILBOX_SERVICES_TABLE); if (isset($params["where"]) && is_array($params["where"]) && count($params["where"])) { foreach ($params["where"] as $field => $value) { $this->DB->where($field, $value); } } if (isset($params["where_in"]) && is_array($params["where_in"]) && count($params["where_in"])) { foreach ($params["where_in"] as $field => $value) { $this->DB->where_in($field, $value); } } if (isset($params["where_sql"]) && is_array($params["where_sql"]) && count($params["where_sql"])) { foreach ($params["where_sql"] as $value) { $this->DB->where($value, null, false); } } if (is_array($order_by) && count($order_by) > 0) { foreach ($order_by as $field => $dir) { if (in_array($field, $this->fields)) { $this->DB->order_by($field . " " . $dir); } } } elseif ($order_by) { $this->DB->order_by($order_by); } if (!is_null($page)) { $page = intval($page) ? intval($page) : 1; $this->DB->limit($limits, $limits * ($page - 1)); } $results = $this->DB->get()->result_array(); if (!empty($results) && is_array($results)) { return $this->format_services($results); } return array(); }
public function __construct($entity, $limit = 10, $alias = NULL, $order = [], $context = NULL, Loops $loops = NULL) { //set alias automatically based on classname if (!$alias) { $alias = strtolower(substr($entity, 0, 1)); } $this->alias = $alias; $this->entity = is_object($entity) ? get_class($entity) : $entity; $this->limit = $limit; parent::__construct($context, $loops); $loops = $this->getLoops(); $doctrine = $loops->getService("doctrine"); $this->builder = new QueryBuilder($doctrine->entity_manager); $this->builder->select($alias); $this->builder->from(is_object($entity) ? get_class($entity) : $entity, $alias); foreach ($order as $key => $value) { if (is_array($value) && is_numeric($key)) { $this->builder->addOrderBy($this->alias . "." . $value[0], $value[1]); } else { $this->builder->addOrderBy($this->alias . "." . $key, $value); } } }
/** * Method to build the query * * @access private * @return string query */ protected function _buildQuery() { static $instance; if (!empty($instance)) { return $instance; } $this->_query->select('a.*,u.name,t.megnevezes'); $this->_query->from($this->_default_table . ' AS a left outer join #__temakorok AS t on t.id = a.temakor_id left outer join #__users AS u on u.id = a.user_id'); $this->_buildContentWhere(); $this->_buildContentOrderBy(); $instance = $this->_query->__toString(); return $instance; }
/** * Update link sorter * @param string $type_gid * @param integer $sorter_new * @param integer $link_1 * @param integer $link_2 */ public function update_sorter($type_gid, $id, $sorter_new, $link_1 = 0, $link_2 = 0) { $type = $this->get_linker_type_by_gid($type_gid); if (!$type) { return false; } $this->DB->select('id, sorter')->from($type["table_name"])->where("id", $id); $result = $this->DB->get()->result(); if (empty($result)) { return false; } $sorter_old = intval($result[0]->sorter); if ($sorter_new - $sorter_old == 0) { return false; } $this->DB->select('id, sorter'); $this->DB->from($type["table_name"]); if (!$type["separated"]) { $this->DB->where("id_type", $type["id"]); } if ($link_1) { $this->DB->where("id_link_1", $link_1); } if ($link_2) { $this->DB->where("id_link_2", $link_2); } if ($sorter_new - $sorter_old > 0) { $this->DB->where("sorter >=", $sorter_old); $this->DB->where("sorter <=", $sorter_new); $dir = -1; } else { $this->DB->where("sorter >=", $sorter_new); $this->DB->where("sorter <=", $sorter_old); $dir = 1; } $this->DB->where("id <>", $id); $this->DB->order_by("sorter, date_add DESC"); $result = $this->DB->get()->result(); if (!empty($result)) { foreach ($result as $res_obj) { $this->db->where('id', $res_obj->id); $this->db->update($type["table_name"], array("sorter" => $res_obj->sorter + $dir)); } } $this->db->where('id', $id); $this->db->update($type["table_name"], array("sorter" => $sorter_new)); }
public function get_news_list($lang_id = 1, $module = 'all', $limit = null, $status = 1, $sorter = 'date_created', $order = 'DESC') { $this->fields_news = array_merge($this->fields_news, array("text_{$lang_id} as text")); $this->DB->select(implode(", ", $this->fields_news)); $this->DB->from(NEWS_TABLE); if ($module != 'all') { $this->DB->where($module, '1'); } $this->DB->where('status', $status); if ($sorter) { $this->DB->order_by($sorter . " " . $order); } if ($limit) { $this->DB->limit($limit); } $results = $this->DB->get()->result_array(); if (!empty($results) && is_array($results)) { return $results; } return array(); }
/** * Return number of meberships in data source * * @param array $params sql criteria * @return integer */ protected function _getMembershipsCount($params = null) { $table = isset($params['table']) ? $params['table'] : MEMBERSHIPS_TABLE; $this->DB->select('COUNT(*) AS cnt'); $this->DB->from($table); if (isset($params['where']) && is_array($params['where']) && count($params['where'])) { foreach ($params['where'] as $field => $value) { $this->DB->where($field, $value); } } if (isset($params['where_in']) && is_array($params['where_in']) && count($params['where_in'])) { foreach ($params['where_in'] as $field => $value) { $this->DB->where_in($field, $value); } } if (isset($params['where_not_in']) && is_array($params['where_not_in']) && count($params['where_not_in'])) { foreach ($params['where_not_in'] as $field => $value) { $this->DB->where_not_in($field, $value); } } if (isset($params['where_sql']) && is_array($params['where_sql']) && count($params['where_sql'])) { foreach ($params['where_sql'] as $value) { $this->DB->where($value, null, false); } } $results = $this->DB->get()->result_array(); if (!empty($results) && is_array($results)) { return intval($results[0]['cnt']); } return 0; }
/** * возвращает нужные ряды данных выбранного сортированного отчета * * @param object $sqlite объект sqlite-базы данных * @param string $sort_field имя поля, по которому осуществляется сортировка * @param string $sort_direction направление сортировки * @param integer $page (опционально) номер запрошенной страницы, при отсутствии - отчет полностью * @param integer $per_page (опционально) количество записей на странице * @return array ряды данных отчета */ public function report($sqlite, $sort_field, $sort_direction, $page = NULL, $per_page = NULL) { $sqlite->from('report'); $sqlite->order_by($sort_field, $sort_direction); if (!is_null($page)) { $sqlite->limit($per_page, ($page - 1) * $per_page); } $res = $sqlite->get(); return $res->result_array(); }
/** * Build the `ON` constraints from a `Relationship` instance * * @param object $rel A Relationship instance * @param string $fromAlias Set a specific alias for the `'from'` `Model`. * @param string $toAlias Set a specific alias for `'to'` `Model`. * @param array $constraints Array of additionnal $constraints. * @return array A constraints array. */ public function on($rel, $aliasFrom = null, $aliasTo = null, $constraints = array()) { $model = $rel->from(); $aliasFrom = $aliasFrom ?: $model::meta('name'); $aliasTo = $aliasTo ?: $rel->name(); $keyConstraints = array(); foreach ($rel->key() as $from => $to) { $keyConstraints["{$aliasFrom}.{$from}"] = "{$aliasTo}.{$to}"; } $mapAlias = array($model::meta('name') => $aliasFrom, $rel->name() => $aliasTo); $relConstraints = $this->_on((array) $rel->constraints(), $aliasFrom, $aliasTo, $mapAlias); $constraints = $this->_on($constraints, $aliasFrom, $aliasTo, array()); return $constraints + $relConstraints + $keyConstraints; }
public function set_settings($controller, $module_gid, $method, $data) { $sett_data = array('controller' => $controller, 'module_gid' => $module_gid, 'method' => $method); $settings = $this->get_settings($controller, $module_gid, $method); $sett_data['noindex'] = $settings['noindex'] ? 1 : 0; if (isset($data["noindex"])) { $sett_data['noindex'] = $data['noindex'] ? 1 : 0; } $sett_data['url_template'] = strval($settings['url_template']); if (isset($data["url_template"])) { $sett_data['url_template'] = strval($data["url_template"]); } $sett_data['lang_in_url'] = $settings['lang_in_url'] ? 1 : 0; if (isset($data["lang_in_url"])) { $sett_data['lang_in_url'] = $data['lang_in_url'] ? 1 : 0; } $languages = $this->CI->pg_language->languages; foreach ($languages as $lang_id => $lang_data) { if (isset($data['title'][$lang_id])) { $sett_data['meta_' . $lang_id]['title'] = $data['title'][$lang_id]; } else { $sett_data['meta_' . $lang_id]['title'] = $settings['meta_' . $lang_id]['title']; } if (isset($data['keyword'][$lang_id])) { $sett_data['meta_' . $lang_id]['keyword'] = $data['keyword'][$lang_id]; } else { $sett_data['meta_' . $lang_id]['keyword'] = $settings['meta_' . $lang_id]['keyword']; } if (isset($data['description'][$lang_id])) { $sett_data['meta_' . $lang_id]['description'] = $data['description'][$lang_id]; } else { $sett_data['meta_' . $lang_id]['description'] = $settings['meta_' . $lang_id]['description']; } if (isset($data['header'][$lang_id])) { $sett_data['meta_' . $lang_id]['header'] = $data['header'][$lang_id]; } else { $sett_data['meta_' . $lang_id]['header'] = $settings['meta_' . $lang_id]['header']; } if (isset($data['og_title'][$lang_id])) { $sett_data['og_' . $lang_id]['og_title'] = $data['og_title'][$lang_id]; } else { $sett_data['og_' . $lang_id]['og_title'] = $settings['og_' . $lang_id]['og_title']; } if (isset($data['og_type'][$lang_id])) { $sett_data['og_' . $lang_id]['og_type'] = $data['og_type'][$lang_id]; } else { $sett_data['og_' . $lang_id]['og_type'] = $settings['og_' . $lang_id]['og_type']; } if (isset($data['og_description'][$lang_id])) { $sett_data['og_' . $lang_id]['og_description'] = $data['og_description'][$lang_id]; } else { $sett_data['og_' . $lang_id]['og_description'] = $settings['og_' . $lang_id]['og_description']; } $sett_data['meta_' . $lang_id] = serialize($sett_data['meta_' . $lang_id]); $sett_data['og_' . $lang_id] = serialize($sett_data['og_' . $lang_id]); } $this->DB->select('COUNT(*) AS cnt'); $this->DB->from(SEO_SETTINGS_TABLE); $this->DB->where('controller', $controller); $this->DB->where('module_gid', $module_gid); $this->DB->where('method', $method); $results = $this->DB->get()->result_array(); if (!empty($results) && is_array($results) && intval($results[0]['cnt'])) { $this->DB->where('controller', $controller); $this->DB->where('module_gid', $module_gid); $this->DB->where('method', $method); $this->DB->update(SEO_SETTINGS_TABLE, $sett_data); } else { $this->DB->insert(SEO_SETTINGS_TABLE, $sett_data); } $this->clear_settings_cache(); return; }