From 14713b0ec7ed93ca45578da069ad4e19a7d8addf Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 28 May 2016 19:48:22 -0400 Subject: Rename all models --- app/Model/NotificationTypeModel.php | 128 ++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 app/Model/NotificationTypeModel.php (limited to 'app/Model/NotificationTypeModel.php') diff --git a/app/Model/NotificationTypeModel.php b/app/Model/NotificationTypeModel.php new file mode 100644 index 00000000..432832ee --- /dev/null +++ b/app/Model/NotificationTypeModel.php @@ -0,0 +1,128 @@ +classes = new Container; + } + + /** + * Add a new notification type + * + * @access public + * @param string $type + * @param string $label + * @param string $class + * @param boolean $hidden + * @return NotificationTypeModel + */ + public function setType($type, $label, $class, $hidden = false) + { + $container = $this->container; + + if ($hidden) { + $this->hiddens[] = $type; + } else { + $this->labels[$type] = $label; + } + + $this->classes[$type] = function () use ($class, $container) { + return new $class($container); + }; + + return $this; + } + + /** + * Get mail notification type instance + * + * @access public + * @param string $type + * @return \Kanboard\Core\Notification\NotificationInterface + */ + public function getType($type) + { + return $this->classes[$type]; + } + + /** + * Get all notification types with labels + * + * @access public + * @return array + */ + public function getTypes() + { + return $this->labels; + } + + /** + * Get all hidden notification types + * + * @access public + * @return array + */ + public function getHiddenTypes() + { + return $this->hiddens; + } + + /** + * Keep only loaded notification types + * + * @access public + * @param string[] $types + * @return array + */ + public function filterTypes(array $types) + { + $classes = $this->classes; + + return array_filter($types, function ($type) use ($classes) { + return isset($classes[$type]); + }); + } +} -- cgit v1.2.3