summaryrefslogtreecommitdiff
path: root/app/Model/NotificationType.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-10-03 12:09:27 -0400
committerFrederic Guillot <fred@kanboard.net>2015-10-03 12:09:27 -0400
commitd67d7c54e65e80d1b484490e42dbecb969aa7686 (patch)
treee62446885fac0d3af5b29d409d8e9a4f6c50940e /app/Model/NotificationType.php
parentb5a2b8f9f7ac9ef947357acd3981993159d64b52 (diff)
Add web notifications
Diffstat (limited to 'app/Model/NotificationType.php')
-rw-r--r--app/Model/NotificationType.php73
1 files changed, 73 insertions, 0 deletions
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 @@
+<?php
+
+namespace Model;
+
+/**
+ * Notification Type model
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class NotificationType extends Base
+{
+ /**
+ * SQL table name
+ *
+ * @var string
+ */
+ const TABLE = 'user_has_notification_types';
+
+ /**
+ * Types
+ *
+ * @var string
+ */
+ const TYPE_WEB = 'web';
+ const TYPE_EMAIL = 'email';
+
+ /**
+ * Get all notification types
+ *
+ * @access public
+ * @return array
+ */
+ public function getTypes()
+ {
+ return array(
+ self::TYPE_EMAIL => 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);
+ }
+}