make jsoncalendareader work with new reader stucture

This commit is contained in:
Georg Ehrke 2014-04-28 10:20:13 +02:00
parent 7e80d99cdc
commit 7fe10be03e
3 changed files with 18 additions and 12 deletions

View File

@ -138,14 +138,13 @@ class Calendar extends Entity {
/**
* @brief set uri property
*/
public function setURI($uri) {
public function setUri($uri) {
if (!is_string($uri) || trim($uri) === '') {
return null;
}
$slugified = CalendarUtility::slugify($uri);
$this->uri = $uri;
return $this;
return parent::setUri($slugified);
}

View File

@ -11,6 +11,8 @@ use \OCA\Calendar\Db\Calendar;
use \OCA\Calendar\Db\ObjectType;
use \OCA\Calendar\Db\Permissions;
use \OCA\Calendar\Http\ReaderException;
use \OCA\Calendar\Utility\CalendarUtility;
use \OCA\Calendar\Utility\JSONUtility;
@ -20,12 +22,19 @@ class JSONCalendarReader extends JSONReader{
* @brief parse jsoncalendar
*/
public function parse() {
$data = $this->getData();
$data = stream_get_contents($this->handle);
$json = json_decode($data, true);
if ($this->isUserDataACollection()) {
$object = $this->parseCollection($data);
if ($json === null) {
$msg = 'JSONCalendarReader: User Error';
$msg .= 'Could not decode json string.';
throw new ReaderException($msg);
}
if ($this->isUserDataACollection($json)) {
$object = $this->parseCollection($json);
} else {
$object = $this->parseSingleEntity($data);
$object = $this->parseSingleEntity($json);
}
return $this->setObject($object);
@ -55,10 +64,8 @@ class JSONCalendarReader extends JSONReader{
* @brief check if $this->data is a collection
* @return boolean
*/
private function isUserDataACollection() {
$data = $this->data;
if (array_key_exists(0, $data) && is_array($data[0])) {
private function isUserDataACollection($json) {
if (array_key_exists(0, $json) && is_array($json[0])) {
return true;
}

View File

@ -89,7 +89,7 @@ abstract class JSONReader implements IReader {
* string should represent key
*/
protected function nullProperties($properties) {
$isCollection = $this->isCollection();
$isCollection = ($this->object instanceof Collection);
foreach($properties as $property) {
if ($isCollection) {