PageRenderTime 67ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/application/models/cts_indicator_model.php

https://gitlab.com/bipsahu/ptcs
PHP | 265 lines | 163 code | 37 blank | 65 comment | 20 complexity | e351342363ca67eab5a05bda9365bb11 MD5 | raw file
  1. <?php
  2. /*
  3. * model class that manipulates indicator table
  4. * */
  5. class cts_indicator_model extends CI_Model
  6. {
  7. /*
  8. * Insert Indicator to indicator tables
  9. * @params : post data
  10. * @return : boolean
  11. * */
  12. public function insert_indicator_details()
  13. {
  14. if ($this->input->is_ajax_request())
  15. {
  16. $formData = $this->input->post("indicator");
  17. $data['indicator_name'] = $formData[0]["value"];
  18. $data['task_category_id'] = $formData[1]["value"];
  19. // print_r($_POST);die;
  20. }
  21. else
  22. {
  23. $data['indicator_name'] = $this->input->post("indicator_name");
  24. $data['task_category_id'] = $this->input->post("task_category");
  25. }
  26. $query_result = $this->db->get_where('indicators', array(
  27. 'indicator_name' => $data['indicator_name'],
  28. 'task_category_id' => $data['task_category_id']
  29. ));
  30. if ($query_result->num_rows() == 1)
  31. {
  32. if ($this->input->is_ajax_request())
  33. {
  34. echo json_encode(false);
  35. }
  36. else
  37. {
  38. return false;
  39. }
  40. }
  41. else
  42. {
  43. $result = $this->db->insert('indicators', $data);
  44. if ($this->input->is_ajax_request())
  45. {
  46. echo json_encode($this->db->insert_id());
  47. }
  48. else
  49. {
  50. return $result;
  51. }
  52. }
  53. }
  54. public function insert_indicator()
  55. {
  56. $data = array(
  57. 'indicator_name' => $this->input->post('indicator_name')
  58. );
  59. $result = $this->db->get_where('indicators', array('indicator_name' => $data['indicator_name']));
  60. if ($result->num_rows >= 1) {
  61. return false;
  62. } else {
  63. $result = $this->db->insert('indicators', $data);
  64. $result = $this->db->get_where('indicators', array('indicator_id' => $this->db->insert_id()));
  65. return $result;
  66. }
  67. }
  68. public function insert_new_indicator()
  69. {
  70. $data = array(
  71. 'indicator_name' => $this->input->post('indicator_name')
  72. );
  73. $result = $this->db->get_where('indicators', array('indicator_name' => $data['indicator_name']));
  74. if ($result->num_rows == 1) {
  75. return false;
  76. } else {
  77. $result = $this->db->insert('indicators', $data);
  78. return $result;
  79. }
  80. }
  81. public function edit_indicator_by_id($indicator_id)
  82. {
  83. $data = array(
  84. 'indicator' => $this->input->post('indicator')
  85. );
  86. $result = $this->db->get_where('indicator', array('indicator' => $data['indicator']));
  87. if ($result->num_rows >= 1) {
  88. return false;
  89. } else {
  90. $this->db->where('indicator_id', $indicator_id);
  91. $result = $this->db->update('indicator', $data);
  92. return $result;
  93. }
  94. }
  95. /*
  96. * get indicator_name from indicators table by the Indicator id
  97. *
  98. * @params : indicator_id
  99. * @return : array
  100. * */
  101. public function get_details_of_indicator_by_id($indicator_id)
  102. {
  103. $result = $this->db->get_where('indicators', array('indicator_id' => $indicator_id))->result_array();
  104. return $result[0]["indicator_name"];
  105. }
  106. public function search_indicator_detail($key)
  107. {
  108. $result = $this->db->query("select * from indicator where indicator like '%" . $key . "%'");
  109. $indicators = array();
  110. foreach ($result->result() as $row) {
  111. $indicator = "";
  112. $indicator .= $row->indicator;
  113. $indicators[] = $indicator;
  114. }
  115. echo json_encode($indicators);
  116. }
  117. /*
  118. * Get all indicators from indicators table
  119. * @params : data limit, resource start value (gatting chunks of datas)
  120. * @return : object of db resource $query
  121. * */
  122. public function getIndicators($limit = NULL, $start = NULL)
  123. {
  124. $this->db->order_by("indicator_id", "asc");
  125. if ($start != NULL && $limit != NULL)
  126. $this->db->limit($limit, $start);
  127. $query = $this->db->get('indicators')->result_array();
  128. return $query;
  129. }
  130. public function getIndicator()
  131. {
  132. $result = $this->db->get('indicators');
  133. return $result->result();
  134. }
  135. public function get_indicator_with_type()
  136. {
  137. $this->db->select('*');
  138. $this->db->from('indicators');
  139. $this->db->order_by("indicator_name", "asc");
  140. // $this->db->join('indicators_type','indicators.indicator_type = indicators_type.id ');
  141. $result = $this->db->get();
  142. return $result->result_array();
  143. }
  144. public function show_all_indicator_for_final_report()
  145. {
  146. $result1 = $this->db->get('indicator');
  147. return $result1;
  148. }
  149. public function delete_indicator_by_id($indicator_id)
  150. {
  151. $result = $this->db->delete('indicators', array('indicator_id' => $indicator_id));
  152. return $result;
  153. }
  154. public function check_indicator()
  155. {
  156. $indicator = $this->input->post('indicator');
  157. $result = $this->db->get_where('indicator', array('indicator' => $indicator));
  158. if ($result->num_rows() >= 1) {
  159. return true;
  160. } else {
  161. return false;
  162. }
  163. }
  164. public function get_all_indicator()
  165. {
  166. $result = $this->db->query('SELECT i.indicator_id AS child_project_id,i.indicator_name AS child_name,c.`indicator_id`,c.`indicator_name` AS parent_name FROM indicators AS i LEFT JOIN indicators AS c ON c.indicator_id = i.indicator_id');
  167. return $result->result_array();
  168. }
  169. public function get_the_indicator_by_id($project_id)
  170. {
  171. $result = $this->db->get_where('indicators', array('indicator_id' => $project_id));
  172. return $result->result_array();
  173. }
  174. public function editIndicator($project_id)
  175. {
  176. $data = array
  177. (
  178. 'indicator_name' => $this->input->post('indicator_name'),
  179. // 'parent_id' => $this->input->post('parent_project')
  180. );
  181. $this->db->where('indicator_id', $project_id);
  182. $result = $this->db->update('indicators', $data);
  183. return $result;
  184. }
  185. // public function insert_task_category()
  186. // {
  187. // $data = array(
  188. // 'name' => $this->input->post('task_category')
  189. // );
  190. // // print_r($data);die;
  191. // $result = $this->db->get_where('task_category', array('name' => $data['name']));
  192. // if ($result->num_rows == 1) {
  193. // return false;
  194. // } else {
  195. // $result = $this->db->insert('task_category', $data);
  196. // return $result;
  197. // }
  198. // }
  199. // public function getTaskCategory()
  200. // {
  201. // $result = $this->db->get('task_category');
  202. // return $result->result_array();
  203. // }
  204. // public function get_task_category_by_id($taskid)
  205. // {
  206. // $result = $this->db->get_where('task_category', array('t_category_id' => $taskid));
  207. // return $result->result_array();
  208. // }
  209. // public function editTaskCategory($taskId)
  210. // {
  211. // $data = array
  212. // (
  213. // 'name' => $this->input->post('task_category'),
  214. // );
  215. // // echo $taskId;
  216. // // print_r($data);die;
  217. // $this->db->where('t_category_id', $taskId);
  218. // $result = $this->db->update('task_category', $data);
  219. // // $this->db->last_query();die;
  220. // return $result;
  221. // }
  222. // public function delete_task_category_by_id($taskCategoryId)
  223. // {
  224. // // echo $taskCategoryId;die;
  225. // $result = $this->db->delete('task_category', array('t_category_id' => $taskCategoryId));
  226. // return $result;
  227. // }
  228. }