New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Introduce public calendar api #11461
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
/** | ||
* ownCloud | ||
* | ||
* @author Thomas Müller | ||
* @copyright 2014 Thomas Müller thomas.mueller@tmit.eu | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OC { | ||
|
||
class CalendarManager implements \OCP\Calendar\IManager { | ||
|
||
/** | ||
* @var \OCP\ICalendar[] | ||
*/ | ||
private $calendars = []; | ||
|
||
/** | ||
* @var \Closure[] to call to load/register calendars | ||
*/ | ||
private $calendarLoaders = []; | ||
|
||
public function search($pattern, $searchProperties = array(), $options = array()) { | ||
$this->loadCalendars(); | ||
$result = array(); | ||
foreach($this->calendars as $cal) { | ||
$r = $cal->search($pattern, $searchProperties, $options); | ||
$contacts = array(); | ||
foreach($r as $c){ | ||
$c['calendar-key'] = $cal->getKey(); | ||
$contacts[] = $c; | ||
} | ||
$result = array_merge($result, $contacts); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* This function can be used to delete the contact identified by the given id | ||
* | ||
* @param object $id the unique identifier to an event/task | ||
* @param string $calendarKey identifier of the calendar in which the task/event shall be deleted | ||
* @return bool successful or not | ||
*/ | ||
public function delete($id, $calendarKey) { | ||
$cal = $this->getCalendar($calendarKey); | ||
if (!$cal) { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @return says bool if successful |
||
} | ||
|
||
if ($cal->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { | ||
return $cal->delete($id); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @param array $properties this array if key-value-pairs defines a task/event | ||
* @param string $calendarKey identifier of the calendar in which the task/event shall be created or updated | ||
* @return array an array representing the task/event just created or updated | ||
*/ | ||
public function createOrUpdate($properties, $calendarKey) { | ||
$cal = $this->getCalendar($calendarKey); | ||
if (!$cal) { | ||
return null; | ||
} | ||
|
||
if ($cal->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { | ||
return $cal->createOrUpdate($properties); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @return bool true if enabled, false if not | ||
*/ | ||
public function isEnabled() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is enabled? You mean the app is enabled? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not realted to a specific app - but if there is any implementation of a calendar available There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call it isCalendarAvailable() or isCalendarRegistered() or something similar then :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 call it isCalendarAvailable() or isCalendarRegistered() or something similar |
||
return !empty($this->calendars) || !empty($this->calendarLoaders); | ||
} | ||
|
||
/** | ||
* @param \OCP\ICalendar $calendar | ||
*/ | ||
public function registerCalendar(\OCP\ICalendar $calendar) { | ||
$this->calendars[$calendar->getKey()] = $calendar; | ||
} | ||
|
||
/** | ||
* @param \OCP\ICalendar $calendar | ||
*/ | ||
public function unregisterCalendar(\OCP\ICalendar $calendar) { | ||
unset($this->calendars[$calendar->getKey()]); | ||
} | ||
|
||
/** | ||
* @return \OCP\ICalendar[] | ||
*/ | ||
public function getCalendars() { | ||
$this->loadCalendars(); | ||
$result = array(); | ||
foreach($this->calendars as $cal) { | ||
$result[$cal->getKey()] = $cal->getDisplayName(); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public function clear() { | ||
$this->calendars = array(); | ||
$this->calendarLoaders = array(); | ||
} | ||
|
||
/** | ||
* @param \Closure $callable | ||
*/ | ||
public function register(\Closure $callable) | ||
{ | ||
$this->calendarLoaders[] = $callable; | ||
} | ||
|
||
/** | ||
* @param string $calendarKey | ||
* @return \OCP\ICalendar | ||
*/ | ||
protected function getCalendar($calendarKey) | ||
{ | ||
$this->loadCalendars(); | ||
if (!array_key_exists($calendarKey, $this->calendars)) { | ||
return null; | ||
} | ||
|
||
return $this->calendars[$calendarKey]; | ||
} | ||
|
||
protected function loadCalendars() | ||
{ | ||
foreach($this->calendarLoaders as $callable) { | ||
$callable($this); | ||
} | ||
$this->calendarLoaders = array(); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
/** | ||
* ownCloud | ||
* | ||
* @author Thomas Müller | ||
* @copyright 2014 Thomas Müller thomas.mueller@tmit.eu | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCP\Calendar { | ||
|
||
/** | ||
* This class provides access to any calendar source within ownCloud. | ||
* Use this class exclusively if you want to access tasks/events. | ||
* | ||
*/ | ||
interface IManager { | ||
|
||
/** | ||
* @param string $pattern which should match within the $searchProperties | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @georgehrke the pattern would be a simple text to be searched for - no regex or something There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, needs better docs what actually should be passed in and an example maybe |
||
* @param array $searchProperties defines the properties within the query pattern should match | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are those search properties? what are the available keys and what does it do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is basically what VCARD uses - should be documented - yes - thx |
||
* @param array $options | ||
* 'from' : defines the starting point in time for the query | ||
* 'to' : defines the end | ||
* | ||
* @return array of events/tasks which are arrays of key-value-pairs | ||
*/ | ||
public function search($pattern, $searchProperties, $options); | ||
|
||
|
||
/** | ||
* This function can be used to delete the task/event identified by the given id | ||
* | ||
* @param object $id the unique identifier to an event/task | ||
* @param string $calendarKey identifier of the calendar in which the task/event shall be deleted | ||
* @return bool successful or not | ||
*/ | ||
function delete($id, $calendarKey); | ||
|
||
/** | ||
* This function is used to create a new task/event if 'id' is not given or not present. | ||
* Otherwise the task/event will be updated by replacing the entire data set. | ||
* | ||
* @param array $properties this array if key-value-pairs defines a task/event | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have a listing of available keys in the phpdoc? |
||
* @param string $calendarKey identifier of the calendar in which the task/event shall be created or updated | ||
* @return array an array representing the task/event just created or updated | ||
*/ | ||
function createOrUpdate($properties, $calendarKey); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is a calendarKey a calendarId? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes - unique key or identifier - name it as you like ;-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should stay consistent with the naming :) if its an id the variable should be called calendarId. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 on staying consistent with the naming |
||
|
||
/** | ||
* Check if task/events are available (e.g. task/events app enabled) | ||
* | ||
* @return bool true if enabled, false if not | ||
*/ | ||
function isEnabled(); | ||
|
||
/** | ||
* Registers a calendar | ||
* | ||
* @param \OCP\ICalendar $calendar | ||
* @return void | ||
*/ | ||
function registerCalendar(\OCP\ICalendar $calendar); | ||
|
||
/** | ||
* Unregisters an calendar | ||
* | ||
* @param \OCP\ICalendar $calendar | ||
* @return void | ||
*/ | ||
function unregisterCalendar(\OCP\ICalendar $calendar); | ||
|
||
/** | ||
* In order to improve lazy loading a closure can be registered which will be called in case | ||
* calendars are actually requested | ||
* | ||
* @param \Closure $callable | ||
* @return void | ||
*/ | ||
function register(\Closure $callable); | ||
|
||
/** | ||
* @return \OCP\ICalendar[] | ||
*/ | ||
function getCalendars(); | ||
|
||
/** | ||
* removes all registered calendars | ||
* @return void | ||
*/ | ||
function clear(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* ownCloud | ||
* | ||
* @author Thomas Müller | ||
* @copyright 2014 Thomas Müller thomas.mueller@tmit.eu | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace OCP { | ||
|
||
interface ICalendar { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a findAll method to get all objects? Or are you just supposed to use search with an empty pattern? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd go for an empty pattern on search - I don't want to clutter the interface with a dozen of methods. |
||
|
||
/** | ||
* @param string $pattern which should match within the $searchProperties | ||
* @param array $searchProperties defines the properties within the query pattern should match | ||
* @param array $options | ||
* 'from' : defines the starting point in time for the query | ||
* 'to' : defines the end | ||
* | ||
* @return array of events/journals/tasks which are arrays of key-value-pairs | ||
*/ | ||
public function search($pattern, $searchProperties, $options); | ||
|
||
/** | ||
* @return string defining the technical unique key | ||
*/ | ||
public function getKey(); | ||
|
||
/** | ||
* In comparison to getKey() this function returns a human readable (maybe translated) name | ||
* @return string | ||
*/ | ||
public function getDisplayName(); | ||
|
||
/** | ||
* @param array $properties this array if key-value-pairs defines a event/task | ||
* @return array an array representing the event/task just created or updated | ||
*/ | ||
public function createOrUpdate($properties); | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getPermissions(); | ||
|
||
/** | ||
* @param object $id the unique identifier to an event/task | ||
* @return bool successful or not | ||
*/ | ||
public function delete($id); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have phpdoc explaining what pattern and the other properties are? I have no idea what this does or what i should pass in by looking at it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be on the interface