getResources() public method

Returns all resources.
public getResources ( ) : array
return array A copy of the resources array.
Ejemplo n.º 1
0
 public function html($active = true)
 {
     if (!$this->_event) {
         echo '<h3>' . _("Event not found") . '</h3>';
         exit;
     }
     if (is_string($this->_event)) {
         echo '<h3>' . $this->_event . '</h3>';
         exit;
     }
     global $conf, $prefs;
     $this->_event->loadHistory();
     $creatorId = $this->_event->creator;
     $description = $this->_event->description;
     $location = $this->_event->location;
     $eventurl = $this->_event->url;
     $private = $this->_event->isPrivate();
     $owner = Kronolith::getUserName($creatorId);
     $status = Kronolith::statusToString($this->_event->status);
     $attendees = $this->_event->attendees;
     $resources = $this->_event->getResources();
     if ($datetime = Horde_Util::getFormData('datetime')) {
         $datetime = new Horde_Date($datetime);
         $month = $datetime->month;
         $year = $datetime->year;
     } else {
         $month = (int) Horde_Util::getFormData('month', date('n'));
         $year = (int) Horde_Util::getFormData('year', date('Y'));
     }
     $dateFormat = $prefs->getValue('date_format');
     $timeFormat = $prefs->getValue('twentyFour') ? 'G:i' : 'g:ia';
     // Tags
     $tags = implode(', ', $this->_event->tags);
     echo '<div id="Event"' . ($active ? '' : ' style="display:none"') . '>';
     require KRONOLITH_TEMPLATES . '/view/view.inc';
     echo '</div>';
     if ($active && $GLOBALS['browser']->hasFeature('dom')) {
         /* We check for read permissions, because we can always save a
          * copy if we can read the event. */
         if ($this->_event->hasPermission(Horde_Perms::READ) && Kronolith::getDefaultCalendar(Horde_Perms::EDIT)) {
             $edit = new Kronolith_View_EditEvent($this->_event);
             $edit->html(false);
         }
         if ($this->_event->hasPermission(Horde_Perms::DELETE)) {
             $delete = new Kronolith_View_DeleteEvent($this->_event);
             $delete->html(false);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Handles checking for resource availability or cancellation.
  *
  * @param Kronolith_Event $event  The event whose resources we are saving.
  *
  * @return array  An array of accepted resource objects.
  */
 public static function checkResources($event)
 {
     $accepted_resources = array();
     // Don't waste time with resource acceptance if the status is cancelled,
     // the event will be removed from the resource calendar anyway.
     if ($event->status != Kronolith::STATUS_CANCELLED) {
         foreach (array_keys($event->getResources()) as $id) {
             /* Get the resource and protect against infinite recursion in
              * case someone is silly enough to add a resource to it's own
              * event.*/
             $resource = Kronolith::getDriver('Resource')->getResource($id);
             $rcal = $resource->get('calendar');
             if ($rcal == $event->calendar) {
                 continue;
             }
             Kronolith::getDriver('Resource')->open($rcal);
             /* Lock the resource and get the response */
             if ($resource->get('response_type') == Kronolith_Resource::RESPONSETYPE_AUTO) {
                 $haveLock = $resource->lock();
                 if (!$haveLock) {
                     throw new Kronolith_Exception(sprintf(_("The resource \"%s\" was locked. Please try again."), $resource->get('name')));
                 }
             } else {
                 $haveLock = false;
             }
             $response = $resource->getResponse($event);
             /* Remember accepted resources so we can add the event to their
              * calendars. Otherwise, clear the lock. */
             if ($response == Kronolith::RESPONSE_ACCEPTED) {
                 $accepted_resources[] = $resource;
             } elseif ($haveLock) {
                 $resource->unlock();
             }
             if ($response == Kronolith::RESPONSE_DECLINED && $event->uid) {
                 $r_driver = Kronolith::getDriver('Resource');
                 $r_event = $r_driver->getByUID($event->uid, array($resource->get('calendar')));
                 $r_driver->deleteEvent($r_event, true, true);
             }
             /* Add the resource to the event */
             $event->addResource($resource, $response);
         }
     } else {
         // If event is cancelled, and actually exists, we need to mark it
         // as cancelled in resource calendar.
         foreach (array_keys($event->getResources()) as $id) {
             $resource = Kronolith::getDriver('Resource')->getResource($id);
             $rcal = $resource->get('calendar');
             if ($rcal == $event->calendar) {
                 continue;
             }
             try {
                 Kronolith::getDriver('Resource')->open($rcal);
                 $resource->addEvent($this);
             } catch (Exception $e) {
             }
         }
     }
     return $accepted_resources;
 }
Ejemplo n.º 3
0
 public function html($active = true)
 {
     if (!$this->_event) {
         echo '<h3>' . _("Event not found") . '</h3>';
         exit;
     }
     if (is_string($this->_event)) {
         echo '<h3>' . $this->_event . '</h3>';
         exit;
     }
     $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
     if ($this->_event->hasPermission(Horde_Perms::EDIT)) {
         $calendar_id = $this->_event->calendarType . '_' . $this->_event->calendar;
     } else {
         $calendar_id = 'internal_' . Kronolith::getDefaultCalendar(Horde_Perms::EDIT);
     }
     if (!$this->_event->hasPermission(Horde_Perms::EDIT)) {
         try {
             $calendar_id .= '\\' . $this->_event->getShare()->get('owner');
         } catch (Exception $e) {
         }
     }
     $GLOBALS['session']->set('kronolith', 'attendees', $this->_event->attendees);
     $GLOBALS['session']->set('kronolith', 'resources', $this->_event->getResources());
     if ($datetime = Horde_Util::getFormData('datetime')) {
         $datetime = new Horde_Date($datetime);
         $month = $datetime->month;
         $year = $datetime->year;
     } else {
         $month = Horde_Util::getFormData('month', date('n'));
         $year = Horde_Util::getFormData('year', date('Y'));
     }
     $url = Horde_Util::getFormData('url');
     $perms = Horde_Perms::EDIT;
     if ($this->_event->creator == $GLOBALS['registry']->getAuth()) {
         $perms |= Kronolith::PERMS_DELEGATE;
     }
     $calendars = Kronolith::listCalendars($perms, true);
     $buttons = array();
     if (!$this->_event->hasPermission(Horde_Perms::EDIT) && ($GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') === true || $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') > Kronolith::countEvents())) {
         $buttons[] = '<input type="submit" class="horde-create" name="saveAsNew" value="' . _("Save As New") . '" />';
     } else {
         if ($this->_event->hasPermission(Horde_Perms::EDIT)) {
             $buttons[] = '<input type="submit" class="horde-default" name="save" value="' . _("Save Event") . '" />';
         }
         if ($this->_event->initialized) {
             if (!$this->_event->recurs() && ($GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') === true || $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') > Kronolith::countEvents())) {
                 $buttons[] = '<input type="submit" class="horde-create" name="saveAsNew" value="' . _("Save As New") . '" />';
             }
         }
     }
     if (isset($url)) {
         $cancelurl = new Horde_Url($url);
     } else {
         $cancelurl = Horde::url('month.php', true)->add(array('month' => $month, 'year' => $year));
     }
     $event =& $this->_event;
     $tags = implode(',', array_values($event->tags));
     Horde_Core_Ui_JsCalendar::init(array('full_weekdays' => true));
     global $page_output;
     $page_output->addScriptFile('hordecore.js', 'horde');
     $page_output->addScriptFile('edit.js');
     $page_output->addScriptFile('popup.js', 'horde');
     echo '<div id="EditEvent"' . ($active ? '' : ' style="display:none"') . '>';
     require KRONOLITH_TEMPLATES . '/edit/edit.inc';
     echo '</div>';
     if ($active && $GLOBALS['browser']->hasFeature('dom')) {
         if ($this->_event->hasPermission(Horde_Perms::READ)) {
             $view = new Kronolith_View_Event($this->_event);
             $view->html(false);
         }
         if ($this->_event->hasPermission(Horde_Perms::DELETE)) {
             $delete = new Kronolith_View_DeleteEvent($this->_event);
             $delete->html(false);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Check for resource declines and push notice to stack if found.
  *
  * @param Kronolith_Event $event
  *
  * @throws Kronolith_Exception
  */
 public static function notifyOfResourceRejection($event)
 {
     $accepted = $declined = array();
     foreach ($event->getResources() as $id => $resource) {
         if ($resource['response'] == self::RESPONSE_DECLINED) {
             $r = self::getDriver('Resource')->getResource($id);
             $declined[] = $r->get('name');
         } elseif ($resource['response'] == self::RESPONSE_ACCEPTED) {
             $r = self::getDriver('Resource')->getResource($id);
             $accepted[] = $r->get('name');
         }
     }
     if (count($declined)) {
         $GLOBALS['notification']->push(sprintf(ngettext("The following resource has declined your request: %s", "The following resources have declined your request: %s", count($declined)), implode(", ", $declined)), 'horde.error');
     }
     if (count($accepted)) {
         $GLOBALS['notification']->push(sprintf(ngettext("The following resource has accepted your request: %s", "The following resources have accepted your request: %s", count($accepted)), implode(", ", $accepted)), 'horde.success');
     }
 }
Ejemplo n.º 5
0
 /**
  * Handles updating/saving this event's resources. Unless this event recurs,
  * this will delete this event from any resource calendars that are no
  * longer needed (as when a resource is removed from an existing event). If
  * this event is an exception, i.e., contains a baseid, AND $existing is
  * provided, the resources from the original event are used for purposes
  * of determining any resources that need to be removed.
  *
  *
  * @param  Kronolith_Event|null $existing  An existing base event.
  * @since 4.2.6
  */
 protected function _handleResources(Kronolith_Event $existing = null)
 {
     global $session;
     if (Horde_Util::getFormData('isajax', false)) {
         $resources = array();
     } else {
         $resources = $session->get('kronolith', 'resources', Horde_Session::TYPE_ARRAY);
     }
     $existingResources = $this->_resources;
     $newresources = Horde_Util::getFormData('resources');
     if (!empty($newresources)) {
         foreach (explode(',', $newresources) as $id) {
             try {
                 $resource = Kronolith::getDriver('Resource')->getResource($id);
             } catch (Kronolith_Exception $e) {
                 $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
                 continue;
             }
             if (!$resource instanceof Kronolith_Resource_Group || $resource->isFree($this)) {
                 $resources[$resource->getId()] = array('attendance' => Kronolith::PART_REQUIRED, 'response' => Kronolith::RESPONSE_NONE, 'name' => $resource->get('name'));
             } else {
                 $GLOBALS['notification']->push(_("No resources from this group were available"), 'horde.error');
             }
         }
     }
     $this->_resources = $resources;
     // Have the base event, and this is an exception so we must
     // match the recurrence in the resource's copy of the base event.
     if (!empty($existing) && $existing->recurs() && !$this->recurs()) {
         foreach ($existing->getResources() as $rid => $data) {
             $resource = Kronolith::getDriver('Resource')->getResource($key);
             $r_event = Kronolith::getDriver('Resource')->getByUID($existing->uid, $resource->calendar);
             $r_event->recurrence = $event->recurrence;
             $r_event->save();
         }
     }
     // If we don't recur, check for removal of any resources so we can
     // update those resources' calendars.
     if (!$this->recurs()) {
         $merged = $existingResources + $this->_resources;
         $delete = array_diff(array_keys($existingResources), array_keys($this->_resources));
         foreach ($delete as $key) {
             // Resource might be declined, in which case it won't have the event
             // on it's calendar.
             if ($merged[$key]['response'] != Kronolith::RESPONSE_DECLINED) {
                 try {
                     Kronolith::getDriver('Resource')->getResource($key)->removeEvent($this);
                 } catch (Kronolith_Exception $e) {
                     $GLOBALS['notification']->push('foo', 'horde.error');
                 }
             }
         }
     }
 }