PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/application/models/M_pmc.php

https://bitbucket.org/nando123/unj-iamperform
PHP | 278 lines | 233 code | 39 blank | 6 comment | 28 complexity | 40bf4be7912892f1496eb472fffbcb91 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. class M_pmc extends CI_Model {
  3. function __construct()
  4. {
  5. parent::__construct();
  6. $this->load->database();
  7. }
  8. function searchAtlet($name,$group_id)
  9. {
  10. $sql_atlet = " SELECT b.value_wellness,b.wellness_date,a.role_id, b.name, b.username, c.master_atlet_nomor_event, b.name, e.master_group_name, b.gambar"
  11. . " FROM master_role AS a"
  12. . " LEFT JOIN users AS b ON a.role_id IN (b.role_id)"
  13. . " LEFT JOIN master_information_personal as c on c.master_atlet_username = b.username"
  14. . " LEFT JOIN master_role as d on d.role_id = b.role_id"
  15. . " LEFT JOIN master_group as e on e.master_group_id = d.group_id"
  16. . " WHERE b.name like '%$name%'"
  17. . " AND a.group_id = '$group_id' AND b.role_type = 'ATL'";
  18. $query_atlet = $this->db->query($sql_atlet);
  19. if($query_atlet->num_rows()>0){
  20. return $query_atlet->result();
  21. }else{
  22. return false;
  23. }
  24. }
  25. function getPmcYear($year,$atlet){
  26. $sql = " SELECT a.distribute_monotony, a.distribute_athlete, b.*"
  27. . " FROM `mdlmonotony_distribute` as a"
  28. . " LEFT JOIN mdlmonotony_detail as b on b.detail_reference = a.distribute_monotony"
  29. . " WHERE a.distribute_athlete = '$atlet' AND YEAR(b.detail_date) = '$year'";
  30. $query = $this->db->query($sql);
  31. if($query -> num_rows() > 0){
  32. return $query->result();
  33. }else{
  34. return false;
  35. }
  36. }
  37. function getPmcMonth($year,$month,$atlet){
  38. $sql = " SELECT a.distribute_monotony, a.distribute_athlete, b.*"
  39. . " FROM `mdlmonotony_distribute` as a"
  40. . " LEFT JOIN mdlmonotony_detail as b on b.detail_reference = a.distribute_monotony"
  41. . " WHERE a.distribute_athlete = '$atlet' AND YEAR(b.detail_date) = '$year' AND MONTH(b.detail_date) = '$month' AND distribute_active ='1'";
  42. $query = $this->db->query($sql);
  43. if($query -> num_rows() > 0){
  44. return $query->result();
  45. }else{
  46. return false;
  47. }
  48. }
  49. function getMonotony($atlet,$year,$month){
  50. if($month == "all"){
  51. $sql = " SELECT a.*, b.mdlmonotony_date FROM mdlmonotony_distribute as a"
  52. . " LEFT JOIN mdlmonotony as b on b.mdlmonotony_id = a.distribute_monotony"
  53. . " WHERE a.distribute_athlete = '$atlet' AND YEAR(b.mdlmonotony_date) = '$year'"
  54. . " AND b.mdlmonotony_active = '0' ORDER by b.mdlmonotony_date DESC";
  55. }else{
  56. $sql = " SELECT a.*, b.mdlmonotony_date FROM mdlmonotony_distribute as a"
  57. . " LEFT JOIN mdlmonotony as b on b.mdlmonotony_id = a.distribute_monotony"
  58. . " WHERE a.distribute_athlete = '$atlet' AND YEAR(b.mdlmonotony_date) = '$year'"
  59. . " AND MONTH(b.mdlmonotony_date) = '$month'"
  60. . " AND b.mdlmonotony_active = '0' ORDER by b.mdlmonotony_date DESC";
  61. }
  62. $query = $this->db->query($sql);
  63. if($query -> num_rows() > 0){
  64. return $query->result();
  65. }else{
  66. return false;
  67. }
  68. }
  69. function getPmcData($monotony_id){
  70. $sql = " SELECT c.* FROM mdlmonotony as a"
  71. . " LEFT JOIN mdlmonotony_distribute as b on b.distribute_monotony = a.mdlmonotony_id"
  72. . " LEFT JOIN mdlmonotony_detail as c on c.detail_reference = a.mdlmonotony_id"
  73. // . " LEFT JOIN master_pmc as d on d.detail_id_pmc = c.detail_id"
  74. . " WHERE b.distribute_id = '$monotony_id'";
  75. $query = $this->db->query($sql);
  76. if($query -> num_rows() > 0){
  77. $result = $query->result();
  78. return $result;
  79. }else{
  80. return false;
  81. }
  82. }
  83. function getPmcMicro($dttm,$atlet){
  84. $detail = " SELECT a.*,e.intensity_name,f.intensity_name as actual_name FROM mdlmonotony_detail as a"
  85. . " LEFT JOIN mdlmonotony_distribute as b on b.distribute_monotony = a.detail_reference "
  86. . " LEFT JOIN mdlmonotony_intensity as e on e.intensity_id = a.detail_intensity"
  87. . " LEFT JOIN mdlmonotony_intensity as f on f.intensity_id = a.detail_actual"
  88. . " WHERE a.detail_date = '$dttm' "
  89. . " AND b.distribute_athlete = '$atlet'"
  90. . " ORDER BY a.detail_date ASC";
  91. $det_res = $this->db->query($detail);
  92. if($det_res->num_rows()>0){
  93. $det_res = $det_res->result();
  94. }else{
  95. $det_res = false;
  96. }
  97. $sql = " SELECT a.detail_id, a.detail_reference,a.detail_date FROM mdlmonotony_detail as a"
  98. . " LEFT JOIN mdlmonotony_distribute as b on b.distribute_monotony = a.detail_reference "
  99. . " WHERE a.detail_date = '$dttm' "
  100. . " AND b.distribute_athlete = '$atlet'"
  101. . " GROUP BY a.detail_date"
  102. . " ORDER BY a.detail_date";
  103. $query = $this->db->query($sql);
  104. if($query -> num_rows() > 0){
  105. $result = $query->result();
  106. }else{
  107. $result = false;
  108. }
  109. return array($result,$det_res);
  110. }
  111. function getPmcWeek($monotony_id){
  112. $sql = " SELECT f.intensity_name as actual_name,e.intensity_name,c.*,b.*,c.detail_id as did FROM mdlmonotony as a"
  113. . " LEFT JOIN mdlmonotony_distribute as b on b.distribute_monotony = a.mdlmonotony_id"
  114. . " LEFT JOIN mdlmonotony_detail as c on c.detail_reference = a.mdlmonotony_id"
  115. // . " LEFT JOIN master_pmc as d on d.detail_id = c.detail_id"
  116. . " LEFT JOIN mdlmonotony_intensity as e on e.intensity_id = c.detail_intensity"
  117. . " LEFT JOIN mdlmonotony_intensity as f on f.intensity_id = c.detail_actual"
  118. . " WHERE b.distribute_id = '$monotony_id' ORDER BY c.detail_date ASC";
  119. $query = $this->db->query($sql);
  120. if($query -> num_rows() > 0){
  121. $result = $query->result();
  122. return $result;
  123. }else{
  124. return false;
  125. }
  126. }
  127. function setPmcDetail($kegiatan,$detail_id,$monotony_id,$username,$atlet){
  128. $pmc_id = $this->pmc_id();
  129. $pmc = " INSERT INTO master_pmc (pmc_id,monotony_id,detail_id,created_user_id,atlet_id,"
  130. . " detail_kegiatan,created_dttm) values "
  131. . " ('$pmc_id','$monotony_id','$detail_id','$username','$atlet','$kegiatan',now())";
  132. $pmc_q = $this->db->query($pmc);
  133. if($pmc_q) {
  134. return true;
  135. } else {
  136. return false;
  137. }
  138. }
  139. function save_pmc($data){
  140. $pmc_id = $this->pmc_id();
  141. $kegiatan = $data['kegiatan'];
  142. // print_r($kegiatan);
  143. $sql = " INSERT INTO master_pmc (pmc_id,detail_id_pmc,created_user_id,atlet_id,created_dttm)"
  144. . " values ('$pmc_id','$data[detail_id]','$data[pelatih]','$data[atlet]',now())";
  145. $query = $this->db->query($sql);
  146. $pmc = "INSERT INTO master_pmc_detail (pmc_id,detail_kegiatan,detail_dttm) values ('$pmc_id','$kegiatan',now())";
  147. $pmc_q = $this->db->query($pmc);
  148. if ($pmc_q) {
  149. return true;
  150. } else {
  151. return false;
  152. }
  153. }
  154. function update_pmc_detail($kegiatan,$pmc_id){
  155. $pmc = "INSERT INTO master_pmc_detail (pmc_id,detail_kegiatan,detail_dttm) values ('$pmc_id','$kegiatan',now())";
  156. $pmc_q = $this->db->query($pmc);
  157. if ($pmc_q) {
  158. return true;
  159. } else {
  160. return false;
  161. }
  162. }
  163. function update_detail($data){
  164. $kegiatan = $data['kegiatan'];
  165. $id = $data['id'];
  166. $values = array();
  167. // for($i = 1; $i = count($kegiatan); $i++){
  168. $pmc = "UPDATE master_pmc_detail SET detail_kegiatan = '$kegiatan' WHERE pmc_id = '$data[pmc_id]' AND id = '$id'";
  169. $pmc_q = $this->db->query($pmc);
  170. if ($pmc_q) {
  171. } else {
  172. return false;
  173. }
  174. // }
  175. return true;
  176. }
  177. function setActual($did,$monotony_id,$actual){
  178. $sql = "UPDATE mdlmonotony_detail SET detail_actual = '$actual' WHERE detail_id = '$did' AND detail_reference = '$monotony_id'";
  179. $query = $this->db->query($sql);
  180. return true;
  181. }
  182. function getMonotonyWeek($monotony_id){
  183. $sql = " SELECT f.intensity_name as actual_name,e.intensity_name,c.*,b.*,c.detail_id as did FROM mdlmonotony as a"
  184. . " LEFT JOIN mdlmonotony_distribute as b on b.distribute_monotony = a.mdlmonotony_id"
  185. . " LEFT JOIN mdlmonotony_detail as c on c.detail_reference = a.mdlmonotony_id"
  186. // . " LEFT JOIN master_pmc as d on d.detail_id = c.detail_id"
  187. . " LEFT JOIN mdlmonotony_intensity as e on e.intensity_id = c.detail_intensity"
  188. . " LEFT JOIN mdlmonotony_intensity as f on f.intensity_id = c.detail_actual"
  189. . " WHERE b.distribute_id = '$monotony_id' ORDER BY c.detail_date ASC";
  190. $query = $this->db->query($sql);
  191. if($query -> num_rows() > 0){
  192. $result = $query->result();
  193. return $result;
  194. }else{
  195. return false;
  196. }
  197. }
  198. function pmc_id(){
  199. $tr = "PMCA_";
  200. $year = date("Y");
  201. $month = date("m");
  202. $day = date("d");
  203. $sql = "SELECT left(a.pmc_id,5) as tr, mid(a.pmc_id,6,4) as fyear,"
  204. . " mid(a.pmc_id,10,2) as fmonth, mid(a.pmc_id,12,2) as fday,"
  205. . " right(a.pmc_id,4) as fno FROM master_pmc AS a"
  206. . " where left(a.pmc_id,5) = '$tr' and mid(a.pmc_id,6,4) = '$year'"
  207. . " and mid(a.pmc_id,10,2) = '$month' and mid(a.pmc_id,12,2)= '$day'"
  208. . " order by fyear desc, CAST(fno AS SIGNED) DESC LIMIT 1";
  209. $result = $this->db->query($sql);
  210. if($result->num_rows($result) > 0) {
  211. $row = $result->row();
  212. $tr = $row->tr;
  213. $fyear = $row->fyear;
  214. $fmonth = $row->fmonth;
  215. $fday = $row->fday;
  216. $fno = $row->fno;
  217. $fno++;
  218. } else {
  219. $tr = $tr;
  220. $fyear = $year;
  221. $fmonth = $month;
  222. $fday = $day;
  223. $fno = 0;
  224. $fno++;
  225. }
  226. if (strlen($fno)==1){
  227. $strfno = "000".$fno;
  228. } else if (strlen($fno)==2){
  229. $strfno = "00".$fno;
  230. } else if (strlen($fno)==3){
  231. $strfno = "0".$fno;
  232. } else if (strlen($fno)==4){
  233. $strfno = $fno;
  234. }
  235. $id_goal = $tr.$fyear.$fmonth.$fday.$strfno;
  236. return $id_goal;
  237. }
  238. }
  239. ?>