| Total Complexity | 4 |
| Total Lines | 153 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class Notifications extends AbstractModel |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * |
||
| 12 | * @var integer |
||
| 13 | */ |
||
| 14 | public $id; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * |
||
| 18 | * @var integer |
||
| 19 | */ |
||
| 20 | public $from_users_id; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * |
||
| 24 | * @var integer |
||
| 25 | */ |
||
| 26 | public $users_id; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * |
||
| 30 | * @var integer |
||
| 31 | */ |
||
| 32 | public $companies_id; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * |
||
| 36 | * @var integer |
||
| 37 | */ |
||
| 38 | public $apps_id; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * |
||
| 42 | * @var integer |
||
| 43 | */ |
||
| 44 | public $system_modules_id; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * |
||
| 48 | * @var integer |
||
| 49 | */ |
||
| 50 | public $notification_type_id; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * |
||
| 54 | * @var integer |
||
| 55 | */ |
||
| 56 | public $entity_id; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | public $content; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * |
||
| 66 | * @var integer |
||
| 67 | */ |
||
| 68 | public $read; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * |
||
| 72 | * @var integer |
||
| 73 | */ |
||
| 74 | public $is_deleted; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * |
||
| 78 | * @var string |
||
| 79 | */ |
||
| 80 | public $created_at; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * |
||
| 84 | * @var string |
||
| 85 | */ |
||
| 86 | public $updated_at; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Initialize method for model. |
||
| 90 | */ |
||
| 91 | public function initialize() |
||
| 92 | { |
||
| 93 | $this->setSource('notifications'); |
||
| 94 | |||
| 95 | $this->belongsTo( |
||
| 96 | 'users_id', |
||
| 97 | 'Canvas\Models\Users', |
||
| 98 | 'id', |
||
| 99 | ['alias' => 'user'] |
||
| 100 | ); |
||
| 101 | |||
| 102 | $this->belongsTo( |
||
| 103 | 'from_users_id', |
||
| 104 | 'Canvas\Models\Users', |
||
| 105 | 'id', |
||
| 106 | ['alias' => 'from'] |
||
| 107 | ); |
||
| 108 | |||
| 109 | $this->belongsTo( |
||
| 110 | 'notification_type_id', |
||
| 111 | 'Canvas\Models\NotificationType', |
||
| 112 | 'id', |
||
| 113 | ['alias' => 'type'] |
||
| 114 | ); |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Returns table name mapped in the model. |
||
| 119 | * |
||
| 120 | * @return string |
||
| 121 | */ |
||
| 122 | public function getSource(): string |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Mark as Read all the notification from a user. |
||
| 129 | * |
||
| 130 | * @param Users $user |
||
| 131 | * @return void |
||
| 132 | */ |
||
| 133 | public static function markAsRead(Users $user): bool |
||
| 134 | { |
||
| 135 | $result = Di::getDefault()->getDb()->prepare( |
||
| 136 | 'UPDATE notifications set `read` = 1 WHERE users_id = ? AND companies_id = ? AND apps_id = ?' |
||
| 137 | ); |
||
| 138 | |||
| 139 | $result->execute([ |
||
| 140 | $user->getId(), |
||
| 141 | $user->currentCompanyId(), |
||
| 142 | Di::getDefault()->getApp()->getId() |
||
| 143 | ]); |
||
| 144 | |||
| 145 | return true; |
||
|
|
|||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Get the total notification for the current user. |
||
| 150 | * |
||
| 151 | * @return int |
||
| 152 | */ |
||
| 153 | public static function totalUnRead(Users $user): int |
||
| 161 | ] |
||
| 162 | ]); |
||
| 165 |