All Data Structures Functions Variables Pages
UserNotificationConfigurationForm.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
40  class UserNotificationConfigurationForm extends CFormModel
41  {
45  private $user;
46 
47  public $inboxAndEmailNotificationSettings;
48 
49  public function __get($name)
50  {
51  try
52  {
53  parent::__get($name);
54  }
55  catch (CException $exception)
56  {
57  list($settingName, $type) = UserNotificationUtil::getSettingNameAndTypeBySuffixedConfigurationAttribute($name);
58  if (isset($this->inboxAndEmailNotificationSettings[$settingName][$type]))
59  {
60  return $this->inboxAndEmailNotificationSettings[$settingName][$type];
61  }
62  return null;
63  }
64  }
65 
66  public function __set($name, $value)
67  {
68  if (property_exists($this, $name))
69  {
70  return $this->$name = $value;
71  }
72  else
73  {
74  list($settingName, $type) = UserNotificationUtil::getSettingNameAndTypeBySuffixedConfigurationAttribute($name);
75  return $this->inboxAndEmailNotificationSettings[$settingName][$type] = $value;
76  }
77  }
78 
79  public function attributeNames()
80  {
81  return array_merge(parent::attributeNames(), UserNotificationUtil::getAllNotificationSettingAttributes());
82  }
83 
84  public function __construct($user)
85  {
86  assert('$user instanceof User');
87  assert('is_int($user->id) && $user->id > 0');
88  $this->user = $user;
89  }
90 
91  public function getUser()
92  {
93  return $this->user;
94  }
95 
100  public function getId()
101  {
102  return $this->user->id;
103  }
104 
105  public function rules()
106  {
107  return array(
108  array('data', 'safe'),
109  );
110  }
111 
112  public function attributeLabels()
113  {
114  $labels = array();
115  foreach ($this->attributeNames() as $name)
116  {
117  list($settingName, $type) = UserNotificationUtil::getSettingNameAndTypeBySuffixedConfigurationAttribute($name);
118  $notificationRulesClassName = str_replace('enable', '', $settingName) . 'Rules';
119  if (@class_exists($notificationRulesClassName))
120  {
121  $rule = NotificationRulesFactory::createNotificationRulesByType(str_replace('NotificationRules', '', $notificationRulesClassName));
122  $labels[$settingName] = $rule->getDisplayName();
123  }
124  }
125  return $labels;
126  }
127  }
128 ?>
Generated on Wed Feb 26 2020 07:10:41