Example #1
0
 /**
  * Wrapper to insert missing elements for a CVI event if they haven't been
  * created (due to access restrictions)
  *
  * NB The inserted elements may be removed in the view context if the user still
  * doesn't have the right to manage the data for that specific element.
  *
  * @param \Event $event
  * @param bool $for_editing
  * @return array|\BaseEventTypeElement[]
  */
 public function getEventElements(\Event $event, $for_editing = false)
 {
     if (!$for_editing) {
         return $event->getElements();
     } else {
         $default = $event->eventType->getDefaultElements();
         $current = $event->getElements();
         if (count($current) == $default) {
             // assume a match implies all the elements are already recorded for the event.
             return $current;
         }
         $editable = array();
         foreach ($default as $el) {
             // check there's something in the current list as might be the last default elements that are not defined
             if (isset($current[0]) && get_class($el) == get_class($current[0])) {
                 // the order should be consistent across default and current.
                 $editable[] = array_shift($current);
             } else {
                 $editable[] = $el;
             }
         }
         return $editable;
     }
 }