/application/controllers/Notification_processor.php

https://bitbucket.org/webtechnologie/pm · PHP · 122 lines · 76 code · 30 blank · 16 comment · 22 complexity · 27c7f847cd0e00fb426ccd84c338f5a3 MD5 · raw file

  1. <?php
  2. if (!defined('BASEPATH'))
  3. exit('No direct script access allowed');
  4. /*
  5. * To process the notifications we'll use this.
  6. * This controller will be called via curl
  7. *
  8. * Purpose of this process is to reduce the processing time in main thread.
  9. *
  10. */
  11. class Notification_processor extends CI_Controller {
  12. function __construct() {
  13. parent::__construct();
  14. $this->load->helper('notifications');
  15. }
  16. //don't show anything here
  17. function index() {
  18. redirect("forbidden");
  19. }
  20. function create_notification() {
  21. ini_set('max_execution_time', 300); //300 seconds
  22. //error_log(date('[Y-m-d H:i:s e] ') . " Process Notification: " . serialize($_POST) . PHP_EOL, 3, "error.log");
  23. //validate notification request
  24. $event = decode_id(get_array_value($_POST, "event"), "notification");
  25. if (!$event) {
  26. die("Access Denied!");
  27. }
  28. $notification_data = get_notification_config($event);
  29. if (!is_array($notification_data)) {
  30. die("Access Denied!!");
  31. }
  32. $user_id = get_array_value($_POST, "user_id");
  33. $activity_log_id = get_array_value($_POST, "activity_log_id");
  34. $options = array(
  35. "project_id" => get_array_value($_POST, "project_id"),
  36. "task_id" => get_array_value($_POST, "task_id"),
  37. "project_comment_id" => get_array_value($_POST, "project_comment_id"),
  38. "ticket_id" => get_array_value($_POST, "ticket_id"),
  39. "ticket_comment_id" => get_array_value($_POST, "ticket_comment_id"),
  40. "project_file_id" => get_array_value($_POST, "project_file_id"),
  41. "leave_id" => get_array_value($_POST, "leave_id"),
  42. "post_id" => get_array_value($_POST, "post_id"),
  43. "to_user_id" => get_array_value($_POST, "to_user_id"),
  44. "activity_log_id" => get_array_value($_POST, "activity_log_id"),
  45. "client_id" => get_array_value($_POST, "client_id"),
  46. "invoice_payment_id" => get_array_value($_POST, "invoice_payment_id"),
  47. "invoice_id" => get_array_value($_POST, "invoice_id"),
  48. "estimate_id" => get_array_value($_POST, "estimate_id"),
  49. "estimate_request_id" => get_array_value($_POST, "estimate_request_id"),
  50. "actual_message_id" => get_array_value($_POST, "actual_message_id"),
  51. "parent_message_id" => get_array_value($_POST, "parent_message_id"),
  52. "event_id" => get_array_value($_POST, "event_id")
  53. );
  54. //clasified the task modification parts
  55. if ($event == "project_task_updated") {
  56. $this->_clasified_task_modification($event, $options, $activity_log_id); //overwrite event and options
  57. }
  58. $this->Notifications_model->create_notification($event, $user_id, $options);
  59. }
  60. private function _clasified_task_modification(&$event, &$options, $activity_log_id = 0) {
  61. //find out what types of changes has made
  62. if ($activity_log_id) {
  63. $activity = $this->Activity_logs_model->get_one($activity_log_id);
  64. if ($activity && $activity->changes) {
  65. $changes = unserialize($activity->changes);
  66. //only chaged assigned_to field?
  67. if (is_array($changes) && count($changes) == 1 && get_array_value($changes, "assigned_to")) {
  68. $event = "project_task_assigned";
  69. $assigned_to = get_array_value($changes, "assigned_to");
  70. $new_assigned_to = get_array_value($assigned_to, "to");
  71. $options["to_user_id"] = $new_assigned_to;
  72. $options["activity_log_id"] = ""; //remove activity log id
  73. }
  74. //only chaged status field? find out the change event
  75. if (is_array($changes) && count($changes) == 1 && get_array_value($changes, "status")) {
  76. $status = get_array_value($changes, "status");
  77. $new_status = get_array_value($status, "to");
  78. if ($new_status == "1") {
  79. $event = "project_task_reopened";
  80. } else if ($new_status == "3") {
  81. $event = "project_task_finished";
  82. } else {
  83. $event = "project_task_started";
  84. }
  85. $options["activity_log_id"] = ""; //remove activity log id
  86. }
  87. }
  88. }
  89. }
  90. }
  91. /* End of file notifications.php */
  92. /* Location: ./application/controllers/Notifications.php */