diff --git a/Core/Frameworks/Baikal/Model/Calendar.php b/Core/Frameworks/Baikal/Model/Calendar.php index e675422c..5bc02c17 100644 --- a/Core/Frameworks/Baikal/Model/Calendar.php +++ b/Core/Frameworks/Baikal/Model/Calendar.php @@ -30,37 +30,43 @@ use Symfony\Component\Yaml\Yaml; class Calendar extends \Flake\Core\Model\Db { - const DATATABLE = "calendarinstances"; + const DATATABLE = "calendars"; const PRIMARYKEY = "id"; - const LABELFIELD = "displayname"; + const LABELFIELD = "components"; protected $aData = [ - "principaluri" => "", - "displayname" => "", - "uri" => "", - "description" => "", - "calendarorder" => 0, - "calendarcolor" => "", - "timezone" => null, - "calendarid" => 0, - "access" => 1, - "share_invitestatus" => 2, + "components" => "", ]; - protected $oCalendar; # Baikal\Model\Calendar\Calendar - - function __construct($sPrimary = false) { - parent::__construct($sPrimary); - try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); - $this->set("timezone", $config['system']["timezone"]); - } catch (\Exception $e) { - error_log('Error reading baikal.yaml file : ' . $e->getMessage()); + + public function getComponents() { + return $this->aData['components']; + } + + public function setComponents($components) { + $this->aData['components'] = $components; + } + + function hasInstances() { + $rSql = $GLOBALS["DB"]->exec_SELECTquery( + "count(*) as count", + "calendarinstances", + "calendarid='" . $this->aData["id"] . "'" + ); + + if (($aRs = $rSql->fetch()) === false) { + return false; + } else { + reset($aRs); + + return $aRs["count"] > 1; } } - protected function initFloating() { - parent::initFloating(); - $this->oCalendar = new Calendar\Calendar(); + function destroy() { + if ($this->hasInstances()) { + throw new \Exception("Trying to destroy a calendar with instances"); + } + parent::destroy(); } protected function initByPrimary($sPrimary) { diff --git a/Core/Frameworks/Baikal/Model/Principal.php b/Core/Frameworks/Baikal/Model/Principal.php index 2b86b1ae..a4678b43 100644 --- a/Core/Frameworks/Baikal/Model/Principal.php +++ b/Core/Frameworks/Baikal/Model/Principal.php @@ -35,4 +35,28 @@ class Principal extends \Flake\Core\Model\Db { "displayname" => "", "email" => "", ]; + + public function getUri() { + return $this->aData['uri']; + } + + public function setUri($uri) { + $this->aData['uri'] = $uri; + } + + public function getDisplayName() { + return $this->aData['displayname']; + } + + public function setDisplayName($displayname) { + $this->aData['displayname'] = $displayname; + } + + public function getEmail() { + return $this->aData['email']; + } + + public function setEmail($email) { + $this->aData['email'] = $email; + } } diff --git a/Core/Frameworks/Baikal/Model/User.php b/Core/Frameworks/Baikal/Model/User.php index aa2ca593..969adae1 100644 --- a/Core/Frameworks/Baikal/Model/User.php +++ b/Core/Frameworks/Baikal/Model/User.php @@ -27,6 +27,10 @@ namespace Baikal\Model; +aData['username']; + } + + public function setUsername($username) { + $this->aData['username'] = $username; + } + + public function getDigesta1() { + return $this->aData['digesta1']; + } + + public function setDigesta1($digesta1) { + $this->aData['digesta1'] = $digesta1; + } + function initByPrimary($sPrimary) { parent::initByPrimary($sPrimary); diff --git a/Core/Frameworks/BaikalAdmin/Controller/User/AddressBooks.php b/Core/Frameworks/BaikalAdmin/Controller/User/AddressBooks.php index d08ec8b6..24d40d09 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/User/AddressBooks.php +++ b/Core/Frameworks/BaikalAdmin/Controller/User/AddressBooks.php @@ -1,279 +1,243 @@ - -# All rights reserved -# -# http://sabre.io/baikal -# -# This script is part of the Baïkal Server project. The Baïkal -# Server project 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 2 of the License, or (at your option) any later version. -# -# The GNU General Public License can be found at -# http://www.gnu.org/copyleft/gpl.html. -# -# This script 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. -# -# This copyright notice MUST APPEAR in all copies of the script! -################################################################# - -namespace BaikalAdmin\Controller\User; - -class AddressBooks extends \Flake\Core\Controller { - protected $aMessages = []; - protected $oModel; # \Baikal\Model\Contact - protected $oUser; # \Baikal\Model\User - protected $oForm; # \Formal\Form - - function execute() { - if (($iUser = $this->currentUserId()) === false) { - throw new \Exception("BaikalAdmin\Controller\User\Contacts::render(): User get-parameter not found."); - } - - $this->oUser = new \Baikal\Model\User($iUser); - - if ($this->actionNewRequested()) { - $this->actionNew(); - } - - if ($this->actionEditRequested()) { - $this->actionEdit(); - } - - if ($this->actionDeleteRequested()) { - $this->actionDelete(); - } - } - - function render() { - $oView = new \BaikalAdmin\View\User\AddressBooks(); - - # User - $oView->setData("user", $this->oUser); - - # Render list of address books - $aAddressBooks = []; - $oAddressBooks = $this->oUser->getAddressBooksBaseRequester()->execute(); - - foreach ($oAddressBooks as $addressbook) { - $aAddressBooks[] = [ - "linkedit" => $this->linkEdit($addressbook), - "linkdelete" => $this->linkDelete($addressbook), - "davuri" => $this->getDavUri($addressbook), - "icon" => $addressbook->icon(), - "label" => $addressbook->label(), - "contacts" => $addressbook->getContactsBaseRequester()->count(), - "description" => $addressbook->get("description"), - ]; - } - - $oView->setData("addressbooks", $aAddressBooks); - - # Messages - $sMessages = implode("\n", $this->aMessages); - $oView->setData("messages", $sMessages); - - if ($this->actionNewRequested() || $this->actionEditRequested()) { - $sForm = $this->oForm->render(); - } else { - $sForm = ""; - } - - $oView->setData("form", $sForm); - $oView->setData("titleicon", \Baikal\Model\AddressBook::bigicon()); - $oView->setData("modelicon", $this->oUser->mediumIcon()); - $oView->setData("modellabel", $this->oUser->label()); - $oView->setData("linkback", \BaikalAdmin\Controller\Users::link()); - $oView->setData("linknew", $this->linkNew()); - $oView->setData("addressbookicon", \Baikal\Model\AddressBook::icon()); - - return $oView->render(); - } - - protected function initForm() { - if ($this->actionEditRequested() || $this->actionNewRequested()) { - $aOptions = [ - "closeurl" => $this->linkHome(), - ]; - - $this->oForm = $this->oModel->formForThisModelInstance($aOptions); - } - } - - protected function currentUserId() { - $aParams = $this->getParams(); - if (($iUser = intval($aParams["user"])) === 0) { - return false; - } - - return $iUser; - } - - # Action new - - function linkNew() { - return self::buildRoute([ - "user" => $this->currentUserId(), - "new" => 1, - ]) . "#form"; - } - - protected function actionNewRequested() { - $aParams = $this->getParams(); - if (array_key_exists("new", $aParams) && intval($aParams["new"]) === 1) { - return true; - } - - return false; - } - - protected function actionNew() { - # Building floating model object - $this->oModel = new \Baikal\Model\AddressBook(); - $this->oModel->set( - "principaluri", - $this->oUser->get("uri") - ); - - $this->initForm(); - - if ($this->oForm->submitted()) { - $this->oForm->execute(); - - if ($this->oForm->persisted()) { - $this->oForm->setOption( - "action", - $this->linkEdit( - $this->oForm->modelInstance() - ) - ); - } - } - } - - # Action edit - - function linkEdit(\Baikal\Model\AddressBook $oModel) { - return self::buildRoute([ - "user" => $this->currentUserId(), - "edit" => $oModel->get("id"), - ]) . "#form"; - } - - protected function actionEditRequested() { - $aParams = $this->getParams(); - if (array_key_exists("edit", $aParams) && intval($aParams["edit"]) > 0) { - return true; - } - - return false; - } - - protected function actionEdit() { - # Building anchored model object - $aParams = $this->getParams(); - $this->oModel = new \Baikal\Model\AddressBook(intval($aParams["edit"])); - - # Initialize corresponding form - $this->initForm(); - - # Process form - if ($this->oForm->submitted()) { - $this->oForm->execute(); - } - } - - # Action delete + confirm - - function linkDelete(\Baikal\Model\AddressBook $oModel) { - return self::buildRoute([ - "user" => $this->currentUserId(), - "delete" => $oModel->get("id"), - ]) . "#message"; - } - - function linkDeleteConfirm(\Baikal\Model\AddressBook $oModel) { - return self::buildRoute([ - "user" => $this->currentUserId(), - "delete" => $oModel->get("id"), - "confirm" => 1, - ]) . "#message"; - } - - protected function actionDeleteRequested() { - $aParams = $this->getParams(); - if (array_key_exists("delete", $aParams) && intval($aParams["delete"]) > 0) { - return true; - } - - return false; - } - - protected function actionDeleteConfirmed() { - if (($iPrimary = $this->actionDeleteRequested()) === false) { - return false; - } - - $aParams = $this->getParams(); - if (array_key_exists("confirm", $aParams) && intval($aParams["confirm"]) > 0) { - return true; - } - - return false; - } - - protected function actionDelete() { - $aParams = $this->getParams(); - $iModel = intval($aParams["delete"]); - - if ($this->actionDeleteConfirmed() !== false) { - # catching Exception thrown when model already destroyed - # happens when user refreshes page on delete-URL, for instance - - try { - $oModel = new \Baikal\Model\AddressBook($iModel); - $oModel->destroy(); - } catch (\Exception $e) { - # already deleted; silently discarding - } - - # Redirecting to admin home - \Flake\Util\Tools::redirectUsingMeta($this->linkHome()); - } else { - $oModel = new \Baikal\Model\AddressBook($iModel); - $this->aMessages[] = \Formal\Core\Message::warningConfirmMessage( - "Check twice, you're about to delete " . $oModel->label() . " from the database !", - "

You are about to delete a contact book and all it's visiting cards. This operation cannot be undone.

So, now that you know all that, what shall we do ?

", - $this->linkDeleteConfirm($oModel), - "Delete " . $oModel->label() . "", - $this->linkHome() - ); - } - } - - # Link to home - function linkHome() { - return self::buildRoute([ - "user" => $this->currentUserId(), - ]); - } - - /** - * Generate a link to the CalDAV/CardDAV URI of the addressbook. - * - * @param \Baikal\Model\AddressBook $addressbook - * - * @return string AddressBook DAV URI - */ - protected function getDavUri(\Baikal\Model\AddressBook $addressbook) { - return PROJECT_URI . 'dav.php/addressbooks/' . $this->oUser->get('username') . '/' . $addressbook->get('uri') . '/'; - } -} + +# All rights reserved +# +# http://sabre.io/baikal +# +# This script is part of the Baïkal Server project. The Baïkal +# Server project 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 2 of the License, or (at your option) any later version. +# +# The GNU General Public License can be found at +# http://www.gnu.org/copyleft/gpl.html. +# +# This script 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. +# +# This copyright notice MUST APPEAR in all copies of the script! +################################################################# + +namespace BaikalAdmin\Controller\User; + +class AddressBooks extends \Flake\Core\Controller { + protected $aMessages = []; + protected $oModel; # \Baikal\Model\Contact + protected $oUser; # \Baikal\Model\User + protected $oForm; # \Formal\Form + + /** + * @var \BaikalAdmin\Service\AddressBooks + */ + private $uService; + + public function __construct() { + $uService = new \BaikalAdmin\Service\AddressBooks(); + } + + function execute() { + if (($iUser = $this->currentUserId()) === false) { + throw new \Exception("BaikalAdmin\Controller\User\Contacts::render(): User get-parameter not found."); + } + + $this->oUser = new \Baikal\Model\User($iUser); + + if ($this->actionNewRequested()) { + $this->actionNew(); + } + + if ($this->actionEditRequested()) { + $this->actionEdit(); + } + + if ($this->actionDeleteRequested()) { + $this->actionDelete(); + } + } + + function render() { + $oView = new \BaikalAdmin\View\User\AddressBooks(); + $aAddressBooks = $this->$uService->getAll(); + return $uService->render($oView, $oUser, $aAddressBooks, $this->aMessages, $oForm, $this); + } + + protected function initForm() { + if ($this->actionEditRequested() || $this->actionNewRequested()) { + $aOptions = [ + "closeurl" => $this->linkHome(), + ]; + + $this->oForm = $this->oModel->formForThisModelInstance($aOptions); + } + } + + protected function currentUserId() { + $aParams = $this->getParams(); + if (($iUser = intval($aParams["user"])) === 0) { + return false; + } + + return $iUser; + } + + # Action new + + function linkNew() { + return self::buildRoute([ + "user" => $this->currentUserId(), + "new" => 1, + ]) . "#form"; + } + + protected function actionNewRequested() { + $aParams = $this->getParams(); + if (array_key_exists("new", $aParams) && intval($aParams["new"]) === 1) { + return true; + } + + return false; + } + + protected function actionNew() { + # Building floating model object + $this->oModel = new \Baikal\Model\AddressBook(); + $this->oModel->set( + "principaluri", + $this->oUser->get("uri") + ); + + $this->initForm(); + + if ($this->oForm->submitted()) { + $this->oForm->execute(); + + if ($this->oForm->persisted()) { + $this->oForm->setOption( + "action", + $this->linkEdit( + $this->oForm->modelInstance() + ) + ); + } + } + } + + # Action edit + + function linkEdit(\Baikal\Model\AddressBook $oModel) { + return self::buildRoute([ + "user" => $this->currentUserId(), + "edit" => $oModel->get("id"), + ]) . "#form"; + } + + protected function actionEditRequested() { + $aParams = $this->getParams(); + if (array_key_exists("edit", $aParams) && intval($aParams["edit"]) > 0) { + return true; + } + + return false; + } + + protected function actionEdit() { + # Building anchored model object + $aParams = $this->getParams(); + $this->oModel = new \Baikal\Model\AddressBook(intval($aParams["edit"])); + + # Initialize corresponding form + $this->initForm(); + + # Process form + if ($this->oForm->submitted()) { + $this->oForm->execute(); + } + } + + # Action delete + confirm + + function linkDelete(\Baikal\Model\AddressBook $oModel) { + return self::buildRoute([ + "user" => $this->currentUserId(), + "delete" => $oModel->get("id"), + ]) . "#message"; + } + + function linkDeleteConfirm(\Baikal\Model\AddressBook $oModel) { + return self::buildRoute([ + "user" => $this->currentUserId(), + "delete" => $oModel->get("id"), + "confirm" => 1, + ]) . "#message"; + } + + protected function actionDeleteRequested() { + $aParams = $this->getParams(); + if (array_key_exists("delete", $aParams) && intval($aParams["delete"]) > 0) { + return true; + } + + return false; + } + + protected function actionDeleteConfirmed() { + if (($iPrimary = $this->actionDeleteRequested()) === false) { + return false; + } + + $aParams = $this->getParams(); + if (array_key_exists("confirm", $aParams) && intval($aParams["confirm"]) > 0) { + return true; + } + + return false; + } + + protected function actionDelete() { + $aParams = $this->getParams(); + $iModel = intval($aParams["delete"]); + + if ($this->actionDeleteConfirmed() !== false) { + # catching Exception thrown when model already destroyed + # happens when user refreshes page on delete-URL, for instance + $this->$uService->delete($iModel); + + # Redirecting to admin home + \Flake\Util\Tools::redirectUsingMeta($this->linkHome()); + } else { + $oModel = new \Baikal\Model\AddressBook($iModel); + $this->aMessages[] = \Formal\Core\Message::warningConfirmMessage( + "Check twice, you're about to delete " . $oModel->label() . " from the database !", + "

You are about to delete a contact book and all it's visiting cards. This operation cannot be undone.

So, now that you know all that, what shall we do ?

", + $this->linkDeleteConfirm($oModel), + "Delete " . $oModel->label() . "", + $this->linkHome() + ); + } + } + + # Link to home + function linkHome() { + return self::buildRoute([ + "user" => $this->currentUserId(), + ]); + } + + /** + * Generate a link to the CalDAV/CardDAV URI of the addressbook. + * + * @param \Baikal\Model\AddressBook $addressbook + * + * @return string AddressBook DAV URI + */ + protected function getDavUri(\Baikal\Model\AddressBook $addressbook) { + return PROJECT_URI . 'dav.php/addressbooks/' . $this->oUser->get('username') . '/' . $addressbook->get('uri') . '/'; + } +} \ No newline at end of file diff --git a/Core/Frameworks/BaikalAdmin/Controller/User/Calendars.php b/Core/Frameworks/BaikalAdmin/Controller/User/Calendars.php index e67fcdcf..fea4e568 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/User/Calendars.php +++ b/Core/Frameworks/BaikalAdmin/Controller/User/Calendars.php @@ -35,6 +35,15 @@ class Calendars extends \Flake\Core\Controller { protected $oUser; # \Baikal\Model\User protected $oForm; # \Formal\Form + /** + * @var \BaikalAdmin\Service\Calendars + */ + private $uService; + + public function __construct() { + $uService = new \BaikalAdmin\Service\Calendars(); + } + function execute() { if (($iUser = $this->currentUserId()) === false) { throw new \Exception("BaikalAdmin\Controller\User\Calendars::render(): User get-parameter not found."); @@ -53,48 +62,8 @@ function execute() { function render() { $oView = new \BaikalAdmin\View\User\Calendars(); - - # User - $oView->setData("user", $this->oUser); - - # List of calendars - $oCalendars = $this->oUser->getCalendarsBaseRequester()->execute(); - $aCalendars = []; - - foreach ($oCalendars as $calendar) { - $aCalendars[] = [ - "linkedit" => $this->linkEdit($calendar), - "linkdelete" => $this->linkDelete($calendar), - "davuri" => $this->getDavUri($calendar), - "icon" => $calendar->icon(), - "label" => $calendar->label(), - "instanced" => $calendar->hasInstances(), - "events" => $calendar->getEventsBaseRequester()->count(), - "description" => $calendar->get("description"), - ]; - } - - $oView->setData("calendars", $aCalendars); - - # Messages - $sMessages = implode("\n", $this->aMessages); - $oView->setData("messages", $sMessages); - - if ($this->actionNewRequested() || $this->actionEditRequested()) { - $sForm = $this->oForm->render(); - } else { - $sForm = ""; - } - - $oView->setData("form", $sForm); - $oView->setData("titleicon", \Baikal\Model\Calendar::bigicon()); - $oView->setData("modelicon", $this->oUser->mediumicon()); - $oView->setData("modellabel", $this->oUser->label()); - $oView->setData("linkback", \BaikalAdmin\Controller\Users::link()); - $oView->setData("linknew", $this->linkNew()); - $oView->setData("calendaricon", \Baikal\Model\Calendar::icon()); - - return $oView->render(); + $aCalendars = $this->$uService->getAll(); + return $uService->render($oView,$oUser, $aCalendars, $this->aMessages, $oForm, $this); } protected function initForm() { @@ -240,13 +209,7 @@ protected function actionDelete() { if ($this->actionDeleteConfirmed() !== false) { # catching Exception thrown when model already destroyed # happens when user refreshes page on delete-URL, for instance - - try { - $oModel = new \Baikal\Model\Calendar($iCalendar); - $oModel->destroy(); - } catch (\Exception $e) { - # already deleted; silently discarding - } + $this->$uService->delete($iCalendar); # Redirecting to admin home \Flake\Util\Tools::redirectUsingMeta($this->linkHome()); diff --git a/Core/Frameworks/BaikalAdmin/Controller/Users.php b/Core/Frameworks/BaikalAdmin/Controller/Users.php index 1b226efc..7e87d758 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Users.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Users.php @@ -66,7 +66,7 @@ function execute() { function render() { $oView = new \BaikalAdmin\View\Users(); $aUsers = $this->$uService->getAll(); - return $uService->render($oView, $aUsers, $this->aMessages, $this); + return $uService->render($oView, $aUsers, $this->aMessages, $oForm, $this); } protected function initForm() { @@ -131,7 +131,10 @@ protected function actionDelete() { if ($this->actionDeleteConfirmed() !== false) { # catching Exception thrown when model already destroyed # happens when user refreshes delete-page, for instance - $this->userService->deleteUser($iUser) + $this->$uService->delete($iUser) + + # Redirecting to admin home + \Flake\Util\Tools::redirectUsingMeta($this->link()); } else { $oUser = new \Baikal\Model\User($iUser); $this->aMessages[] = \Formal\Core\Message::warningConfirmMessage( diff --git a/Core/Frameworks/BaikalAdmin/Service/AddressBooks.php b/Core/Frameworks/BaikalAdmin/Service/AddressBooks.php new file mode 100644 index 00000000..b6342915 --- /dev/null +++ b/Core/Frameworks/BaikalAdmin/Service/AddressBooks.php @@ -0,0 +1,112 @@ + +# All rights reserved +# +# http://sabre.io/baikal +# +# This script is part of the Baïkal Server project. The Baïkal +# Server project 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 2 of the License, or (at your option) any later version. +# +# The GNU General Public License can be found at +# http://www.gnu.org/copyleft/gpl.html. +# +# This script 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. +# +# This copyright notice MUST APPEAR in all copies of the script! +################################################################# + +namespace BaikalAdmin\Service; + +use Baikal\Model\AddressBook; + +class AddressBooks extends \BaikalAdmin\Service\Service { + /** + * Fetches all address books and returns them as an array + * + * @return array + */ + public function getAll(): array { + # Render list of address books + $aAddressBooks = []; + $oAddressBooks = \Baikal\Model\User::getAddressBooksBaseRequester()->execute(); + foreach ($oAddressBooks as $addressbook) { + $aAddressBooks[] = [ + "linkedit" => \BaikalAdmin\Controller\User\AddressBooks::linkEdit($addressbook), + "linkdelete" => \BaikalAdmin\Controller\User\AddressBooks::linkDelete($addressbook), + "davuri" => \BaikalAdmin\Controller\User\AddressBooks::getDavUri($addressbook), + "icon" => $addressbook->icon(), + "label" => $addressbook->label(), + "contacts" => $addressbook->getContactsBaseRequester()->count(), + "description" => $addressbook->get("description"), + ]; + } + + return $aAddressBooks; + } + + /** + * Render the view for the address books page. + * + * @return string + */ + public function render(\BaikalAdmin\View\User\AddressBooks $oView + \Baikal\Model\User $oUser, + array $aAddressBooks, + array $aMessages, + \Formal\Form $oForm, + \BaikalAdmin\Controller\User\AddressBooks $controller + ): string { + + # User + $oView->setData("user", $oUser); + + $oView->setData("addressbooks", $aAddressBooks); + + # Messages + $sMessages = implode("\n", $aMessages); + $oView->setData("messages", $sMessages); + + if ($controller->actionNewRequested() || $controller->actionEditRequested()) { + $sForm = $oForm->render(); + } else { + $sForm = ""; + } + + $oView->setData("form", $sForm); + $oView->setData("titleicon", \Baikal\Core\Icons::bigiconBook()); + $oView->setData("modelicon", \Baikal\Core\Icons::mediumiconUser()); + $oView->setData("modellabel", $oUser->label()); + $oView->setData("linkback", \BaikalAdmin\Controller\Users::link()); + $oView->setData("linknew", $controller->linkNew()); + $oView->setData("addressbookicon", \Baikal\Core\Icons::iconBook()); + + return $oView->render(); + } + + /** + * Delete an AddressBook by ID. + * + * @param int $iModel + * @return bool + */ + public function delete(int $iModel) { + try { + $oModel = new \Baikal\Model\AddressBooks($iModel); + $oModel->destroy(); + } catch (\Exception $e) { + // Log the error and return false if the user doesn't exist or is already deleted. + error_log($e); + } + } + +} \ No newline at end of file diff --git a/Core/Frameworks/BaikalAdmin/Service/Calendars.php b/Core/Frameworks/BaikalAdmin/Service/Calendars.php new file mode 100644 index 00000000..9f75c8b0 --- /dev/null +++ b/Core/Frameworks/BaikalAdmin/Service/Calendars.php @@ -0,0 +1,114 @@ + +# All rights reserved +# +# http://sabre.io/baikal +# +# This script is part of the Baïkal Server project. The Baïkal +# Server project 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 2 of the License, or (at your option) any later version. +# +# The GNU General Public License can be found at +# http://www.gnu.org/copyleft/gpl.html. +# +# This script 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. +# +# This copyright notice MUST APPEAR in all copies of the script! +################################################################# + +namespace BaikalAdmin\Service; + +use Baikal\Model\Calendar; + +class Calendars extends \BaikalAdmin\Service\Service { + /** + * Fetches all calendars and returns them as an array + * + * @return array + */ + public function getAll(): array { + # List of calendars + $oCalendars = \Baikal\Model\User::getCalendarsBaseRequester()->execute(); + $aCalendars = []; + + foreach ($oCalendars as $calendar) { + $aCalendars[] = [ + "linkedit" => \BaikalAdmin\Controller\User\Calendars::->linkEdit($calendar), + "linkdelete" => \BaikalAdmin\Controller\User\Calendars::->linkDelete($calendar), + "davuri" => \BaikalAdmin\Controller\User\Calendars::->getDavUri($calendar), + "icon" => $calendar->icon(), + "label" => $calendar->label(), + "instanced" => $calendar->hasInstances(), + "events" => $calendar->getEventsBaseRequester()->count(), + "description" => $calendar->get("description"), + ]; + } + + return $aCalendars; + } + + /** + * Render the view for the calendars page. + * + * @return string + */ + public function render(\BaikalAdmin\View\User\Calendars $oView + \Baikal\Model\User $oUser, + array $aCalendars, + array $aMessages, + \Formal\Form $oForm, + \BaikalAdmin\Controller\User\Calendars $controller + ): string { + + # User + $oView->setData("user", $this->oUser); + + $oView->setData("calendars", $aCalendars); + + # Messages + $sMessages = implode("\n", $aMessages); + $oView->setData("messages", $sMessages); + + if ($controller->actionNewRequested() || $controller->actionEditRequested()) { + $sForm = $oForm->render(); + } else { + $sForm = ""; + } + + $oView->setData("form", $sForm); + $oView->setData("titleicon", \Baikal\Core\Icons::bigiconCalendar()); + $oView->setData("modelicon", \Baikal\Core\Icons::mediumiconUser()); + $oView->setData("modellabel", $oUser->label()); + $oView->setData("linkback", \BaikalAdmin\Controller\Users::link()); + $oView->setData("linknew", $controller->linkNew()); + $oView->setData("calendaricon", \Baikal\Core\Icons::iconCalendar()); + + return $oView->render(); + } + + /** + * Delete a calendar by ID. + * + * @param int $iCalendar + * @return bool + */ + public function delete(int $iCalendar) { + try { + $calendar = new \Baikal\Model\Calendar($iCalendar); + $calendar->destroy(); + } catch (\Exception $e) { + // Log the error and return false if the user doesn't exist or is already deleted. + error_log($e); + } + } + +} \ No newline at end of file diff --git a/Core/Frameworks/BaikalAdmin/Service/Users.php b/Core/Frameworks/BaikalAdmin/Service/Users.php index 29104603..713741ad 100644 --- a/Core/Frameworks/BaikalAdmin/Service/Users.php +++ b/Core/Frameworks/BaikalAdmin/Service/Users.php @@ -29,7 +29,7 @@ use Baikal\Model\User; -class Users extends \BaikalAdmin\Interface\Service { +class Users extends \BaikalAdmin\Service\Service { /** * Fetches all users and returns them as an array * @@ -37,7 +37,7 @@ class Users extends \BaikalAdmin\Interface\Service { */ public function getAll(): array { $users = []; - $userObjects = User::getBaseRequester()->execute(); + $userObjects = \Baikal\Model\User::getBaseRequester()->execute(); foreach ($userObjects as $user) { $users[] = [ @@ -77,7 +77,7 @@ public function render(\Baikal\Model\User $oView, $oView->setData("messages", $sMessages); # Form - if ($this->actionNewRequested() || $this->actionEditRequested()) { + if ($controller->actionNewRequested() || $controller->actionEditRequested()) { $sForm = $oForm->render(); } else { $sForm = ""; @@ -93,10 +93,10 @@ public function render(\Baikal\Model\User $oView, /** * Delete a user by ID. * - * @param int $userId + * @param int $iUser * @return bool */ - public function delete(int $userId) { + public function delete(int $iUser) { try { $user = new \Baikal\Model\User($iUser); $user->destroy(); @@ -104,8 +104,6 @@ public function delete(int $userId) { // Log the error and return false if the user doesn't exist or is already deleted. error_log($e); } - # Redirecting to admin home - \Flake\Util\Tools::redirectUsingMeta($this->link()); } -} \ No newline at end of file +}