summaryrefslogtreecommitdiff
path: root/app/php/facades
diff options
context:
space:
mode:
Diffstat (limited to 'app/php/facades')
-rw-r--r--app/php/facades/CalendarFacade.php22
-rw-r--r--app/php/facades/EventFacade.php33
-rw-r--r--app/php/facades/UserFacade.php66
3 files changed, 106 insertions, 15 deletions
diff --git a/app/php/facades/CalendarFacade.php b/app/php/facades/CalendarFacade.php
index a1ff42d..c342cd2 100644
--- a/app/php/facades/CalendarFacade.php
+++ b/app/php/facades/CalendarFacade.php
@@ -22,8 +22,16 @@ class CalendarFacade extends Facade {
);
}
+ public function getCalendarPreference(DbUser $user) {
+ if ($user->IsGuest) {
+ return Calendar::finder()->findAllByIsVisible(1);
+ } else {
+ return $user->DbRecord->Calendars;
+ }
+ }
+
public function getPreferenceList(DbUser $user) {
- $calendars = $user->getCalendarPreference();
+ $calendars = $this->getCalendarPreference($user);
if ($calendars) {
$categories = array_map(
function($category) use($calendars) {
@@ -39,6 +47,18 @@ class CalendarFacade extends Facade {
return [];
}
+ public function isCalendarPreferred(DbUser $user, $calendarID) {
+ return in_array(
+ $calendarID,
+ array_map(
+ function($calendar) {
+ return $calendar->UID;
+ },
+ $this->getCalendarPreference($user)
+ )
+ );
+ }
+
public function addToPreference(DbUser $user, $calendarID) {
if (!$user->IsGuest) {
$calendar = Calendar::finder()->findByPk($calendarID);
diff --git a/app/php/facades/EventFacade.php b/app/php/facades/EventFacade.php
index a41b2f7..9533448 100644
--- a/app/php/facades/EventFacade.php
+++ b/app/php/facades/EventFacade.php
@@ -3,6 +3,7 @@
Prado::using('Application.facades.Facade');
Prado::using('Application.dto.EventDTO');
Prado::using('Application.model.Calendar');
+Prado::using('Application.facades.CalendarFacade');
Prado::using('Application.user.DbUser');
class EventFacade extends Facade {
@@ -37,20 +38,24 @@ class EventFacade extends Facade {
public function getTimeframeListForUser(DbUser $user,
DateTime $dateFrom,
DateTime $dateTo) {
- $events = $this->getEventList(
- $dateFrom->format('Y-m-d H:i:s'),
- $dateTo->format('Y-m-d H:i:s'),
- $user->getCalendarPreference()
- );
- $calendars = $this->_getCalendarsForEvents($events);
- return array_map(
- function($event) use($calendars) {
- $dto = new EventDTO();
- $dto->loadRecord($event, $calendars);
- return $dto;
- },
- $events
- );
+ $calendars = CalendarFacade::getInstance()->getCalendarPreference($user);
+ if ($calendars) {
+ $events = $this->getEventList(
+ $dateFrom->format('Y-m-d H:i:s'),
+ $dateTo->format('Y-m-d H:i:s'),
+ $calendars
+ );
+ $calendars = $this->_getCalendarsForEvents($events);
+ return array_map(
+ function($event) use($calendars) {
+ $dto = new EventDTO();
+ $dto->loadRecord($event, $calendars);
+ return $dto;
+ },
+ $events
+ );
+ }
+ return [];
}
private function _getCalendarsForEvents(array $events) {
diff --git a/app/php/facades/UserFacade.php b/app/php/facades/UserFacade.php
new file mode 100644
index 0000000..696f77f
--- /dev/null
+++ b/app/php/facades/UserFacade.php
@@ -0,0 +1,66 @@
+<?php
+
+Prado::using('Application.facades.Facade');
+Prado::using('Application.user.DbUser');
+Prado::using('Application.model.User');
+Prado::using('Application.dto.TimezoneDTO');
+
+class UserFacade extends Facade {
+
+ public function setTimezonePreference(DbUser $user, $timezone) {
+ if ($user->IsGuest) {
+ throw new TInvalidDataException(
+ 'Timezone preference change impossible for guest user'
+ );
+ }
+ $user->DbRecord->Timezone = $timezone;
+ $user->DbRecord->save();
+ }
+
+ public function getTimezonePreference(DbUser $user) {
+ if (!$user->IsGuest) {
+ try {
+ return new TimezoneDTO($user->DbRecord->Timezone);
+ } catch(Exception $e) {}
+ }
+ return new TimezoneDTO(date_default_timezone_get());
+ }
+
+ public function checkForUsername($login) {
+ return !User::finder()->countByLogin($login);
+ }
+
+ public function registerUser($login, $password, $admin) {
+ $newUser = new User();
+ $newUser->Login = $login;
+ $newUser->Password = $this->generatePassword($password);
+ $newUser->IsAdmin = $admin;
+ $newUser->save();
+ return $newUser;
+ }
+
+ public function changePassword(DbUser $user, $pass) {
+ if (!$user->IsGuest) {
+ $user->DbRecord->Password = $this->generatePassword($pass);
+ $user->DbRecord->save();
+ }
+ }
+
+ public function verifyUserPassword($password, DbUser $user) {
+ $dbPassword = $user->IsGuest ? '' : $user->DbRecord->Password;
+ return $this->verifyPassword($password, $dbPassword);
+ }
+
+ public function generatePassword($password) {
+ return password_hash($password, PASSWORD_DEFAULT);
+ }
+
+ public function verifyPassword($password, $dbPassword) {
+ return password_verify($password, $dbPassword);
+ }
+
+
+
+}
+
+?>