topics.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <?php
  2. /****************************
  3. * File : topics.php
  4. * Author : Cygnusa
  5. * @2018
  6. ****************************/
  7. //SECURITY
  8. if (!defined('APPLICATION_PATH')) {
  9. exit('No direct script access allowed');
  10. }
  11. class topics
  12. {
  13. //FUNCTION LISTS
  14. public function __construct($parent)
  15. {
  16. //GET PAGE MESSAGE
  17. $this->page_data = globalfunc::getMessage($parent, $parent->lang, 'topics');
  18. if (count($parent->params) == 0) {
  19. //$this->topicsfunc($parent);
  20. } else {
  21. $qry_params = explode("?", $parent->params[0]);
  22. $parameter_val = strtolower($qry_params[0]);
  23. if (strtolower($parent->device_type) == 'app') {
  24. switch ($parameter_val) {
  25. case "content":
  26. case "content_status":
  27. case "get_content_details":
  28. $this->$parameter_val($parent);
  29. break;
  30. default:
  31. $this->topicsfunc($parent);
  32. break;
  33. }
  34. } else if (strtolower($parent->device_type) == 'web') {
  35. switch ($parameter_val) {
  36. case "content":
  37. case "content_status":
  38. case "get_content_details":
  39. $this->$parameter_val($parent);
  40. break;
  41. default:
  42. $this->topicsfunc($parent);
  43. break;
  44. }
  45. }
  46. }
  47. $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
  48. }
  49. /* /////////////////////////////// TOPICS LIST //////////////////////////////////////////////// */
  50. private function topicsfunc($parent)
  51. {
  52. globalfunc::checkMethodType($parent, array('GET'));
  53. globalfunc::checkParamCount($parent, 1);
  54. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  55. //PAGINATION SETTINGS
  56. $limit_cond = '';
  57. $data_arr = array();
  58. $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
  59. $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
  60. $data = @explode('?', $parent->params[0]);
  61. $cateid = escape_str($data[0]); //GET CATE ID
  62. $userid = $parent->current_user_id;
  63. //USER FILTER CONDITION APPLY
  64. $user_cond = " AND cateid='" . $cateid . "' ";
  65. $user_cond .= ($parent->current_user_role == 15) ? " AND assettopicid=61" : "AND assettopicid!=61";
  66. //NEW ROLE CONDITION
  67. //$user_cond.=($parent->current_user_role>7 && $parent->current_user_role<14)?" AND user_type=0 ":" AND user_type=1 ";
  68. //NEW SEGMENT CONDITION
  69. if ($parent->current_user_role > 7 && $parent->current_user_role < 14) {
  70. $user_cond .= " AND (segment='0' OR segment='" . $parent->current_user_data->segment . "')";
  71. }
  72. ///////////////////////////////////////////////////////////////////////////////////////
  73. $check_user_str = "SELECT userid,segment,role FROM " . TABLE_USER . " WHERE status='1' AND is_deleted='0' AND userid='" . $userid . "' LIMIT 1";
  74. $check_user_arr = $parent->getQueryValue($check_user_str);
  75. if (!count($check_user_arr) > 0) {
  76. $parent->response(array('response' => 'failed', 'message' => $this->page_data["error2"]), 406);
  77. }
  78. if ($check_user_arr[0]->role > 7 && $check_user_arr[0]->role < 14) {
  79. $user_filter_str = projectfunc::getUserfiltervalue($parent, array('role', 'zone', 'city', 'dealer_code'), $userid);
  80. } else {
  81. $user_filter_str = projectfunc::getUserfiltervalue($parent, array('role'), $userid);
  82. }
  83. $peruser_cond = str_replace("filter_", "c.filter_", $user_filter_str);
  84. if ($check_user_arr[0]->role > 7 && $check_user_arr[0]->role < 14) {
  85. switch ($check_user_arr[0]->segment) {
  86. case "1":$peruser_cond .= " AND t.segment IN (0,1) AND c.segment IN (0,1)";
  87. break;
  88. case "2":$peruser_cond .= " AND t.segment IN (0,2) AND c.segment IN (0,2)";
  89. break;
  90. default:$peruser_cond .= " AND t.segment IN (0) AND c.segment IN (0)";
  91. break;
  92. }
  93. }
  94. ///////////////////////////////////////////////////////////////////////////////////////
  95. $getuser_topics_arr = $parent->selectQuery(TABLE_ASSET_TOPIC, "*", " status='1' AND is_deleted='0' " . $user_cond . " ORDER BY position ASC, assettopicid ASC " . $limit_cond, "");
  96. if ($getuser_topics_arr['nr']) {
  97. //CONNECT S3
  98. $s3 = awsfileserver::connectS3();
  99. foreach ($getuser_topics_arr['result'] as $res) {
  100. $res->image_url = TRAININGIMAGE_URL;
  101. if ($res->image) {
  102. $res->image_url = awsfileserver::getS3FileUrl($s3, S3_BUCKET, S3_TOPICS_URL . $res->image);
  103. }
  104. $get_course_str = "SELECT COUNT(c.`contentid`) as totcontent FROM " . TABLE_ASSET_CONTENT . " as c JOIN " . TABLE_ASSET_TOPIC . " as t ON t.assettopicid=c.assettopicid WHERE t.status='1' AND t.is_deleted='0' AND c.status='1' AND c.is_deleted='0' AND t.cateid='" . $cateid . "' AND t.assettopicid='" . $res->assettopicid . "' " . $peruser_cond;
  105. $res->total_q = $get_course_str;
  106. $get_course_arr = $parent->getQueryValue($get_course_str);
  107. $total_content = (count($get_course_arr) > 0) ? $get_course_arr[0]->totcontent : '0';
  108. //GET USER COMPLETED CONTENT COUNT
  109. $get_user_completed_str = "SELECT COUNT(c.`contentid`) as totcontent FROM " . TABLE_ASSET_CONTENT . " as c JOIN " . TABLE_ASSET_TOPIC . " as t ON t.assettopicid=c.assettopicid JOIN (SELECT * FROM " . TABLE_USER_COMPLETE_CONTENT . " WHERE userid='" . $userid . "' AND status='2') as a ON a.contentid=c.contentid WHERE t.status='1' AND t.is_deleted='0' AND c.status='1' AND c.is_deleted='0' AND t.cateid='" . $cateid . "' AND t.assettopicid='" . $res->assettopicid . "' " . $peruser_cond;
  110. $get_user_completed_arr = $parent->getQueryValue($get_user_completed_str);
  111. $user_content = (count($get_user_completed_arr) > 0) ? $get_user_completed_arr[0]->totcontent : '0';
  112. //$res->total_cq = $get_user_completed_str;
  113. $res->total = ($total_content > 0) ? $total_content : '0';
  114. $res->completed = ($user_content > 0) ? $user_content : '0';
  115. $res->percentage = ($total_content > 0) ? round(($user_content / $total_content) * 100) : '0';
  116. $data_arr[] = $res;
  117. }
  118. }
  119. //GET COUNT
  120. $getuser_topics_count = $parent->selectQuery(TABLE_ASSET_TOPIC, "COUNT(assettopicid)as topic_count", " status='1' AND is_deleted='0' " . $user_cond, "1");
  121. $total = ($getuser_topics_count['nr']) ? $getuser_topics_count['result'][0]->topic_count : 0;
  122. //LOG
  123. $logstr = 'TOPICS';
  124. globalfunc::insertUserLog($parent, $logstr, $cateid);
  125. $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
  126. $parent->response(array('response' => 'success', 'data' => $data_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
  127. }
  128. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  129. /* /////////////////////////////// TOPICS CONTENT LIST //////////////////////////////////////////////// */
  130. private function content($parent)
  131. {
  132. globalfunc::checkMethodType($parent, array('GET'));
  133. globalfunc::checkParamCount($parent, 2);
  134. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  135. //PAGINATION SETTINGS
  136. $limit_cond = '';
  137. $data_arr = array();
  138. $limit_str = globalfunc::setPageLimit($parent, $parent->params[1]);
  139. $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
  140. $data = @explode('?', $parent->params[1]);
  141. $assettopicid = escape_str($data[0]);
  142. //$lvl_id= projectfunc::getUserLvlId($parent);
  143. //AND lvl_id='".$lvl_id."'
  144. //NEW ROLE CONDITION
  145. //$user_cond.=($parent->current_user_role>7 && $parent->current_user_role<14)?" AND user_type=0 ":" AND user_type=1 ";
  146. $seg_cond = '';
  147. //NEW SEGMENT CONDITION
  148. if ($parent->current_user_role > 7 && $parent->current_user_role < 14) {
  149. $seg_cond .= " AND (segment='0' OR segment='" . $parent->current_user_data->segment . "')";
  150. }
  151. //CHECK TOPIC VALIDATION
  152. $getcheck_topic = $parent->selectQuery(TABLE_ASSET_TOPIC, "*", " status='1' AND is_deleted='0' " . $user_cond . " AND assettopicid='" . $assettopicid . "' ", "1");
  153. if (!$getcheck_topic['nr'] > 0) {
  154. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error1']), 406);
  155. }
  156. //ORDER BY COND
  157. $orderby_cond = ($getcheck_topic['result'][0]->listorder == '1') ? "ORDER BY uploaddate DESC,contentid ASC " : "ORDER BY uploaddate ASC,contentid ASC ";
  158. //USER FILTER CONDITION APPLY
  159. $user_cond = " AND assettopicid='" . $assettopicid . "' " . $seg_cond;
  160. //COMMAN USER FILTER
  161. $user_filter_str = projectfunc::getUserfiltervalue($parent, array('role', 'zone', 'city', 'dealer_code'));
  162. $user_cond .= $user_filter_str;
  163. $getuser_content_arr = $parent->selectQuery(TABLE_ASSET_CONTENT, "*", " status='1' AND is_deleted='0' " . $user_cond . " " . $orderby_cond . $limit_cond, "");
  164. if ($getuser_content_arr['nr']) {
  165. //CONNECT S3
  166. $s3 = awsfileserver::connectS3();
  167. foreach ($getuser_content_arr['result'] as $res) {
  168. //GET USER STATUS OF CONTENT
  169. $content_status_arr = projectfunc::getContentStatus($parent, $res->contentid);
  170. $res->status = $content_status_arr['status'];
  171. $res->status_str = $content_status_arr['status_str'];
  172. $res->content_files = $this->getContentFiles($parent, $s3, $res->contentid);
  173. $data_arr[] = $res;
  174. }
  175. }
  176. //GET COUNT
  177. $getuser_content_count = $parent->selectQuery(TABLE_ASSET_CONTENT, "COUNT(contentid)as content_count", " status='1' AND is_deleted='0' " . $user_cond, "1");
  178. $total = ($getuser_content_count['nr']) ? $getuser_content_count['result'][0]->content_count : 0;
  179. //LOG
  180. $logstr = 'CONTENT';
  181. globalfunc::insertUserLog($parent, $logstr, $assettopicid);
  182. $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
  183. $parent->response(array('response' => 'success', 'data' => $data_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
  184. }
  185. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  186. /* /////////////////////////////// TOPIC CONTENT //////////////////////////////////////////////// */
  187. private function getContentFiles($parent, $s3, $contentid)
  188. {
  189. $data_arr = array();
  190. //GET FILES ONLY ONE FILE
  191. $getuser_contentfiles_arr = $parent->selectQuery(TABLE_ASSET_FILE . " as f JOIN " . TABLE_MASTER_LANGUAGE . " as l ON l.language_id=f.language_id", " f.`language_id`, f.`filepath`,f.filetypeid, f.`thumbpath`, f.`filetypeid`, f.`filetype`, f.`filesize`, f.`filequality`, l.`language_code`, l. `language_title`", " f.contentid='" . $contentid . "' ORDER BY l.language_title ASC,f.id ASC ", "");
  192. if ($getuser_contentfiles_arr['nr']) {
  193. foreach ($getuser_contentfiles_arr['result'] as $tkey => $res) {
  194. //S3 FILE URL
  195. $fileurl = '';
  196. if ($res->filepath != '') {
  197. $url = awsfileserver::getS3FileUrl($s3, S3_BUCKET, S3_TOPICS_URL . $res->filepath);
  198. //PDF ISSUE FIX FOR WEB DEVICE
  199. $url = (strtolower($parent->device_type) == 'web' && $res->filetypeid == '1') ? projectfunc::pdfUrlStr($parent, $url) : $url;
  200. $fileurl = $url;
  201. }
  202. $getuser_contentfiles_arr['result'][$tkey]->file_url = $fileurl;
  203. //S3 THUMBIMAGE URL
  204. $thumb_fileurl = '';
  205. if ($res->thumbpath != '') {
  206. $thumb_fileurl = awsfileserver::getS3FileUrl($s3, S3_BUCKET, S3_TOPICS_URL . $res->thumbpath);
  207. }
  208. $getuser_contentfiles_arr['result'][$tkey]->thumb_fileurl = $thumb_fileurl;
  209. }
  210. $data_arr = $getuser_contentfiles_arr['result'];
  211. }
  212. return $data_arr;
  213. }
  214. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  215. /* /////////////////////////////// USER COMPLETE CONTENT TABLE //////////////////////////////////////////////// */
  216. private function content_status($parent)
  217. {
  218. globalfunc::checkMethodType($parent, array('POST'));
  219. globalfunc::checkParamCount($parent, 1);
  220. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  221. $REQUEST_KEYS = array('status' => 'integer', 'contentid' => 'integer', 'assettopicid' => 'integer');
  222. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  223. $contentid = escape_str($parent->_request['contentid']);
  224. $assettopicid = escape_str($parent->_request['assettopicid']);
  225. $status = escape_str($parent->_request['status']); //0-started, 1-In progress, 2-Completed
  226. $completeddate = '';
  227. if ($status == '2') {
  228. $completeddate = CUR_DATE;
  229. }
  230. //GET USER Level ID
  231. //$lvl_id= projectfunc::getUserLvlId($parent);
  232. //AND lvl_id='".$lvl_id."'
  233. //NEW ROLE CONDITION
  234. //$user_cond.=($parent->current_user_role>7 && $parent->current_user_role<14)?" AND user_type=0 ":" AND user_type=1 ";
  235. $seg_cond = '';
  236. //NEW SEGMENT CONDITION
  237. if ($parent->current_user_role > 7 && $parent->current_user_role < 14) {
  238. $seg_cond .= " AND (segment='0' OR segment='" . $parent->current_user_data->segment . "')";
  239. }
  240. //CHECK TOPIC VALIDATION
  241. $getcheck_topic = $parent->selectQuery(TABLE_ASSET_TOPIC, "*", " status='1' AND is_deleted='0' AND assettopicid='" . $assettopicid . "' " . $user_cond . " " . $seg_cond, "1");
  242. if (!$getcheck_topic['nr'] > 0) {
  243. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error1']), 406);
  244. }
  245. $cateid = $getcheck_topic['result'][0]->cateid;
  246. //GET CONTENT STATUS
  247. $query_user_status = $parent->selectQuery(TABLE_USER_COMPLETE_CONTENT, "*", " userid='" . $parent->current_user_id . "' AND assettopicid='" . $assettopicid . "' AND contentid='" . $contentid . "'", "1");
  248. if ($query_user_status['nr'] > 0) {
  249. //UPDATE
  250. if ($query_user_status['result'][0]->status != 2) {
  251. $econd = ($completeddate != '') ? ", completeddate='" . $completeddate . "'" : '';
  252. $update_user_status_str = "UPDATE " . TABLE_USER_COMPLETE_CONTENT . " SET status='" . $status . "',modified_on='" . NOW . "' " . $econd . " WHERE id='" . $query_user_status['result'][0]->id . "'";
  253. }
  254. } else {
  255. //INSERT
  256. $update_user_status_str = "INSERT INTO " . TABLE_USER_COMPLETE_CONTENT . " (`cateid`, `assettopicid`, `contentid`, `userid`, `status`, `completeddate`, `created_on`, `modified_on`) VALUES ('" . $cateid . "', '" . $assettopicid . "','" . $contentid . "','" . $parent->current_user_id . "','" . $status . "','" . $completeddate . "','" . NOW . "','" . NOW . "') ";
  257. }
  258. $parent->executeQuery($update_user_status_str);
  259. //LOG
  260. $logstr = 'CONTENT STATUS UPDATE';
  261. globalfunc::insertUserLog($parent, $logstr, $contentid);
  262. $parent->response(array('response' => 'success', 'message' => $this->page_data['success1']), 200);
  263. }
  264. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  265. /* /////////////////////////////// TOPICS CONTENT DETAILS //////////////////////////////////////////////// */
  266. private function get_content_details($parent)
  267. {
  268. globalfunc::checkMethodType($parent, array('GET'));
  269. globalfunc::checkParamCount($parent, 2);
  270. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  271. $data = @explode('?', $parent->params[1]);
  272. $contentid = escape_str($data[0]);
  273. $data_arr = array();
  274. //GET USER Level ID
  275. // $lvl_id= projectfunc::getUserLvlId($parent);
  276. // AND lvl_id='".$lvl_id."'
  277. //NEW ROLE CONDITION
  278. //$user_cond.=($parent->current_user_role>7 && $parent->current_user_role<14)?" AND user_type=0 ":" AND user_type=1 ";
  279. $seg_cond = '';
  280. //NEW SEGMENT CONDITION
  281. if ($parent->current_user_role > 7 && $parent->current_user_role < 14) {
  282. $seg_cond .= " AND (segment='0' OR segment='" . $parent->current_user_data->segment . "')";
  283. }
  284. //CHECK TOPIC VALIDATION
  285. $getcheck_topic = $parent->selectQuery(TABLE_ASSET_TOPIC, "*", " status='1' AND is_deleted='0' " . $user_cond . " AND assettopicid IN (SELECT assettopicid FROM " . TABLE_ASSET_CONTENT . " WHERE contentid='" . $contentid . "')" . $seg_cond, "1");
  286. if (!$getcheck_topic['nr'] > 0) {
  287. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error1']), 406);
  288. }
  289. //USER FILTER CONDITION APPLY
  290. $user_cond = " AND contentid='" . $contentid . "' ";
  291. $getuser_content_arr = $parent->selectQuery(TABLE_ASSET_CONTENT, "*", " status='1' AND is_deleted='0' " . $user_cond . $seg_cond, "1");
  292. if ($getuser_content_arr['nr']) {
  293. //CONNECT S3
  294. $s3 = awsfileserver::connectS3();
  295. foreach ($getuser_content_arr['result'] as $res) {
  296. //GET USER STATUS OF CONTENT
  297. $content_status_arr = projectfunc::getContentStatus($parent, $res->contentid);
  298. $res->status = $content_status_arr['status'];
  299. $res->status_str = $content_status_arr['status_str'];
  300. $res->content_files = $this->getContentFiles($parent, $s3, $res->contentid);
  301. $data_arr = $res;
  302. }
  303. }
  304. //LOG
  305. $logstr = 'CONTENT DETAILS';
  306. globalfunc::insertUserLog($parent, $logstr, $contentid);
  307. $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
  308. }
  309. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  310. }