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)
|
---|
37 | {
|
---|
38 | $from = date("Y-m-d 00:00:00",$from);
|
---|
39 | $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."'";
|
---|
40 |
|
---|
41 | $result = $this->db->query($sql)->result_array();
|
---|
42 | foreach ($result as $index=>$paidlog)
|
---|
43 | {
|
---|
44 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
45 | }
|
---|
46 | return $result;
|
---|
47 | }
|
---|
48 | function getCountCollaboratorUser($data)
|
---|
49 | {
|
---|
50 | $order = "";
|
---|
51 | if ($data['sorting_order'] != "sorting") {
|
---|
52 |
|
---|
53 | $sort = "DESC";
|
---|
54 | if ($data['sorting_order'] == "sorting_asc")
|
---|
55 | $sort = "ASC";
|
---|
56 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
57 |
|
---|
58 | }
|
---|
59 | $where="";
|
---|
60 | if ($data['keyword']) {
|
---|
61 | if ($data['search_field'] == "cellphone") {
|
---|
62 | $where.=" WHERE (tblcollaborator.cellphone LIKE '%" . $data['keyword'] . "%')";
|
---|
63 | } else {
|
---|
64 | $where.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%') ";
|
---|
65 | }
|
---|
66 | }
|
---|
67 | // $from = date("Y-m-d 00:00:00",$from);
|
---|
68 | $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'] . " ";
|
---|
69 | echo $sql;
|
---|
70 | $result = $this->db->query($sql)->result_array();
|
---|
71 | foreach ($result as $index=>$paidlog)
|
---|
72 | {
|
---|
73 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
74 | }
|
---|
75 |
|
---|
76 | return $result;
|
---|
77 | }
|
---|
78 | function isExist($data) {
|
---|
79 | $sql = "SELECT COUNT(id) as total FROM " . $this->table_name . " WHERE " . $data['field'] . " = '" . $data['value'] . "'";
|
---|
80 | if (isset($data['id']))
|
---|
81 | {
|
---|
82 | $id=$data['id'];
|
---|
83 | $sql.=" AND id <> ".$id." LIMIT 1";
|
---|
84 | }
|
---|
85 | $result = $this->db->query($sql)->row_array();
|
---|
86 | if ($result['total'] == 1) {
|
---|
87 | return true;
|
---|
88 | } else {
|
---|
89 | return false;
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | function countCollaborator($data) {
|
---|
94 | $sql = "SELECT COUNT(id) as total FROM " . $this->table_name;
|
---|
95 | if ($data['keyword']) {
|
---|
96 | if ($data['search_field'] == "cellphone") {
|
---|
97 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')";
|
---|
98 | } else {
|
---|
99 | $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%') ";
|
---|
100 | }
|
---|
101 | }
|
---|
102 | $result = $this->db->query($sql)->row_array();
|
---|
103 | return $result['total'];
|
---|
104 | }
|
---|
105 | function getCollaborator($id)
|
---|
106 | {
|
---|
107 | $sql="SELECT * FROM ".$this->table_name." WHERE id=".$id." LIMIT 1";
|
---|
108 | $result = $this->db->query($sql)->row_array();
|
---|
109 | return $result;
|
---|
110 | }
|
---|
111 |
|
---|
112 | }
|
---|