Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SavedCalendarSubscriptions.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 
38  {
39  protected $mySavedCalendarsAndSelected = array();
40 
41  protected $subscribedToSavedCalendarsAndSelected = array();
42 
50  public static function makeByUser(User $user, $selectedCalendarIds = null, $subscribedCalendarIds = null)
51  {
52  assert('is_string($subscribedCalendarIds) || ($subscribedCalendarIds === null)');
53  assert('is_string($selectedCalendarIds) || ($selectedCalendarIds === null)');
54  $savedCalendarSubscriptions = new SavedCalendarSubscriptions();
55  self::addMySavedCalendars($savedCalendarSubscriptions, $user, $selectedCalendarIds);
56  self::addMySubscribedCalendars($savedCalendarSubscriptions, $user, $subscribedCalendarIds);
57  return $savedCalendarSubscriptions;
58  }
59 
68  private static function addMySavedCalendars(SavedCalendarSubscriptions $savedCalendarSubscriptions,
69  User $user, $selectedCalendarIds)
70  {
71  $mySavedCalendars = CalendarUtil::getUserSavedCalendars($user);
72  if (count($mySavedCalendars) == 0)
73  {
74  $mySavedCalendars = CalendarUtil::loadDefaultCalendars($user);
75  $selectedCalendarIds = $mySavedCalendars[0]->id . ',' . $mySavedCalendars[1]->id; // Not Coding Standard
76  }
78  'CalendarsModule',
79  'myCalendarSelections', $selectedCalendarIds);
80  $selectedCalendarIdArray = array();
81  if ($selectedCalendarIds != null)
82  {
83  $selectedCalendarIdArray = explode(',', $selectedCalendarIds); // Not Coding Standard
84  }
85  foreach ($mySavedCalendars as $key => $mySavedCalendar)
86  {
87  CalendarUtil::setMyCalendarColor($mySavedCalendar, $user);
88  if (in_array($mySavedCalendar->id, $selectedCalendarIdArray))
89  {
90  $savedCalendarSubscriptions->addMySavedCalendar($mySavedCalendar, true);
91  }
92  else
93  {
94  $savedCalendarSubscriptions->addMySavedCalendar($mySavedCalendar, false);
95  }
96  }
97  }
98 
106  private static function addMySubscribedCalendars(SavedCalendarSubscriptions $savedCalendarSubscriptions,
107  User $user,
108  $subscribedCalendarIds)
109  {
110  $mySubscribedCalendars = CalendarUtil::getUserSubscribedCalendars($user);
111  if (count($mySubscribedCalendars) > 0)
112  {
114  'CalendarsModule',
115  'mySubscribedCalendarSelections', $subscribedCalendarIds);
116  $subscribedCalendarIdArray = array();
117  if ($subscribedCalendarIds != null)
118  {
119  $subscribedCalendarIdArray = explode(',', $subscribedCalendarIds); // Not Coding Standard
120  }
121  foreach ($mySubscribedCalendars as $key => $mySubscribedCalendar)
122  {
123  CalendarUtil::setSharedCalendarColor($mySubscribedCalendar);
124  if (in_array($mySubscribedCalendar->id, $subscribedCalendarIdArray))
125  {
126  $savedCalendarSubscriptions->addSubscribedToCalendar($mySubscribedCalendar, true);
127  }
128  else
129  {
130  $savedCalendarSubscriptions->addSubscribedToCalendar($mySubscribedCalendar, false);
131  }
132  }
133  }
134  }
135 
140  public function addMySavedCalendar(SavedCalendar $savedCalendar, $selected)
141  {
142  assert('is_bool($selected)');
143  if (!isset($this->mySavedCalendarsAndSelected[$savedCalendar->id]))
144  {
145  $this->mySavedCalendarsAndSelected[$savedCalendar->id] = array($savedCalendar, $selected);
146  }
147  }
148 
153  public function addSubscribedToCalendar(SavedCalendarSubscription $subscribedCalendar, $selected)
154  {
155  assert('is_bool($selected)');
156  if (!isset($this->subscribedToSavedCalendarsAndSelected[$subscribedCalendar->id]))
157  {
158  $this->subscribedToSavedCalendarsAndSelected[$subscribedCalendar->id] = array($subscribedCalendar, $selected);
159  }
160  }
161 
166  {
167  return $this->mySavedCalendarsAndSelected;
168  }
169 
174  {
175  return $this->subscribedToSavedCalendarsAndSelected;
176  }
177  }
178 ?>
static getUserSubscribedCalendars(User $user)
static setMyCalendarColor(SavedCalendar $savedCalendar, User $user)
Definition: User.php:37
static setByUserAndModuleName($user, $moduleName, $key, $value, $cache=true)
static getUserSavedCalendars(User $user)
addMySavedCalendar(SavedCalendar $savedCalendar, $selected)
addSubscribedToCalendar(SavedCalendarSubscription $subscribedCalendar, $selected)
static loadDefaultCalendars(User $user)
static makeByUser(User $user, $selectedCalendarIds=null, $subscribedCalendarIds=null)
static setSharedCalendarColor(SavedCalendarSubscription $sharedCalendar)
Generated on Fri Jul 10 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.