mirror of https://github.com/nextcloud/calendar
cleanup mappers and controllers
This commit is contained in:
parent
6eb6fd5b12
commit
6ff023bb48
|
@ -7,12 +7,13 @@
|
|||
* See the COPYING-README file.
|
||||
*/
|
||||
use \OCA\Calendar;
|
||||
//set up simple routes
|
||||
|
||||
$this->create('calendar.view.index', '/')->action(function($params){
|
||||
$app = new \OCA\Calendar\App($params);
|
||||
$app->dispatch('ViewController', 'index');
|
||||
});
|
||||
|
||||
|
||||
$this->create('calendar.settings.getView', '/getView')->get()->action(function($params){
|
||||
$app = new \OCA\Calendar\App($params);
|
||||
$app->dispatch('SettingsController', 'getView');
|
||||
|
@ -48,6 +49,11 @@ $this->create('calendar.calendars.forceUpdate', '/v1/calendars-forceUpdate')->ac
|
|||
});
|
||||
|
||||
|
||||
$this->create('calendar.timezone.getList', '/v1/timezones-list')->action(function($params){
|
||||
$app = new \OCA\Calendar\App($params);
|
||||
$app->dispatch('TimezoneController', 'getList');
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,20 +9,15 @@ namespace OCA\Calendar\Controller;
|
|||
|
||||
use \OCP\AppFramework\Http;
|
||||
|
||||
use \OCA\Calendar\Db\DoesNotExistException;
|
||||
use \OCA\Calendar\BusinessLayer\BusinessLayerException;
|
||||
|
||||
use \OCA\Calendar\Db\Calendar;
|
||||
use \OCA\Calendar\Db\CalendarCollection;
|
||||
|
||||
use \OCA\Calendar\Db\ObjectType;
|
||||
use \OCA\Calendar\Db\Permission;
|
||||
|
||||
use \OCA\Calendar\Http\Response;
|
||||
|
||||
use \OCA\Calendar\Http\Reader;
|
||||
use \OCA\Calendar\Http\Serializer;
|
||||
use \OCA\Calendar\Http\ReaderExpcetion;
|
||||
use \OCA\Calendar\Http\Serializer;
|
||||
use \OCA\Calendar\Http\SerializerException;
|
||||
|
||||
class CalendarController extends Controller {
|
||||
|
@ -50,6 +45,9 @@ class CalendarController extends Controller {
|
|||
} catch (BusinessLayerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
} catch (SerializerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +68,9 @@ class CalendarController extends Controller {
|
|||
} catch (BusinessLayerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
} catch (SerializerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,6 +105,9 @@ class CalendarController extends Controller {
|
|||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
} catch(ReaderException $ex) {
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_UNPROCESSABLE_ENTITY);
|
||||
} catch (SerializerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,6 +141,9 @@ class CalendarController extends Controller {
|
|||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
} catch(ReaderException $ex) {
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_UNPROCESSABLE_ENTITY);
|
||||
} catch (SerializerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,32 +182,4 @@ class CalendarController extends Controller {
|
|||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function availableBackends() {
|
||||
try {
|
||||
$avialableBackends = $this->calendarBusinessLayer->findAllEnabledBackends();
|
||||
|
||||
$backends = array();
|
||||
$avialableBackends->iterate(function($backend) use (&$backends) {
|
||||
$backends[$backend->getBackend()] = array(
|
||||
'createCalendar' => $backend->api->implementsActions(\OCA\Calendar\Backend\CREATE_CALENDAR),
|
||||
'updateCalendar' => $backend->api->implementsActions(\OCA\Calendar\Backend\UPDATE_CALENDAR),
|
||||
'deleteCalendar' => $backend->api->implementsActions(\OCA\Calendar\Backend\DELETE_CALENDAR),
|
||||
'createObject' => $backend->api->implementsActions(\OCA\Calendar\Backend\CREATE_OBJECT),
|
||||
'updateObject' => $backend->api->implementsActions(\OCA\Calendar\Backend\UPDATE_OBJECT),
|
||||
'deleteObject' => $backend->api->implementsActions(\OCA\Calendar\Backend\DELETE_OBJECT),
|
||||
);
|
||||
});
|
||||
|
||||
return new Response($backends);
|
||||
} catch (BusinessLayerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -107,6 +107,10 @@ abstract class Controller extends \OCP\AppFramework\Controller {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* get accept header
|
||||
* @return string
|
||||
*/
|
||||
protected function accept() {
|
||||
$accept = $this->header('accept');
|
||||
|
||||
|
@ -121,6 +125,10 @@ abstract class Controller extends \OCP\AppFramework\Controller {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* get content type header
|
||||
* @return string
|
||||
*/
|
||||
protected function contentType() {
|
||||
$contentType = $this->header('content-type');
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@ use \OCP\IRequest;
|
|||
|
||||
use \OCA\Calendar\BusinessLayer\CalendarBusinessLayer;
|
||||
use \OCA\Calendar\BusinessLayer\ObjectBusinessLayer;
|
||||
use OCA\Calendar\Db\ObjectType;
|
||||
|
||||
use \OCA\Calendar\Db\ObjectType;
|
||||
|
||||
class EventController extends ObjectTypeController {
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@ use \OCP\IRequest;
|
|||
|
||||
use \OCA\Calendar\BusinessLayer\CalendarBusinessLayer;
|
||||
use \OCA\Calendar\BusinessLayer\ObjectBusinessLayer;
|
||||
use OCA\Calendar\Db\ObjectType;
|
||||
|
||||
use \OCA\Calendar\Db\ObjectType;
|
||||
|
||||
class JournalController extends ObjectTypeController {
|
||||
|
||||
|
|
|
@ -56,13 +56,15 @@ class ObjectController extends Controller {
|
|||
|
||||
return new Response($serializer);
|
||||
} catch (BusinessLayerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'warn');
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
} catch (SerializerException $ex) {
|
||||
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
|
@ -95,13 +97,15 @@ class ObjectController extends Controller {
|
|||
|
||||
return new Response($serializer);
|
||||
} catch (BusinessLayerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'warn');
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
} catch (SerializerException $ex) {
|
||||
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
|
@ -123,13 +127,15 @@ class ObjectController extends Controller {
|
|||
|
||||
return new Response($serializer);
|
||||
} catch (BusinessLayerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'warn');
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
} catch (SerializerException $ex) {
|
||||
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
|
@ -164,11 +170,17 @@ class ObjectController extends Controller {
|
|||
|
||||
return new Response($serializer, Http::STATUS_CREATED);
|
||||
} catch (BusinessLayerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'warn');
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
} catch(ReaderException $ex) {
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_UNPROCESSABLE_ENTITY);
|
||||
} catch (SerializerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
|
@ -205,12 +217,18 @@ class ObjectController extends Controller {
|
|||
$serializer = new Serializer($this->app, Serializer::Object, $object, $this->accept());
|
||||
|
||||
return new Response($serializer);
|
||||
} catch(BusinessLayerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'warn');
|
||||
} catch (BusinessLayerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
} catch(ReaderException $ex) {
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_UNPROCESSABLE_ENTITY);
|
||||
} catch (SerializerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
|
@ -231,8 +249,8 @@ class ObjectController extends Controller {
|
|||
|
||||
return new Response(null, HTTP::STATUS_NO_CONTENT);
|
||||
} catch (BusinessLayerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'warn');
|
||||
return new Response(null, HTTP::STATUS_BAD_REQUEST);
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -41,6 +41,7 @@ abstract class ObjectTypeController extends ObjectController {
|
|||
*/
|
||||
protected $objectType;
|
||||
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param IAppContainer $app interface to the app
|
||||
|
@ -61,6 +62,7 @@ abstract class ObjectTypeController extends ObjectController {
|
|||
$this->objectType = $type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
|
@ -84,8 +86,8 @@ abstract class ObjectTypeController extends ObjectController {
|
|||
$type = $this->objectType;
|
||||
|
||||
$calendar = $this->calendarBusinessLayer->find($calendarId, $userId);
|
||||
if ($calendar->doesAllow(Permissions::READ) === false) {
|
||||
throw new ForbiddenExpcetion();
|
||||
if (!$calendar->doesAllow(Permissions::READ)) {
|
||||
return new Reponse(null, Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
|
||||
$objectCollection = $this->objectBusinessLayer->findAllByType($calendar, $type,
|
||||
|
@ -95,11 +97,15 @@ abstract class ObjectTypeController extends ObjectController {
|
|||
|
||||
return new Response($serializer);
|
||||
} catch (BusinessLayerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'warn');
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
} catch (SerializerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
|
@ -134,13 +140,15 @@ abstract class ObjectTypeController extends ObjectController {
|
|||
|
||||
return new Response($serializer);
|
||||
} catch (BusinessLayerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'warn');
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
} catch (SerializerException $ex) {
|
||||
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
|
@ -164,11 +172,15 @@ abstract class ObjectTypeController extends ObjectController {
|
|||
|
||||
return new Response($serializer);
|
||||
} catch (BusinessLayerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'warn');
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), $ex->getCode());
|
||||
} catch (SerializerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get objectId of request
|
||||
* TODO - find a better solution
|
||||
|
|
|
@ -9,13 +9,22 @@ namespace OCA\Calendar\Controller;
|
|||
|
||||
use \OCA\Calendar\Http\Response;
|
||||
|
||||
class ViewController extends Controller {
|
||||
class SettingsController extends Controller {
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function setView() {
|
||||
$userId = $this->api->getUserId();
|
||||
$app = $this->appName;
|
||||
$key = 'currentView';
|
||||
$view = $this->params('view');
|
||||
|
||||
if(trim($view) !== '') {
|
||||
OCP\Config::setUserValue($userId, $app, $key, $view);
|
||||
}
|
||||
|
||||
return new Response();
|
||||
}
|
||||
|
||||
|
@ -25,6 +34,16 @@ class ViewController extends Controller {
|
|||
* @NoCSRFRequired
|
||||
*/
|
||||
public function getView() {
|
||||
return new Response();
|
||||
$userId = $this->api->getUserId();
|
||||
$app = $this->appName;
|
||||
$key = 'currentView';
|
||||
$default = $this->params('month');
|
||||
|
||||
$value = OCP\Config::getUserValue($userId, $app, $key, $default);
|
||||
$response = array(
|
||||
'view' => $value
|
||||
);
|
||||
|
||||
return new Response($response);
|
||||
}
|
||||
}
|
|
@ -7,9 +7,8 @@
|
|||
*/
|
||||
namespace OCA\Calendar\Controller;
|
||||
|
||||
use \OCP\AppFramework\Http;
|
||||
|
||||
use \OCP\AppFramework\IAppContainer;
|
||||
use \OCP\AppFramework\Http;
|
||||
use \OCP\IRequest;
|
||||
|
||||
use \OCA\Calendar\Db\DoesNotExistException;
|
||||
|
@ -19,10 +18,9 @@ use \OCA\Calendar\Db\TimezoneCollection;
|
|||
use \OCA\Calendar\Db\TimezoneMapper;
|
||||
|
||||
use \OCA\Calendar\Http\Response;
|
||||
|
||||
use \OCA\Calendar\Http\Reader;
|
||||
use \OCA\Calendar\Http\Serializer;
|
||||
use \OCA\Calendar\Http\ReaderExpcetion;
|
||||
use \OCA\Calendar\Http\Serializer;
|
||||
use \OCA\Calendar\Http\SerializerException;
|
||||
|
||||
class TimezoneController extends Controller {
|
||||
|
@ -52,18 +50,23 @@ class TimezoneController extends Controller {
|
|||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index() {
|
||||
$nolimit = $this->params('nolimit', false);
|
||||
if ($nolimit) {
|
||||
$limit = $offset = null;
|
||||
} else {
|
||||
$limit = $this->params('limit', 25);
|
||||
$offset = $this->params('offset', 0);
|
||||
try {
|
||||
$nolimit = $this->params('nolimit', false);
|
||||
if ($nolimit) {
|
||||
$limit = $offset = null;
|
||||
} else {
|
||||
$limit = $this->params('limit', 25);
|
||||
$offset = $this->params('offset', 0);
|
||||
}
|
||||
|
||||
$timezoneCollection = $this->timezoneMapper->findAll($limit, $offset);
|
||||
|
||||
$serializer = new Serializer($this->app, Serializer::TimezoneCollection, $timezoneCollection, $this->accept());
|
||||
return new Response($serializer);
|
||||
} catch (SerializerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
$timezoneCollection = $this->timezoneMapper->findAll($limit, $offset);
|
||||
|
||||
$serializer = new Serializer($this->app, Serializer::TimezoneCollection, $timezoneCollection, $this->accept());
|
||||
return new Response($serializer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -81,10 +84,23 @@ class TimezoneController extends Controller {
|
|||
return new Response($serializer);
|
||||
} catch (DoesNotExistException $ex) {
|
||||
return new Response(null, Http::STATUS_NOT_FOUND);
|
||||
} catch (SerializerException $ex) {
|
||||
$this->app->log($ex->getMessage(), 'debug');
|
||||
return new Response(array('message' => $ex->getMessage()), Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function getList() {
|
||||
$timezones = $this->timezoneMapper->getList();
|
||||
return new Response($timezones);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
|
|
|
@ -12,7 +12,8 @@ use \OCP\IRequest;
|
|||
|
||||
use \OCA\Calendar\BusinessLayer\CalendarBusinessLayer;
|
||||
use \OCA\Calendar\BusinessLayer\ObjectBusinessLayer;
|
||||
use OCA\Calendar\Db\ObjectType;
|
||||
|
||||
use \OCA\Calendar\Db\ObjectType;
|
||||
|
||||
class TodoController extends ObjectTypeController {
|
||||
|
||||
|
|
|
@ -7,64 +7,42 @@
|
|||
*/
|
||||
namespace OCA\Calendar\Controller;
|
||||
|
||||
use \OCA\Calendar\BusinessLayer\BackendBusinessLayer;
|
||||
use \OCA\Calendar\BusinessLayer\CalendarBusinessLayer;
|
||||
use \OCA\Calendar\BusinessLayer\ObjectBusinessLayer;
|
||||
|
||||
use \OCA\Calendar\BusinessLayer\BusinessLayerException;
|
||||
|
||||
use OCA\Calendar\Db\Calendar;
|
||||
use OCA\Calendar\Db\JSONCalendar;
|
||||
use OCA\Calendar\Db\Object;
|
||||
use OCA\Calendar\Db\JSONObject;
|
||||
use \OCA\Calendar\Http\Response;
|
||||
|
||||
class ViewController extends Controller {
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @brief renders the index page
|
||||
* @return an instance of a Response implementation
|
||||
*/
|
||||
public function index(){
|
||||
var_dump('index_called');
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @brief renders \DateTimeZone::listAbbreviations(); as JSON
|
||||
* @return an instance of a JSONResponse implementation
|
||||
*/
|
||||
public function timezoneIndex() {
|
||||
$timezones = \DateTimeZone::listAbbreviations();
|
||||
return new JSONResponse($timezones);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @brief saves the new view
|
||||
* @return an instance of a JSONResponse implementation
|
||||
*/
|
||||
public function setView(){
|
||||
$newView = $this->param('view');
|
||||
switch($newView) {
|
||||
case 'agendaDay';
|
||||
case 'agendaWeek';
|
||||
case 'basic2Weeks':
|
||||
case 'basic4Weeks':
|
||||
case 'list':
|
||||
\OCP\Config::setUserValue($this->app->getUserId(), 'calendar', 'currentview', $newView);
|
||||
return new JSONResponse(array('newView' => $newView));
|
||||
break;
|
||||
default:
|
||||
return new JSONRespose(array('message'=>'Invalid view'), HTTP::STATUS_BAD_REQUEST);
|
||||
break;
|
||||
public function searchLocation() {
|
||||
$location = $this->params('location');
|
||||
|
||||
$result = \OCP\Contacts::search($location, array('FN', 'ADR'));
|
||||
|
||||
$contacts = array();
|
||||
|
||||
foreach ($result as $r) {
|
||||
if (!isset($r['ADR'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tmp = $r['ADR'][0];
|
||||
$address = trim(implode(" ", $tmp));
|
||||
|
||||
$contacts[] = array('label' => $address);
|
||||
}
|
||||
|
||||
return new Reponse($contacts);
|
||||
}
|
||||
}
|
|
@ -20,18 +20,22 @@ class Backend extends Entity {
|
|||
|
||||
public $api;
|
||||
|
||||
|
||||
/**
|
||||
* @brief init Backend object with data from db row
|
||||
* @param array $fromRow
|
||||
*/
|
||||
public function __construct($fromRow=null){
|
||||
$this->addType('backend', 'string');
|
||||
$this->addType('classname', 'string');
|
||||
$this->addType('enabled', 'boolean');
|
||||
|
||||
if (is_array($fromRow)){
|
||||
$this->fromRow($fromRow);
|
||||
}
|
||||
|
||||
$this->api = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* registers an API for a backend
|
||||
* @param CalendarInterface $api
|
||||
|
@ -42,6 +46,7 @@ class Backend extends Entity {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief take data from VObject and put into this Calendar object
|
||||
* @return VCalendar Object
|
||||
|
@ -51,6 +56,7 @@ class Backend extends Entity {
|
|||
throw new \BadFunctionCallException($msg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get VObject from Calendar Object
|
||||
* @return VCalendar Object
|
||||
|
@ -60,44 +66,45 @@ class Backend extends Entity {
|
|||
throw new \BadFunctionCallException($msg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* disables a backend
|
||||
* @return Backend
|
||||
*/
|
||||
public function disable() {
|
||||
$this->setEnabled(false);
|
||||
return $this;
|
||||
return $this->setEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* enables a backend
|
||||
* @return Backend
|
||||
*/
|
||||
public function enable() {
|
||||
$this->setEnabled(true);
|
||||
return $this;
|
||||
return $this->setEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief check if object is valid
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid() {
|
||||
if (is_string($this->backend) === false) {
|
||||
if (!is_string($this->backend)) {
|
||||
return false;
|
||||
}
|
||||
if (trim($this->backend) === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_string($this->classname) === false) {
|
||||
if (!is_string($this->classname)) {
|
||||
return false;
|
||||
}
|
||||
if (class_exists($this->classname) === false) {
|
||||
if (!class_exists($this->classname)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_array($this->arguments) === false && $this->arguments !== null) {
|
||||
if ($this->arguments !== null && !is_array($this->arguments)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -105,13 +112,18 @@ class Backend extends Entity {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (($this->api instanceof IBackend) === false && $this->api !== null) {
|
||||
if ($this->api !== null && !($this->api instanceof IBackend)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief create string representation of object
|
||||
* @return string
|
||||
*/
|
||||
public function __toString() {
|
||||
return $this->backend . '::' . $this->classname;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ class BackendCollection extends Collection {
|
|||
return $this->search('enabled', true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get a collection of all disabled backends within collection
|
||||
* @return BackendCollection of all disabled backends
|
||||
|
@ -25,6 +26,7 @@ class BackendCollection extends Collection {
|
|||
return $this->search('enabled', false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief find backend by name
|
||||
* @return Backend object
|
||||
|
|
|
@ -14,15 +14,38 @@ use \OCA\Calendar\Db\BackendCollection;
|
|||
|
||||
class BackendMapper extends Mapper {
|
||||
|
||||
/**
|
||||
* IAppContainer object
|
||||
* @var \OCP\AppFramework\IAppContainer
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
|
||||
/**
|
||||
* name of config
|
||||
* @var string
|
||||
*/
|
||||
protected $configName;
|
||||
|
||||
|
||||
/**
|
||||
* backendcollection object
|
||||
* @var \OCA\Calendar\Db\BackendCollectiom
|
||||
*/
|
||||
private $backendCollection;
|
||||
private $didChange;
|
||||
|
||||
|
||||
/**
|
||||
* whether or not object changed
|
||||
* @var boolean
|
||||
*/
|
||||
private $didChange=false;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param API $api: Instance of the API abstraction layer
|
||||
* @param IAppContainer $api: Instance of the API abstraction layer
|
||||
* @param string $configName
|
||||
*/
|
||||
public function __construct(IAppContainer $app, $configName='calendar_backends'){
|
||||
$this->app = $app;
|
||||
|
@ -34,28 +57,30 @@ class BackendMapper extends Mapper {
|
|||
}
|
||||
|
||||
$backendCollection = new BackendCollection();
|
||||
|
||||
foreach($backends as $id => $backend) {
|
||||
$backend = new Backend($backend);
|
||||
$backend->setId($id);
|
||||
|
||||
$backendCollection->add($backend);
|
||||
}
|
||||
$this->backendCollection = $backendCollection;
|
||||
|
||||
$this->didChange = false;
|
||||
$this->backendCollection = $backendCollection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Destructor - write changes
|
||||
* @param API $api: Instance of the API abstraction layer
|
||||
*/
|
||||
public function __destruct() {
|
||||
if ($this->didChange === true) {
|
||||
if ($this->didChange) {
|
||||
$newConfig = $this->backendCollection->getObjects();
|
||||
//\OCP\Config::setSystemValue($this->configName, $newConfig);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Finds an item by it's name
|
||||
* @param string $backend name of backend
|
||||
|
@ -66,6 +91,7 @@ class BackendMapper extends Mapper {
|
|||
return $this->backendCollection->find($backend);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds all Items
|
||||
* @return array containing all items
|
||||
|
@ -74,6 +100,7 @@ class BackendMapper extends Mapper {
|
|||
return $this->backendCollection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds all Items where enabled is ?
|
||||
* @return array containing all items where enabled is ?
|
||||
|
@ -82,6 +109,7 @@ class BackendMapper extends Mapper {
|
|||
return $this->backendCollection->search('enabled', $isEnabled);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves an item into the database
|
||||
* @param Item $item: the item to be saved
|
||||
|
@ -94,6 +122,7 @@ class BackendMapper extends Mapper {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates an item
|
||||
* @param Item $item: the item to be updated
|
||||
|
@ -107,6 +136,7 @@ class BackendMapper extends Mapper {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deletes an item
|
||||
* @param Entity $item: the item to be deleted
|
||||
|
@ -119,6 +149,11 @@ class BackendMapper extends Mapper {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get backend object of default backend
|
||||
* @return Backend object
|
||||
*/
|
||||
public function getDefault() {
|
||||
return $this->find($this->app->query('defaultBackend'));
|
||||
}
|
||||
|
|
|
@ -115,6 +115,24 @@ class Calendar extends Entity {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief does a calendar allow
|
||||
* @return boolean
|
||||
*/
|
||||
public function doesAllow($cruds) {
|
||||
return ($this->cruds & $cruds);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief does a calendar allow a certian component
|
||||
* @return boolean
|
||||
*/
|
||||
public function doesSupport($components) {
|
||||
return ($this->components & $components);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief increment ctag
|
||||
* @return $this
|
||||
|
@ -129,15 +147,16 @@ class Calendar extends Entity {
|
|||
* @brief set uri property
|
||||
*/
|
||||
public function setURI($uri) {
|
||||
if (is_string($uri) === false || trim($uri) === '') {
|
||||
if (!is_string($uri) || trim($uri) === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$slugified = CalendarUtility::slugify($uri);
|
||||
$this->uri = $uri;
|
||||
parent::setUri($this->slugify('uri'));
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief set timezone
|
||||
* @param \OCA\Calendar\Db\Timezone $timezone
|
||||
|
@ -147,16 +166,12 @@ class Calendar extends Entity {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get calendarId of object
|
||||
* @return string
|
||||
*/
|
||||
public function getCalendarId(){
|
||||
if (!property_exists($this, 'backend') || !property_exists($this, 'uri')) {
|
||||
$msg = 'getCalendarId is not applicable to this kind of object';
|
||||
throw new \BadFunctionCallException($msg);
|
||||
}
|
||||
|
||||
$backend = $this->backend;
|
||||
$calendarURI = $this->uri;
|
||||
|
||||
|
@ -174,11 +189,6 @@ class Calendar extends Entity {
|
|||
* false if calendarId could not be set
|
||||
*/
|
||||
public function setCalendarId($calendarId) {
|
||||
if (!property_exists($this, 'backend') || !property_exists($this, 'uri')) {
|
||||
$msg = 'setCalendarId is not applicable to this kind of object';
|
||||
throw new \BadFunctionCallException($msg);
|
||||
}
|
||||
|
||||
list($backend, $calendarURI) = CalendarUtility::splitURI($calendarId);
|
||||
|
||||
if ($backend !== false && $calendarURI !== false) {
|
||||
|
@ -191,6 +201,7 @@ class Calendar extends Entity {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief check if object is valid
|
||||
* @return boolean
|
||||
|
@ -206,7 +217,7 @@ class Calendar extends Entity {
|
|||
);
|
||||
|
||||
foreach($strings as $string) {
|
||||
if (is_string($string) === false) {
|
||||
if (!is_string($string)) {
|
||||
return false;
|
||||
}
|
||||
if (trim($string) === '') {
|
||||
|
@ -222,7 +233,7 @@ class Calendar extends Entity {
|
|||
);
|
||||
|
||||
foreach($uInts as $integer) {
|
||||
if (is_int($integer) === false) {
|
||||
if (!is_int($integer)) {
|
||||
return false;
|
||||
}
|
||||
if ($integer < 0) {
|
||||
|
@ -235,7 +246,7 @@ class Calendar extends Entity {
|
|||
);
|
||||
|
||||
foreach($booleans as $boolean) {
|
||||
if (is_bool($boolean) === false) {
|
||||
if (!is_bool($boolean)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +267,7 @@ class Calendar extends Entity {
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($this->timezone instanceof Timezone && $this->timezone->isValid() === false) {
|
||||
if ($this->timezone instanceof Timezone && !$this->timezone->isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -264,15 +275,11 @@ class Calendar extends Entity {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief create string representation of object
|
||||
* @return string
|
||||
*/
|
||||
public function __toString() {
|
||||
return $this->userId . '::' . $this->getCalendarId();
|
||||
}
|
||||
|
||||
public function doesAllow($cruds) {
|
||||
return ($this->cruds & $cruds);
|
||||
}
|
||||
|
||||
public function doesSupport($components) {
|
||||
return ($this->components & $components);
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ class CalendarCollection extends Collection {
|
|||
return $this->search('enabled', true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get a collection of all disabled calendars within collection
|
||||
* @return CalendarCollection of all disabled calendars
|
||||
|
@ -27,6 +28,7 @@ class CalendarCollection extends Collection {
|
|||
return $this->search('enabled', false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get a collection of all calendars owned by a certian user
|
||||
* @param string userId of owner
|
||||
|
@ -36,6 +38,7 @@ class CalendarCollection extends Collection {
|
|||
return $this->search('ownerId', $userId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get a collection of calendars that supports certian components
|
||||
* @param int $component use \OCA\Calendar\Db\ObjectType to get wanted component code
|
||||
|
@ -53,6 +56,7 @@ class CalendarCollection extends Collection {
|
|||
return $newCollection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get a collection of calendars with a certain permission
|
||||
* @param int $cruds use \OCA\Calendar\Db\Permissions to get wanted permission code
|
||||
|
@ -70,6 +74,12 @@ class CalendarCollection extends Collection {
|
|||
return $newCollection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief filter calendars by BackendCollection
|
||||
* @param BackendCollection $backends
|
||||
* @return CalendarCollection of calendars on backends in BackendCollection
|
||||
*/
|
||||
public function filterByBackends(BackendCollection $backends) {
|
||||
$filteredCalendars = new CalendarCollection();
|
||||
$objects = $backends->getObjects();
|
||||
|
|
|
@ -28,6 +28,7 @@ class CalendarMapper extends Mapper {
|
|||
$this->timezoneMapper = $app->query('TimezoneMapper');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* find calendar by backend, uri and userId
|
||||
* @param string $backend
|
||||
|
@ -46,6 +47,7 @@ class CalendarMapper extends Mapper {
|
|||
return new Calendar($row);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* find all calendars of a user
|
||||
* @param string $userId
|
||||
|
@ -60,6 +62,7 @@ class CalendarMapper extends Mapper {
|
|||
return $this->findEntities($sql, array($userId), $limit, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* find all calendars of a user on a backend
|
||||
* @param string $backend
|
||||
|
@ -75,6 +78,7 @@ class CalendarMapper extends Mapper {
|
|||
return $this->findEntities($sql, array($backend, $userId), $limit, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* number of calendars by user
|
||||
* @param string $userId
|
||||
|
@ -90,6 +94,7 @@ class CalendarMapper extends Mapper {
|
|||
return intval($row['count']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* number of calendars by user on a backend
|
||||
* @param string $backend
|
||||
|
@ -106,6 +111,7 @@ class CalendarMapper extends Mapper {
|
|||
return intval($row['count']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* does a calendar exist
|
||||
* @param string $backend
|
||||
|
@ -128,6 +134,7 @@ class CalendarMapper extends Mapper {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* checks if a calendar allows a certain action
|
||||
* @param integer $cruds
|
||||
|
@ -151,6 +158,7 @@ class CalendarMapper extends Mapper {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* checks if a calendar supports a certian component
|
||||
* @param integer $component
|
||||
|
|
|
@ -39,6 +39,7 @@ abstract class Collection {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief add entity to collection
|
||||
* @param Entity $object entity to be added
|
||||
|
@ -56,6 +57,7 @@ abstract class Collection {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief add entities to collection
|
||||
* @param Collection $objects collection of entities to be added
|
||||
|
@ -77,6 +79,7 @@ abstract class Collection {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief remove entity from collection
|
||||
* @param integer $nth remove nth element, if not set, current element will be removed
|
||||
|
@ -90,6 +93,7 @@ abstract class Collection {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief remove entity by it's information
|
||||
* @param integer $nth remove nth element, if not set, current element will be removed
|
||||
|
@ -107,6 +111,7 @@ abstract class Collection {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief remove entities by a single property
|
||||
* @param string $key key for property
|
||||
|
@ -125,6 +130,7 @@ abstract class Collection {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get number of elements within collection
|
||||
* @return integer
|
||||
|
@ -133,6 +139,7 @@ abstract class Collection {
|
|||
return count($this->objects);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get current entity
|
||||
* @return single Entity
|
||||
|
@ -141,6 +148,7 @@ abstract class Collection {
|
|||
return current($this->objects);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get num index of current entity
|
||||
* @return integer
|
||||
|
@ -149,6 +157,7 @@ abstract class Collection {
|
|||
return key($this->objects);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief goto next entity and get it
|
||||
* @return single Entity
|
||||
|
@ -157,6 +166,7 @@ abstract class Collection {
|
|||
return next($this->objects);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief goto previous entity and get it
|
||||
* @return single Entity
|
||||
|
@ -165,6 +175,7 @@ abstract class Collection {
|
|||
return prev($this->objects);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief goto first entity and get it
|
||||
* @return single Entity
|
||||
|
@ -173,6 +184,7 @@ abstract class Collection {
|
|||
return reset($this->objects);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief goto last entity and get it
|
||||
* @return single Entity
|
||||
|
@ -181,6 +193,7 @@ abstract class Collection {
|
|||
return end($this->objects);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get nth entity of collection
|
||||
* @param integer $nth
|
||||
|
@ -194,6 +207,7 @@ abstract class Collection {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get array of all entities
|
||||
* @return array of Entities
|
||||
|
@ -202,6 +216,7 @@ abstract class Collection {
|
|||
return $this->objects;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get a subset of current collection
|
||||
* @param int $limit
|
||||
|
@ -231,17 +246,16 @@ abstract class Collection {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief check if entity is in collection
|
||||
* @return boolean
|
||||
*/
|
||||
public function inCollection(Entity $object) {
|
||||
var_dump($object);
|
||||
var_dump($this->objects);
|
||||
exit;
|
||||
return in_array($object, $this->objects);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get one VCalendar object containing all information
|
||||
* @return VCalendar object
|
||||
|
@ -265,6 +279,7 @@ abstract class Collection {
|
|||
return $vObject;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get an array of VCalendar objects
|
||||
* @return array of VCalendar object
|
||||
|
@ -279,6 +294,7 @@ abstract class Collection {
|
|||
return $vobjects;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get a collection of entities that meet criteria
|
||||
* @param string $key property that's supposed to be searched
|
||||
|
@ -301,6 +317,7 @@ abstract class Collection {
|
|||
return $matchingObjects;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get a collection of entities that meet criteria; search calendar data
|
||||
* @param string $class class of new collection
|
||||
|
@ -323,6 +340,7 @@ abstract class Collection {
|
|||
return $matchingObjects;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief set a property for all calendars
|
||||
* @param string $key key for property
|
||||
|
@ -341,6 +359,7 @@ abstract class Collection {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief checks if all entities are valid
|
||||
* Stops when it finds the first invalid one
|
||||
|
@ -348,7 +367,7 @@ abstract class Collection {
|
|||
*/
|
||||
public function isValid() {
|
||||
foreach($this->objects as &$object) {
|
||||
if ($object->isValid() === false) {
|
||||
if (!$object->isValid()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -356,6 +375,7 @@ abstract class Collection {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief iterate over each entity of collection
|
||||
* @param anonymous function
|
||||
|
@ -368,7 +388,13 @@ abstract class Collection {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief remove duplicates from collection
|
||||
* @return $this
|
||||
*/
|
||||
public function noDuplicates() {
|
||||
$this->objects = array_unique($this->objects);
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -56,6 +56,7 @@ class Object extends Entity {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Maps the keys of the row array to the attributes
|
||||
* @param array $row the row to map onto the entity
|
||||
|
@ -79,6 +80,7 @@ class Object extends Entity {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set the calendarData
|
||||
* @param string $data CalendarData
|
||||
|
@ -94,6 +96,7 @@ class Object extends Entity {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array array of updated fields for update query
|
||||
*/
|
||||
|
@ -117,6 +120,7 @@ class Object extends Entity {
|
|||
return $updatedFields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief take data from VObject and put into this Object object
|
||||
* @param \Sabre\VObject\Component\VCalendar $vcalendar
|
||||
|
@ -135,6 +139,7 @@ class Object extends Entity {
|
|||
$this->objectName = SabreUtility::getObjectName($vcalendar);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get VObject from Calendar Object
|
||||
* @return \Sabre\VObject\Component\VCalendar object
|
||||
|
@ -155,14 +160,17 @@ class Object extends Entity {
|
|||
$etag = new TextProperty($this->vObject, 'X-OC-ETAG', $currentETag);
|
||||
$this->vObject->{$objectName}->add($etag);
|
||||
}
|
||||
if (!isset($this->vObject->{$objectName}->{'X-OC-RUDS'})) {
|
||||
$ruds = new IntegerProperty($this->vObject, 'X-OC-RUDS', $this->ruds);
|
||||
$this->vObject->{$objectName}->add($ruds);
|
||||
if ($this->ruds !== null) {
|
||||
if (!isset($this->vObject->{$objectName}->{'X-OC-RUDS'})) {
|
||||
$ruds = new IntegerProperty($this->vObject, 'X-OC-RUDS', $this->ruds);
|
||||
$this->vObject->{$objectName}->add($ruds);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->vObject;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief expand an Array
|
||||
* @param DateTime $start
|
||||
|
@ -179,15 +187,23 @@ class Object extends Entity {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief set lastModified to now and update ETag
|
||||
* @return $this
|
||||
*/
|
||||
public function touch() {
|
||||
$now = new DateTime();
|
||||
$this->vObject->{$objectName}->{'LAST-MODIFIED'}->setDateTime($now);
|
||||
$this->generateEtag();
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get etag
|
||||
* @return string
|
||||
*/
|
||||
public function getETag() {
|
||||
if($this->etag === null) {
|
||||
$this->generateEtag();
|
||||
|
@ -196,6 +212,7 @@ class Object extends Entity {
|
|||
return $this->etag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief update Etag
|
||||
*/
|
||||
|
@ -206,6 +223,7 @@ class Object extends Entity {
|
|||
$this->etag = md5($etag);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get type of stored object
|
||||
* @return integer
|
||||
|
@ -214,6 +232,7 @@ class Object extends Entity {
|
|||
return ObjectType::getTypeByString($this->objectName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get startDate
|
||||
* @return DateTime
|
||||
|
@ -223,6 +242,7 @@ class Object extends Entity {
|
|||
return SabreUtility::getDTStart($this->vObject->{$objectName});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get endDate
|
||||
* @return DateTime
|
||||
|
@ -232,6 +252,7 @@ class Object extends Entity {
|
|||
return SabreUtility::getDTEnd($this->vObject->{$objectName});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get whether or not object is repeating
|
||||
* @return boolean
|
||||
|
@ -240,14 +261,15 @@ class Object extends Entity {
|
|||
$objectName = $this->objectName;
|
||||
|
||||
if (isset($this->vObject->{$objectName}->{'RRULE'}) ||
|
||||
isset($this->vObject->{$objectName}->{'RDATE'}) ||
|
||||
isset($this->vObject->{$objectName}->{'RECURRENCE-ID'})) {
|
||||
isset($this->vObject->{$objectName}->{'RDATE'}) ||
|
||||
isset($this->vObject->{$objectName}->{'RECURRENCE-ID'})) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get last occurence of repeating object
|
||||
* @return mixed DateTime/null
|
||||
|
@ -275,6 +297,7 @@ class Object extends Entity {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get summary of object
|
||||
* @return string
|
||||
|
@ -289,6 +312,7 @@ class Object extends Entity {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get text/calendar representation of stored object
|
||||
* @return integer
|
||||
|
@ -302,6 +326,12 @@ class Object extends Entity {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get ruds
|
||||
* @param boolean $force return value all the time
|
||||
* @return mixed (integer|null)
|
||||
*/
|
||||
public function getRuds($force=false) {
|
||||
if ($this->ruds !== null) {
|
||||
return $this->ruds;
|
||||
|
@ -317,14 +347,20 @@ class Object extends Entity {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief set ruds value
|
||||
*/
|
||||
public function setRuds($ruds) {
|
||||
if ($ruds & Permissions::CREATE) {
|
||||
$ruds -= Permissions::CREATE;
|
||||
}
|
||||
|
||||
$this->ruds = $ruds;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get last modified of object
|
||||
* @return DateTime
|
||||
|
@ -339,6 +375,7 @@ class Object extends Entity {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief check if object is valid
|
||||
* @return boolean
|
||||
|
@ -353,7 +390,7 @@ class Object extends Entity {
|
|||
}
|
||||
|
||||
foreach($strings as $string) {
|
||||
if (is_string($string) === false) {
|
||||
if (!is_string($string)) {
|
||||
return false;
|
||||
}
|
||||
if (trim($string) === '') {
|
||||
|
@ -369,8 +406,4 @@ class Object extends Entity {
|
|||
$isVObjectValid = $this->vObject->validate();
|
||||
//TODO - finish implementation
|
||||
}
|
||||
|
||||
private function iterateOverObjects() {
|
||||
|
||||
}
|
||||
}
|
|
@ -33,6 +33,7 @@ class ObjectCollection extends Collection {
|
|||
return $objectsInPeriod;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief expand all entities of collection
|
||||
* @param DateTime $start
|
||||
|
@ -55,6 +56,7 @@ class ObjectCollection extends Collection {
|
|||
return $expandedObjects;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get a collection of all calendars owned by a certian user
|
||||
* @param string userId of owner
|
||||
|
@ -64,6 +66,7 @@ class ObjectCollection extends Collection {
|
|||
return $this->search('ownerId', $userId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get a collection of all enabled calendars within collection
|
||||
* @return ObjectCollection
|
||||
|
|
|
@ -12,13 +12,15 @@ use \OCP\AppFramework\IAppContainer;
|
|||
use \OCA\Calendar\Db\Object;
|
||||
|
||||
class ObjectMapper extends Mapper {
|
||||
|
||||
/**
|
||||
* @param API $api: Instance of the API abstraction layer
|
||||
*/
|
||||
public function __construct($app, $tablename = 'clndr_objcache'){
|
||||
public function __construct(IAppContainer $app, $tablename = 'clndr_objcache'){
|
||||
parent::__construct($app, $tablename);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds an item from user by it's uri
|
||||
* @param string $uid
|
||||
|
@ -32,6 +34,7 @@ class ObjectMapper extends Mapper {
|
|||
return new Object($row);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds all Items of calendar $calendarId
|
||||
* @param integer $calendarId
|
||||
|
@ -42,6 +45,7 @@ class ObjectMapper extends Mapper {
|
|||
return $this->findEntities($sql, array($calendarId), $limit, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds all Items of calendar $calendarId of type $type
|
||||
* @param integer $calendarId
|
||||
|
@ -53,6 +57,7 @@ class ObjectMapper extends Mapper {
|
|||
return $this->findEntities($sql, array($calendarId, $type), $limit, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds all Items of calendar $calendarId from $start to $end
|
||||
* @param integer $calendarId
|
||||
|
@ -77,6 +82,7 @@ class ObjectMapper extends Mapper {
|
|||
$limit, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds all Items of calendar $calendarId of type $type in period from $start to $end
|
||||
* @param integer $calendarId
|
||||
|
@ -102,6 +108,7 @@ class ObjectMapper extends Mapper {
|
|||
$limit, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deletes all objects of calendar $calendarid
|
||||
* @param integer $calendarId
|
||||
|
@ -113,6 +120,7 @@ class ObjectMapper extends Mapper {
|
|||
$this->execute($sql, array($calendarId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get UTC from a datetime object
|
||||
* @param DateTime $datetime
|
||||
|
|
|
@ -8,11 +8,18 @@
|
|||
namespace OCA\Calendar\Db;
|
||||
|
||||
class ObjectType {
|
||||
|
||||
const EVENT = 1;
|
||||
const JOURNAL = 2;
|
||||
const TODO = 4;
|
||||
const ALL = 7;
|
||||
|
||||
|
||||
/**
|
||||
* @brief get type as string
|
||||
* @param integer $type
|
||||
* @return string
|
||||
*/
|
||||
public static function getAsString($type) {
|
||||
$types = array();
|
||||
|
||||
|
@ -30,6 +37,12 @@ class ObjectType {
|
|||
return $string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get types as string
|
||||
* @param integer $type
|
||||
* @return string
|
||||
*/
|
||||
public static function getAsReadableString($type) {
|
||||
$types = array();
|
||||
|
||||
|
@ -47,6 +60,12 @@ class ObjectType {
|
|||
return $string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get type by string
|
||||
* @param string $string
|
||||
* @return integer
|
||||
*/
|
||||
public static function getTypeByString($string) {
|
||||
$type = 0;
|
||||
|
||||
|
@ -70,6 +89,12 @@ class ObjectType {
|
|||
return $type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get types by string
|
||||
* @param string $string
|
||||
* @return integer
|
||||
*/
|
||||
public static function getTypesByString($string) {
|
||||
$types = 0;
|
||||
|
||||
|
@ -85,10 +110,16 @@ class ObjectType {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get type by sabre classname
|
||||
* @param mixed (string|object) $string
|
||||
* @return integer
|
||||
*/
|
||||
public static function getTypeBySabreClass($class) {
|
||||
$type = 0;
|
||||
|
||||
if (is_string($class)) {
|
||||
if (!is_string($class)) {
|
||||
$class = get_class($class);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,6 +88,10 @@ class Timezone extends Entity {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief create string representation of object
|
||||
* @return string
|
||||
*/
|
||||
public function __toString() {
|
||||
return $this->tzId;
|
||||
}
|
||||
|
|
|
@ -54,6 +54,24 @@ class TimezoneMapper extends Mapper {
|
|||
return new Timezone($tzId, $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get all timezones as a list
|
||||
* @param integer $limit
|
||||
* @param integer $offset
|
||||
* @return array
|
||||
*/
|
||||
public function getList() {
|
||||
$tzFiles = scandir($this->folderName);
|
||||
$timezones = array_values(array_diff($tzFiles, $this->fileBlacklist));
|
||||
|
||||
return array_map(function($value) {
|
||||
$value = str_replace('-', '/', $value);
|
||||
return substr($value, 0, -4);
|
||||
}, $timezones);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief find all timezones
|
||||
* @param integer $limit
|
||||
|
@ -61,8 +79,7 @@ class TimezoneMapper extends Mapper {
|
|||
* @return \OCA\Calendar\Db\TimezoneCollection
|
||||
*/
|
||||
public function findAll($limit, $offset) {
|
||||
$tzFiles = scandir($this->folderName);
|
||||
$files = array_values(array_diff($tzFiles, $this->fileBlacklist));
|
||||
$files = $this->getList();
|
||||
|
||||
if (is_null($limit)) {
|
||||
$limit = (count($files) - 1);
|
||||
|
@ -73,8 +90,13 @@ class TimezoneMapper extends Mapper {
|
|||
|
||||
$collection = new TimezoneCollection();
|
||||
for($i = $offset; $i < ($offset + $limit); $i++) {
|
||||
$tzId = str_replace('-', '/', str_replace('.ics', '', $files[$i]));
|
||||
$data = file_get_contents($this->folderName . $files[$i]);
|
||||
$tzId = $files[$i];
|
||||
|
||||
$filename = $this->folderName;
|
||||
$filename .= str_replace('/', '-', $files[$i]);
|
||||
$filename .= '.ics';
|
||||
$data = file_get_contents($filename);
|
||||
|
||||
$timezone = new Timezone($tzId, $data);
|
||||
$collection->add($timezone);
|
||||
}
|
||||
|
@ -83,16 +105,25 @@ class TimezoneMapper extends Mapper {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief deleting timezones is not supported
|
||||
*/
|
||||
public function delete(Entity $entity){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief create timezones is not supported
|
||||
*/
|
||||
public function insert(Entity $entity){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief updating timezones is not supported
|
||||
*/
|
||||
public function update(Entity $entity){
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue