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 | function getAllCollaboratorUser($from,$id=false)
|
---|
37 | {
|
---|
38 | $from = date("Y-m-d 00:00:00",$from);
|
---|
39 | $where="";
|
---|
40 | if ($id)
|
---|
41 | {
|
---|
42 | $where = " AND tbluser.collaborator = $id ";
|
---|
43 | }
|
---|
44 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id WHERE tbluser.created_time > '".$from."'".$where."";
|
---|
45 |
|
---|
46 | $result = $this->db->query($sql)->result_array();
|
---|
47 | foreach ($result as $index=>$paidlog)
|
---|
48 | {
|
---|
49 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
50 | }
|
---|
51 | return $result;
|
---|
52 | }
|
---|
53 | function countCountCollaboratorUser($data)
|
---|
54 | {
|
---|
55 | $order = "";
|
---|
56 | if ($data['sorting_order'] != "sorting") {
|
---|
57 |
|
---|
58 | $sort = "DESC";
|
---|
59 | if ($data['sorting_order'] == "sorting_asc")
|
---|
60 | $sort = "ASC";
|
---|
61 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
62 |
|
---|
63 | }
|
---|
64 | $where="";
|
---|
65 | if ($data['keyword']) {
|
---|
66 | if ($data['search_field'] == "cellphone") {
|
---|
67 | $where.=" WHERE (tblcollaborator.cellphone LIKE '%" . $data['keyword'] . "%')";
|
---|
68 | } else {
|
---|
69 | $where.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%') ";
|
---|
70 | }
|
---|
71 | }
|
---|
72 | // $from = date("Y-m-d 00:00:00",$from);
|
---|
73 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time, COUNT(tbluser.collaborator) as total_user FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id ".$where." GROUP BY tblcollaborator.id ".$order." ";
|
---|
74 |
|
---|
75 | $result = $this->db->query($sql)->result_array();
|
---|
76 |
|
---|
77 |
|
---|
78 | return count($result);
|
---|
79 | }
|
---|
80 | function getCountCollaboratorUser($data)
|
---|
81 | {
|
---|
82 | $order = "";
|
---|
83 | if ($data['sorting_order'] != "sorting") {
|
---|
84 |
|
---|
85 | $sort = "DESC";
|
---|
86 | if ($data['sorting_order'] == "sorting_asc")
|
---|
87 | $sort = "ASC";
|
---|
88 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
89 |
|
---|
90 | }
|
---|
91 | $where="";
|
---|
92 | if ($data['keyword']) {
|
---|
93 | if ($data['search_field'] == "cellphone") {
|
---|
94 | $where.=" WHERE (tblcollaborator.cellphone LIKE '%" . $data['keyword'] . "%')";
|
---|
95 | } else {
|
---|
96 | $where.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%') ";
|
---|
97 | }
|
---|
98 | }
|
---|
99 | // $from = date("Y-m-d 00:00:00",$from);
|
---|
100 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time, COUNT(tbluser.collaborator) as total_user FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id ".$where." GROUP BY tblcollaborator.id ".$order." LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
|
---|
101 |
|
---|
102 | $result = $this->db->query($sql)->result_array();
|
---|
103 | foreach ($result as $index=>$paidlog)
|
---|
104 | {
|
---|
105 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
106 | }
|
---|
107 |
|
---|
108 | return $result;
|
---|
109 | }
|
---|
110 |
|
---|
111 | function countCountCollaboratorUsers($data)
|
---|
112 | {
|
---|
113 | $order = "";
|
---|
114 | if ($data['sorting_order'] != "sorting") {
|
---|
115 |
|
---|
116 | $sort = "DESC";
|
---|
117 | if ($data['sorting_order'] == "sorting_asc")
|
---|
118 | $sort = "ASC";
|
---|
119 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
120 |
|
---|
121 | }
|
---|
122 | $where="";
|
---|
123 | if ($data['keyword']) {
|
---|
124 | if ($data['search_field'] == "cellphone") {
|
---|
125 | $where.=" WHERE (tbluser.cellphone LIKE '%" . $data['keyword'] . "%')";
|
---|
126 | }
|
---|
127 | }
|
---|
128 | // $from = date("Y-m-d 00:00:00",$from);
|
---|
129 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id ".$where." AND tbluser.collaborator = ".$data['id']." ".$order."";
|
---|
130 |
|
---|
131 | $result = $this->db->query($sql)->result_array();
|
---|
132 | foreach ($result as $index=>$paidlog)
|
---|
133 | {
|
---|
134 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
135 | }
|
---|
136 |
|
---|
137 | return count($result);
|
---|
138 | }
|
---|
139 | function getCountCollaboratorUsers($data)
|
---|
140 | {
|
---|
141 | $order = "";
|
---|
142 | if ($data['sorting_order'] != "sorting") {
|
---|
143 |
|
---|
144 | $sort = "DESC";
|
---|
145 | if ($data['sorting_order'] == "sorting_asc")
|
---|
146 | $sort = "ASC";
|
---|
147 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
148 |
|
---|
149 | }
|
---|
150 | $where="";
|
---|
151 | if ($data['keyword']) {
|
---|
152 | if ($data['search_field'] == "cellphone") {
|
---|
153 | $where.=" WHERE (tbluser.cellphone LIKE '%" . $data['keyword'] . "%')";
|
---|
154 | }
|
---|
155 | }
|
---|
156 | // $from = date("Y-m-d 00:00:00",$from);
|
---|
157 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id ".$where." AND tbluser.collaborator = ".$data['id']." ".$order." LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
|
---|
158 | $result = $this->db->query($sql)->result_array();
|
---|
159 | foreach ($result as $index=>$paidlog)
|
---|
160 | {
|
---|
161 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
162 | }
|
---|
163 |
|
---|
164 | return $result;
|
---|
165 | }
|
---|
166 |
|
---|
167 | function isExist($data) {
|
---|
168 | $sql = "SELECT COUNT(id) as total FROM " . $this->table_name . " WHERE " . $data['field'] . " = '" . $data['value'] . "'";
|
---|
169 | if (isset($data['id']))
|
---|
170 | {
|
---|
171 | $id=$data['id'];
|
---|
172 | $sql.=" AND id <> ".$id." LIMIT 1";
|
---|
173 | }
|
---|
174 | $result = $this->db->query($sql)->row_array();
|
---|
175 | if ($result['total'] == 1) {
|
---|
176 | return true;
|
---|
177 | } else {
|
---|
178 | return false;
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | function countCollaborator($data) {
|
---|
183 | $sql = "SELECT COUNT(id) as total FROM " . $this->table_name;
|
---|
184 | if ($data['keyword']) {
|
---|
185 | if ($data['search_field'] == "cellphone") {
|
---|
186 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')";
|
---|
187 | } else {
|
---|
188 | $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%') ";
|
---|
189 | }
|
---|
190 | }
|
---|
191 | $result = $this->db->query($sql)->row_array();
|
---|
192 | return $result['total'];
|
---|
193 | }
|
---|
194 | function getCollaborator($id)
|
---|
195 | {
|
---|
196 | $sql="SELECT * FROM ".$this->table_name." WHERE id=".$id." LIMIT 1";
|
---|
197 | $result = $this->db->query($sql)->row_array();
|
---|
198 | return $result;
|
---|
199 | }
|
---|
200 |
|
---|
201 | }
|
---|