1 | <?php
|
---|
2 | if (!defined('BASEPATH'))
|
---|
3 | exit('No direct script access allowed');
|
---|
4 |
|
---|
5 | class 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 (isset($data['keyword'])) {
|
---|
49 | $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%') ";
|
---|
50 | }
|
---|
51 |
|
---|
52 | return $this->db->query($sql)->row_array()['total'];
|
---|
53 | }
|
---|
54 |
|
---|
55 | }
|
---|