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 getCollaborators($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 |
|
---|
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'] . "'";
|
---|
39 | if (isset($data['id']))
|
---|
40 | {
|
---|
41 | $id=$data['id'];
|
---|
42 | $sql.=" AND id <> ".$id." LIMIT 1";
|
---|
43 | }
|
---|
44 | $result = $this->db->query($sql)->row_array();
|
---|
45 | if ($result['total'] == 1) {
|
---|
46 | return true;
|
---|
47 | } else {
|
---|
48 | return false;
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | function countCollaborator($data) {
|
---|
53 | $sql = "SELECT COUNT(id) as total FROM " . $this->table_name;
|
---|
54 | if ($data['keyword']) {
|
---|
55 | if ($data['search_field'] == "cellphone") {
|
---|
56 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')";
|
---|
57 | } else {
|
---|
58 | $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%') ";
|
---|
59 | }
|
---|
60 | }
|
---|
61 | $result = $this->db->query($sql)->row_array();
|
---|
62 | return $result['total'];
|
---|
63 | }
|
---|
64 | function getCollaborator($id)
|
---|
65 | {
|
---|
66 | $sql="SELECT * FROM ".$this->table_name." WHERE id=".$id." LIMIT 1";
|
---|
67 | $result = $this->db->query($sql)->row_array();
|
---|
68 | return $result;
|
---|
69 | }
|
---|
70 |
|
---|
71 | }
|
---|