Commit [r2480] Maximize Restore History

added schedule/resource filter to My Calendar

lqqkout13 2014-07-06

added /2.5/Presenters/Calendar/CalendarFilters.php
changed /2.5/build.xml
changed /2.5/Pages/PersonalCalendarPage.php
changed /2.5/tpl/Calendar/mycalendar.day.tpl
changed /2.5/tpl/Calendar/calendar.filter.tpl
changed /2.5/tests/Presenters/CalendarPresenterTests.php
changed /2.5/lib/Config/Configuration.php
changed /2.5/tpl/Calendar/mycalendar.month.tpl
changed /2.5/tests/Presenters/PersonalCalendarPresenterTests.php
changed /2.5/tpl/Calendar/mycalendar.common.tpl
changed /2.5/tpl/Calendar/mycalendar.week.tpl
changed /2.5/Web/scripts/calendar.js
changed /2.5/Pages/CalendarPage.php
copied /2.5/Presenters/CalendarPresenter.php -> /2.5/Presenters/Calendar/PersonalCalendarPresenter.php
copied /2.5/Presenters/PersonalCalendarPresenter.php -> /2.5/Presenters/Calendar/CalendarPresenter.php
/2.5/Presenters/Calendar/CalendarFilters.php Diff Switch to side-by-side view
Loading...
/2.5/build.xml Diff Switch to side-by-side view
Loading...
/2.5/Pages/PersonalCalendarPage.php Diff Switch to side-by-side view
Loading...
/2.5/tpl/Calendar/mycalendar.day.tpl Diff Switch to side-by-side view
Loading...
/2.5/tpl/Calendar/calendar.filter.tpl Diff Switch to side-by-side view
Loading...
/2.5/tests/Presenters/CalendarPresenterTests.php Diff Switch to side-by-side view
Loading...
/2.5/lib/Config/Configuration.php Diff Switch to side-by-side view
Loading...
/2.5/tpl/Calendar/mycalendar.month.tpl Diff Switch to side-by-side view
Loading...
/2.5/tests/Presenters/PersonalCalendarPresenterTests.php Diff Switch to side-by-side view
Loading...
/2.5/tpl/Calendar/mycalendar.common.tpl Diff Switch to side-by-side view
Loading...
/2.5/tpl/Calendar/mycalendar.week.tpl Diff Switch to side-by-side view
Loading...
/2.5/Web/scripts/calendar.js Diff Switch to side-by-side view
Loading...
/2.5/Pages/CalendarPage.php Diff Switch to side-by-side view
Loading...
/2.5/Presenters/CalendarPresenter.php to /2.5/Presenters/Calendar/PersonalCalendarPresenter.php
--- a/2.5/Presenters/CalendarPresenter.php
+++ b/2.5/Presenters/Calendar/PersonalCalendarPresenter.php
@@ -1,50 +1,60 @@
 <?php
 /**
-Copyright 2011-2014 Nick Korbel
-
-This file is part of Booked Scheduler.
-
-Booked Scheduler is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-Booked Scheduler is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Booked Scheduler.  If not, see <http://www.gnu.org/licenses/>.
+ * Copyright 2011-2014 Nick Korbel
+ *
+ * This file is part of Booked Scheduler.
+ *
+ * Booked Scheduler is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Booked Scheduler is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Booked Scheduler.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-require_once(ROOT_DIR . 'lib/Config/namespace.php');
-require_once(ROOT_DIR . 'lib/Common/namespace.php');
 require_once(ROOT_DIR . 'Domain/Access/namespace.php');
 require_once(ROOT_DIR . 'lib/Application/Schedule/namespace.php');
-require_once(ROOT_DIR . 'lib/Application/Reservation/namespace.php');
+require_once(ROOT_DIR . 'Presenters/ActionPresenter.php');
+require_once(ROOT_DIR . 'Presenters/Calendar/CalendarFilters.php');
 
-class CalendarPresenter
+class PersonalCalendarActions
+{
+	const ActionEnableSubscription = 'enable';
+	const ActionDisableSubscription = 'disable';
+}
+
+class PersonalCalendarPresenter extends ActionPresenter
 {
 	/**
-	 * @var ICalendarPage
+	 * @var \IPersonalCalendarPage
 	 */
 	private $page;
 
 	/**
-	 * @var ICalendarFactory
+	 * @var \IReservationViewRepository
+	 */
+	private $reservationRepository;
+
+	/**
+	 * @var \ICalendarFactory
 	 */
 	private $calendarFactory;
 
 	/**
-	 * @var IReservationViewRepository
+	 * @var ICalendarSubscriptionService
 	 */
-	private $reservationRepository;
+	private $subscriptionService;
 
 	/**
-	 * @var IScheduleRepository
+	 * @var IUserRepository
 	 */
-	private $scheduleRepository;
+	private $userRepository;
 
 	/**
 	 * @var IResourceService
@@ -52,32 +62,37 @@
 	private $resourceService;
 
 	/**
-	 * @var ICalendarSubscriptionService
+	 * @var IScheduleRepository
 	 */
-	private $subscriptionService;
+	private $scheduleRepository;
+
+	public function __construct(
+			IPersonalCalendarPage $page,
+			IReservationViewRepository $repository,
+			ICalendarFactory $calendarFactory,
+			ICalendarSubscriptionService $subscriptionService,
+			IUserRepository $userRepository,
+			IResourceService $resourceService,
+			IScheduleRepository $scheduleRepository)
+	{
+		parent::__construct($page);
+
+		$this->page = $page;
+		$this->reservationRepository = $repository;
+		$this->calendarFactory = $calendarFactory;
+		$this->subscriptionService = $subscriptionService;
+		$this->userRepository = $userRepository;
+		$this->resourceService = $resourceService;
+		$this->scheduleRepository = $scheduleRepository;
+
+		$this->AddAction(PersonalCalendarActions::ActionEnableSubscription, 'EnableSubscription');
+		$this->AddAction(PersonalCalendarActions::ActionDisableSubscription, 'DisableSubscription');
+	}
 
 	/**
-	 * @var IPrivacyFilter
+	 * @param UserSession $userSession
+	 * @param string $timezone
 	 */
-	private $privacyFilter;
-
-	public function __construct(ICalendarPage $page,
-								ICalendarFactory $calendarFactory,
-								IReservationViewRepository $reservationRepository,
-								IScheduleRepository $scheduleRepository,
-								IResourceService $resourceService,
-								ICalendarSubscriptionService $subscriptionService,
-								IPrivacyFilter $privacyFilter)
-	{
-		$this->page = $page;
-		$this->calendarFactory = $calendarFactory;
-		$this->reservationRepository = $reservationRepository;
-		$this->scheduleRepository = $scheduleRepository;
-		$this->resourceService = $resourceService;
-		$this->subscriptionService = $subscriptionService;
-		$this->privacyFilter = $privacyFilter;
-	}
-
 	public function PageLoad($userSession, $timezone)
 	{
 		$type = $this->page->GetCalendarType();
@@ -102,42 +117,51 @@
 		}
 
 		$schedules = $this->scheduleRepository->GetAll();
-		$showInaccessible = Configuration::Instance()->GetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_SHOW_INACCESSIBLE_RESOURCES, new BooleanConverter());
+		$showInaccessible = Configuration::Instance()
+										 ->GetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_SHOW_INACCESSIBLE_RESOURCES, new BooleanConverter());
 		$resources = $this->resourceService->GetAllResources($showInaccessible, $userSession);
 
 		$selectedScheduleId = $this->page->GetScheduleId();
 		$selectedSchedule = $this->GetDefaultSchedule($schedules);
 		$selectedResourceId = $this->page->GetResourceId();
 
-		if (!empty($selectedResourceId))
-		{
-			$subscriptionDetails = $this->subscriptionService->ForResource($selectedResourceId);
-		}
-		else
-		{
-			$subscriptionDetails = $this->subscriptionService->ForSchedule($selectedSchedule->GetId());
-		}
+		$calendar = $this->calendarFactory->Create($type, $year, $month, $day, $timezone);
+		$reservations = $this->reservationRepository->GetReservationList($calendar->FirstDay(), $calendar->LastDay(), $userSession->UserId,
+																		 ReservationUserLevel::ALL, $selectedScheduleId, $selectedResourceId);
+		$calendar->AddReservations(CalendarReservation::FromViewList($reservations, $timezone));
+		$this->page->BindCalendar($calendar);
 
-		$calendar = $this->calendarFactory->Create($type, $year, $month, $day, $timezone);
-		$reservations = $this->reservationRepository->GetReservationList($calendar->FirstDay(), $calendar->LastDay(),
-																		 null, null, $selectedScheduleId,
-																		 $selectedResourceId);
-		$calendar->AddReservations(CalendarReservation::FromScheduleReservationList(
-									   $reservations,
-									   $resources,
-									   $userSession,
-									   $this->privacyFilter));
-		$this->page->BindCalendar($calendar);
+		$this->page->SetDisplayDate($calendar->FirstDay());
 
 		$this->page->BindFilters(new CalendarFilters($schedules, $resources, $selectedScheduleId, $selectedResourceId));
 
-		$this->page->SetDisplayDate($calendar->FirstDay());
 		$this->page->SetScheduleId($selectedScheduleId);
 		$this->page->SetResourceId($selectedResourceId);
 
 		$this->page->SetFirstDay($selectedSchedule->GetWeekdayStart());
 
-		$this->page->BindSubscription($subscriptionDetails);
+		$details = $this->subscriptionService->ForUser($userSession->UserId);
+		$this->page->BindSubscription($details);
+	}
+
+	public function EnableSubscription()
+	{
+		$userId = ServiceLocator::GetServer()->GetUserSession()->UserId;
+		Log::Debug('Enabling calendar subscription for userId: %s', $userId);
+
+		$user = $this->userRepository->LoadById($userId);
+		$user->EnableSubscription();
+		$this->userRepository->Update($user);
+	}
+
+	public function DisableSubscription()
+	{
+		$userId = ServiceLocator::GetServer()->GetUserSession()->UserId;
+		Log::Debug('Disabling calendar subscription for userId: %s', $userId);
+
+		$user = $this->userRepository->LoadById($userId);
+		$user->DisableSubscription();
+		$this->userRepository->Update($user);
 	}
 
 	/**
@@ -165,164 +189,4 @@
 
 		return $default;
 	}
-}
-
-class CalendarFilters
-{
-	const FilterSchedule = 'schedule';
-	const FilterResource = 'resource';
-
-	/**
-	 * @var array|CalendarFilter[]
-	 */
-	private $filters = array();
-
-	/**
-	 * @param array|Schedule[] $schedules
-	 * @param array|ResourceDto[] $resources
-	 * @param int $selectedScheduleId
-	 * @param int $selectedResourceId
-	 */
-	public function __construct($schedules, $resources, $selectedScheduleId, $selectedResourceId)
-	{
-		if (!empty($resources))
-		{
-			$this->filters[] = new CalendarFilter(self::FilterSchedule, null, Resources::GetInstance()->GetString("AllReservations"), (empty($selectedResourceId) && empty($selectedScheduleId)));
-		}
-		foreach ($schedules as $schedule)
-		{
-			if ($this->ScheduleContainsNoResources($schedule, $resources))
-			{
-				continue;
-			}
-
-			$filter = new CalendarFilter(self::FilterSchedule, $schedule->GetId(), $schedule->GetName(), (empty($selectedResourceId) && $selectedScheduleId == $schedule->GetId()));
-
-			foreach ($resources as $resource)
-			{
-				if ($resource->GetScheduleId() == $schedule->GetId())
-				{
-					$filter->AddSubFilter(new CalendarFilter(self::FilterResource, $resource->GetResourceId(), $resource->GetName(), ($selectedResourceId == $resource->GetResourceId())));
-				}
-			}
-
-			$this->filters[] = $filter;
-		}
-	}
-
-	/**
-	 * @return bool
-	 */
-	public function IsEmpty()
-	{
-		return empty($this->filters);
-	}
-
-	/**
-	 * @return array|CalendarFilter[]
-	 */
-	public function GetFilters()
-	{
-		return $this->filters;
-	}
-
-	/**
-	 * @param Schedule $schedule
-	 * @param ResourceDto[] $resources
-	 * @return bool
-	 */
-	private function ScheduleContainsNoResources(Schedule $schedule, $resources)
-	{
-		foreach ($resources as $resource)
-		{
-			if ($resource->GetScheduleId() == $schedule->GetId())
-			{
-				return false;
-			}
-		}
-
-		return true;
-	}
-}
-
-class CalendarFilter
-{
-	/**
-	 * @var array|CalendarFilter[]
-	 */
-	private $filters = array();
-
-	/**
-	 * @var string
-	 */
-	private $type;
-
-	/**
-	 * @var string
-	 */
-	private $id;
-
-	/**
-	 * @var string
-	 */
-	private $name;
-
-	/**
-	 * @var bool
-	 */
-	private $selected;
-
-	/**
-	 * @return string
-	 */
-	public function Name()
-	{
-		return $this->name;
-	}
-
-	/**
-	 * @return string
-	 */
-	public function Id()
-	{
-		return $this->id;
-	}
-
-	/**
-	 * @return string
-	 */
-	public function Type()
-	{
-		return $this->type;
-	}
-
-	/**
-	 * @return bool
-	 */
-	public function Selected()
-	{
-		return $this->selected;
-	}
-
-	public function __construct($type, $id, $name, $selected)
-	{
-		$this->type = $type;
-		$this->id = $id;
-		$this->name = $name;
-		$this->selected = $selected;
-	}
-
-	public function AddSubFilter(CalendarFilter $subfilter)
-	{
-		$this->filters[] = $subfilter;
-	}
-
-	/**
-	 * @return array|CalendarFilter[]
-	 */
-	public function GetFilters()
-	{
-		return $this->filters;
-	}
-
 }
/2.5/Presenters/PersonalCalendarPresenter.php to /2.5/Presenters/Calendar/CalendarPresenter.php
--- a/2.5/Presenters/PersonalCalendarPresenter.php
+++ b/2.5/Presenters/Calendar/CalendarPresenter.php
@@ -16,65 +16,70 @@
 
 You should have received a copy of the GNU General Public License
 along with Booked Scheduler.  If not, see <http://www.gnu.org/licenses/>.
-*/
+ */
 
+require_once(ROOT_DIR . 'lib/Config/namespace.php');
+require_once(ROOT_DIR . 'lib/Common/namespace.php');
 require_once(ROOT_DIR . 'Domain/Access/namespace.php');
 require_once(ROOT_DIR . 'lib/Application/Schedule/namespace.php');
-require_once(ROOT_DIR . 'Presenters/ActionPresenter.php');
+require_once(ROOT_DIR . 'lib/Application/Reservation/namespace.php');
+require_once(ROOT_DIR . 'Presenters/Calendar/CalendarFilters.php');
 
-class PersonalCalendarActions
-{
-    const ActionEnableSubscription = 'enable';
-    const ActionDisableSubscription = 'disable';
-}
-
-class PersonalCalendarPresenter extends ActionPresenter
+class CalendarPresenter
 {
 	/**
-	 * @var \IPersonalCalendarPage
+	 * @var ICalendarPage
 	 */
 	private $page;
 
 	/**
-	 * @var \IReservationViewRepository
-	 */
-	private $repository;
-
-	/**
-	 * @var \ICalendarFactory
+	 * @var ICalendarFactory
 	 */
 	private $calendarFactory;
 
-    /**
-     * @var ICalendarSubscriptionService
-     */
-    private $subscriptionService;
+	/**
+	 * @var IReservationViewRepository
+	 */
+	private $reservationRepository;
 
-    /**
-     * @var IUserRepository
-     */
-    private $userRepository;
+	/**
+	 * @var IScheduleRepository
+	 */
+	private $scheduleRepository;
 
-	public function __construct(
-        IPersonalCalendarPage $page,
-        IReservationViewRepository $repository,
-        ICalendarFactory $calendarFactory,
-        ICalendarSubscriptionService $subscriptionService,
-        IUserRepository $userRepository)
+	/**
+	 * @var IResourceService
+	 */
+	private $resourceService;
+
+	/**
+	 * @var ICalendarSubscriptionService
+	 */
+	private $subscriptionService;
+
+	/**
+	 * @var IPrivacyFilter
+	 */
+	private $privacyFilter;
+
+	public function __construct(ICalendarPage $page,
+								ICalendarFactory $calendarFactory,
+								IReservationViewRepository $reservationRepository,
+								IScheduleRepository $scheduleRepository,
+								IResourceService $resourceService,
+								ICalendarSubscriptionService $subscriptionService,
+								IPrivacyFilter $privacyFilter)
 	{
-        parent::__construct($page);
-
 		$this->page = $page;
-		$this->repository = $repository;
 		$this->calendarFactory = $calendarFactory;
+		$this->reservationRepository = $reservationRepository;
+		$this->scheduleRepository = $scheduleRepository;
+		$this->resourceService = $resourceService;
 		$this->subscriptionService = $subscriptionService;
-		$this->userRepository = $userRepository;
-
-        $this->AddAction(PersonalCalendarActions::ActionEnableSubscription, 'EnableSubscription');
-        $this->AddAction(PersonalCalendarActions::ActionDisableSubscription, 'DisableSubscription');
+		$this->privacyFilter = $privacyFilter;
 	}
 
-	public function PageLoad($userId, $timezone)
+	public function PageLoad($userSession, $timezone)
 	{
 		$type = $this->page->GetCalendarType();
 
@@ -97,35 +102,69 @@
 			$day = $defaultDate->Day();
 		}
 
+		$schedules = $this->scheduleRepository->GetAll();
+		$showInaccessible = Configuration::Instance()->GetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_SHOW_INACCESSIBLE_RESOURCES, new BooleanConverter());
+		$resources = $this->resourceService->GetAllResources($showInaccessible, $userSession);
+
+		$selectedScheduleId = $this->page->GetScheduleId();
+		$selectedSchedule = $this->GetDefaultSchedule($schedules);
+		$selectedResourceId = $this->page->GetResourceId();
+
+		if (!empty($selectedResourceId))
+		{
+			$subscriptionDetails = $this->subscriptionService->ForResource($selectedResourceId);
+		}
+		else
+		{
+			$subscriptionDetails = $this->subscriptionService->ForSchedule($selectedSchedule->GetId());
+		}
+
 		$calendar = $this->calendarFactory->Create($type, $year, $month, $day, $timezone);
-		$reservations = $this->repository->GetReservationList($calendar->FirstDay(), $calendar->LastDay(), $userId, ReservationUserLevel::ALL);
-		$calendar->AddReservations(CalendarReservation::FromViewList($reservations, $timezone));
+		$reservations = $this->reservationRepository->GetReservationList($calendar->FirstDay(), $calendar->LastDay(),
+																		 null, null, $selectedScheduleId,
+																		 $selectedResourceId);
+		$calendar->AddReservations(CalendarReservation::FromScheduleReservationList(
+									   $reservations,
+									   $resources,
+									   $userSession,
+									   $this->privacyFilter));
 		$this->page->BindCalendar($calendar);
 
+		$this->page->BindFilters(new CalendarFilters($schedules, $resources, $selectedScheduleId, $selectedResourceId));
+
 		$this->page->SetDisplayDate($calendar->FirstDay());
+		$this->page->SetScheduleId($selectedScheduleId);
+		$this->page->SetResourceId($selectedResourceId);
 
-        $details = $this->subscriptionService->ForUser($userId);
-        $this->page->BindSubscription($details);
+		$this->page->SetFirstDay($selectedSchedule->GetWeekdayStart());
+
+		$this->page->BindSubscription($subscriptionDetails);
 	}
 
-    public function EnableSubscription()
-    {
-        $userId = ServiceLocator::GetServer()->GetUserSession()->UserId;
-        Log::Debug('Enabling calendar subscription for userId: %s', $userId);
+	/**
+	 * @param array|Schedule[] $schedules
+	 * @return Schedule
+	 */
+	private function GetDefaultSchedule($schedules)
+	{
+		$default = null;
+		$scheduleId = $this->page->GetScheduleId();
 
-        $user = $this->userRepository->LoadById($userId);
-        $user->EnableSubscription();
-        $this->userRepository->Update($user);
-    }
+		/** @var $schedule Schedule */
+		foreach ($schedules as $schedule)
+		{
+			if (!empty($scheduleId) && $schedule->GetId() == $scheduleId)
+			{
+				return $schedule;
+			}
 
-    public function DisableSubscription()
-    {
-        $userId = ServiceLocator::GetServer()->GetUserSession()->UserId;
-        Log::Debug('Disabling calendar subscription for userId: %s', $userId);
+			if ($schedule->GetIsDefault())
+			{
+				$default = $schedule;
+			}
+		}
 
-        $user = $this->userRepository->LoadById($userId);
-        $user->DisableSubscription();
-        $this->userRepository->Update($user);
-    }
+		return $default;
+	}
 }
-?>+