summaryrefslogtreecommitdiff
path: root/app/Model/NotificationType.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-10-17 09:51:15 -0400
committerFrederic Guillot <fred@kanboard.net>2015-10-17 09:51:15 -0400
commit73a5b9bc75d40a30e7c9674b292957657ac01f63 (patch)
treeff5bb8a90452a2ff1351c192575e5d241a8b4417 /app/Model/NotificationType.php
parent98b203fe691ec1ea9d6d19e916827185b575b05a (diff)
Make user notifications pluggable
Diffstat (limited to 'app/Model/NotificationType.php')
-rw-r--r--app/Model/NotificationType.php76
1 files changed, 43 insertions, 33 deletions
diff --git a/app/Model/NotificationType.php b/app/Model/NotificationType.php
index b0514b19..9ec250ab 100644
--- a/app/Model/NotificationType.php
+++ b/app/Model/NotificationType.php
@@ -2,72 +2,82 @@
namespace Kanboard\Model;
+use Pimple\Container;
+
/**
- * Notification Type model
+ * Notification Type
*
* @package model
* @author Frederic Guillot
*/
-class NotificationType extends Base
+abstract class NotificationType extends Base
{
/**
- * SQL table name
+ * Mail transport instances
*
- * @var string
+ * @access private
+ * @var \Pimple\Container
*/
- const TABLE = 'user_has_notification_types';
+ private $classes;
/**
- * Types
+ * Mail transport instances
*
- * @var string
+ * @access private
+ * @var array
*/
- const TYPE_WEB = 'web';
- const TYPE_EMAIL = 'email';
+ private $labels = array();
/**
- * Get all notification types
+ * Constructor
*
* @access public
- * @return array
+ * @param \Pimple\Container $container
*/
- public function getTypes()
+ public function __construct(Container $container)
{
- return array(
- self::TYPE_EMAIL => t('Email'),
- self::TYPE_WEB => t('Web'),
- );
+ parent::__construct($container);
+ $this->classes = new Container;
}
/**
- * Get selected notification types for a given user
+ * Add a new notification type
*
* @access public
- * @param integer $user_id
- * @return array
+ * @param string $type
+ * @param string $label
+ * @param string $class
*/
- public function getUserSelectedTypes($user_id)
+ public function setType($type, $label, $class)
{
- return $this->db->table(self::TABLE)->eq('user_id', $user_id)->asc('notification_type')->findAllByColumn('notification_type');
+ $container = $this->container;
+ $this->labels[$type] = $label;
+
+ $this->classes[$type] = function() use ($class, $container) {
+ return new $class($container);
+ };
}
/**
- * Save notification types for a given user
+ * Get mail notification type instance
*
* @access public
- * @param integer $user_id
- * @param string[] $types
- * @return boolean
+ * @param string $type
+ * @return NotificationInterface
*/
- public function saveUserSelectedTypes($user_id, array $types)
+ public function getType($type)
{
- $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 $this->classes[$type];
+ }
- return ! in_array(false, $results);
+ /**
+ * Get all notification types with labels
+ *
+ * @access public
+ * @return array
+ */
+ public function getTypes()
+ {
+ return $this->labels;
}
}