get('DB'), self::TABLE_NAME); } /** * Remove all notifications matching the supplied code. * * @param int $code Notification code to remove from the database. * @return void * @side-effects Deletes matching notification records. */ public function Remove(int $code) { $this->reset(); $this->erase([self::CODE_CONDITION, $code]); } /** * Remove every notification from the table. * * @return void * @side-effects Truncates the notifications table. */ public function emptyAll() { global $f3; $f3->get('DB')->exec('TRUNCATE TABLE ' . self::TABLE_NAME); } /** * Send a custom notification to the system. * * @param int $code Notification code, such as FB_GENERIC or FB_IMPORT. * @param string|null $caption Notification caption. * @param mixed $link Optional notification link. * @return void * @side-effects Persists the notification when the code is allowed. */ public function notify(int $code, string $caption = null, $link = null) { if ($code === $this::FB_GENERIC || $this->check($code)) { $this->reset(); $this->code = $code; $this->caption = $caption; $this->link = $link; $this->save(); } } /** * Check whether a notification with the supplied code exists. * * @param int $code Notification code to check. * @return bool Whether a matching notification exists. * @side-effects Loads matching records into the mapper. */ public function check(int $code) { $this->load([self::CODE_CONDITION, $code]); return $this->dry(); } }