Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 132.09 KB | None | 0 0
  1. <?php
  2.  
  3. class Notifications extends EMongoDocument {
  4. /* Actions */
  5.  
  6. CONST TYPE_LIKE = 'like';
  7. CONST TYPE_REPLY = 'reply';
  8. CONST TYPE_VOTE = 'vote';
  9. CONST TYPE_EVENT = 'event';
  10. CONST TYPE_REQUEST = 'request';
  11. CONST TYPE_REVOKE = 'revoke';
  12. CONST TYPE_NONE = 'none';
  13. CONST TYPE_UNLIKE = 'unlike';
  14.  
  15. /* FILTER TYPE */
  16. CONST FILTER_UPDATE = 'update';
  17. CONST FILTER_LINK = 'link';
  18. CONST FILTER_QUESTION = 'question';
  19. CONST FILTER_POLL = 'poll';
  20. CONST FILTER_EVENT = 'event';
  21. CONST FILTER_LEAVE = 'leave';
  22. CONST FILTER_THUMBSUP = 'thumbsup';
  23. CONST FILTER_INVITE = 'invite';
  24. CONST FILTER_REQUEST = 'request';
  25. CONST FILTER_INVITE_GROUP = 'invite_group';
  26. CONST FILTER_SYSTEM_EVENT = 'system_event';
  27. CONST READ_STATUS_UNREAD = 0;
  28. CONST READ_STATUS_READ = 1;
  29. CONST NOTIFICATIONS = 'notifications';
  30. CONST REQUESTS = 'requests';
  31. CONST FILTER_SUB_NEWUSER = 'user';
  32. CONST FILTER_SUB_BIRTHDAY = 'birthday';
  33. CONST FILTER_SUB_ANNIVERSARY = 'anniversary';
  34. CONST FILTER_SUB_YEARS_SPENT = 'years_spent';
  35. CONST FILTER_ATTENDANCE = 'attendance';
  36. const FILTER_ATTEDANCE_REQUEST = 'attendance_request';
  37. CONST NOTIFICATION_REQUEST_LETTER = "request_letter";
  38. CONST NOTIFICATION_RESPONSE_LETTER = "response_letter";
  39.  
  40. /* Notification categoires for sending emails */
  41. CONST NOTIFY_LEAVE_REQUEST = 'leave_request';
  42. CONST NOTIFY_LEAVE_RESPONSE = 'leave_response';
  43. CONST NOTIFY_REQUEST_OWNER = 'request_owner';
  44. CONST NOTIFY_REQUEST_USER = 'request_user';
  45. CONST NOTIFY_MESSAGE_LIKE = 'other_like_message';
  46. CONST NOTIFY_MESSAGE_REPLY = 'other_reply_message';
  47. CONST NOTIFY_MESSAGE_MENTION = 'other_mention';
  48. CONST NOTIFY_MESSAGE_PRIVATE = 'other_private_message';
  49. CONST NOTIFY_EVENT_SALARY = 'event_salary';
  50. CONST NOTIFY_EVENT_SPECIAL = 'special_event';
  51. CONST NOTIFY_REQUEST_EXPENSE = 'request_expense';
  52. CONST NOTIFY_RESPONSE_EXPENSE = 'response_expense';
  53. CONST NOTIFY_REQUEST_ATTENDANCE = 'request_attendance';
  54. CONST NOTIFY_RESPONSE_ATTENDANCE = 'response_attendance';
  55. CONST NOTIFY_RESET_PASSWORD = 'reset_password';
  56. CONST NOTIFY_CLOCKOUT_REMINDER = 'clockout_reminder';
  57. CONST NOTIFY_ASSIGN_SHIFT = 'assign_shift';
  58. CONST NOTIFY_LEAVE_ONBEHALF_REQUEST = 'leave_request_behalf';
  59. CONST NOTIFY_PAYROLL_SALARYSLIP = "payroll_salary_slip";
  60. CONST NOTIFICATION_ACTIVE = 1;
  61. CONST NOTIFICATION_INACTVE = 0;
  62.  
  63. public $id; //uniqid()
  64. public $message_id;
  65. public $group_id;
  66. public $type;
  67. public $category; //Identifying what type of notification
  68. public $body;
  69. public $data = array();
  70. public $sender_id;
  71. public $recipient_id;
  72. public $isRequest = false;
  73. public $read_status;
  74. public $read_time;
  75. public $tenant_id;
  76. public $created;
  77. public $status = self::NOTIFICATION_ACTIVE;
  78. public $filter_type;
  79. public $is_for;
  80.  
  81. /**
  82. * Returns the static model of the specified AR class.
  83. * @return UserPersonal the static model class
  84. */
  85. public static function model($className = __CLASS__) {
  86. return parent::model($className);
  87. }
  88.  
  89. /**
  90. * @return string the associated collection name
  91. */
  92. public function getCollectionName() {
  93. return 'notifications';
  94. }
  95.  
  96. public function primaryKey() {
  97. return 'id'; // Model field name, by default the _id field is used
  98. }
  99.  
  100. /**
  101. * @return array validation rules for model attributes.
  102. */
  103. public function rules() {
  104. // NOTE: you should only define rules for those attributes that
  105. // will receive user inputs.
  106. return array(
  107. );
  108. }
  109.  
  110. /**
  111. * @return array customized attribute labels (name=>label)
  112. */
  113. public function attributeLabels() {
  114. return array(
  115. );
  116. }
  117.  
  118. /**
  119. * Populate default values for system fields
  120. */
  121. public function beforeSave() {
  122. if ($this->isNewRecord) {
  123. $this->id = uniqid();
  124. $this->tenant_id = ($this->tenant_id == null) ? Yii::app()->user->getTenantId() : $this->tenant_id;
  125. $this->created = new MongoDate(time());
  126. }
  127. return parent::beforeSave();
  128. }
  129.  
  130. public function afterSave() {
  131. if ($this->isNewRecord) {
  132. $this->processSendEmails();
  133. }
  134. return parent::afterSave(); // parent::beforeSave();
  135. }
  136.  
  137. public function processSendEmails() {
  138. $post_data = array();
  139. $attachment = array();
  140. $template_data_leaves_response = array();
  141. $template_data_attendace_update = array();
  142. $user = UserMongo::model()->tenant($this->tenant_id)->findByAttributes(array('user_id' => $this->recipient_id));
  143. $sender_user = UserMongo::model()->tenant($this->tenant_id)->findByAttributes(array('user_id' => $this->sender_id));
  144. $oldUser = null;
  145. if (!empty($user)) {
  146. $oldUser = $user->oldUser($this->tenant_id);
  147. }
  148. $tenant = Tenants::model()->findByPk($this->tenant_id);
  149. $subdomain = $tenant->tenant_subdomain;
  150. if ($user != null && $oldUser != null && ($this->sender_id == null || $user->isInSettingsNotify('notification', $this->category)) && $oldUser->isSelfService()) {
  151. //Data for sending email
  152. if ($this->sender_id == null) {
  153. $message_link = Yii::app()->createAbsoluteUrl('notifications/notifications');
  154. if ($this->category == Notifications::NOTIFY_EVENT_SALARY) {
  155. $subject_data = sprintf(self::itemAlias('category', $this->category), $this->data['month']);
  156. $message_data = $this->body;
  157. } else if ($this->category == Notifications::NOTIFY_RESPONSE_EXPENSE) {
  158. $subject_data = sprintf(self::itemAlias('category', $this->category), $this->data['status']);
  159. if(isset(Yii::app()->session['name_email']) && Yii::app()->session['name_email'] != "")
  160. {
  161. $subject_data = str_replace("Your",Yii::app()->session['name_email'],$subject_data);
  162. unset(Yii::app()->session['name_email']);
  163. }
  164. $message_data = $this->body;
  165. $message_link = Yii::app()->createAbsoluteUrl('notifications/requests');
  166. } else if ($this->category == Notifications::NOTIFY_CLOCKOUT_REMINDER) {
  167. $subject_data = sprintf(self::itemAlias('category', $this->category), null);
  168. //$last_action = UserAttendance::getLastAction($user->id, $this->tenant_id);
  169. $today = strtotime(date('Y-m-d'));
  170. $last_log = UserAttendanceLog::getLastWorkingDayLog(($today - (24 * 3600)), $user->id, $this->tenant_id);
  171. if (!empty($last_log)) {
  172. $subject_data = sprintf(self::itemAlias('category', $this->category), date('Y-m-d', $last_log->shift_date->sec));
  173. }
  174. $message_data = $this->body;
  175. $message_link = Yii::app()->createAbsoluteUrl('notifications/notifications');
  176. //reset link in case of cron
  177. if (Yii::app()->user->getTenantId() == null) {
  178. $tenants = Tenants::model()->findByPk($this->tenant_id);
  179. if (!empty($tenants)) {
  180. $subdomain = $tenants->tenant_subdomain;
  181. $domain_url = $subdomain . '.darwinbox.in';
  182. $message_link = str_replace('darwinbox.darwinbox.in', $domain_url, $message_link);
  183. }
  184. }
  185. } elseif ($this->category == Notifications::NOTIFY_ASSIGN_SHIFT) {
  186. $subject_data = sprintf(self::itemAlias('category', $this->category), null);
  187. $message_data = Yii::app()->params['change_shift'];
  188. $message_link = Yii::app()->createAbsoluteUrl('notifications/notifications');
  189. }
  190. $template_data = array(
  191. 'tofullname' => $user->getFullname(),
  192. 'toemail' => $user->oldUser()->email,
  193. 'type' => $this->getType(),
  194. 'messagelink' => $message_link,
  195. 'messagedata' => $message_data,
  196. 'settingsurl' => null,
  197. 'created_date' => date("F d, Y", $this->created->sec),
  198. 'created_time' => date("h:i A", $this->created->sec),
  199. 'tenant' => $tenant->tenant_name,
  200. );
  201. } else {
  202. if ($this->category == self::NOTIFY_MESSAGE_REPLY || $this->category == self::NOTIFY_MESSAGE_LIKE) {
  203. $subject_data = sprintf(self::itemAlias('category', $this->category), $this->sender()->getFullname(), $this->getRootMessageType());
  204. } else {
  205. $messages = Messages::model()->findByPk($this->message_id);
  206. if (!empty($messages)) {
  207. /* leaves email changed as per new requirement */
  208. if ($messages->filter_type == "leave" && $this->isRequest == true) {
  209. /**/
  210. $from_date = strtotime($messages->attachments['items']['from_date']);
  211. $to_date = strtotime($messages->attachments['items']['to_date']);
  212. $datediff = $to_date - $from_date;
  213. $total_leaves_days_count = floor($datediff/(60*60*24)) + 1;
  214. /**/
  215. //$total_leaves_days_count = count($messages->attachments['items']['total_days']);
  216. //$total_working_days = count(RandomHelper::getWorkingDays(strtotime($messages->attachments['items']['from_date']),strtotime($messages->attachments['items']['to_date']),$sender_user->id,$sender_user->tenant_id));
  217. /**/
  218. $check_holiday = false;
  219. $check_weekly_off = false;
  220. $leave_type = $messages->attachments['items']['type'];
  221. $tenant_leaves_model = Leaves::model()->tenant()->findByPk($leave_type);
  222. if(isset($tenant_leaves_model) && !empty($tenant_leaves_model))
  223. {
  224. if($tenant_leaves_model->policy_count_intervening_holidays->status == Leaves::STATUS_ENABLE)
  225. {
  226. if(isset($tenant_leaves_model->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday']) && $tenant_leaves_model->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday'] == Leaves::STATUS_ENABLE)
  227. {
  228. $check_holiday = true;
  229. }
  230. if(isset($tenant_leaves_model->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off']) && $tenant_leaves_model->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off'] == Leaves::STATUS_ENABLE)
  231. {
  232. $check_weekly_off = true;
  233. }
  234. }
  235. }
  236. if($check_weekly_off && !$check_holiday)
  237. {
  238. $days_co = RandomHelper::getWorkingDaysIncludingWeeklyoff(strtotime($messages->attachments['items']['from_date']),strtotime($messages->attachments['items']['to_date']),$sender_user->id,$sender_user->tenant_id);
  239. $holidays = RandomHelper::getHolidays(strtotime($messages->attachments['items']['from_date']),strtotime($messages->attachments['items']['to_date']), $this->tenant_id);
  240. $total_working_days = count(RandomHelper::excludeHolidays($days_co, $holidays));
  241. }
  242. /*else{
  243. $days_co = RandomHelper::getWorkingDays(strtotime($messages->attachments['items']['from_date']),strtotime($messages->attachments['items']['to_date']),$sender_user->id,$sender_user->tenant_id);
  244. }*/
  245. elseif($check_holiday && !$check_weekly_off)
  246. {
  247. $days_co = RandomHelper::getWorkingDays(strtotime($messages->attachments['items']['from_date']),strtotime($messages->attachments['items']['to_date']),$sender_user->id,$sender_user->tenant_id);
  248. $total_working_days = count($days_co);
  249. }
  250. elseif($check_holiday && $check_weekly_off)
  251. {
  252. $total_working_days = $total_leaves_days_count;
  253. }
  254. else
  255. {
  256. $days_co = RandomHelper::getWorkingDays(strtotime($messages->attachments['items']['from_date']),strtotime($messages->attachments['items']['to_date']),$sender_user->id,$sender_user->tenant_id);
  257. $holidays = RandomHelper::getHolidays(strtotime($messages->attachments['items']['from_date']),strtotime($messages->attachments['items']['to_date']), $this->tenant_id);
  258. $total_working_days = count(RandomHelper::excludeHolidays($days_co, $holidays));
  259. }
  260. /**/
  261. $total_non_working_days = $total_leaves_days_count - $total_working_days;
  262. if($total_leaves_days_count == 1)
  263. {
  264. $leave_id_for_user = $messages->attachments['items']['id'];
  265. $leave_object = UserLeaves::model()->findByPk($leave_id_for_user);
  266. if(isset($leave_object) && !empty($leave_object))
  267. {
  268. $is_half_day = $leave_object->is_half_day;
  269. if(isset($is_half_day) && $is_half_day == UserLeaves::HALF_DAY_YES)
  270. {
  271. $total_leaves_days_count = "Half Day";
  272. }
  273. }
  274. }
  275. $template_data_leaves = array(
  276. "leave_from_date" => $messages->attachments['items']['from_date'],
  277. "leave_to_date" => $messages->attachments['items']['to_date'],
  278. "leaves_total_days" => $total_leaves_days_count,
  279. "leaves_total_working_days" => $total_working_days,
  280. "leaves_total_non_working_days" => $total_non_working_days,
  281. "leaves_message_reason" => $messages->body_plain,
  282. "leaves_image_url" => "https://".$subdomain.".darwinbox.in" . Yii::app()->theme->baseUrl . "/images/leave.png",
  283. "leaves_leaves_name" => $messages->getLeaveType(),
  284. "leaves_user_image" => $messages->whosPhoto(),
  285. "url_approve" => "https://".$subdomain.".darwinbox.in/messages/LeaveActionEmailOrRequestPage/leave_id/" . $messages->attachments['items']['id'] . "/message_id/" . $messages->id . "/user_id/" . $user->user_id . "/action/approve",
  286. "url_decline" => "https://".$subdomain.".darwinbox.in/messages/LeaveActionEmailOrRequestPage/leave_id/" . $messages->attachments['items']['id'] . "/message_id/" . $messages->id . "/user_id/" . $user->user_id . "/action/decline",
  287. );
  288. } else {
  289. $template_data_leaves = array();
  290. }
  291. /* leaves email changed as per new requirement */
  292. /* attendance request email as per new requirement */
  293. if ($messages->filter_type == "attendance_request" && $this->isRequest == true) {
  294. /* getting location requested */
  295. if (isset($messages->attachments['items']['location']) && $messages->attachments['items']['location'] != "") {
  296. if ($messages->attachments['items']['location'] == UserAttendance::WORK_FROM_OFFICE) {
  297. $attendance_request_location = "Office";
  298. } elseif ($messages->attachments['items']['location'] == UserAttendance::WORK_FROM_HOME) {
  299. $attendance_request_location = "Home";
  300. } else {
  301. $attendance_request_location = "Field Duty";
  302. }
  303. } else {
  304. $attendance_request_location = "N.A.";
  305. }
  306. /* getting location requested */
  307.  
  308. /*get logs for the same date previously stored*/
  309. if(isset($messages->attachments['items']['clock_in_timestamp']->sec) && $messages->attachments['items']['clock_in_timestamp']->sec != "")
  310. {
  311. $start = strtotime(date("Y-m-d", $messages->attachments['items']['clock_in_timestamp']->sec));
  312. $criteria = new EMongoCriteria();
  313. $criteria->user_id = $sender_user->id;
  314. $criteria->shift_date('==', new MongoDate($start));
  315. $user_attendance_log = UserAttendanceLog::model()->tenant($messages->tenant_id)->find($criteria);
  316. $attendance_request_punchin_time = (isset($user_attendance_log->punchin_time) && $user_attendance_log->punchin_time != "") ? $user_attendance_log->punchin_time : "N.A.";
  317. $attendance_request_punchout_time = (isset($user_attendance_log->punchout_time) && $user_attendance_log->punchout_time != "") ? $user_attendance_log->punchout_time : "N.A.";
  318. $attendance_request_previous_location = "Office";
  319. }
  320. else{
  321. $attendance_request_punchin_time = "N.A.";
  322. $attendance_request_punchout_time = "N.A.";
  323. $attendance_request_previous_location = "N.A.";
  324. }
  325. /*get logs for the same date previously stored*/
  326. $template_data_attendance_request = array(
  327. "attendance_request_user_image" => $messages->whosPhoto(),
  328. "attendance_request_clockin_time" => date("H:i:s, Y-m-d", $messages->attachments['items']['clock_in_timestamp']->sec),
  329. "attendance_request_clockout_time" => date("H:i:s, Y-m-d", $messages->attachments['items']['clock_out_timestamp']->sec),
  330. "attendance_request_location" => $attendance_request_location,
  331. "attendance_request_message_reason" => $messages->body_plain,
  332. "attendance_request_previous_clockin_time" => $attendance_request_punchin_time,
  333. "attendance_request_previous_clockout_time" => $attendance_request_punchout_time,
  334. "attendance_request_previous_location" => $attendance_request_previous_location,
  335. "attendance_request_image_url" => "https://".$subdomain.".darwinbox.in" . Yii::app()->baseUrl . "/images/icons/attendanceClock.png",
  336. //"attendance_request_leaves_name" => $messages->getLeaveType(),
  337. "attendance_request_url_approve" => "https://".$subdomain.".darwinbox.in/request/process/id/" . $messages->id ."/action/accept",
  338. "attendance_request_url_decline" => "https://".$subdomain.".darwinbox.in/request/process/id/" . $messages->id ."/action/reject",
  339. );
  340. } else {
  341. $template_data_attendance_request = array();
  342. }
  343.  
  344. /* attendance request email as per new requirement */
  345.  
  346. /* attendance clock in request email as per new requirement */
  347. if ($messages->filter_type == "attendance" && $this->isRequest == true) {
  348. /* getting location requested */
  349. if (isset($messages->attachments['items']['location']) && $messages->attachments['items']['location'] != "") {
  350. if ($messages->attachments['items']['location'] == UserAttendance::WORK_FROM_OFFICE) {
  351. $attendance_request_location = "Office";
  352. } elseif ($messages->attachments['items']['location'] == UserAttendance::WORK_FROM_HOME) {
  353. $attendance_request_location = "Home";
  354. } else {
  355. $attendance_request_location = "Field Duty";
  356. }
  357. } else {
  358. $attendance_request_location = "N.A.";
  359. }
  360. /* getting location requested */
  361.  
  362. /*get logs for the same date previously stored*/
  363. if(isset($messages->attachments['items']['clock_in_timestamp']->sec) && $messages->attachments['items']['clock_in_timestamp']->sec != "")
  364. {
  365. $start = strtotime(date("Y-m-d", $messages->attachments['items']['clock_in_timestamp']->sec));
  366. $criteria = new EMongoCriteria();
  367. $criteria->user_id = $sender_user->id;
  368. $criteria->shift_date('==', new MongoDate($start));
  369. $user_attendance_log = UserAttendanceLog::model()->tenant($messages->tenant_id)->find($criteria);
  370. $attendance_request_punchin_time = (isset($user_attendance_log->punchin_time) && $user_attendance_log->punchin_time != "") ? $user_attendance_log->punchin_time : "N.A.";
  371. //$attendance_request_punchout_time = (isset($user_attendance_log->punchout_time) && $user_attendance_log->punchout_time != "") ? $user_attendance_log->punchout_time : "N.A.";
  372. if(isset($attendance_request_punchin_time) && $attendance_request_punchin_time != "N.A.")
  373. {
  374. $attendance_request_previous_location = "Office";
  375. }
  376. else{
  377. $attendance_request_previous_location = "N.A.";
  378. }
  379. }
  380. else{
  381. $attendance_request_punchin_time = "N.A.";
  382. //$attendance_request_punchout_time = "N.A.";
  383. $attendance_request_previous_location = "N.A.";
  384. }
  385. /*get logs for the same date previously stored*/
  386. $template_data_attendance_request_clock_in = array(
  387. "attendance_request_user_image" => $messages->whosPhoto(),
  388. "attendance_request_clockin_time" => date("H:i:s, Y-m-d", $messages->attachments['items']['clock_in_timestamp']->sec),
  389. //"attendance_request_clockout_time" => date("H:i:s, Y-m-d", $messages->attachments['items']['clock_out_timestamp']->sec),
  390. "attendance_request_location" => $attendance_request_location,
  391. "attendance_request_message_reason" => $messages->body_plain,
  392. "attendance_request_previous_clockin_time" => $attendance_request_punchin_time,
  393. //"attendance_request_previous_clockout_time" => $attendance_request_punchout_time,
  394. "attendance_request_previous_location" => $attendance_request_previous_location,
  395. "attendance_request_image_url" => "https://".$subdomain.".darwinbox.in" . Yii::app()->baseUrl . "/images/icons/attendanceClock.png",
  396. //"attendance_request_leaves_name" => $messages->getLeaveType(),
  397. "attendance_request_url_approve" => "https://".$subdomain.".darwinbox.in/request/process/id/" . $messages->id ."/action/accept",
  398. "attendance_request_url_decline" => "https://".$subdomain.".darwinbox.in/request/process/id/" . $messages->id ."/action/reject",
  399. );
  400. } else {
  401. $template_data_attendance_request_clock_in = array();
  402. }
  403.  
  404. /* attendance clock in request email as per new requirement */
  405. /* Admin or Manager Responded on Leave Request*/
  406. if(isset($this->message_id) && $this->message_id!=''){
  407. $leave_attn_status = "responded to";
  408. // $messages = Messages::model()->findByPk($this->message_id);
  409. if($messages->filter_type == "leave" && $this->isRequest == FALSE){
  410. if(isset($messages->attachments['items']['status']) && $messages->attachments['items']['status'] == UserLeaves::STATUS_APPROVED){
  411. $leave_attn_status = "Approved";
  412. }else{
  413. $leave_attn_status = "Rejected";
  414. }
  415. $template_data_leaves_response = array(
  416. "leave_from_date" => $messages->attachments['items']['from_date'],
  417. "leave_to_date" => $messages->attachments['items']['to_date'],
  418. "leaves_message_reason" => $messages->body_plain,
  419. "leaves_image_url" => "https://".$subdomain.".darwinbox.in" . Yii::app()->theme->baseUrl . "/images/leave.png",
  420. "leaves_leaves_name" => $messages->getLeaveType(),
  421. "status"=>$leave_attn_status
  422. );
  423. }
  424. if(($messages->filter_type == "attendance" || $messages->filter_type =="attendance_request") && ($messages->message_type == "update" && $this->isRequest == FALSE) ){
  425. if(isset($messages->attachments['items']['status']) && $messages->attachments['items']['status'] == UserLeaves::STATUS_APPROVED){
  426. $leave_attn_status = "Approved";
  427. }else{
  428. $leave_attn_status = "Rejected";
  429. }
  430. if($messages->filter_type == "attendance"){
  431. $update_type ="Clock In";
  432. }else{
  433. $update_type ="Attendance Update";
  434. }
  435. $template_data_attendace_update = array(
  436. "clock_in_timestamp" => $messages->attachments['items']['clock_in_timestamp'],
  437. "clock_out_timestamp" => $messages->attachments['items']['clock_out_timestamp'],
  438. "status"=>$leave_attn_status,
  439. "update_type" => $update_type
  440. );
  441. }
  442. }
  443.  
  444. /* EOF Admin or Manager Responded on Leave Request*/
  445. if (Yii::app()->user->id == $messages->sender_id) {
  446. if($this->category == self::NOTIFY_LEAVE_RESPONSE || $this->category == self::NOTIFY_RESPONSE_ATTENDANCE){
  447. $subject_data = sprintf(self::itemAlias('category', $this->category), $this->sender($this->tenant_id)->getFullname(),$leave_attn_status);
  448. }else{
  449. $subject_data = sprintf(self::itemAlias('category', $this->category), $this->sender($this->tenant_id)->getFullname());
  450. }
  451.  
  452. } else {
  453. if ($messages->last_action == null) { //!= Notifications::TYPE_REQUEST && $messages->last_action != Notifications::TYPE_LIKE) {
  454. $applying_user = UserMongo::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
  455. $appling_user_name = null;
  456. if (!empty($applying_user)) {
  457. $appling_user_name = $applying_user->getFullname();
  458. }
  459. $messageSenderUser = UserMongo::model()->findByAttributes(array("user_id" => $messages->sender_id));
  460. $message_sender_user = "";
  461. if (!empty($messageSenderUser)) {
  462. $message_sender_user = $messageSenderUser->getFullname();
  463. }
  464. $subject_data = sprintf(self::itemAlias('category', self::NOTIFY_LEAVE_ONBEHALF_REQUEST), $appling_user_name, $message_sender_user);
  465. } else {
  466. if($this->category == self::NOTIFY_LEAVE_RESPONSE || $this->category == self::NOTIFY_RESPONSE_ATTENDANCE){
  467. $subject_data = sprintf(self::itemAlias('category', $this->category), $this->sender($this->tenant_id)->getFullname(),$leave_attn_status);
  468. }else{
  469. $subject_data = sprintf(self::itemAlias('category', $this->category), $this->sender($this->tenant_id)->getFullname());
  470. }
  471.  
  472. }
  473. }
  474. } else {
  475. $subject_data = sprintf(self::itemAlias('category', $this->category), $this->sender($this->tenant_id)->getFullname());
  476. }
  477. }
  478.  
  479. //reset link in case of cron
  480. if ($this->category == self::NOTIFY_RESET_PASSWORD || $this->category == self::NOTIFY_ASSIGN_SHIFT) {
  481. $email_message_link = Yii::app()->createAbsoluteUrl('notifications/notifications');
  482. $subject_data = Yii::app()->params['change_shift'];
  483. } else {
  484. $email_message_link = ($this->message_id != null) ? Yii::app()->createAbsoluteUrl('messages/thread', array('id' => $this->message_id)) : Yii::app()->createAbsoluteUrl('notifications/requests');
  485. }
  486. $email_setting_url = Yii::app()->createAbsoluteUrl('employee/settings');
  487. if (Yii::app()->user->getTenantId() == null) {
  488. $tenants = Tenants::model()->findByPk($this->tenant_id);
  489. if (!empty($tenants)) {
  490. $subdomain = $tenants->tenant_subdomain;
  491. $domain_url = $subdomain . '.darwinbox.in';
  492. $email_message_link = str_replace('darwinbox.darwinbox.in', $domain_url, $email_message_link);
  493. $email_setting_url = str_replace('darwinbox.darwinbox.in', $domain_url, $email_message_link);
  494. }
  495. }
  496.  
  497. $template_data = array(
  498. 'tofullname' => $user->getFullname(),
  499. 'toemail' => $user->oldUser()->email,
  500. 'type' => $this->getType(),
  501. 'messagelink' => $email_message_link, //($this->message_id != null) ? Yii::app()->createAbsoluteUrl('messages/thread', array('id' => $this->message_id)) : Yii::app()->createAbsoluteUrl('notifications/requests'),
  502. 'messagedata' => ($this->category == self::NOTIFY_RESET_PASSWORD ) ? $this->body : $subject_data,
  503. 'settingsurl' => $email_setting_url, //Yii::app()->createAbsoluteUrl('employee/settings'),
  504. 'created_date' => date("F d, Y", $this->created->sec),
  505. 'created_time' => date("h:i A", $this->created->sec),
  506. 'tenant' => (isset($tenant->tenant_name) && $tenant->tenant_name != "") ? $tenant->tenant_name : $tenant->tenant_subdomain,
  507. 'darwinbox_logo' => "https://".$subdomain.".darwinbox.in" . Yii::app()->baseUrl . "/images/darwinbox/darwinbox_logo.png",
  508. );
  509. }
  510. /*Check manager if not manager then dont send new emails which contains approve and decline button*/
  511. if(isset($template_data_leaves) && !empty($template_data_leaves))
  512. {
  513. $managers = $sender_user->getAllManagers();
  514. if(!in_array($this->recipient_id, $managers))
  515. {
  516. $template_data_leaves = array();
  517. }
  518. }
  519. /*Check manager if not manager then dont send new emails which contains approve and decline button*/
  520.  
  521. if(!isset($template_data_leaves))
  522. {
  523. $template_data_leaves = array();
  524. }
  525. if(!isset($template_data_attendance_request))
  526. {
  527. $template_data_attendance_request = array();
  528. }
  529. if(!isset($template_data_attendance_request_clock_in))
  530. {
  531. $template_data_attendance_request_clock_in = array();
  532. }
  533. $_view = Yii::app()->controller->renderPartial("//emailTemplates/notification", array('data' => $template_data,'date_leaves_response'=>$template_data_leaves_response,'update_clockin_response'=>$template_data_attendace_update, 'data_leaves' => $template_data_leaves, 'data_attendance_request' => $template_data_attendance_request, 'template_data_attendance_request_clock_in' => $template_data_attendance_request_clock_in, 'tenant_id' => Yii::app()->user->getTenantId()), true);
  534. $tenant_name_email = (isset($tenant->tenant_name) && $tenant->tenant_name != "") ? $tenant->tenant_name : $tenant->tenant_subdomain;
  535. /*from email changing according to new email sending email ids*/
  536. if(isset($this->is_for) && ($this->is_for == Messages::MESSAGE_LIKE_DONE || $this->is_for == Messages::MESSAGE_SALARY_DONE || $this->is_for == Messages::MESSAGE_PRIVATE_EMAIL))
  537. {
  538. $from_email_final = $tenant_name_email." <alerts@darwinbox.in>";
  539. }
  540. else{
  541. $from_email_final = $tenant_name_email." <requests@darwinbox.in>";
  542. }
  543. /*from email changing according to new email sending email ids*/
  544. // making a check for reset password request
  545. $subject_data = ($this->category == self::NOTIFY_RESET_PASSWORD ) ? strip_tags($this->body) : $subject_data;
  546. // making a check for reset password request
  547. $emails = array(
  548. 'tofullname' => $user->getFullname(),
  549. 'toemail' => $user->oldUser()->email,
  550. 'fromemail' => $from_email_final,
  551. 'subject' => $subject_data,
  552. 'html' => $_view,
  553. );
  554. $encode_json = array("data" => json_encode($emails));
  555.  
  556. $post_result = PostRequest::post_request("http://localhost/sendNotificationEmail", $encode_json, $attachment);
  557. if (isset($post_result['status']) && $post_result['status'] == 'ok') {
  558. EmailLogs::log(EmailLogs::TYPE_NOTIFICATION, $emails['toemail'], $emails['tofullname'], $emails['subject'], $_view, null, "sent", $this->message_id);
  559. } else {
  560. EmailLogs::log(EmailLogs::TYPE_NOTIFICATION, $emails['toemail'], $emails['tofullname'], $emails['subject'], $_view, null, "pending", $this->message_id);
  561. }
  562. }
  563. }
  564.  
  565. public static function itemAlias($type, $code = NULL) {
  566. $_items = array(
  567. 'type' => array(
  568. self::TYPE_LIKE => 'likes',
  569. self::TYPE_REPLY => 'replied',
  570. self::TYPE_VOTE => 'voted',
  571. self::TYPE_EVENT => 'responded',
  572. self::TYPE_REQUEST => 'requested',
  573. ),
  574. 'filter' => array(
  575. self::FILTER_UPDATE => 'Update',
  576. self::FILTER_QUESTION => 'Question',
  577. self::FILTER_POLL => 'Poll',
  578. self::FILTER_EVENT => 'Event',
  579. self::FILTER_LEAVE => 'Leave',
  580. self::FILTER_INVITE => 'Invitation',
  581. self::FILTER_SYSTEM_EVENT => 'System',
  582. self::FILTER_ATTEDANCE_REQUEST => 'Attendance Request',
  583. self::FILTER_ATTENDANCE => 'Attendance Request'
  584. ),
  585. 'category' => array(
  586. self::NOTIFY_MESSAGE_MENTION => "You have been Mentioned by %s",
  587. self::NOTIFY_LEAVE_REQUEST => "Leave requested by %s",
  588. self::NOTIFY_LEAVE_RESPONSE => "%s has %s your Leave Request",
  589. self::NOTIFY_MESSAGE_LIKE => "%s likes your %s",
  590. self::NOTIFY_MESSAGE_PRIVATE => "%s has sent you a Private Message",
  591. self::NOTIFY_MESSAGE_REPLY => "%s has replied to your %s",
  592. self::NOTIFY_REQUEST_OWNER => "%s has invited you to join a Group",
  593. self::NOTIFY_REQUEST_USER => "%s has requested to join a Group",
  594. self::NOTIFY_EVENT_SALARY => "Your salary for the month of %s has been processed.",
  595. self::NOTIFY_REQUEST_EXPENSE => "%s has requested a reimbursement",
  596. self::NOTIFY_RESPONSE_EXPENSE => "Your expense request has been %s",
  597. self::NOTIFY_REQUEST_ATTENDANCE => "Attendance update requested By %s",
  598. self::NOTIFY_RESPONSE_ATTENDANCE => "%s has %s your Attendance Request",
  599. self::NOTIFY_RESET_PASSWORD => "%s has reset your password.",
  600. self::NOTIFY_CLOCKOUT_REMINDER => "You are marked absent for %s",
  601. self::NOTIFY_ASSIGN_SHIFT => "Assigned New Shift.",
  602. self::NOTIFY_LEAVE_ONBEHALF_REQUEST => "%s has applied for leave on behalf of %s",
  603. )
  604. );
  605. if (isset($code))
  606. return isset($_items[$type][$code]) ? $_items[$type][$code] : false;
  607. else
  608. return isset($_items[$type]) ? $_items[$type] : false;
  609. }
  610.  
  611. public function weekly() {
  612. $today = new MongoDate(strtotime(date('Y-m-d')));
  613. $last_week = new MongoDate(strtotime(date('Y-m-d', strtotime('-1 Week'))));
  614. $this->getDbCriteria()->mergeWith(array(
  615. 'conditions' => array(
  616. 'created' => array('<=' => $today),
  617. 'created' => array('>' => $last_week),
  618. ),
  619. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  620. ));
  621. return $this;
  622. }
  623.  
  624. public function daily() {
  625. $start = new MongoDate(strtotime(date('Y-m-d 00:00:00')));
  626.  
  627. $this->getDbCriteria()->mergeWith(array(
  628. 'conditions' => array(
  629. 'created' => array('>=' => $start),
  630. ),
  631. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  632. ));
  633. return $this;
  634. }
  635.  
  636. public function tenant($tenant_id = null) {
  637. $this->getDbCriteria()->mergeWith(array(
  638. 'conditions' => array(
  639. 'tenant_id' => array('==' => ($tenant_id == null) ? Yii::app()->user->getTenantId() : $tenant_id),
  640. ),
  641. ));
  642. return $this;
  643. }
  644.  
  645. public function getAll($type = null) {
  646. //$when = strtotime('-3 months');
  647. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  648. {
  649. $this->getDbCriteria()->mergeWith(array(
  650. 'conditions' => array(
  651. 'isRequest' => array('==' => ($type == null) ? false : true),
  652. ),
  653. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  654. ));
  655. }
  656. else{
  657. $this->getDbCriteria()->mergeWith(array(
  658. 'conditions' => array(
  659. 'recipient_id' => array('==' => Yii::app()->user->id),
  660. 'isRequest' => array('==' => ($type == null) ? false : true),
  661. //'type'=> array('==' => self::FILTER_INVITE_GROUP),
  662. //'created' => array('>=' => new MongoDate($when)),
  663. ),
  664. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  665. ));
  666. }
  667.  
  668. return $this;
  669. }
  670.  
  671. public function getAllSender($type = null) {
  672.  
  673. $this->getDbCriteria()->mergeWith(array(
  674. 'conditions' => array(
  675. 'sender_id' => array('==' => Yii::app()->user->id),
  676. 'isRequest' => array('==' => ($type == null) ? false : true),
  677. ),
  678. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  679. ));
  680. return $this;
  681. }
  682.  
  683. public function getAllArchieved($type = null) {
  684. $when = strtotime('-3 months');
  685. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  686. {
  687. $this->getDbCriteria()->mergeWith(array(
  688. 'conditions' => array(
  689. 'read_status' => array('==' => self::READ_STATUS_READ),
  690. 'isRequest' => array('==' => ($type == null) ? false : true),
  691. 'created' => array('<=' => new MongoDate($when)),
  692. ),
  693. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  694. ));
  695. }
  696. else{
  697. $this->getDbCriteria()->mergeWith(array(
  698. 'conditions' => array(
  699. 'recipient_id' => array('==' => Yii::app()->user->id),
  700. 'read_status' => array('==' => self::READ_STATUS_READ),
  701. 'isRequest' => array('==' => ($type == null) ? false : true),
  702. 'created' => array('<=' => new MongoDate($when)),
  703. ),
  704. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  705. ));
  706. }
  707. return $this;
  708. }
  709. public function getAllArchievedSender($type = null) {
  710. $when = strtotime('-3 months');
  711. $this->getDbCriteria()->mergeWith(array(
  712. 'conditions' => array(
  713. 'sender_id' => array('==' => Yii::app()->user->id),
  714. 'read_status' => array('==' => self::READ_STATUS_READ),
  715. 'isRequest' => array('==' => ($type == null) ? false : true),
  716. 'created' => array('<=' => new MongoDate($when)),
  717. ),
  718. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  719. ));
  720. return $this;
  721. }
  722.  
  723. public function getAllProcessed($type = null) {
  724. $when = strtotime('-3 months');
  725. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  726. {
  727. $this->getDbCriteria()->mergeWith(array(
  728. 'conditions' => array(
  729. 'read_status' => array('==' => self::READ_STATUS_READ),
  730. 'isRequest' => array('==' => ($type == null) ? false : true),
  731. 'created' => array('>=' => new MongoDate($when)),
  732. ),
  733. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  734. ));
  735. }
  736. else{
  737. $this->getDbCriteria()->mergeWith(array(
  738. 'conditions' => array(
  739. 'recipient_id' => array('==' => Yii::app()->user->id),
  740. 'read_status' => array('==' => self::READ_STATUS_READ),
  741. 'isRequest' => array('==' => ($type == null) ? false : true),
  742. 'created' => array('>=' => new MongoDate($when)),
  743. ),
  744. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  745. ));
  746. }
  747. return $this;
  748. }
  749.  
  750. public function getAllProcessedSender($type = null) {
  751. $when = strtotime('-3 months');
  752. $this->getDbCriteria()->mergeWith(array(
  753. 'conditions' => array(
  754. 'sender_id' => array('==' => Yii::app()->user->id),
  755. 'read_status' => array('==' => self::READ_STATUS_READ),
  756. 'isRequest' => array('==' => ($type == null) ? false : true),
  757. 'created' => array('>=' => new MongoDate($when)),
  758. ),
  759. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  760. ));
  761. return $this;
  762. }
  763.  
  764. public function getAllPending($type = null) {
  765. //$when = strtotime('-3 months');
  766. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  767. {
  768. $this->getDbCriteria()->mergeWith(array(
  769. 'conditions' => array(
  770. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  771. 'isRequest' => array('==' => ($type == null) ? false : true),
  772. //'created' => array('>=' => new MongoDate($when)),
  773. ),
  774. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  775. ));
  776. }
  777. else{
  778. $this->getDbCriteria()->mergeWith(array(
  779. 'conditions' => array(
  780. 'recipient_id' => array('==' => Yii::app()->user->id),
  781. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  782. 'isRequest' => array('==' => ($type == null) ? false : true),
  783. //'created' => array('>=' => new MongoDate($when)),
  784. ),
  785. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  786. ));
  787. }
  788.  
  789. return $this;
  790. }
  791. public function getAllPendingSender($type = null) {
  792. //$when = strtotime('-3 months');
  793. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  794. {
  795. $this->getDbCriteria()->mergeWith(array(
  796. 'conditions' => array(
  797. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  798. 'isRequest' => array('==' => ($type == null) ? false : true),
  799. ),
  800. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  801. ));
  802. }
  803. else{
  804. $this->getDbCriteria()->mergeWith(array(
  805. 'conditions' => array(
  806. 'sender_id' => array('==' => Yii::app()->user->id),
  807. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  808. 'isRequest' => array('==' => ($type == null) ? false : true),
  809. //'created' => array('>=' => new MongoDate($when)),
  810. ),
  811. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  812. ));
  813. }
  814.  
  815. return $this;
  816. }
  817.  
  818. public function getAllPendingatt($type = null, $request_type = self::FILTER_ATTENDANCE, $user_id = null) {
  819. if ($user_id == null) {
  820. $user_id = Yii::app()->user->id;
  821. }
  822. if ($request_type == self::FILTER_ATTENDANCE) {
  823. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  824. {
  825. $this->getDbCriteria()->mergeWith(array(
  826. 'conditions' => array(
  827. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  828. 'isRequest' => array('==' => ($type == null) ? false : true),
  829. //'type'=> array('==' => self::FILTER_ATTEDANCE_REQUEST),
  830. 'type' => array('==' => self::FILTER_ATTENDANCE),
  831. ),
  832. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  833. ));
  834. }
  835. else{
  836. $this->getDbCriteria()->mergeWith(array(
  837. 'conditions' => array(
  838. 'recipient_id' => array('==' => $user_id),
  839. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  840. 'isRequest' => array('==' => ($type == null) ? false : true),
  841. //'type'=> array('==' => self::FILTER_ATTEDANCE_REQUEST),
  842. 'type' => array('==' => self::FILTER_ATTENDANCE),
  843. ),
  844. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  845. ));
  846. }
  847.  
  848. } else {
  849. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  850. {
  851. $this->getDbCriteria()->mergeWith(array(
  852. 'conditions' => array(
  853. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  854. 'isRequest' => array('==' => ($type == null) ? false : true),
  855. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  856. // 'type'=> array('==' => self::FILTER_ATTENDANCE),
  857. ),
  858. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  859. ));
  860. }
  861. else{
  862. $this->getDbCriteria()->mergeWith(array(
  863. 'conditions' => array(
  864. 'recipient_id' => array('==' => $user_id),
  865. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  866. 'isRequest' => array('==' => ($type == null) ? false : true),
  867. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  868. // 'type'=> array('==' => self::FILTER_ATTENDANCE),
  869. ),
  870. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  871. ));
  872. }
  873.  
  874. }
  875. return $this;
  876. }
  877.  
  878. public function getAllPendingattSender($type = null, $request_type = self::FILTER_ATTENDANCE, $user_id = null) {
  879. if ($user_id == null) {
  880. $user_id = Yii::app()->user->id;
  881. }
  882. if ($request_type == self::FILTER_ATTENDANCE) {
  883. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  884. {
  885. $this->getDbCriteria()->mergeWith(array(
  886. 'conditions' => array(
  887. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  888. 'isRequest' => array('==' => ($type == null) ? false : true),
  889. 'type' => array('==' => self::FILTER_ATTENDANCE),
  890. ),
  891. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  892. ));
  893. }
  894. else{
  895. $this->getDbCriteria()->mergeWith(array(
  896. 'conditions' => array(
  897. 'sender_id' => array('==' => $user_id),
  898. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  899. 'isRequest' => array('==' => ($type == null) ? false : true),
  900. 'type' => array('==' => self::FILTER_ATTENDANCE),
  901. ),
  902. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  903. ));
  904. }
  905.  
  906. } else {
  907. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  908. {
  909. $this->getDbCriteria()->mergeWith(array(
  910. 'conditions' => array(
  911. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  912. 'isRequest' => array('==' => ($type == null) ? false : true),
  913. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  914. ),
  915. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  916. ));
  917. }
  918. else{
  919. $this->getDbCriteria()->mergeWith(array(
  920. 'conditions' => array(
  921. 'sender_id' => array('==' => $user_id),
  922. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  923. 'isRequest' => array('==' => ($type == null) ? false : true),
  924. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  925. ),
  926. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  927. ));
  928. }
  929.  
  930. }
  931. return $this;
  932. }
  933.  
  934. public function getAllProcessedatt($type = null, $request_type = self::FILTER_ATTENDANCE) {
  935. $when = strtotime('-3 months');
  936. if ($request_type == self::FILTER_ATTENDANCE) {
  937. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  938. {
  939. $this->getDbCriteria()->mergeWith(array(
  940. 'conditions' => array(
  941. 'read_status' => array('==' => self::READ_STATUS_READ),
  942. 'isRequest' => array('==' => ($type == null) ? false : true),
  943. 'type' => array('==' => self::FILTER_ATTENDANCE),
  944. 'created' => array('>=' => new MongoDate($when)),
  945. ),
  946. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  947. ));
  948. }
  949. else{
  950. $this->getDbCriteria()->mergeWith(array(
  951. 'conditions' => array(
  952. 'recipient_id' => array('==' => Yii::app()->user->id),
  953. 'read_status' => array('==' => self::READ_STATUS_READ),
  954. 'isRequest' => array('==' => ($type == null) ? false : true),
  955. 'type' => array('==' => self::FILTER_ATTENDANCE),
  956. 'created' => array('>=' => new MongoDate($when)),
  957. ),
  958. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  959. ));
  960. }
  961.  
  962. } else {
  963. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  964. {
  965. $this->getDbCriteria()->mergeWith(array(
  966. 'conditions' => array(
  967. 'read_status' => array('==' => self::READ_STATUS_READ),
  968. 'isRequest' => array('==' => ($type == null) ? false : true),
  969. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  970. 'created' => array('>=' => new MongoDate($when)),
  971. ),
  972. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  973. ));
  974. }
  975. else{
  976. $this->getDbCriteria()->mergeWith(array(
  977. 'conditions' => array(
  978. 'recipient_id' => array('==' => Yii::app()->user->id),
  979. 'read_status' => array('==' => self::READ_STATUS_READ),
  980. 'isRequest' => array('==' => ($type == null) ? false : true),
  981. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  982. 'created' => array('>=' => new MongoDate($when)),
  983. ),
  984. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  985. ));
  986. }
  987. }
  988. return $this;
  989. }
  990.  
  991. public function getAllProcessedattSender($type = null, $request_type = self::FILTER_ATTENDANCE) {
  992. $when = strtotime('-3 months');
  993. if ($request_type == self::FILTER_ATTENDANCE) {
  994. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  995. {
  996. $this->getDbCriteria()->mergeWith(array(
  997. 'conditions' => array(
  998. 'read_status' => array('==' => self::READ_STATUS_READ),
  999. 'isRequest' => array('==' => ($type == null) ? false : true),
  1000. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1001. 'created' => array('>=' => new MongoDate($when)),
  1002. ),
  1003. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1004. ));
  1005. }
  1006. else{
  1007. $this->getDbCriteria()->mergeWith(array(
  1008. 'conditions' => array(
  1009. 'sender_id' => array('==' => Yii::app()->user->id),
  1010. 'read_status' => array('==' => self::READ_STATUS_READ),
  1011. 'isRequest' => array('==' => ($type == null) ? false : true),
  1012. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1013. 'created' => array('>=' => new MongoDate($when)),
  1014. ),
  1015. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1016. ));
  1017. }
  1018.  
  1019. } else {
  1020. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  1021. {
  1022. $this->getDbCriteria()->mergeWith(array(
  1023. 'conditions' => array(
  1024. 'read_status' => array('==' => self::READ_STATUS_READ),
  1025. 'isRequest' => array('==' => ($type == null) ? false : true),
  1026. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  1027. 'created' => array('>=' => new MongoDate($when)),
  1028. ),
  1029. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1030. ));
  1031. }
  1032. else{
  1033. $this->getDbCriteria()->mergeWith(array(
  1034. 'conditions' => array(
  1035. 'sender_id' => array('==' => Yii::app()->user->id),
  1036. 'read_status' => array('==' => self::READ_STATUS_READ),
  1037. 'isRequest' => array('==' => ($type == null) ? false : true),
  1038. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  1039. 'created' => array('>=' => new MongoDate($when)),
  1040. ),
  1041. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1042. ));
  1043. }
  1044. }
  1045. return $this;
  1046. }
  1047.  
  1048. public function getAllArchievedatt($type = null, $request_type = self::FILTER_ATTENDANCE) {
  1049. $when = strtotime('-3 months');
  1050. if ($request_type == self::FILTER_ATTENDANCE) {
  1051. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  1052. {
  1053. $this->getDbCriteria()->mergeWith(array(
  1054. 'conditions' => array(
  1055. 'read_status' => array('==' => self::READ_STATUS_READ),
  1056. 'isRequest' => array('==' => ($type == null) ? false : true),
  1057. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1058. 'created' => array('<=' => new MongoDate($when)),
  1059. ),
  1060. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1061. ));
  1062. }
  1063. else{
  1064. $this->getDbCriteria()->mergeWith(array(
  1065. 'conditions' => array(
  1066. 'recipient_id' => array('==' => Yii::app()->user->id),
  1067. 'read_status' => array('==' => self::READ_STATUS_READ),
  1068. 'isRequest' => array('==' => ($type == null) ? false : true),
  1069. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1070. 'created' => array('<=' => new MongoDate($when)),
  1071. ),
  1072. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1073. ));
  1074. }
  1075. } else {
  1076. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  1077. {
  1078. $this->getDbCriteria()->mergeWith(array(
  1079. 'conditions' => array(
  1080. 'read_status' => array('==' => self::READ_STATUS_READ),
  1081. 'isRequest' => array('==' => ($type == null) ? false : true),
  1082. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  1083. 'created' => array('<=' => new MongoDate($when)),
  1084. ),
  1085. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1086. ));
  1087. }
  1088. else{
  1089. $this->getDbCriteria()->mergeWith(array(
  1090. 'conditions' => array(
  1091. 'recipient_id' => array('==' => Yii::app()->user->id),
  1092. 'read_status' => array('==' => self::READ_STATUS_READ),
  1093. 'isRequest' => array('==' => ($type == null) ? false : true),
  1094. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  1095. 'created' => array('<=' => new MongoDate($when)),
  1096. ),
  1097. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1098. ));
  1099. }
  1100. }
  1101. return $this;
  1102. }
  1103.  
  1104. public function getAllatt($type = null, $request_type = self::FILTER_ATTENDANCE) {
  1105. if ($request_type == self::FILTER_ATTENDANCE) {
  1106. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  1107. {
  1108. $this->getDbCriteria()->mergeWith(array(
  1109. 'conditions' => array(
  1110. 'isRequest' => array('==' => ($type == null) ? false : true),
  1111. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1112. ),
  1113. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1114. ));
  1115. }
  1116. else{
  1117. $this->getDbCriteria()->mergeWith(array(
  1118. 'conditions' => array(
  1119. 'recipient_id' => array('==' => Yii::app()->user->id),
  1120. 'isRequest' => array('==' => ($type == null) ? false : true),
  1121. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1122. ),
  1123. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1124. ));
  1125. }
  1126.  
  1127. } else {
  1128. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  1129. {
  1130. $this->getDbCriteria()->mergeWith(array(
  1131. 'conditions' => array(
  1132. 'isRequest' => array('==' => ($type == null) ? false : true),
  1133. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  1134. ),
  1135. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1136. ));
  1137. }
  1138. else{
  1139. $this->getDbCriteria()->mergeWith(array(
  1140. 'conditions' => array(
  1141. 'recipient_id' => array('==' => Yii::app()->user->id),
  1142. 'isRequest' => array('==' => ($type == null) ? false : true),
  1143. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  1144. ),
  1145. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1146. ));
  1147. }
  1148.  
  1149. }
  1150. return $this;
  1151. }
  1152.  
  1153. public function getAllPendingleav($type = null, $user_id = null) {
  1154. if ($user_id == null) {
  1155. $user_id = Yii::app()->user->id;
  1156. }
  1157. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  1158. {
  1159. $this->getDbCriteria()->mergeWith(array(
  1160. 'conditions' => array(
  1161. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  1162. 'isRequest' => array('==' => ($type == null) ? false : true),
  1163. 'type' => array('==' => self::FILTER_LEAVE),
  1164. ),
  1165. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1166. ));
  1167. }
  1168. else{
  1169. $this->getDbCriteria()->mergeWith(array(
  1170. 'conditions' => array(
  1171. 'recipient_id' => array('==' => $user_id),
  1172. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  1173. 'isRequest' => array('==' => ($type == null) ? false : true),
  1174. 'type' => array('==' => self::FILTER_LEAVE),
  1175. ),
  1176. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1177. ));
  1178. }
  1179.  
  1180. return $this;
  1181. }
  1182.  
  1183. public function getAllPendingleavSender($type = null, $user_id = null) {
  1184. if ($user_id == null) {
  1185. $user_id = Yii::app()->user->id;
  1186. }
  1187.  
  1188. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  1189. {
  1190. $this->getDbCriteria()->mergeWith(array(
  1191. 'conditions' => array(
  1192. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  1193. 'isRequest' => array('==' => ($type == null) ? false : true),
  1194. 'type' => array('==' => self::FILTER_LEAVE),
  1195. ),
  1196. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1197. ));
  1198. }
  1199. else{
  1200. $this->getDbCriteria()->mergeWith(array(
  1201. 'conditions' => array(
  1202. 'sender_id' => array('==' => $user_id),
  1203. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  1204. 'isRequest' => array('==' => ($type == null) ? false : true),
  1205. 'type' => array('==' => self::FILTER_LEAVE),
  1206. ),
  1207. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1208. ));
  1209. }
  1210.  
  1211. return $this;
  1212. }
  1213.  
  1214. public function getAllProcessedleav($type = null) {
  1215. $when = strtotime('-3 months');
  1216. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  1217. {
  1218. $this->getDbCriteria()->mergeWith(array(
  1219. 'conditions' => array(
  1220. 'read_status' => array('==' => self::READ_STATUS_READ),
  1221. 'isRequest' => array('==' => ($type == null) ? false : true),
  1222. 'type' => array('==' => self::FILTER_LEAVE),
  1223. 'created' => array('>=' => new MongoDate($when)),
  1224. ),
  1225. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1226. ));
  1227. }
  1228. else{
  1229. $this->getDbCriteria()->mergeWith(array(
  1230. 'conditions' => array(
  1231. 'recipient_id' => array('==' => Yii::app()->user->id),
  1232. 'read_status' => array('==' => self::READ_STATUS_READ),
  1233. 'isRequest' => array('==' => ($type == null) ? false : true),
  1234. 'type' => array('==' => self::FILTER_LEAVE),
  1235. 'created' => array('>=' => new MongoDate($when)),
  1236. ),
  1237. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1238. ));
  1239. }
  1240.  
  1241. return $this;
  1242. }
  1243.  
  1244. public function getAllProcessedleavSender($type = null) {
  1245. $when = strtotime('-3 months');
  1246. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  1247. {
  1248. $this->getDbCriteria()->mergeWith(array(
  1249. 'conditions' => array(
  1250. 'read_status' => array('==' => self::READ_STATUS_READ),
  1251. 'isRequest' => array('==' => ($type == null) ? false : true),
  1252. 'type' => array('==' => self::FILTER_LEAVE),
  1253. 'created' => array('>=' => new MongoDate($when)),
  1254. ),
  1255. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1256. ));
  1257. }
  1258. else{
  1259. $this->getDbCriteria()->mergeWith(array(
  1260. 'conditions' => array(
  1261. 'sender_id' => array('==' => Yii::app()->user->id),
  1262. 'read_status' => array('==' => self::READ_STATUS_READ),
  1263. 'isRequest' => array('==' => ($type == null) ? false : true),
  1264. 'type' => array('==' => self::FILTER_LEAVE),
  1265. 'created' => array('>=' => new MongoDate($when)),
  1266. ),
  1267. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1268. ));
  1269. }
  1270.  
  1271. return $this;
  1272. }
  1273.  
  1274. public function getAllArchievedleav($type = null) {
  1275. $when = strtotime('-3 months');
  1276. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  1277. {
  1278. $this->getDbCriteria()->mergeWith(array(
  1279. 'conditions' => array(
  1280. 'read_status' => array('==' => self::READ_STATUS_READ),
  1281. 'type' => array('==' => self::FILTER_LEAVE),
  1282. 'isRequest' => array('==' => ($type == null) ? false : true),
  1283. 'created' => array('<=' => new MongoDate($when)),
  1284. ),
  1285. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1286. ));
  1287. }
  1288. else{
  1289. $this->getDbCriteria()->mergeWith(array(
  1290. 'conditions' => array(
  1291. 'recipient_id' => array('==' => Yii::app()->user->id),
  1292. 'read_status' => array('==' => self::READ_STATUS_READ),
  1293. 'type' => array('==' => self::FILTER_LEAVE),
  1294. 'isRequest' => array('==' => ($type == null) ? false : true),
  1295. 'created' => array('<=' => new MongoDate($when)),
  1296. ),
  1297. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1298. ));
  1299. }
  1300.  
  1301. return $this;
  1302. }
  1303.  
  1304. public function getAllleav($type = null) {
  1305. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")))
  1306. {
  1307. $this->getDbCriteria()->mergeWith(array(
  1308. 'conditions' => array(
  1309. 'isRequest' => array('==' => ($type == null) ? false : true),
  1310. 'type' => array('==' => self::FILTER_LEAVE),
  1311. ),
  1312. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1313. ));
  1314. }
  1315. else{
  1316. $this->getDbCriteria()->mergeWith(array(
  1317. 'conditions' => array(
  1318. 'recipient_id' => array('==' => Yii::app()->user->id),
  1319. 'isRequest' => array('==' => ($type == null) ? false : true),
  1320. 'type' => array('==' => self::FILTER_LEAVE),
  1321. ),
  1322. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1323. ));
  1324. }
  1325.  
  1326. return $this;
  1327. }
  1328.  
  1329. /* others filter */
  1330.  
  1331. public function getAllPendingother($type = null) {
  1332. $this->getDbCriteria()->mergeWith(array(
  1333. 'conditions' => array(
  1334. 'recipient_id' => array('==' => Yii::app()->user->id),
  1335. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  1336. 'isRequest' => array('==' => ($type == null) ? false : true),
  1337. 'sender_id' => array('!=' => Yii::app()->user->id),
  1338. ),
  1339. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1340. ));
  1341.  
  1342. return $this;
  1343. }
  1344.  
  1345. public function getAllPendingotheratt($type = null, $request_type = self::FILTER_ATTENDANCE) {
  1346. if ($request_type == self::FILTER_ATTENDANCE) {
  1347. $this->getDbCriteria()->mergeWith(array(
  1348. 'conditions' => array(
  1349. 'recipient_id' => array('==' => Yii::app()->user->id),
  1350. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  1351. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1352. 'isRequest' => array('==' => ($type == null) ? false : true),
  1353. 'sender_id' => array('!=' => Yii::app()->user->id),
  1354. ),
  1355. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1356. ));
  1357. } else {
  1358. $this->getDbCriteria()->mergeWith(array(
  1359. 'conditions' => array(
  1360. 'recipient_id' => array('==' => Yii::app()->user->id),
  1361. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  1362. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  1363. 'isRequest' => array('==' => ($type == null) ? false : true),
  1364. 'sender_id' => array('!=' => Yii::app()->user->id),
  1365. ),
  1366. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1367. ));
  1368. }
  1369. return $this;
  1370. }
  1371.  
  1372. public function getAllPendingotherleav($type = null) {
  1373. $this->getDbCriteria()->mergeWith(array(
  1374. 'conditions' => array(
  1375. 'recipient_id' => array('==' => Yii::app()->user->id),
  1376. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  1377. 'type' => array('==' => self::FILTER_LEAVE),
  1378. 'isRequest' => array('==' => ($type == null) ? false : true),
  1379. 'sender_id' => array('!=' => Yii::app()->user->id),
  1380. ),
  1381. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1382. ));
  1383. return $this;
  1384. }
  1385.  
  1386. public function getAllPendingmeatt($type = null, $request_type = self::FILTER_ATTENDANCE) {
  1387. if ($request_type == self::FILTER_ATTENDANCE) {
  1388. $this->getDbCriteria()->mergeWith(array(
  1389. 'conditions' => array(
  1390. //'recipient_id' => array('==' => Yii::app()->user->id),
  1391. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  1392. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1393. 'isRequest' => array('==' => ($type == null) ? false : true),
  1394. 'sender_id' => array('==' => Yii::app()->user->id),
  1395. ),
  1396. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1397. ));
  1398. } else {
  1399. $this->getDbCriteria()->mergeWith(array(
  1400. 'conditions' => array(
  1401. //'recipient_id' => array('==' => Yii::app()->user->id),
  1402. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  1403. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  1404. 'isRequest' => array('==' => ($type == null) ? false : true),
  1405. 'sender_id' => array('==' => Yii::app()->user->id),
  1406. ),
  1407. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1408. ));
  1409. }
  1410. return $this;
  1411. }
  1412.  
  1413. public function getAllPendingmeleav($type = null) {
  1414. $this->getDbCriteria()->mergeWith(array(
  1415. 'conditions' => array(
  1416. //'recipient_id' => array('==' => Yii::app()->user->id),
  1417. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  1418. 'type' => array('==' => self::FILTER_LEAVE),
  1419. 'isRequest' => array('==' => ($type == null) ? false : true),
  1420. 'sender_id' => array('==' => Yii::app()->user->id),
  1421. ),
  1422. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1423. ));
  1424. return $this;
  1425. }
  1426.  
  1427. public function getAllProcessedother($type = null) {
  1428. $when = strtotime('-3 months');
  1429. $this->getDbCriteria()->mergeWith(array(
  1430. 'conditions' => array(
  1431. 'recipient_id' => array('==' => Yii::app()->user->id),
  1432. 'read_status' => array('==' => self::READ_STATUS_READ),
  1433. 'isRequest' => array('==' => ($type == null) ? false : true),
  1434. 'sender_id' => array('!=' => Yii::app()->user->id),
  1435. 'created' => array('>=' => new MongoDate($when)),
  1436. ),
  1437. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1438. ));
  1439. return $this;
  1440. }
  1441.  
  1442. public function getAllProcessedotheratt($type = null) {
  1443. $when = strtotime('-3 months');
  1444. $this->getDbCriteria()->mergeWith(array(
  1445. 'conditions' => array(
  1446. 'recipient_id' => array('==' => Yii::app()->user->id),
  1447. 'read_status' => array('==' => self::READ_STATUS_READ),
  1448. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1449. 'isRequest' => array('==' => ($type == null) ? false : true),
  1450. 'sender_id' => array('!=' => Yii::app()->user->id),
  1451. 'created' => array('>=' => new MongoDate($when)),
  1452. ),
  1453. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1454. ));
  1455. return $this;
  1456. }
  1457.  
  1458. public function getAllProcessedotherleav($type = null) {
  1459. $when = strtotime('-3 months');
  1460. $this->getDbCriteria()->mergeWith(array(
  1461. 'conditions' => array(
  1462. 'recipient_id' => array('==' => Yii::app()->user->id),
  1463. 'read_status' => array('==' => self::READ_STATUS_READ),
  1464. 'type' => array('==' => self::FILTER_LEAVE),
  1465. 'isRequest' => array('==' => ($type == null) ? false : true),
  1466. 'sender_id' => array('!=' => Yii::app()->user->id),
  1467. 'created' => array('>=' => new MongoDate($when)),
  1468. ),
  1469. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1470. ));
  1471. return $this;
  1472. }
  1473.  
  1474. public function getAllProcessedmeatt($type = null, $request_type = self::FILTER_ATTENDANCE) {
  1475. $when = strtotime('-3 months');
  1476. if ($request_type == self::FILTER_ATTENDANCE) {
  1477. $this->getDbCriteria()->mergeWith(array(
  1478. 'conditions' => array(
  1479. //'recipient_id' => array('==' => Yii::app()->user->id),
  1480. 'read_status' => array('==' => self::READ_STATUS_READ),
  1481. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1482. 'isRequest' => array('==' => ($type == null) ? false : true),
  1483. 'sender_id' => array('==' => Yii::app()->user->id),
  1484. 'created' => array('>=' => new MongoDate($when)),
  1485. ),
  1486. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1487. ));
  1488. } else {
  1489. $this->getDbCriteria()->mergeWith(array(
  1490. 'conditions' => array(
  1491. //'recipient_id' => array('==' => Yii::app()->user->id),
  1492. 'read_status' => array('==' => self::READ_STATUS_READ),
  1493. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  1494. 'isRequest' => array('==' => ($type == null) ? false : true),
  1495. 'sender_id' => array('==' => Yii::app()->user->id),
  1496. 'created' => array('>=' => new MongoDate($when)),
  1497. ),
  1498. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1499. ));
  1500. }
  1501. return $this;
  1502. }
  1503.  
  1504. public function getAllProcessedmeleav($type = null) {
  1505. $when = strtotime('-3 months');
  1506. $this->getDbCriteria()->mergeWith(array(
  1507. 'conditions' => array(
  1508. //'recipient_id' => array('==' => Yii::app()->user->id),
  1509. 'read_status' => array('==' => self::READ_STATUS_READ),
  1510. 'type' => array('==' => self::FILTER_LEAVE),
  1511. 'isRequest' => array('==' => ($type == null) ? false : true),
  1512. 'sender_id' => array('==' => Yii::app()->user->id),
  1513. 'created' => array('>=' => new MongoDate($when)),
  1514. ),
  1515. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1516. ));
  1517. return $this;
  1518. }
  1519.  
  1520. public function getAllArchievedother($type = null) {
  1521. $when = strtotime('-3 months');
  1522. $this->getDbCriteria()->mergeWith(array(
  1523. 'conditions' => array(
  1524. 'recipient_id' => array('==' => Yii::app()->user->id),
  1525. 'read_status' => array('==' => self::READ_STATUS_READ),
  1526. 'sender_id' => array('!=' => Yii::app()->user->id),
  1527. 'isRequest' => array('==' => ($type == null) ? false : true),
  1528. 'created' => array('<=' => new MongoDate($when)),
  1529. ),
  1530. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1531. ));
  1532. return $this;
  1533. }
  1534.  
  1535. public function getAllArchievedotheratt($type = null, $request_type = self::FILTER_ATTENDANCE) {
  1536. $when = strtotime('-3 months');
  1537. if ($request_type == self::FILTER_ATTENDANCE) {
  1538. $this->getDbCriteria()->mergeWith(array(
  1539. 'conditions' => array(
  1540. 'recipient_id' => array('==' => Yii::app()->user->id),
  1541. 'read_status' => array('==' => self::READ_STATUS_READ),
  1542. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1543. 'sender_id' => array('!=' => Yii::app()->user->id),
  1544. 'isRequest' => array('==' => ($type == null) ? false : true),
  1545. 'created' => array('<=' => new MongoDate($when)),
  1546. ),
  1547. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1548. ));
  1549. } else {
  1550. $this->getDbCriteria()->mergeWith(array(
  1551. 'conditions' => array(
  1552. 'recipient_id' => array('==' => Yii::app()->user->id),
  1553. 'read_status' => array('==' => self::READ_STATUS_READ),
  1554. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  1555. 'sender_id' => array('!=' => Yii::app()->user->id),
  1556. 'isRequest' => array('==' => ($type == null) ? false : true),
  1557. 'created' => array('<=' => new MongoDate($when)),
  1558. ),
  1559. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1560. ));
  1561. }
  1562. return $this;
  1563. }
  1564.  
  1565. public function getAllArchievedotherleav($type = null) {
  1566. $when = strtotime('-3 months');
  1567. $this->getDbCriteria()->mergeWith(array(
  1568. 'conditions' => array(
  1569. 'recipient_id' => array('==' => Yii::app()->user->id),
  1570. 'read_status' => array('==' => self::READ_STATUS_READ),
  1571. 'type' => array('==' => self::FILTER_LEAVE),
  1572. 'sender_id' => array('!=' => Yii::app()->user->id),
  1573. 'isRequest' => array('==' => ($type == null) ? false : true),
  1574. 'created' => array('<=' => new MongoDate($when)),
  1575. ),
  1576. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1577. ));
  1578. return $this;
  1579. }
  1580.  
  1581. public function getAllArchievedmeatt($type = null, $request_type = self::FILTER_ATTENDANCE) {
  1582. $when = strtotime('-3 months');
  1583. if ($request_type == self::FILTER_ATTENDANCE) {
  1584. $this->getDbCriteria()->mergeWith(array(
  1585. 'conditions' => array(
  1586. 'recipient_id' => array('==' => Yii::app()->user->id),
  1587. 'read_status' => array('==' => self::READ_STATUS_READ),
  1588. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1589. 'sender_id' => array('==' => Yii::app()->user->id),
  1590. 'isRequest' => array('==' => ($type == null) ? false : true),
  1591. 'created' => array('<=' => new MongoDate($when)),
  1592. ),
  1593. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1594. ));
  1595. } else {
  1596. $this->getDbCriteria()->mergeWith(array(
  1597. 'conditions' => array(
  1598. 'recipient_id' => array('==' => Yii::app()->user->id),
  1599. 'read_status' => array('==' => self::READ_STATUS_READ),
  1600. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  1601. 'sender_id' => array('==' => Yii::app()->user->id),
  1602. 'isRequest' => array('==' => ($type == null) ? false : true),
  1603. 'created' => array('<=' => new MongoDate($when)),
  1604. ),
  1605. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1606. ));
  1607. }
  1608. return $this;
  1609. }
  1610.  
  1611. public function getAllArchievedmeleav($type = null) {
  1612. $when = strtotime('-3 months');
  1613. $this->getDbCriteria()->mergeWith(array(
  1614. 'conditions' => array(
  1615. 'recipient_id' => array('==' => Yii::app()->user->id),
  1616. 'read_status' => array('==' => self::READ_STATUS_READ),
  1617. 'type' => array('==' => self::FILTER_LEAVE),
  1618. 'sender_id' => array('==' => Yii::app()->user->id),
  1619. 'isRequest' => array('==' => ($type == null) ? false : true),
  1620. 'created' => array('<=' => new MongoDate($when)),
  1621. ),
  1622. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1623. ));
  1624. return $this;
  1625. }
  1626.  
  1627. public function getAllother($type = null) {
  1628. $this->getDbCriteria()->mergeWith(array(
  1629. 'conditions' => array(
  1630. 'recipient_id' => array('==' => Yii::app()->user->id),
  1631. 'isRequest' => array('==' => ($type == null) ? false : true),
  1632. 'sender_id' => array('!=' => Yii::app()->user->id),
  1633. ),
  1634. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1635. ));
  1636. return $this;
  1637. }
  1638.  
  1639. public function getAllotheratt($type = null, $request_type = self::FILTER_ATTENDANCE) {
  1640. if ($request_type == self::FILTER_ATTENDANCE) {
  1641. $this->getDbCriteria()->mergeWith(array(
  1642. 'conditions' => array(
  1643. 'recipient_id' => array('==' => Yii::app()->user->id),
  1644. 'isRequest' => array('==' => ($type == null) ? false : true),
  1645. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1646. 'sender_id' => array('!=' => Yii::app()->user->id),
  1647. ),
  1648. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1649. ));
  1650. } else {
  1651. $this->getDbCriteria()->mergeWith(array(
  1652. 'conditions' => array(
  1653. 'recipient_id' => array('==' => Yii::app()->user->id),
  1654. 'isRequest' => array('==' => ($type == null) ? false : true),
  1655. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  1656. 'sender_id' => array('!=' => Yii::app()->user->id),
  1657. ),
  1658. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1659. ));
  1660. }
  1661. return $this;
  1662. }
  1663.  
  1664. public function getAllotherleav($type = null) {
  1665. $this->getDbCriteria()->mergeWith(array(
  1666. 'conditions' => array(
  1667. 'recipient_id' => array('==' => Yii::app()->user->id),
  1668. 'isRequest' => array('==' => ($type == null) ? false : true),
  1669. 'type' => array('==' => self::FILTER_LEAVE),
  1670. 'sender_id' => array('!=' => Yii::app()->user->id),
  1671. ),
  1672. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1673. ));
  1674. return $this;
  1675. }
  1676.  
  1677. public function getAllmeatt($type = null, $request_type = self::FILTER_ATTENDANCE) {
  1678. if ($request_type == self::FILTER_ATTENDANCE) {
  1679. $this->getDbCriteria()->mergeWith(array(
  1680. 'conditions' => array(
  1681. 'recipient_id' => array('==' => Yii::app()->user->id),
  1682. 'isRequest' => array('==' => ($type == null) ? false : true),
  1683. 'type' => array('==' => self::FILTER_ATTENDANCE),
  1684. 'sender_id' => array('==' => Yii::app()->user->id),
  1685. ),
  1686. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1687. ));
  1688. } else {
  1689. $this->getDbCriteria()->mergeWith(array(
  1690. 'conditions' => array(
  1691. 'recipient_id' => array('==' => Yii::app()->user->id),
  1692. 'isRequest' => array('==' => ($type == null) ? false : true),
  1693. 'type' => array('==' => self::FILTER_ATTEDANCE_REQUEST),
  1694. 'sender_id' => array('==' => Yii::app()->user->id),
  1695. ),
  1696. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1697. ));
  1698. }
  1699. return $this;
  1700. }
  1701.  
  1702. public function getAllmeleav($type = null) {
  1703. $this->getDbCriteria()->mergeWith(array(
  1704. 'conditions' => array(
  1705. 'recipient_id' => array('==' => Yii::app()->user->id),
  1706. 'isRequest' => array('==' => ($type == null) ? false : true),
  1707. 'type' => array('==' => self::FILTER_LEAVE),
  1708. 'sender_id' => array('==' => Yii::app()->user->id),
  1709. ),
  1710. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1711. ));
  1712. return $this;
  1713. }
  1714.  
  1715. /* others filter */
  1716.  
  1717. /* ME filter */
  1718.  
  1719. public function getAllPendingme($type = null) {
  1720. $this->getDbCriteria()->mergeWith(array(
  1721. 'conditions' => array(
  1722. //'recipient_id' => array('==' => Yii::app()->user->id),
  1723. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  1724. 'isRequest' => array('==' => ($type == null) ? false : true),
  1725. 'sender_id' => array('==' => Yii::app()->user->id),
  1726. ),
  1727. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1728. ));
  1729. return $this;
  1730. }
  1731.  
  1732. public function getAllProcessedme($type = null) {
  1733. $when = strtotime('-3 months');
  1734. $this->getDbCriteria()->mergeWith(array(
  1735. 'conditions' => array(
  1736. //'recipient_id' => array('==' => Yii::app()->user->id),
  1737. 'read_status' => array('==' => self::READ_STATUS_READ),
  1738. 'isRequest' => array('==' => ($type == null) ? false : true),
  1739. 'sender_id' => array('==' => Yii::app()->user->id),
  1740. 'created' => array('>=' => new MongoDate($when)),
  1741. ),
  1742. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1743. ));
  1744. return $this;
  1745. }
  1746.  
  1747. public function getAllArchievedme($type = null) {
  1748. $when = strtotime('-3 months');
  1749. $this->getDbCriteria()->mergeWith(array(
  1750. 'conditions' => array(
  1751. //'recipient_id' => array('==' => Yii::app()->user->id),
  1752. 'read_status' => array('==' => self::READ_STATUS_READ),
  1753. 'sender_id' => array('==' => Yii::app()->user->id),
  1754. 'isRequest' => array('==' => ($type == null) ? false : true),
  1755. 'created' => array('<=' => new MongoDate($when)),
  1756. ),
  1757. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1758. ));
  1759. return $this;
  1760. }
  1761.  
  1762. public function getAllme($type = null) {
  1763. $this->getDbCriteria()->mergeWith(array(
  1764. 'conditions' => array(
  1765. //'recipient_id' => array('==' => Yii::app()->user->id),
  1766. 'isRequest' => array('==' => ($type == null) ? false : true),
  1767. 'sender_id' => array('==' => Yii::app()->user->id),
  1768. ),
  1769. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1770. ));
  1771. return $this;
  1772. }
  1773.  
  1774. /* ME filter */
  1775.  
  1776. public function getUnread($type = null) {
  1777. $this->getDbCriteria()->mergeWith(array(
  1778. 'conditions' => array(
  1779. 'recipient_id' => array('==' => Yii::app()->user->id),
  1780. 'read_status' => array('==' => self::READ_STATUS_UNREAD),
  1781. 'isRequest' => array('==' => ($type == null) ? FALSE : true),
  1782. ),
  1783. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1784. ));
  1785. return $this;
  1786. }
  1787.  
  1788. public function getRead($type = null) {
  1789. $this->getDbCriteria()->mergeWith(array(
  1790. 'conditions' => array(
  1791. 'recipient_id' => array('==' => Yii::app()->user->id),
  1792. 'read_status' => array('==' => self::READ_STATUS_READ),
  1793. 'isRequest' => array('==' => ($type == null) ? FALSE : true),
  1794. ),
  1795. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  1796. ));
  1797. return $this;
  1798. }
  1799.  
  1800. public function isReceiver($user_id = null) {
  1801. $user_id = ($user_id == null) ? Yii::app()->user->id : $user_id;
  1802. //$user = User::model()->findByPk($user_id);
  1803. $user = UserMongoView::model()->findByAttributes(array('user_id'=>$user_id));
  1804. return ($user->id == $this->recipient_id) ? true : false;
  1805. }
  1806.  
  1807. public function isActive() {
  1808. $this->getDbCriteria()->mergeWith(array(
  1809. 'conditions' => array(
  1810. 'status' => array('==' => self::NOTIFICATION_ACTIVE),
  1811. ),
  1812. ));
  1813. return $this;
  1814. }
  1815.  
  1816. public function isPending($status = null) {
  1817. $this->getDbCriteria()->mergeWith(array(
  1818. 'conditions' => array(
  1819. 'read_status' => array('==' => ($status == null) ? self::READ_STATUS_UNREAD : self::READ_STATUS_READ),
  1820. ),
  1821. ));
  1822. return $this;
  1823. }
  1824.  
  1825. public function isRequest($type = null) {
  1826. $this->getDbCriteria()->mergeWith(array(
  1827. 'conditions' => array(
  1828. 'isRequest' => array('==' => ($type == null) ? false : true),
  1829. ),
  1830. ));
  1831. return $this;
  1832. }
  1833.  
  1834. public function sortCreated($sort = null) {
  1835. $this->getDbCriteria()->mergeWith(array(
  1836. 'sort' => array('created' => ($sort == null) ? EMongoCriteria::SORT_DESC : EMongoCriteria::SORT_ASC),
  1837. ));
  1838. return $this;
  1839. }
  1840.  
  1841. public static function getUnreadNotificationsCount() {
  1842. $notifications = Notifications::model()->tenant()->getUnread()->isActive()->findAll();
  1843. /* code below is not required as we can directly do count($notifications) */
  1844. /* $unread = array();
  1845. foreach ($notifications as $notification) {
  1846. $unread[] = $notification;
  1847. } */
  1848. return count($notifications);
  1849. }
  1850.  
  1851. public static function displayNotifications($unreadCount = 0) {
  1852. //$unreadCount = Notifications::getUnreadNotificationsCount();
  1853. $unread = Notifications::model()->tenant()->getUnread()->isActive()->findAll();
  1854. if ($unreadCount < 5) {
  1855. $readCount = 5 - $unreadCount;
  1856. $read = array();
  1857. $readNotifications = Notifications::model()->tenant()->getRead()->isActive()->findAll();
  1858. foreach ($readNotifications as $notification) {
  1859. $read[] = $notification;
  1860. $readCount--;
  1861. if ($readCount == 0)
  1862. break;
  1863. }
  1864. $unread = array_merge($unread, $read);
  1865. } else {
  1866. $temp = array();
  1867. foreach ($unread as $n) {
  1868. if (count($temp) < 5) {
  1869. $temp[] = $n;
  1870. }
  1871. }
  1872. $unread = $temp;
  1873. }
  1874. return $unread;
  1875. }
  1876.  
  1877. public static function getUnreadRequestsCount() {
  1878. /* chnaging the complete logic as this is showing wrong count
  1879. requests = Notifications::model()->tenant()->getUnread(Notifications::REQUESTS)->isActive()->findAll();
  1880. return count($requests);*/
  1881. /*for leaves*/
  1882. /*$leave_data = array();
  1883. $att_count = array();
  1884. $reim_count = array();
  1885. $grp_invite_count = array();*/
  1886. // new comment
  1887. // $requests = 0;
  1888. // $criteria = new EMongoCriteria();
  1889. // $criteria->tenant_id('==', Yii::app()->user->getTenantId());
  1890. // $criteria->filter_type('==', Notifications::FILTER_LEAVE);
  1891. // $criteria->attachments->items->status('==', UserLeaves::STATUS_PENDING);
  1892. // $leave_data = Messages::model()->findAll($criteria);
  1893. // foreach ($leave_data as $key => $value) {
  1894. // if(!in_array(Yii::app()->user->id, $value->receiver_id))
  1895. // unset($leave_data[$key]);
  1896. // }
  1897. // $leaves_count = count($leave_data);
  1898. // /*for leaves*/
  1899. // /*for attendance*/
  1900. // $criteria = new EMongoCriteria();
  1901. // $criteria->tenant_id('==', Yii::app()->user->getTenantId());
  1902. // $criteria->addCond('filter_type','or', Notifications::FILTER_ATTENDANCE);
  1903. // $criteria->addCond('filter_type','or', Notifications::FILTER_ATTEDANCE_REQUEST);
  1904. // $criteria->attachments->items->status('==', Request::STATUS_PENDING);
  1905. // $attendance_data = Messages::model()->findAll($criteria);
  1906. // foreach ($attendance_data as $key => $value) {
  1907. // if(!in_array(Yii::app()->user->id, $value->receiver_id))
  1908. // unset($attendance_data[$key]);
  1909. // }
  1910. // $att_count = count($attendance_data);
  1911. // /*for attendance*/
  1912. // /*for reimbursement*/
  1913. // $criteria = new EMongoCriteria();
  1914. // $criteria->tenant_id('==', Yii::app()->user->getTenantId());
  1915. // $criteria->status('==', UserExpenses::STATUS_PENDING);
  1916. // $reimbursement_data = UserExpenses::model()->findAll($criteria);
  1917. // foreach ($reimbursement_data as $key => $value) {
  1918. // if(!in_array(Yii::app()->user->id, $value->recipients))
  1919. // unset($reimbursement_data[$key]);
  1920. // }
  1921. // $reim_count = count($reimbursement_data);
  1922. // /*for reimbursement*/
  1923.  
  1924. // /**/
  1925. // $criteria = new EMongoCriteria();
  1926. // $criteria->tenant_id('==', Yii::app()->user->getTenantId());
  1927. // $criteria->addCond('type','or', Notifications::FILTER_INVITE);
  1928. // $criteria->addCond('type','or', Notifications::FILTER_INVITE_GROUP);
  1929. // $criteria->recipient_id('==', Yii::app()->user->id);
  1930. // $criteria->read_status('==', Notifications::READ_STATUS_UNREAD);
  1931. // $group_invite_data = Notifications::model()->findAll($criteria);
  1932. // $grp_invite_count = count($group_invite_data);
  1933. // /**/
  1934. // $requests = $leaves_count + $att_count + $reim_count + $grp_invite_count;
  1935. $requests = 0 ;
  1936. return $requests;
  1937.  
  1938. }
  1939.  
  1940. public static function displayRequests($unreadCount = 0) {
  1941. //$unreadCount = Notifications::getUnreadRequestsCount();
  1942. $unread = Notifications::model()->tenant()->getUnread(Notifications::REQUESTS)->isActive()->findAll();
  1943. if ($unreadCount < 5) {
  1944. $readCount = 5 - $unreadCount;
  1945. $read = array();
  1946. $readRequests = Notifications::model()->tenant()->getRead(Notifications::REQUESTS)->isActive()->findAll();
  1947. foreach ($readRequests as $request) {
  1948. $read[] = $request;
  1949. $readCount--;
  1950. if ($readCount == 0)
  1951. break;
  1952. }
  1953. $unread = array_merge($unread, $read);
  1954. } else {
  1955. $temp = array();
  1956. foreach ($unread as $n) {
  1957. if (count($temp) < 5) {
  1958. $temp[] = $n;
  1959. }
  1960. }
  1961. $unread = $temp;
  1962. }
  1963. return $unread;
  1964. }
  1965.  
  1966. public function whosPhoto() {
  1967. $user = UserMongo::model()->tenant()->findByAttributes(array('user_id' => $this->sender_id));
  1968. return $user->getAvatarWithFullname();
  1969. }
  1970.  
  1971. public function getHumanTime() {
  1972. if(isset($this->message_id) && $this->message_id != null && $this->category != "request_expense")
  1973. {
  1974. $message_data = Messages::model()->findByPk($this->message_id);
  1975. if(isset($message_data) && !empty($message_data)){
  1976. $to_return = $message_data->getHumanTime();
  1977. return $to_return;
  1978. }
  1979. return RandomHelper::humanTiming($this->created->sec);
  1980. }
  1981. return RandomHelper::humanTiming($this->created->sec);
  1982. }
  1983.  
  1984. //Invitation
  1985. public function generateInviteNotification($group_id, $user_id, $fromUser = false, $message_id = null) {
  1986. $group = Groups::model()->tenant()->findByPk($group_id);
  1987. //$user = User::model()->tenant()->findByPk($user_id);
  1988. $notify = new Notifications;
  1989.  
  1990. $notify->group_id = $group->id;
  1991. $notify->isRequest = true;
  1992.  
  1993. if (!$fromUser) {
  1994. //Group Owner -> User
  1995. $notify->category = Notifications::NOTIFY_REQUEST_OWNER;
  1996. $notify->type = self::FILTER_INVITE;
  1997. $notify->body = Yii::t('notifications', Yii::app()->params['groupinvite'], array('{username}' => $group->owner()->getUserLink(), '{groupname}' => $group->getURL()));
  1998. $notify->sender_id = $group->getGroupOwner();
  1999. $notify->recipient_id = $user_id;
  2000. } else {
  2001. //User -> Group Owner
  2002. $notify->category = Notifications::NOTIFY_REQUEST_USER;
  2003. $notify->type = self::FILTER_INVITE_GROUP;
  2004. $notify->body = Yii::t('notifications', Yii::app()->params['groupjoinrequest'], array('{username}' => $user->mongo()->getUserLink(), '{groupname}' => $group->getURL()));
  2005. $notify->sender_id = $user_id;
  2006. $notify->recipient_id = $group->getGroupOwner();
  2007. }
  2008.  
  2009. $notify->read_status = Notifications::READ_STATUS_UNREAD;
  2010. if ($notify->validate()) {
  2011. $notify->save();
  2012. }
  2013. }
  2014.  
  2015. //Special Events
  2016. public function generateSpecialNotification($type, $user_id, $salary = null, $expense = null) {
  2017. //$user = User::model()->tenant()->findByPk($user_id);
  2018. $user_mongo = UserMongo::model()->tenant()->findByAttributes(array('user_id' => $user_id));
  2019. $notify = new Notifications;
  2020.  
  2021. $notify->isRequest = false;
  2022.  
  2023. if ($type == Notifications::NOTIFY_EVENT_SALARY) {
  2024. //Salary Paid Notification
  2025. $salary = UserSalary::model()->findByPk($salary);
  2026. if ($salary != null) {
  2027. $notify->type = Notifications::FILTER_SYSTEM_EVENT;
  2028. $notify->category = Notifications::NOTIFY_EVENT_SALARY;
  2029. $notify->body = Yii::t('notifications', Yii::app()->params['event_salary'], array('{month}' => $salary->getPayMonth(), '{link}' => $salary->getPDFLink('here')));
  2030. $notify->data = array('month' => $salary->getPayMonth(), 'amount' => $salary->total_net, 'link' => $salary->getPDFLink('here'));
  2031. $notify->sender_id = null;
  2032. $notify->recipient_id = $user_mongo->user_id;
  2033. }
  2034. } else if ($type == Notifications::NOTIFY_RESPONSE_EXPENSE) {
  2035. $expense = UserExpenses::model()->tenant()->findByPk($expense);
  2036. if ($expense != null) {
  2037. $notify->type = Notifications::FILTER_SYSTEM_EVENT;
  2038. $notify->category = Notifications::NOTIFY_RESPONSE_EXPENSE;
  2039. if($expense->user_id == $user_mongo->id)
  2040. {
  2041. $name_email = 'Your';
  2042. $notify->body = Yii::t('notifications', Yii::app()->params['expense_response'], array('{reimbursement}' => $expense->link(), '{status}' => UserExpenses::itemAlias('status', $expense->status)));
  2043. }
  2044. else
  2045. {
  2046. $requested_user = UserMongo::model()->tenant()->findByPk($expense->user_id);
  2047. $requested_users_name = $requested_user->getFullname() . "'s";
  2048. $body = Yii::t('notifications', Yii::app()->params['expense_response'], array('{reimbursement}' => $expense->link(), '{status}' => UserExpenses::itemAlias('status', $expense->status)));
  2049. $new_body = str_replace("Your",$requested_users_name,$body);
  2050. $notify->body = $new_body;
  2051. $name_email = $requested_users_name;
  2052. }
  2053. $notify->data = array('approver' => Yii::app()->user->id, 'status' => UserExpenses::itemAlias('status', $expense->status));
  2054. $notify->sender_id = null;
  2055. $notify->recipient_id = $user_mongo->user_id;
  2056. }
  2057. }
  2058.  
  2059. $notify->read_status = Notifications::READ_STATUS_UNREAD;
  2060. if ($notify->validate()) {
  2061. if(isset($name_email) && $name_email != "")
  2062. {
  2063. Yii::app()->session['name_email'] = $name_email;
  2064. }
  2065. $notify->save();
  2066. }
  2067. }
  2068.  
  2069. //Expenses Request
  2070. public function generateExpenseRequest($expense_id, $user_id, $manager_id) {
  2071. $expense = UserExpenses::model()->tenant()->findByPk($expense_id);
  2072. $user = UserMongo::model()->tenant()->findByPk($user_id);
  2073. $notify = new Notifications;
  2074. $notify->isRequest = true;
  2075. $notify->category = Notifications::NOTIFY_REQUEST_EXPENSE;
  2076. $notify->type = Notifications::FILTER_REQUEST;
  2077. $notify->body = Yii::t('notifications', Yii::app()->params['expense_request'], array('{username}' => $user->getUserLink(), '{reimbursement}' => $expense->link(), '{expensename}' => $expense->title));
  2078. $notify->sender_id = $user->user_id;
  2079. $notify->recipient_id = $manager_id;
  2080. $notify->data = array('expense' => $expense->id);
  2081. $notify->read_status = Notifications::READ_STATUS_UNREAD;
  2082. if ($notify->validate()) {
  2083. $notify->save();
  2084. }
  2085. }
  2086.  
  2087. //Announcement notification
  2088. /**
  2089. * @todo Remove if not in use
  2090. */
  2091. public function generateAnnouncementNotification() {
  2092. $notify = new Notifications;
  2093. $notify->isRequest = false;
  2094. $notify->type = Notifications::FILTER_SYSTEM_EVENT;
  2095. $notify->category = Notifications::NOTIFY_RESPONSE_EXPENSE;
  2096. $notify->body = Yii::t('notifications', Yii::app()->params['expense_response'], array('{reimbursement}' => $expense->link(), '{status}' => UserExpenses::itemAlias('status', $expense->status)));
  2097. $notify->data = array('approver' => Yii::app()->user->id, 'status' => UserExpenses::itemAlias('status', $expense->status));
  2098. $notify->sender_id = null;
  2099. $notify->recipient_id = $user->id;
  2100. }
  2101.  
  2102. public function fromTenant($user_id) {
  2103. //$user = User::model()->findByPk($user_id);
  2104. $user = UserMongoView::model()->tenant()->findByAttributes(array('user_id'=>$user_id));
  2105. if ($this->tenant_id == $user->tenant->id) {
  2106. return true;
  2107. }
  2108. return false;
  2109. }
  2110.  
  2111. public function getURL() {
  2112. return Yii::app()->createUrl('messages/thread', array('id' => $this->message_id));
  2113. }
  2114.  
  2115. public function sender($tenant_id = null) {
  2116. return UserMongo::model()->tenant($tenant_id)->findByAttributes(array('user_id' => $this->sender_id));
  2117. }
  2118.  
  2119. public function receiver() {
  2120. return UserMongo::model()->tenant()->findByAttributes(array('user_id' => $this->recipient_id));
  2121. }
  2122.  
  2123. public function receiverLink() {
  2124. $user = UserMongo::model()->tenant()->findByAttributes(array('user_id' => $this->recipient_id));
  2125. return (!empty($user)) ? CHtml::link($user->getFullname(), Yii::app()->createUrl('employee/view', array('id' => $user->user_id))) : null;
  2126. }
  2127.  
  2128. public function getType() {
  2129. return ($this->isRequest) ? "Request" : "Notification";
  2130. }
  2131.  
  2132. public function getRootMessageType() {
  2133. $mes = Messages::model()->tenant()->findByPk($this->message_id)->getRootThread();
  2134. return $mes->filter_type;
  2135. }
  2136.  
  2137. public function message() {
  2138. $message = null;
  2139. if ($this->message_id != null) {
  2140. $message = Messages::model()->tenant()->findByPk($this->message_id);
  2141. }
  2142. return $message;
  2143. }
  2144.  
  2145. public function senderPhoto() {
  2146. if ($this->sender_id == null) {
  2147. $tenant = Tenants::model()->findByPk(Yii::app()->user->getTenantId());
  2148. $baseUrl = Yii::app()->request->baseUrl;
  2149. if ($tenant->logo != null) {
  2150. $imgUrl = Yii::app()->createUrl('messages/showimage', array(
  2151. 'filename' => urlencode($tenant->logo),
  2152. 'adaptive' => 'true',
  2153. 'width' => '25',
  2154. 'height' => '25'
  2155. )
  2156. );
  2157. } else {
  2158. $imgUrl = Yii::app()->theme->baseUrl . '/images/darwinbox-25x25.png';
  2159. }
  2160. $photo = CHtml::image($imgUrl, 'Image', array('class' => 'profile'));
  2161. } else {
  2162. $photo = $this->sender()->getAvatarWithFullname();
  2163. }
  2164. return $photo;
  2165. }
  2166.  
  2167. /**
  2168. * function to get cached notification object for the give tenant
  2169. * @param number $tenant_id sql id
  2170. * @param constant $read_status
  2171. * @return object otification object
  2172. */
  2173. public static function getCachedNotifications($tenant_id, $read_status = Notifications::READ_STATUS_READ, $is_request = null) {
  2174. if ($read_status == self::READ_STATUS_READ) {
  2175. $cache_key = ($is_request == null) ? 'READ_NOTIFICATIONS_' . $tenant_id : 'REQUEST_READ_NOTIFICATIONS_' . $tenant_id;
  2176. } else {
  2177. $cache_key = ($is_request == null) ? 'UNREAD_NOTIFICATIONS_' . $tenant_id : 'REQUEST_UNREAD_NOTIFICATIONS_' . $tenant_id;
  2178. }
  2179.  
  2180. if (($cache = Yii::app()->cache) !== null) {
  2181. if (($notifications = $cache->get($cache_key)) !== false) {
  2182. return $notifications;
  2183. } else {
  2184. $notifications = ($read_status == Notifications::READ_STATUS_READ) ? Notifications::model()->tenant($tenant_id)->getRead($is_request)->isActive()->findAll() : Notifications::model()->tenant($tenant_id)->getUnread($is_request)->isActive()->findAll();
  2185. if (!empty($notifications)) {
  2186. //set cache
  2187. $cache->set($cache_key, $notifications, 60);
  2188. return $notifications;
  2189. }
  2190. }
  2191. }
  2192.  
  2193. $notifications = ($read_status == Notifications::READ_STATUS_READ) ? Notifications::model()->tenant($tenant_id)->getRead($is_request)->isActive()->findAll() : Notifications::model()->tenant($tenant_id)->getUnread($is_request)->isActive()->findAll();
  2194. return $notifications;
  2195. }
  2196.  
  2197. /**
  2198. * Genearate salary slip notification and send mail to user (salary slip link)
  2199. * @param type $type constant
  2200. * @param type $salary Id
  2201. */
  2202. public static function generateSalarySlipNotification($type, $salary_id = null) {
  2203. $notify = new Notifications;
  2204. $notify->isRequest = false;
  2205. $salary = UserSalarySlip::model()->findByPk($salary_id);
  2206. $user = UserMongo::model()->findByPk($salary->user_id);
  2207. if (isset($user) && $type == Notifications::NOTIFY_EVENT_SALARY) {
  2208. //Salary Paid Notification
  2209. if ($salary != null) {
  2210. $notify->type = Notifications::FILTER_SYSTEM_EVENT;
  2211. $notify->category = Notifications::NOTIFY_EVENT_SALARY;
  2212. $notify->body = Yii::t('notifications', Yii::app()->params['event_salary'], array('{month}' => $salary->for_month, '{link}' => $salary->getPDFLink('here')));
  2213. $notify->data = array('month' => $salary->for_month, 'amount' => $salary->total_net, 'link' => $salary->getPDFLink('here'));
  2214. $notify->sender_id = null;
  2215. $notify->recipient_id = $user->user_id;
  2216. $notify->is_for = Messages::MESSAGE_SALARY_DONE;
  2217. }
  2218. $notify->read_status = Notifications::READ_STATUS_UNREAD;
  2219. if ($notify->validate()) {
  2220. $notify->save();
  2221. }
  2222. }
  2223. }
  2224.  
  2225. public function getSender($sender_id) {
  2226. $this->getDbCriteria()->mergeWith(
  2227. array(
  2228. 'conditions' => array(
  2229. 'sender_id' => array('==' => $sender_id)
  2230. )
  2231. )
  2232. );
  2233. return $this;
  2234. }
  2235. public static function FilterAcctoReportees($requests) {
  2236. $list_of_reportees = UserMongo::getReporteesUserId();
  2237. if(isset($list_of_reportees) && !empty($list_of_reportees)){
  2238. foreach ($requests as $key => $value) {
  2239. if(isset($value->sender_id) && !in_array($value->sender_id, $list_of_reportees))
  2240. {
  2241. unset($requests[$key]);
  2242. }
  2243. }
  2244. $requests = array_values($requests);
  2245. return $requests;
  2246. }
  2247. else{
  2248. $requests = array();
  2249. return $requests;
  2250. }
  2251. }
  2252.  
  2253. public function type($type) {
  2254. $this->getDbCriteria()->mergeWith(array(
  2255. 'conditions' => array(
  2256. 'type' => array('==' => $type),
  2257. ),
  2258. ));
  2259. return $this;
  2260. }
  2261.  
  2262. public function readStatus($read_status = null) {
  2263. $this->getDbCriteria()->mergeWith(array(
  2264. 'conditions' => array(
  2265. 'read_status' => array('==' => ($read_status == null) ? self::READ_STATUS_UNREAD : $read_status),
  2266. ),
  2267. ));
  2268. return $this;
  2269. }
  2270.  
  2271. public function getAllOnlyNotifications($type = null) {
  2272. $this->getDbCriteria()->mergeWith(array(
  2273. 'conditions' => array(
  2274. 'recipient_id' => array('==' => Yii::app()->user->id),
  2275. 'isRequest' => array('==' => ($type == null) ? false : true),
  2276. ),
  2277. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  2278. ));
  2279. return $this;
  2280. }
  2281. //Hr Letter Request
  2282. public function generateLetterRequest($request_id, $user_id, $manager_id) {
  2283. $user = UserMongo::model()->tenant()->findByPk($user_id);
  2284. $notify = new Notifications;
  2285. $notify->isRequest = true;
  2286. $notify->category = Notifications::NOTIFICATION_REQUEST_LETTER;
  2287. $notify->type = Notifications::FILTER_REQUEST;
  2288. $notify->body = Yii::t('notifications', Yii::app()->params['letter_request'], array('{username}' => $user->getUserLink(), '{hrletter}' => $request_id->link(), '{lettername}' => $request_id->name));
  2289. $notify->sender_id = $user->user_id;
  2290. $notify->recipient_id = $manager_id;
  2291. $notify->data = array('hrletter' => $request_id->id);
  2292. $notify->read_status = Notifications::READ_STATUS_UNREAD;
  2293. if ($notify->validate()) {
  2294. $notify->save();
  2295. }
  2296. }
  2297.  
  2298. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement