/application/controllers/Cron.php

https://gitlab.com/surya.ayrus22/Matrimony · PHP · 220 lines · 141 code · 25 blank · 54 comment · 27 complexity · 1b8eb58ed7bf9d9c1bcee1ce927f8fd6 MD5 · raw file

  1. <?php
  2. if (!defined('BASEPATH'))
  3. exit('No direct script access allowed');
  4. error_reporting(0);
  5. class Cron extends CI_Controller {
  6. function __construct() {
  7. parent::__construct();
  8. $this->load->database();
  9. $this->load->model('User_model', '', TRUE);
  10. $this->load->model('Prefrence_model', '', TRUE);
  11. $this->load->model('Profilemanager_model', '', TRUE);
  12. $this->load->model('Utils', '', TRUE);
  13. }
  14. /**
  15. * cron run every 12 hours or 24hours once
  16. */
  17. function index() {
  18. /** To set cron running */
  19. echo 'cron running';
  20. /** get over all users */
  21. $userInfo = $this->User_model->getUserinformation();
  22. if (!empty($userInfo)) {
  23. foreach ($userInfo as $userData) {
  24. $userguid = $userData['userGuid'];
  25. /** get user prefrence details based on all users */
  26. $partnerInfo = $this->User_model->getUserPartnerInfo($userguid);
  27. if (!empty($partnerInfo) && !empty($userData['gender'])) {
  28. $prefrence = (!empty($partnerInfo[0]['prefrence']) ? json_decode($partnerInfo[0]['prefrence'], true) : '');
  29. if (!empty($prefrence)) {
  30. $gender = 'M';
  31. if (strtoupper($userData['gender']) == 'M') {
  32. $gender = 'F';
  33. }
  34. /** get block and ignore user list */
  35. $id = array(REQUEST_IGNORE, REQUEST_NOT_INETREST, REQUEST_BLOCK);
  36. /* * get login user blocked user list (Me blocked from others) * */
  37. $exists = $this->User_model->ProfileRequestInfo($userguid, '', '', $id);
  38. /* * Any one blocked from login user list (Others blocked from me) * */
  39. $exists1 = $this->User_model->ProfileRequestInfo('', $userguid, '', $id);
  40. $userList = array();
  41. $blockList = array();
  42. $otherBlockList = array();
  43. if ($exists) {
  44. foreach ($exists as $user) {
  45. $blockList[] = $user['request_to'];
  46. }
  47. }
  48. if ($exists1) {
  49. foreach ($exists1 as $user) {
  50. $otherBlockList[] = $user['request_from'];
  51. }
  52. }
  53. $userList = array_merge($blockList, $otherBlockList);
  54. $recentExists = $this->User_model->getRecentlyUpdatedProfile('', $caste);
  55. $recentList = array();
  56. if (!empty($recentExists)) {
  57. foreach ($recentExists as $user1) {
  58. $recentList[] = $user1['user_guid'];
  59. }
  60. }
  61. $limits = 5;
  62. $recentUserList = array();
  63. $recentdata = array();
  64. $similardata = array();
  65. $recentUpdated = array('maritalstatus' => $prefrence['maritalstatus'], 'caste' => $prefrence['caste'], 'eduction' => $prefrence['education']);
  66. /* * recently updated profile */
  67. $recent = $this->Prefrence_model->getUserPrefrenceDetails($recentUpdated, $gender, $userList, $recentList, $limits);
  68. if (!empty($recent)) {
  69. foreach ($recent as $key => $data) {
  70. $recentdata[] = $data['userGuid'];
  71. }
  72. if (!empty($recentdata)) {
  73. $recentUserList['matches'] = $this->Profilemanager_model->getUserInformation($recentdata);
  74. }
  75. $recentCount = (!empty($recentUserList['matches']) ? count($recentUserList['matches']) : 0);
  76. if ($recentCount < 5) {
  77. /** similar matches */
  78. $similar = array('maritalstatus' => $prefrence['maritalstatus'], 'caste' => $prefrence['caste']);
  79. $simiarLimits = $limits - $recentCount;
  80. $similarUserList = $this->Prefrence_model->getUserPrefrenceDetails($similar, $gender, $userList, '', $simiarLimits);
  81. if (!empty($similarUserList)) {
  82. foreach ($similarUserList as $key => $val) {
  83. $similardata[] = $val['userGuid'];
  84. }
  85. if (!empty($similardata)) {
  86. $recentUserList['similar'] = $this->Profilemanager_model->getUserInformation($similardata);
  87. }
  88. }
  89. }
  90. }
  91. /* if ( !empty( $recentUserList ) && !empty( $userData['email'] )){
  92. $recentUserList['username'] = $userData['username'];
  93. $recentUserList['userId'] = $userData['userId'];
  94. $recentUserList['title'] = $this->lang->line("mail_matches_title1");
  95. $recentUserList['title1'] = $this->lang->line("mail_matches_title2");
  96. $subject = sprintf($this->lang->line("mail_matches_sub1"), $userData['username']);
  97. $body = $this->load->view('template/mail/matches.php',$recentUserList,TRUE);
  98. echo '<pre>';print_r($body);exit;
  99. $sendmail = $this->Mail->sendmail( '', $userData['email'], $subject, $body ,$attachment ='' );
  100. } */
  101. $similarUserInfoList = array();
  102. /** similar matches */
  103. $newlyAdded = array('maritalstatus' => $prefrence['maritalstatus'], 'caste' => $prefrence['caste']);
  104. $similarmatches = $this->Prefrence_model->getUserPrefrenceDetails($newlyAdded, $gender, $userList, '', $limits);
  105. if (!empty($similarmatches)) {
  106. foreach ($similarmatches as $key => $data1) {
  107. $similarGuid[] = $data1['userGuid'];
  108. }
  109. if (!empty($similarGuid)) {
  110. $similarUserInfoList['similar'] = $this->Profilemanager_model->getUserInformation($similarGuid);
  111. }
  112. }
  113. /*
  114. if ( !empty( $similarUserInfoList ) && !empty( $userData['email'] )){
  115. $similarUserInfoList['username'] = $userData['username'];
  116. $similarUserInfoList['userId'] = $userData['userId'];
  117. $similarUserInfoList['title1'] = $this->lang->line("mail_matches_title2");
  118. $subject = sprintf($this->lang->line("mail_matches_sub2"), $userData['username']);
  119. $body = $this->load->view('template/mail/matches.php',$similarUserInfoList,TRUE);
  120. echo '<pre>';print_r($body);exit;
  121. $sendmail = $this->Mail->sendmail( '', $userData['email'], $subject, $body ,$attachment ='' );
  122. } */
  123. $newmatchesUserList = array();
  124. $mathesdata = array();
  125. $newMatchesGuid = array();
  126. /** newly added maches */
  127. $newmatches = $this->Prefrence_model->getUserPrefrenceDetails($prefrence, $gender, $userList, '', $limits);
  128. if (!empty($newmatches)) {
  129. foreach ($newmatches as $key => $data2) {
  130. $newMatchesGuid[] = $data2['userGuid'];
  131. }
  132. if (!empty($newMatchesGuid)) {
  133. $newmatchesUserList['matches'] = $this->Profilemanager_model->getUserInformation($newMatchesGuid);
  134. }
  135. $matchesCount = (!empty($newmatchesUserList['matches']) ? count($newmatchesUserList['matches']) : 0);
  136. if (($matchesCount < 5) && ( $matchesCount != 0 )) {
  137. /** similar matches */
  138. $newmatches_similar = array('maritalstatus' => $prefrence['maritalstatus'], 'caste' => $prefrence['caste']);
  139. $newimits = $limits - $matchesCount;
  140. $matchesUserList = $this->Prefrence_model->getUserPrefrenceDetails($newmatches_similar, $gender, $userList, '', $newimits);
  141. if (!empty($matchesUserList)) {
  142. foreach ($matchesUserList as $key => $val1) {
  143. $mathesdata[] = $val1['userGuid'];
  144. }
  145. if (!empty($mathesdata)) {
  146. $newmatchesUserList['similar'] = $this->Profilemanager_model->getUserInformation($mathesdata);
  147. }
  148. }
  149. }
  150. }
  151. /* if ( !empty( $newmatchesUserList ) && !empty( $userData['email'] )){
  152. $newmatchesUserList['username'] = $userData['username'];
  153. $newmatchesUserList['userId'] = $userData['userId'];
  154. $newmatchesUserList['title'] = $this->lang->line("mail_matches_title3");
  155. $newmatchesUserList['title1'] = $this->lang->line("mail_matches_title2");
  156. $subject = sprintf($this->lang->line("mail_matches_sub4"), $userData['username']);
  157. $body = $this->load->view('template/mail/matches.php',$newmatchesUserList,TRUE);
  158. $sendmail = $this->Mail->sendmail( '', $userData['email'], $subject, $body ,$attachment ='' );
  159. } */
  160. /** viewed user list */
  161. $viewedUserList = array();
  162. $viewedList = array();
  163. $viewedInfo = $this->User_model->viwedProfileInfo('', $userguid);
  164. if (!empty($viewedInfo)) {
  165. $viewedList = array();
  166. foreach ($viewedInfo as $key => $value) {
  167. $viewedList[] = $value['viewed_from'];
  168. }
  169. }
  170. /** removed ignore user list and get viewed user list * */
  171. $userGuidList = array();
  172. if (!empty($viewedList)) {
  173. $userGuidList = array_diff($viewedList, $userList);
  174. }
  175. $getUserList = array();
  176. if (!empty($userGuidList)) {
  177. $viewedUserList['matches'] = $this->Profilemanager_model->getUserInformation($userGuidList, $gender, $limits);
  178. }
  179. /* if ( !empty( $viewedUserList ) && !empty( $userData['email'] )){
  180. $viewedUserList['username']= $userData['username'];
  181. $viewedUserList['userId'] = $userData['userId'];
  182. $viewedUserList['title'] = $this->lang->line("mail_matches_title4");
  183. $subject = sprintf($this->lang->line("mail_matches_sub3"), $userData['username']);
  184. $body = $this->load->view('template/mail/matches.php',$viewedUserList,TRUE);
  185. $sendmail = $this->Mail->sendmail( '', $userData['email'], $subject, $body ,$attachment ='' );
  186. } */
  187. }
  188. }
  189. }
  190. }
  191. die('Cron completed');
  192. /** To set cron executed */
  193. }
  194. }
  195. ?>