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/UserNotificationTypeModel.php | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/Model/UserNotificationTypeModel.php (limited to 'app/Model/UserNotificationTypeModel.php') diff --git a/app/Model/UserNotificationTypeModel.php b/app/Model/UserNotificationTypeModel.php new file mode 100644 index 00000000..0f377220 --- /dev/null +++ b/app/Model/UserNotificationTypeModel.php @@ -0,0 +1,52 @@ +db->table(self::TABLE)->eq('user_id', $user_id)->asc('notification_type')->findAllByColumn('notification_type'); + return $this->filterTypes($types); + } + + /** + * Save notification types for a given user + * + * @access public + * @param integer $user_id + * @param string[] $types + * @return boolean + */ + public function saveSelectedTypes($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, true); + } +} -- cgit v1.2.3