public function generateReport($request) { $this->includeThumbnails = false; if (is_array($values = $this->form->getValue('includeThumbnails'))) { $this->includeThumbnails = 1 == $values[0]; } // Get "item" term in "level of description" taxonomy $c2 = new Criteria(); $c2->addJoin(QubitTerm::ID, QubitTermI18n::ID, Criteria::INNER_JOIN); $c2->add(QubitTermI18n::NAME, 'item'); $c2->add(QubitTermI18n::CULTURE, 'en'); $c2->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::LEVEL_OF_DESCRIPTION_ID); $lod = QubitTermI18n::getOne($c2); if (null === $lod) { throw new sfException('Can\'t find "item" level of description in term table'); } $criteria = new Criteria(); $criteria->add(QubitInformationObject::LFT, $this->resource->lft, Criteria::GREATER_EQUAL); $criteria->add(QubitInformationObject::RGT, $this->resource->rgt, Criteria::LESS_EQUAL); $criteria->addAscendingOrderByColumn(QubitInformationObject::LFT); // Filter drafts $criteria = QubitAcl::addFilterDraftsCriteria($criteria); $this->results = array(); $this->resultCount = 0; if (null !== ($results = QubitInformationObject::get($criteria))) { foreach ($results as $item) { if ($lod->id == $item->levelOfDescriptionId) { $parentIsad = new sfIsadPlugin($item->parent); $isad = new sfIsadPlugin($item); $creationDates = self::getCreationDates($item); $this->results[$parentIsad->__toString()][] = array('resource' => $item, 'referenceCode' => $isad->referenceCode, 'title' => $item->getTitle(array('cultureFallback' => true)), 'dates' => isset($creationDates) ? Qubit::renderDateStartEnd($creationDates->getDate(array('cultureFallback' => true)), $creationDates->startDate, $creationDates->endDate) : ' ', 'startDate' => isset($creationDates) ? $creationDates->startDate : null, 'accessConditions' => $item->getAccessConditions(array('cultureFallback' => true)), 'locations' => self::getLocationString($item)); $this->resultCount++; } } // Sort items by selected criteria $sortBy = $this->form->getValue('sortBy'); foreach ($this->results as $key => &$items) { uasort($items, function ($a, $b) use($sortBy) { return strnatcasecmp($a[$sortBy], $b[$sortBy]); }); } } }
public function setDates($date, $options = array()) { // parse the normalized dates into an Event start and end date $normalizedDate = array(); if (isset($options['normalized_dates'])) { preg_match('/(?P<start>\\d{4}(-\\d{2})?(-\\d{2})?)\\/?(?P<end>\\d{4}(-\\d{2})?(-\\d{2})?)?/', $options['normalized_dates'], $matches); $normalizedDate['start'] = new DateTime($this->getDefaultDateValue($matches['start'])); if (isset($matches['end'])) { $normalizedDate['end'] = new DateTime($this->getDefaultDateValue($matches['end'])); } else { $normalizedDate['end'] = null; } } else { $normalizedDate['start'] = null; $normalizedDate['end'] = null; } // determine the Event type if (isset($options['date_type'])) { $eventType = $options['date_type']; // see if Event Type already exists, if so use it $criteria = new Criteria(); $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::EVENT_TYPE_ID); $criteria->addJoin(QubitTerm::ID, QubitTermI18n::ID); $criteria->add(QubitTermI18n::NAME, $eventType); if ($term = QubitTermI18n::getOne($criteria)) { $eventTypeId = $term->id; } else { // if the Event Type does not already exist, create a new type and use it $term = new QubitTerm(); $term->setTaxonomyId(QubitTaxonomy::EVENT_TYPE_ID); $term->setName($eventType); $term->setRoot(); $term->save(); $eventTypeId = $term->id; } } else { // set event type to 'creation' by default $eventTypeId = QubitTerm::CREATION_ID; } // assign the dates to the same event as the creator for this information object // if there is more than one creator, assign it to the first one that is returned if (count($creationEvents = $this->getCreationEvents()) > 0) { $event = $creationEvents[0]; $event->setIndexOnSave(false); $event->setStartDate($normalizedDate['start']); $event->setEndDate($normalizedDate['end']); $event->setTypeId($eventTypeId); $event->setDate($date); $event->save(); } else { // if this information object is not linked to a creator, create an event object // and link it to the information object $event = new QubitEvent(); $event->setTypeId($eventTypeId); $event->setStartDate($normalizedDate['start']); $event->setEndDate($normalizedDate['end']); $event->setDate($date); $this->events[] = $event; } }