public function post_add() { $model = Model_Blog::forge(); $model->set(Input::post()); $model->set(BLOG_CREATED_DATE, DB::expr('now()')); $model->set(DELETE_FLG, '0'); $model->save(); Response::redirect(Config::get('base_url')); }
public static function up() { $table_exists = DBUtil::table_exists(self::$_table_name); if ($table_exists) { return false; } DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'group_id' => ['constraint' => 50, 'type' => 'varchar'], 'group_name' => ['constraint' => 50, 'type' => 'varchar'], 'privacy' => ['constraint' => 255, 'type' => 'varchar'], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci'); DBUtil::create_index(self::$_table_name, 'group_id', 'group_id'); }
public static function up() { $table_exists = DBUtil::table_exists(self::$_table_name); if ($table_exists) { return false; } DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'maintenance' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 0], 'email' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'telephone' => ['constraint' => 12, 'type' => 'varchar', 'null' => true], 'address' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'fb_url' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'shop_name' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci'); DBUtil::create_index(self::$_table_name, 'maintenance', 'maintenance'); }
public static function up() { $table_exists = DBUtil::table_exists(self::$_table_name); if ($table_exists) { return false; } DBUtil::create_table(self::$_table_name, ['order_item_id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'order_id' => ['constraint' => 11, 'type' => 'int'], 'product_id' => ['constraint' => 11, 'type' => 'int'], 'product_price' => ['constraint' => 11, 'type' => 'int'], 'quantity' => ['constraint' => 11, 'type' => 'int'], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')]], ['order_item_id'], true, 'InnoDB', 'utf8_general_ci'); DBUtil::create_index(self::$_table_name, 'order_id', 'order_id'); DBUtil::create_index(self::$_table_name, 'product_id', 'product_id'); }
/** * @author Thuanth6589 <*****@*****.**> * @param array $filters * @return $this */ private function _get_where($filters = array()) { $query = \Fuel\Core\DB::select('m_ss.*', 'm_partner.branch_name', 'm_group.name')->from('m_ss'); $query->join('m_partner', 'left')->on('m_ss.partner_code', '=', 'm_partner.partner_code'); $query->join('m_group', 'left')->on('m_group.m_group_id', '=', 'm_partner.m_group_id'); if (isset($filters['department_id']) && $filters['department_id']) { $query->where('m_partner.department_id', '=', $filters['department_id']); } if (isset($filters['addr1']) && $filters['addr1']) { $query->where('m_ss.addr1', '=', $filters['addr1']); } if (isset($filters['addr2']) && $filters['addr2']) { $query->where('m_ss.addr2', '=', $filters['addr2']); } if (isset($filters['group_id']) && $filters['group_id']) { $query->where('m_partner.m_group_id', '=', $filters['group_id']); } if (isset($filters['partner_code']) && $filters['partner_code']) { $query->where('m_ss.partner_code', '=', $filters['partner_code']); } if (isset($filters['base_code']) && $filters['base_code'] !== '') { $query->where('m_ss.base_code', '=', $filters['base_code']); } if (isset($filters['status']) && $filters['status'] !== '') { $query->where('m_ss.status', '=', $filters['status']); } if (isset($filters['is_available']) && $filters['is_available'] !== '') { $query->where('m_ss.is_available', '=', $filters['is_available']); } if (isset($filters['keyword']) && $filters['keyword']) { $arr_keyword = array_filter(preg_split('/\\s|\\s+| /', trim($filters['keyword']))); $query->and_where_open(); $query->and_where_open(); foreach ($arr_keyword as $k => $v) { $query->where(\Fuel\Core\DB::expr('CONCAT(m_group.name, m_partner.branch_name)'), 'like', '%' . $v . '%'); } $query->and_where_close(); $query->and_where_close(); } if (isset($filters['department_id']) && $filters['department_id']) { $partner_code = Model_Mpartner::get_partnercode_department($filters['department_id']); if (empty($partner_code)) { $partner_code = array(''); } $query->where('m_ss.partner_code', 'IN', $partner_code); } if (isset($filters['limit']) && $filters['limit']) { $query->limit($filters['limit']); } if (isset($filters['offset']) && $filters['offset']) { $query->offset($filters['offset']); } $query->order_by('m_ss.ss_id', 'desc'); return $query; }
public static function up() { $table_exists = DBUtil::table_exists(self::$_table_name); if ($table_exists) { return false; } DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'code' => ['constraint' => 50, 'type' => 'varchar'], 'product_name' => ['type' => 'text'], 'product_description' => ['type' => 'text', 'null' => true], 'product_info' => ['type' => 'text', 'null' => true], 'note' => ['type' => 'text', 'null' => true], 'product_photo' => ['constraint' => 50, 'type' => 'varchar', 'null' => true], 'status' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 2], 'highlight' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 0], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci'); DBUtil::create_index(self::$_table_name, 'code', 'code'); DBUtil::create_index(self::$_table_name, 'status', 'status'); DBUtil::create_index(self::$_table_name, 'highlight', 'highlight'); }
public static function up() { $table_exists = DBUtil::table_exists(self::$_table_name); if ($table_exists) { return false; } DBUtil::create_table(self::$_table_name, ['order_id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'user_id' => ['constraint' => 11, 'type' => 'int'], 'message' => ['type' => 'text', 'null' => true], 'order_email' => ['type' => 'text', 'null' => true], 'order_gender' => ['type' => 'text', 'null' => true], 'order_last_name' => ['type' => 'text', 'null' => true], 'order_first_name' => ['type' => 'text', 'null' => true], 'order_last_name_kana' => ['type' => 'text', 'null' => true], 'order_first_name_kana' => ['type' => 'text', 'null' => true], 'order_tel' => ['type' => 'text', 'null' => true], 'order_fax' => ['type' => 'text', 'null' => true], 'order_zip' => ['type' => 'text', 'null' => true], 'order_addr' => ['type' => 'text', 'null' => true], 'payment_total' => ['constraint' => 11, 'type' => 'int'], 'payment_method' => ['constraint' => 1, 'type' => 'int'], 'payment_status' => ['constraint' => 1, 'type' => 'int', 'default' => 1], 'payment_date' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00'], 'del_flg' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 0], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['order_id'], true, 'InnoDB', 'utf8_general_ci'); DBUtil::create_index(self::$_table_name, 'user_id', 'user_id'); DBUtil::create_index(self::$_table_name, 'payment_method', 'payment_method'); DBUtil::create_index(self::$_table_name, 'payment_status', 'payment_status'); DBUtil::create_index(self::$_table_name, 'del_flg', 'del_flg'); }
public static function up() { $table_exists = DBUtil::table_exists(self::$_table_name); if ($table_exists) { return false; } DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'username' => ['constraint' => 32, 'type' => 'varchar'], 'email' => ['constraint' => 255, 'type' => 'varchar'], 'password' => ['constraint' => 255, 'type' => 'varchar'], 'login_hash' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'last_login' => ['constraint' => 11, 'type' => 'int', 'default' => 0], 'group' => ['constraint' => 11, 'type' => 'int', 'default' => 1], 'password_code' => ['constraint' => 32, 'type' => 'varchar', 'null' => true], 'full_name' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'gender' => ['constraint' => 1, 'type' => 'int', 'default' => 0], 'birthday' => ['constraint' => 10, 'type' => 'varchar', 'null' => true], 'address' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'telephone' => ['constraint' => 12, 'type' => 'varchar', 'null' => true], 'user_photo' => ['constraint' => 50, 'type' => 'varchar', 'null' => true], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci'); DBUtil::create_index(self::$_table_name, 'username', 'username'); DBUtil::create_index(self::$_table_name, 'email', 'email'); DBUtil::create_index(self::$_table_name, 'password', 'password'); DBUtil::create_index(self::$_table_name, 'login_hash', 'login_hash'); DBUtil::create_index(self::$_table_name, 'group', 'group'); }
/** * @author DangBc <*****@*****.**> * @param is where */ public function _where($filter = array()) { $is_where = DB::select('*')->from('m_partner')->join('m_group', 'INNER')->on('m_partner.m_group_id', '=', 'm_group.m_group_id')->order_by('m_partner.created_at', 'desc'); if (isset($filter['type']) && $filter['type'] != '') { $is_where->where('type', '=', $filter['type']); } if (isset($filter['addr1']) && $filter['addr1'] != '') { $is_where->where('addr1', '=', $filter['addr1']); } if (isset($filter['partner_code']) && $filter['partner_code'] != '') { $is_where->where('partner_code', '=', $filter['partner_code']); } if (isset($filter['status'])) { $is_where->where('status', '=', $filter['status']); } if (isset($filter['keyword']) && $filter['keyword'] != '') { $arr_keyword = array_filter(preg_split('/\\s|\\s+| /', trim($filter['keyword']))); $is_where->and_where_open(); $is_where->and_where_open(); foreach ($arr_keyword as $k => $v) { $is_where->where(\Fuel\Core\DB::expr('CONCAT(m_group.name, m_partner.branch_name)'), 'like', '%' . $v . '%'); } $is_where->and_where_close(); $is_where->and_where_close(); } if (isset($filter['department_id']) && $filter['department_id'] != '') { $is_where->where('department_id', '=', $filter['department_id']); } if (isset($filter['group_id']) && $filter['group_id'] != '') { $is_where->where('m_partner.m_group_id', '=', $filter['group_id']); } if (isset($filter['limit'])) { $is_where->limit($filter['limit']); } if (isset($filter['offset'])) { $is_where->offset($filter['offset']); } return $is_where; }
public function _where($filter = array()) { $is_where = DB::select('person.*', DB::expr('person.name as p_name'), 'employment.contact_result', 'employment.review_date', 'employment.classification', 'employment.adoption_result', 'employment.registration_expiration', 'employment.rank', 'employment.register_date', 'employment.contract_date', 'employment.contract_result', 'employment.hire_date', 'employment.work_confirmation', 'employment.employee_code', 'employment.code_registration_date', 'm_ss.ss_name', 'm_partner.branch_name', 'job.job_id', DB::expr('m_group.name as g_name'), 'm_partner.department_id', 'm_user.name', 'sssale.sale_name', 'sssale.sale_type', array('m_group.name', 'm_group_name'), array('sssale2.sale_name', 'job_sale_name'), array('m_ss2.ss_name', 'job_ss_name'))->from('person')->join('job', 'LEFT')->on('job.job_id', '=', 'person.job_id'); $is_where->join('sssale', 'LEFT')->on('person.sssale_id', '=', 'sssale.sssale_id'); $is_where->join('m_ss', 'LEFT')->on('m_ss.ss_id', '=', 'sssale.ss_id'); $is_where->join('m_partner', 'LEFT')->on('m_partner.partner_code', '=', 'm_ss.partner_code'); $is_where->join('m_group', 'LEFT')->on('m_partner.m_group_id', '=', 'm_group.m_group_id'); $is_where->join('employment', 'LEFT')->on('employment.person_id', '=', 'person.person_id'); $is_where->join('m_user', 'LEFT')->on('m_partner.user_id', '=', 'm_user.user_id'); $is_where->join(array('sssale', 'sssale2'), 'LEFT')->on('job.sssale_id', '=', 'sssale2.sssale_id'); $is_where->join(array('m_ss', 'm_ss2'), 'LEFT')->on('sssale2.ss_id', '=', 'm_ss2.ss_id'); $is_where->order_by('person_id', 'desc'); $is_where->group_by('person_id'); if (isset($filter['addr1']) && $filter['addr1'] != '') { $is_where->and_where('person.addr1', 'like', '%' . $filter['addr1'] . '%'); } if (isset($filter['addr2']) && $filter['addr2'] != '') { $arr_addr = array_filter(preg_split('/\\s|\\s+| /', trim($filter['addr2']))); $is_where->and_where_open(); $is_where->and_where_open(); foreach ($arr_addr as $k => $v) { $is_where->where(\Fuel\Core\DB::expr('CONCAT(person.addr2, person.addr3)'), 'like', '%' . $v . '%'); } $is_where->and_where_close(); $is_where->and_where_close(); } if (isset($filter['status']) && $filter['status'] != '') { $is_where->where('person.status', '=', $filter['status']); } if (isset($filter['email']) && $filter['email'] != '') { $is_where->and_where_open(); $is_where->where('mail_addr1', 'LIKE', '%' . $filter['email'] . '%')->or_where('mail_addr2', 'LIKE', '%' . $filter['email'] . '%'); $is_where->and_where_close(); } if (isset($filter['name']) && $filter['name'] != '') { $is_where->and_where_open(); $is_where->where('person.name', 'LIKE', '%' . $filter['name'] . '%'); $is_where->or_where('person.name_kana', 'LIKE', '%' . $filter['name'] . '%'); $is_where->and_where_close(); } if (isset($filter['phone']) && $filter['phone'] != '') { $is_where->and_where_open(); $is_where->where('person.tel', 'LIKE', '%' . $filter['phone'] . '%')->or_where('person.mobile', 'LIKE', '%' . $filter['phone'] . '%'); $is_where->and_where_close(); } if (isset($filter['group_id']) && $filter['group_id'] != '') { $is_where->and_where_open(); $is_where->where('m_partner.m_group_id', '=', $filter['group_id']); $is_where->and_where_close(); } if (isset($filter['partner_code']) && $filter['partner_code'] != '') { $is_where->and_where_open(); $is_where->where('m_ss.partner_code', '=', $filter['partner_code']); $is_where->and_where_close(); } if (isset($filter['ss_id']) && $filter['ss_id'] != '') { $is_where->and_where_open(); $is_where->where('sssale.ss_id', '=', $filter['ss_id']); $is_where->and_where_close(); } if (isset($filter['ss_name']) && $filter['ss_name'] != '') { $is_where->and_where_open(); $is_where->where('ss_name', 'LIKE', '%' . $filter['ss_name'] . '%'); $is_where->and_where_close(); } if (isset($filter['branch_name']) && $filter['branch_name'] != '') { $is_where->and_where_open(); $is_where->where('branch_name', 'LIKE', '%' . $filter['branch_name'] . '%'); $is_where->and_where_close(); } if (isset($filter['to_date']) && $filter['to_date'] != '') { $filter_date = strtotime($filter['to_date']) + 86399; $date_to = date('Y-m-d H:i:s', $filter_date); } if (isset($filter['from_date']) && isset($filter['to_date']) && $filter['from_date'] != '' && $filter['to_date'] == '') { $is_where->and_where_open(); $is_where->where('application_date', '>=', $filter['from_date']); $is_where->and_where_close(); } if (isset($filter['to_date']) && $filter['from_date'] == '' && $filter['to_date'] != '') { $is_where->and_where_open(); $is_where->and_where('application_date', '<=', $date_to); $is_where->and_where_close(); } if (isset($filter['from_date']) && $filter['from_date'] != '' && $filter['to_date'] != '') { $is_where->and_where_open(); $is_where->where('application_date', '>=', $filter['from_date']); $is_where->and_where('application_date', '<=', $date_to); $is_where->and_where_close(); } if (isset($filter['gender']) && $filter['gender'] != '') { $is_where->and_where_open(); $is_where->where('gender', 'IN', $filter['gender']); $is_where->and_where_close(); } if (isset($filter['age_from']) && $filter['age_from'] != '' && $filter['age_to'] != '' && isset($filter['age_to'])) { $is_where->and_where_open(); $is_where->where(DB::expr("DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(birthday, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(birthday, '00-%m-%d'))"), '>=', $filter['age_from']); $is_where->where(DB::expr("DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(birthday, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(birthday, '00-%m-%d'))"), '<=', $filter['age_to']); $is_where->and_where_close(); } elseif (isset($filter['age_from']) && $filter['age_from'] != '' && $filter['age_to'] == '') { $is_where->and_where_open(); $is_where->where(DB::expr("DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(birthday, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(birthday, '00-%m-%d'))"), '>=', $filter['age_from']); $is_where->and_where_close(); } elseif (isset($filter['age_to']) && $filter['age_to'] != '' && $filter['age_from'] == '') { $is_where->and_where_open(); $is_where->where(DB::expr("DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(birthday, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(birthday, '00-%m-%d'))"), '<=', $filter['age_to']); $is_where->and_where_close(); } $datas = array(); for ($i = 1; $i <= 3; $i++) { $datas['license' . $i] = ''; if (isset($filter['license' . $i])) { $is_where->and_where_open(); foreach ($filter['license' . $i] as $key => $value) { $datas['license' . $i] .= ',' . $value; } if (isset($datas['license' . $i]) && $datas['license' . $i] != '') { $x = explode(',', $datas['license' . $i]); unset($x[0]); foreach ($x as $key => $value) { $is_where->or_where(DB::expr('FIND_IN_SET("' . $value . '",license' . $i . ')')); } } $is_where->and_where_close(); } } if (isset($filter['review_result']) && $filter['review_result'] != '') { $is_where->and_where_open(); if (isset($filter['review_result'][0]) && !isset($filter['review_result'][1])) { $is_where->where('review_result', '=', 1); } elseif (!isset($filter['review_result'][0]) && isset($filter['review_result'][1])) { $is_where->where('review_result', '<>', 1); $is_where->or_where('review_result', 'is', null); } else { $is_where->where(DB::expr(1, '=', 1)); } $is_where->and_where_close(); } if (isset($filter['rank']) && $filter['rank'] != '') { $is_where->and_where_open(); $is_where->where('rank', 'IN', $filter['rank']); $is_where->and_where_close(); } if (isset($filter['contract_result']) && $filter['contract_result'] != '') { $is_where->and_where_open(); $is_where->where('contract_result', 'IN', $filter['contract_result']); $is_where->and_where_close(); } if (isset($filter['adoption_result']) && $filter['adoption_result'] != '') { $is_where->and_where_open(); $is_where->where('adoption_result', 'IN', $filter['adoption_result']); $is_where->and_where_close(); } if (isset($filter['user_id']) && $filter['user_id'] != '') { $is_where->and_where_open(); $is_where->where('m_partner.user_id', '=', $filter['user_id']); $is_where->and_where_close(); } if (isset($filter['department']) && $filter['department'] != '' && $filter['user_id'] == '') { $list_user_id = array(); $model_user = new \Model_Muser(); $list_users = $model_user->get_list_user_by_departmentid($filter['department']); foreach ($list_users as $key => $val) { $list_user_id[] = $val['user_id']; } if (count($list_user_id)) { $is_where->and_where_open(); $is_where->where('m_partner.user_id', 'in', $list_user_id); $is_where->and_where_close(); } } if (isset($filter['media_name']) && $filter['media_name'] != '') { $model_m_media = new \Model_Mmedia(); $model_m_post = new \Model_Mpost(); $model_order = new \Model_Orders(); $media_id_list = $model_m_media->get_media_id_list_by_name($filter['media_name']); if (count($media_id_list) == 0) { $is_where->and_where_open(); $is_where->where('person.order_id', '=', '-1'); $is_where->and_where_close(); return $is_where; } foreach ($media_id_list as $key => $value) { $media_id_list[$key] = $value['m_media_id']; } $post_id_list = $model_m_post->get_list_post_id($media_id_list); if (count($post_id_list) == 0) { $is_where->and_where_open(); $is_where->where('person.order_id', '=', '-1'); $is_where->and_where_close(); return $is_where; } foreach ($post_id_list as $key => $value) { $post_id_list[$key] = $value['post_id']; } $order_id_list = $model_order->get_order_id_list($post_id_list); if (count($order_id_list) == 0) { $is_where->and_where_open(); $is_where->where('person.order_id', '=', '-1'); $is_where->and_where_close(); return $is_where; } foreach ($order_id_list as $key => $value) { $order_id_list[$key] = $value['order_id']; } $is_where->and_where_open(); $is_where->where('person.order_id', 'in', $order_id_list); $is_where->and_where_close(); } if (isset($filter['job_id']) && !empty($filter['job_id'])) { $is_where->where('person.job_id', '=', $filter['job_id']); } if (isset($filter['order_id']) && $filter['order_id']) { $is_where->where('person.order_id', '=', $filter['order_id']); } if (isset($filter['array_person'])) { $filter['array_person'] = empty($filter['array_person']) ? array(0) : $filter['array_person']; $is_where->where('person.person_id', 'in', $filter['array_person']); } if (isset($filter['reprinted_via']) && $filter['reprinted_via']) { $is_where->where('person.reprinted_via', '=', $filter['reprinted_via']); } if (isset($filter['sale_type']) && $filter['sale_type']) { $sql = 'select sssale_id from sssale where sale_type = ' . $filter['sale_type']; $rs = \Fuel\Core\DB::query($sql)->execute(); $sssale_id = [-1]; foreach ($rs as $item) { $sssale_id[] = $item['sssale_id']; } $is_where->where('person.sssale_id', 'in', $sssale_id); } if (isset($filter['limit'])) { $is_where->limit($filter['limit']); } if (isset($filter['offset'])) { $is_where->offset($filter['offset']); } return $is_where; }
/** * find for pagination * * @param mixed $params array - like model find param * Database_Query_Builder_Select instance - you can use raw DB model * boolean $need_count * @return array * |-- list (array) * `-- count (int) */ public function find($params, $need_count = true) { if ($params instanceof \Fuel\Core\Database_Query_Builder_Select) { $query_cnt = clone $params; $query_cnt->select_array(array(\Fuel\Core\DB::expr('COUNT(*) as cnt')), true); $query_list = $params; $query_list->limit($this->per_page)->offset($this->get_offset()); } else { $default = array('select' => array('*'), 'where' => array(), 'limit' => $this->per_page, 'offset' => $this->get_offset(), 'order_by' => array(array('id', 'ASC'))); $params = array_merge($default, $params); if (!isset($params['from'])) { throw new \Fuel\Core\Database_Exception('Query "from" not found!'); } $query_list = \Fuel\Core\DB::select_array($params['select'])->from($params['from'])->limit($params['limit'])->offset($params['offset']); $query_cnt = \Fuel\Core\DB::select(\Fuel\Core\DB::expr('COUNT(*) as cnt'))->from($params['from']); foreach ($params['where'] as $w) { if (count($w) > 1) { call_user_func_array(array($query_list, 'where'), $w); call_user_func_array(array($query_cnt, 'where'), $w); } else { $query_list->where($w); $query_cnt->where($w); } } foreach ($params['order_by'] as $order) { call_user_func_array(array($query_list, 'order_by'), $order); } if (isset($params['group_by'])) { if (is_string($params['group_by'])) { $params['group_by'] = array($params['group_by']); } call_user_func_array(array($query_list, 'group_by'), $params['group_by']); call_user_func_array(array($query_cnt, 'group_by'), $params['group_by']); } } $list = $query_list->execute()->as_array(); $cnt = 0; if ($need_count) { $cnt = $query_cnt->execute()->as_array(); if (count($cnt) > 1) { $cnt = count($cnt); } else { $cnt = \Arr::get(\Arr::get($cnt, 0, array()), 'cnt', 0); } } // set items automatically $this->item_list = $list; $this->total_items = $cnt; return array('list' => $list, 'count' => $cnt); }