source: pro-violet-viettel/sourcecode/application/modules/admin/models/collabolator_model.php @ 379

Last change on this file since 379 was 374, checked in by quyenla, 11 years ago

collaborator order sourcecode

File size: 2.2 KB
Line 
1<?php
2if (!defined('BASEPATH'))
3    exit('No direct script access allowed');
4
5class Collabolator_model extends MY_Model {
6
7    protected $table_name = 'tblcollaborator';
8    protected $id_name = 'id';
9
10    function __construct() {
11        parent::__construct();
12    }
13
14    function getCollaborator($data) {
15        $sql = "SELECT * FROM " . $this->table_name;
16        if ($data['keyword']) {
17            if ($data['search_field'] == "cellphone") {
18                $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')";
19            } else {
20                $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%') ";
21            }
22        }
23
24        $order = "";
25        if ($data['sorting_order'] != "sorting") {
26            if ($data['sorting_field'] != "money") {
27                $sort = "DESC";
28                if ($data['sorting_order'] == "sorting_asc")
29                    $sort = "ASC";
30                $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
31            }
32        }
33       
34        return $this->db->query($sql . " " . $order . " LIMIT " . $data['start'] . ", " . $data['perpage'] . " ")->result_array();
35    }
36
37    function isExist($data) {
38        $sql = "SELECT COUNT(id) as total FROM " . $this->table_name . " WHERE " . $data['field'] . " = '" . $data['value'] . "' LIMIT 1";
39        if ($this->db->query($sql)->row_array()['total'] == 1) {
40            return true;
41        } else {
42            return false;
43        }
44    }
45
46    function countCollaborator($data) {
47        $sql = "SELECT COUNT(id) as total FROM " . $this->table_name;
48        if ($data['keyword']) {
49            if ($data['search_field'] == "cellphone") {
50                $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')";
51            } else {
52                $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%') ";
53            }
54        }
55        if (isset($this->db->query($sql)->row_array()['total']))
56        {
57        return $this->db->query($sql)->row_array()['total'];
58        }
59        else
60        {
61            return 0;
62        }
63    }
64
65}
Note: See TracBrowser for help on using the repository browser.