/**
  * @NoAdminRequired
  */
 public function editCalendar()
 {
     $calendarid = (int) $this->params('id');
     $pName = (string) $this->params('name');
     $pActive = (int) $this->params('active');
     $pColor = (string) $this->params('color');
     if (trim($pName) === '') {
         $params = ['status' => 'error', 'message' => 'empty'];
         $response = new JSONResponse($params);
         return $response;
     }
     $calendars = CalendarCalendar::allCalendars($this->userId);
     foreach ($calendars as $cal) {
         if ($cal['userid'] !== $this->userId) {
             continue;
         }
         if ($cal['displayname'] === $pName && (int) $cal['id'] !== $calendarid) {
             $params = ['status' => 'error', 'message' => 'namenotavailable'];
             $response = new JSONResponse($params);
             return $response;
         }
     }
     try {
         CalendarCalendar::editCalendar($calendarid, strip_tags($pName), null, null, null, $pColor, null);
         CalendarCalendar::setCalendarActive($calendarid, $pActive);
     } catch (Exception $e) {
         $params = ['status' => 'error', 'message' => $e->getMessage()];
         $response = new JSONResponse($params);
         return $response;
     }
     $calendar = CalendarCalendar::find($calendarid);
     $isShareApiActive = \OC::$server->getAppConfig()->getValue('core', 'shareapi_enabled', 'yes');
     $shared = false;
     if ($calendar['userid'] !== $this->userId) {
         $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $calendarid);
         if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE) {
             $shared = true;
         }
     }
     $paramsList = ['calendar' => $calendar, 'shared' => $shared, 'appname' => $this->appName, 'isShareApi' => $isShareApiActive];
     $calendarRow = new TemplateResponse($this->appName, 'part.choosecalendar.rowfields', $paramsList, '');
     $params = ['status' => 'success', 'eventSource' => CalendarCalendar::getEventSourceInfo($calendar), 'calid' => $calendarid, 'countEvents' => false, 'page' => $calendarRow->render()];
     $response = new JSONResponse($params);
     return $response;
 }
 /**
  * @NoAdminRequired
  */
 public function editCalendar()
 {
     $calendarid = (int) $this->params('id');
     $pName = (string) $this->params('name');
     $pActive = (int) $this->params('active');
     $pColor = (string) $this->params('color');
     if (trim($pName) === '') {
         $params = ['status' => 'error', 'message' => 'empty'];
         $response = new JSONResponse($params);
         return $response;
     }
     $calendars = CalendarCalendar::allCalendars($this->userId);
     foreach ($calendars as $cal) {
         if ($cal['userid'] !== $this->userId) {
             continue;
         }
         if ($cal['displayname'] === $pName && (int) $cal['id'] !== $calendarid) {
             $params = ['status' => 'error', 'message' => 'namenotavailable'];
             $response = new JSONResponse($params);
             return $response;
         }
     }
     try {
         CalendarCalendar::editCalendar($calendarid, strip_tags($pName), null, null, null, $pColor, null);
         CalendarCalendar::setCalendarActive($calendarid, $pActive);
     } catch (Exception $e) {
         $params = ['status' => 'error', 'message' => $e->getMessage()];
         $response = new JSONResponse($params);
         return $response;
     }
     $calendar = CalendarCalendar::find($calendarid);
     $isShareApiActive = \OC::$server->getAppConfig()->getValue('core', 'shareapi_enabled', 'yes');
     $shared = false;
     if ($calendar['userid'] !== $this->userId) {
         $sharedCalendar = $this->shareConnector->getItemSharedWithBySourceCalendar($calendarid);
         if ($sharedCalendar && $sharedCalendar['permissions'] & $this->shareConnector->getUpdateAccess()) {
             $shared = true;
         }
     }
     $params = ['status' => 'success', 'eventSource' => CalendarCalendar::getEventSourceInfo($calendar), 'calid' => $calendarid];
     $response = new JSONResponse($params);
     return $response;
 }
Example #3
0
 /**
  * Updates a calendars properties
  *
  * The properties array uses the propertyName in clark-notation as key,
  * and the array value for the property value. In the case a property
  * should be deleted, the property value will be null.
  *
  * This method must be atomic. If one property cannot be changed, the
  * entire operation must fail.
  *
  * If the operation was successful, true can be returned.
  * If the operation failed, false can be returned.
  *
  * Deletion of a non-existant property is always succesful.
  *
  * Lastly, it is optional to return detailed information about any
  * failures. In this case an array should be returned with the following
  * structure:
  *
  * array(
  *   403 => array(
  *	  '{DAV:}displayname' => null,
  *   ),
  *   424 => array(
  *	  '{DAV:}owner' => null,
  *   )
  * )
  *
  * In this example it was forbidden to update {DAV:}displayname.
  * (403 Forbidden), which in turn also caused {DAV:}owner to fail
  * (424 Failed Dependency) because the request needs to be atomic.
  *
  * @param string $calendarId
  * @param array $properties
  * @return bool|array
  */
 public function updateCalendar($calendarId, \Sabre\DAV\PropPatch $propPatch)
 {
     $supportedProperties = array_keys($this->propertyMap);
     $supportedProperties[] = '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}schedule-calendar-transp';
     $propPatch->handle($supportedProperties, function ($mutations) use($calendarId) {
         $newValues = array();
         $bChange = false;
         foreach ($mutations as $propertyName => $propertyValue) {
             switch ($propertyName) {
                 case '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}schedule-calendar-transp':
                     $fieldName = 'transparent';
                     $newValues[$fieldName] = $propertyValue->getValue() === 'transparent';
                     break;
                 default:
                     $fieldName = $this->propertyMap[$propertyName];
                     $newValues[$fieldName] = $propertyValue;
                     break;
             }
             $bChange = true;
         }
         //\OCP\Util::writeLog('calendar',' change Found: '.$bChange, \OCP\Util::DEBUG);
         // Success
         if (!isset($newValues['displayname'])) {
             $newValues['displayname'] = null;
         }
         if (!isset($newValues['timezone'])) {
             $newValues['timezone'] = null;
         }
         if (!isset($newValues['calendarorder'])) {
             $newValues['calendarorder'] = null;
         }
         if (!isset($newValues['calendarcolor'])) {
             $newValues['calendarcolor'] = null;
         }
         if (!is_null($newValues['calendarcolor']) && strlen($newValues['calendarcolor']) == 9) {
             $newValues['calendarcolor'] = substr($newValues['calendarcolor'], 0, 7);
         }
         CalendarCalendar::editCalendar($calendarId, $newValues['displayname'], null, $newValues['timezone'], $newValues['calendarorder'], $newValues['calendarcolor']);
         return true;
     });
     //	return \OCA\Calendar\Calendar::editCalendarFromDAVData($principalUri,$calendarUri,$values['displayname'],$values['components'],$values['timezone'],$values['calendarorder'],$values['calendarcolor']);
     //return true;
 }