for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Canvas\Models;
use Phalcon\Di;
class Notifications extends AbstractModel
{
/**
*
* @var integer
*/
public $id;
public $from_users_id;
public $users_id;
public $companies_id;
public $apps_id;
public $system_modules_id;
public $notification_type_id;
public $entity_id;
* @var string
public $content;
public $read;
public $is_deleted;
public $created_at;
public $updated_at;
* Initialize method for model.
public function initialize()
$this->setSource('notifications');
$this->belongsTo(
'users_id',
'Canvas\Models\Users',
'id',
['alias' => 'user']
);
'from_users_id',
['alias' => 'from']
'notification_type_id',
'Canvas\Models\NotificationType',
['alias' => 'type']
}
* Returns table name mapped in the model.
* @return string
public function getSource(): string
return 'notifications';
* Mark as Read all the notification from a user.
* @param Users $user
* @return void
public static function markAsRead(Users $user): bool
$result = Di::getDefault()->getDb()->prepare(
'UPDATE notifications set `read` = 1 WHERE users_id = ? AND companies_id = ? AND apps_id = ?'
$result->execute([
$user->getId(),
$user->currentCompanyId(),
Di::getDefault()->getApp()->getId()
]);
return true;
return true
true
void
* Get the total notification for the current user.
* @return int
public static function totalUnRead(Users $user): int
return self::count([
'conditions' => 'is_deleted = 0 AND read = 0 AND users_id = ?0 AND companies_id = ?1 AND apps_id = ?2',
'bind' => [
]