mirror of https://github.com/nextcloud/calendar
implement inPeriod and clean up objectbusinesslayer
This commit is contained in:
parent
a3b9d15d29
commit
673e5a5969
|
@ -28,10 +28,22 @@ $this->create('calendar.calendars.forceUpdate', '/v1/calendars-forceUpdate')->ac
|
|||
$app->dispatch('CalendarController', 'forceUpdate');
|
||||
});
|
||||
|
||||
$this->create('calendar.calendars.indexInPeriod', '/v1/calendars/{calendarId}/objects/inPeriod/{start}/{end}')->action(function($params){
|
||||
$this->create('calendar.object.indexInPeriod', '/v1/calendars/{calendarId}/objects/inPeriod/{start}/{end}')->action(function($params){
|
||||
$app = new \OCA\Calendar\App($params);
|
||||
$app->dispatch('ObjectController', 'indexInPeriod');
|
||||
});
|
||||
$this->create('calendar.event.indexInPeriod', '/v1/calendars/{calendarId}/events/inPeriod/{start}/{end}')->action(function($params){
|
||||
$app = new \OCA\Calendar\App($params);
|
||||
$app->dispatch('EventController', 'indexInPeriod');
|
||||
});
|
||||
$this->create('calendar.journal.indexInPeriod', '/v1/calendars/{calendarId}/journals/inPeriod/{start}/{end}')->action(function($params){
|
||||
$app = new \OCA\Calendar\App($params);
|
||||
$app->dispatch('JournalController', 'indexInPeriod');
|
||||
});
|
||||
$this->create('calendar.todo.indexInPeriod', '/v1/calendars/{calendarId}/objects/todos/{start}/{end}')->action(function($params){
|
||||
$app = new \OCA\Calendar\App($params);
|
||||
$app->dispatch('TodoController', 'indexInPeriod');
|
||||
});
|
||||
|
||||
//set up resources
|
||||
$routes = array(
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014 Georg Ehrke <oc.list@georgehrke.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
namespace OCA\Calendar\Backend;
|
||||
|
||||
class CacheOutDatedException extends \Exception{}
|
|
@ -401,6 +401,15 @@ class Local extends Backend {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* transfer a calendar to another user
|
||||
* @param Calendar $calendar
|
||||
* @param string $oldCalendarURI
|
||||
* @param string $oldUserId
|
||||
*/
|
||||
/*public function transferCalendar(Calendar &$calendar, $oldCalendarURI, $oldUserId) {}*/
|
||||
|
||||
|
||||
/**
|
||||
* find object
|
||||
* @param Calendar $calendar
|
||||
|
@ -432,7 +441,7 @@ class Local extends Backend {
|
|||
if ($row === false || $row === null){
|
||||
$msg = 'Backend\Local::findObject(): Internal Error: ';
|
||||
$msg .= 'No matching entry found';
|
||||
throw new CacheOutDatedException($msg);
|
||||
throw new DoesNotExistException($msg);
|
||||
}
|
||||
|
||||
$row2 = $result->fetchRow();
|
||||
|
@ -515,16 +524,14 @@ class Local extends Backend {
|
|||
$sql .= ' OR (objtbl.`startdate` <= ? AND objtbl.`repeating` = 1))';
|
||||
$sql .= ' ORDER BY objtbl.`repeating`';
|
||||
|
||||
$start = $this->getUTCforMDB($start);
|
||||
$end = $this->getUTCforMDB($end);
|
||||
$result = $stmt->execute(array(
|
||||
$result = \OCP\DB::prepare($sql, $limit, $offset)->execute(array(
|
||||
$calendarURI,
|
||||
$userId,
|
||||
$start,
|
||||
$end,
|
||||
$start,
|
||||
$end,
|
||||
$end
|
||||
$this->getUTCforMDB($start),
|
||||
$this->getUTCforMDB($end),
|
||||
$this->getUTCforMDB($start),
|
||||
$this->getUTCforMDB($end),
|
||||
$this->getUTCforMDB($end),
|
||||
));
|
||||
|
||||
$objectCollection = new ObjectCollection();
|
||||
|
@ -554,7 +561,6 @@ class Local extends Backend {
|
|||
public function findObjectsByType(Calendar $calendar, $type, $limit, $offset) {
|
||||
$calendarURI = $calendar->getUri();
|
||||
$userId = $calendar->getUserId();
|
||||
$type = static::$typeMapper[$type];
|
||||
|
||||
$caltbl = $this->calTableName;
|
||||
$objtbl = $this->objTableName;
|
||||
|
@ -563,10 +569,11 @@ class Local extends Backend {
|
|||
$sql .= '`' . $caltbl . '` AS caltbl ';
|
||||
$sql .= 'WHERE objtbl.`calendarid` = caltbl.`id` ';
|
||||
$sql .= 'AND caltbl.`uri` = ? and caltbl.`userid` = ? AND objtbl.`objecttype` = ?';
|
||||
|
||||
$result = \OCP\DB::prepare($sql, $limit, $offset)->execute(array(
|
||||
$calendarURI,
|
||||
$userId,
|
||||
$type
|
||||
$this->getType($type)
|
||||
));
|
||||
|
||||
$objectCollection = new ObjectCollection();
|
||||
|
@ -606,20 +613,22 @@ class Local extends Backend {
|
|||
$sql .= '`' . $caltbl . '` AS caltbl ';
|
||||
$sql .= 'WHERE objtbl.`calendarid` = caltbl.`id`';
|
||||
$sql .= ' AND caltbl.`uri` = ? AND caltbl.`userid` = ?';
|
||||
$sql .= ' AND ((objtbl.`startdate` >= ? AND objtbl.`enddate` <= ? AND objtbl`.repeating` = 0)';
|
||||
$sql .= ' AND ((objtbl.`startdate` >= ? AND objtbl.`enddate` <= ? AND objtbl.`repeating` = 0)';
|
||||
$sql .= ' OR (objtbl.`enddate` >= ? AND objtbl.`startdate` <= ? AND objtbl.`repeating` = 0)';
|
||||
$sql .= ' OR (objtbl.`startdate` <= ? AND objtbl.`repeating` = 1))';
|
||||
$sql .= ' AND objtbl.`objecttype` = ?';
|
||||
$sql .= ' ORDER BY objtbl.`repeating`';
|
||||
|
||||
$start = $this->getUTCforMDB($start);
|
||||
$end = $this->getUTCforMDB($end);
|
||||
$result = $stmt->execute(array(
|
||||
$calendarURI, $userId,
|
||||
$start, $end,
|
||||
$start, $end,
|
||||
$end,
|
||||
$type));
|
||||
$result = \OCP\DB::prepare($sql, $limit, $offset)->execute(array(
|
||||
$calendarURI,
|
||||
$userId,
|
||||
$this->getUTCforMDB($start),
|
||||
$this->getUTCforMDB($end),
|
||||
$this->getUTCforMDB($start),
|
||||
$this->getUTCforMDB($end),
|
||||
$this->getUTCforMDB($end),
|
||||
$this->getType($type)
|
||||
));
|
||||
|
||||
$objectCollection = new ObjectCollection();
|
||||
while($row = $result->fetchRow()){
|
||||
|
@ -770,7 +779,7 @@ class Local extends Backend {
|
|||
$object->getObjectURI(),
|
||||
$this->getUTCforMDB($object->getLastModified()),
|
||||
$userId,
|
||||
$calendarURI,
|
||||
$calendarURI
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -778,11 +787,10 @@ class Local extends Backend {
|
|||
/**
|
||||
* update an object
|
||||
* @param Object $object
|
||||
* @param Calendar $oldCalendar
|
||||
* @throws CacheOutDatedException if calendar does not exist
|
||||
* @return Calendar
|
||||
*/
|
||||
public function updateObject(Object &$object, Calendar $oldCalendar) {
|
||||
public function updateObject(Object &$object) {
|
||||
$calendarURI = $object->getCalendar()->getUri();
|
||||
$userId = $object->getCalendar()->getUserId();
|
||||
|
||||
|
@ -800,28 +808,56 @@ class Local extends Backend {
|
|||
$caltbl = $this->calTableName;
|
||||
$objtbl = $this->objTableName;
|
||||
|
||||
$sql = 'UPDATE objtbl SET objecttype` = ?, `startdate` = ?, ';
|
||||
$sql = 'UPDATE objtbl SET `objecttype` = ?, `startdate` = ?, ';
|
||||
$sql .= '`enddate` = ?, `repeating` = ?, `summary` = ?, `calendardata` = ?, ';
|
||||
$sql .= '`lastmodified` = ? FROM `' . $obltbl . '` AS objtbl, ';
|
||||
$sql .= '`lastmodified` = ? FROM `' . $objtbl . '` AS objtbl, ';
|
||||
$sql .= '`' . $caltbl . '` AS caltbl WHERE objtbl.`calendarid` = caltbl.`id` ';
|
||||
$sql .= 'AND caltbl.`uri` = ? AND caltbl.`userid` = ?';
|
||||
$sql .= 'AND caltbl.`uri` = ? AND caltbl.`userid` = ? AND objtbl.`uri` = ?';
|
||||
|
||||
$result = \OCP\DB::prepare($sql)->execute(array(
|
||||
$object->getType(),
|
||||
$object->getStartDate(),
|
||||
$object->getEndDate(),
|
||||
$this->getType($object->getType()),
|
||||
$this->getUTCforMDB($object->getStartDate()->getDateTime()),
|
||||
$this->getUTCforMDB($object->getEndDate()->getDateTime()),
|
||||
$object->getRepeating(),
|
||||
$object->getSummary(),
|
||||
$object->getCalendarData(),
|
||||
$object->getLastModified(),
|
||||
$object->getObjectURI(),
|
||||
$object->gerLastModified(),
|
||||
$this->getUTCforMDB($object->getLastModified()),
|
||||
$calendarURI,
|
||||
$userId,
|
||||
$object->getObjectURI()
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* move an object to another calendar
|
||||
* @param Object $object
|
||||
* @param Calendar $oldCalendar
|
||||
* @throws CacheOutDatedException if calendar does not exist
|
||||
* @return Calendar
|
||||
*/
|
||||
public function moveObject(Object &$object, Calendar $oldCalendar) {
|
||||
$newCalendarURI = $object->getCalendar()->getUri();
|
||||
$oldCalendarURI = $oldCalendar->getUri();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* move an object to another user
|
||||
* @param Object $object
|
||||
* @param Calendar $oldCalendar
|
||||
* @throws CacheOutDatedException if calendar does not exist
|
||||
* @return Calendar
|
||||
*/
|
||||
public function transferObject(Object &$object, Calendar $oldCalendar) {
|
||||
$newCalendarURI = $object->getCalendar()->getUri();
|
||||
$oldCalendarURI = $oldCalendar->getUri();
|
||||
|
||||
$newUserId = $object->getCalendar()->getUserId();
|
||||
$oldUserId = $oldCalendar->getUserId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* delete an object
|
||||
* @param Object $object
|
||||
|
|
|
@ -42,6 +42,13 @@ class CalendarBusinessLayer extends BusinessLayer {
|
|||
private $obl;
|
||||
|
||||
|
||||
/**
|
||||
* runtime cache for calendars
|
||||
* @var array
|
||||
*/
|
||||
private $runtimeCache;
|
||||
|
||||
|
||||
/**
|
||||
* @param IAppContainer $app
|
||||
* @param BackendMapper $backendMapper
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,6 +14,8 @@ use \OCA\Calendar\BusinessLayer\BusinessLayer;
|
|||
use \OCA\Calendar\BusinessLayer\CalendarBusinessLayer;
|
||||
use \OCA\Calendar\BusinessLayer\ObjectBusinessLayer;
|
||||
|
||||
use \DateTime;
|
||||
|
||||
abstract class Controller extends \OCP\AppFramework\Controller {
|
||||
|
||||
/**
|
||||
|
@ -70,7 +72,11 @@ abstract class Controller extends \OCP\AppFramework\Controller {
|
|||
public function params($key, $default=null){
|
||||
$value = parent::params($key, $default);
|
||||
if ($default !== null) {
|
||||
settype($value, gettype($default));
|
||||
if ($default instanceof DateTime) {
|
||||
$value = DateTime::createFromFormat(DateTime::ISO8601, $value);
|
||||
} else {
|
||||
settype($value, gettype($default));
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ use \OCA\Calendar\Http\Serializer;
|
|||
use \OCA\Calendar\Http\ReaderExpcetion;
|
||||
use \OCA\Calendar\Http\SerializerException;
|
||||
|
||||
use \DateTime;
|
||||
|
||||
class ObjectController extends Controller {
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,6 +31,8 @@ use \OCA\Calendar\Http\Serializer;
|
|||
use \OCA\Calendar\Http\ReaderExpcetion;
|
||||
use \OCA\Calendar\Http\SerializerException;
|
||||
|
||||
use \DateTime;
|
||||
|
||||
abstract class ObjectTypeController extends ObjectController {
|
||||
|
||||
/**
|
||||
|
|
|
@ -141,15 +141,18 @@ class Object extends Entity {
|
|||
*/
|
||||
public function getVObject() {
|
||||
$objectName = $this->objectName;
|
||||
|
||||
if ($this->etag === null) {
|
||||
$this->generateEtag();
|
||||
}
|
||||
$currentETag = $this->etag;
|
||||
|
||||
if (!isset($this->vObject->{$objectName}->{'X-OC-URI'})) {
|
||||
$uri = new TextProperty($this->vObject, 'X-OC-URI', $this->objectURI);
|
||||
$this->vObject->{$objectName}->add($uri);
|
||||
}
|
||||
if (!isset($this->vObject->{$objectName}->{'X-OC-ETAG'})) {
|
||||
if ($this->etag === null) {
|
||||
$this->generateEtag();
|
||||
}
|
||||
$etag = new TextProperty($this->vObject, 'X-OC-ETAG', $this->etag);
|
||||
$etag = new TextProperty($this->vObject, 'X-OC-ETAG', $currentETag);
|
||||
$this->vObject->{$objectName}->add($etag);
|
||||
}
|
||||
if (!isset($this->vObject->{$objectName}->{'X-OC-RUDS'})) {
|
||||
|
@ -185,6 +188,14 @@ class Object extends Entity {
|
|||
$this->generateEtag();
|
||||
}
|
||||
|
||||
public function getETag() {
|
||||
if($this->etag === null) {
|
||||
$this->generateEtag();
|
||||
}
|
||||
|
||||
return $this->etag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief update Etag
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014 Georg Ehrke <oc.list@georgehrke.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
namespace OCA\Calendar\Db;
|
||||
|
||||
use \OCP\AppFramework\IAppContainer;
|
||||
|
||||
use \OCA\Calendar\Db\Object;
|
||||
|
||||
class ObjectCacheManager extends Mapper {
|
||||
|
||||
const DELETED = 1;
|
||||
const CREATED = 2;
|
||||
const OUTDATED = 3;
|
||||
|
||||
public function setDeleted($calendar, $objectURIs) {
|
||||
|
||||
}
|
||||
|
||||
public function setOneDeleted($calendar, $objectURI) {
|
||||
|
||||
}
|
||||
|
||||
public function getDeleted($calendar, $limit, $offset) {
|
||||
|
||||
}
|
||||
|
||||
public function deleteDeleted($calendar, $objectURI) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function setCreated($calendar, $objectURIs) {
|
||||
|
||||
}
|
||||
|
||||
public function setOneCreated($calendar, $objectURI) {
|
||||
|
||||
}
|
||||
|
||||
public function getCreated($calendar, $limit, $offset) {
|
||||
|
||||
}
|
||||
|
||||
public function deleteCreated($calendar, $objectURI) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function setOutDated($calendar, $objectURIs) {
|
||||
|
||||
}
|
||||
|
||||
public function getOutDated($calendar, $limit, $offset) {
|
||||
|
||||
}
|
||||
|
||||
public function deleteUpdated($calendar, $objectURI) {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue