From d67d7c54e65e80d1b484490e42dbecb969aa7686 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 3 Oct 2015 12:09:27 -0400 Subject: Add web notifications --- app/Model/NotificationType.php | 73 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 app/Model/NotificationType.php (limited to 'app/Model/NotificationType.php') diff --git a/app/Model/NotificationType.php b/app/Model/NotificationType.php new file mode 100644 index 00000000..3fd5c157 --- /dev/null +++ b/app/Model/NotificationType.php @@ -0,0 +1,73 @@ + t('Email'), + self::TYPE_WEB => t('Web'), + ); + } + + /** + * Get selected notification types for a given user + * + * @access public + * @param integer $user_id + * @return array + */ + public function getUserSelectedTypes($user_id) + { + return $this->db->table(self::TABLE)->eq('user_id', $user_id)->asc('notification_type')->findAllByColumn('notification_type'); + } + + /** + * Save notification types for a given user + * + * @access public + * @param integer $user_id + * @param string[] $types + * @return boolean + */ + public function saveUserSelectedTypes($user_id, array $types) + { + $results = array(); + $this->db->table(self::TABLE)->eq('user_id', $user_id)->remove(); + + foreach ($types as $type) { + $results[] = $this->db->table(self::TABLE)->insert(array('user_id' => $user_id, 'notification_type' => $type)); + } + + return ! in_array(false, $results); + } +} -- cgit v1.2.3