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 static function gettermI18nsById($id, array $options = array()) { $criteria = new Criteria(); self::addtermI18nsCriteriaById($criteria, $id); return QubitTermI18n::get($criteria, $options); }
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; } }
/** * Process form fields * * @param $field mixed symfony form widget * @return void */ protected function processField($field) { switch ($field->getName()) { case 'displayNote': case 'scopeNote': case 'sourceNote': $value = $filtered = $this->form->getValue($field->getName()); foreach ($this[$field->getName()] as $item) { if (isset($value[$item->id])) { $item->content = $value[$item->id]; unset($filtered[$item->id]); } else { $item->delete(); } } foreach ($filtered as $item) { $note = new QubitNote(); $note->content = $item; switch ($field->getName()) { case 'scopeNote': $note->typeId = QubitTerm::SCOPE_NOTE_ID; break; case 'sourceNote': $note->typeId = QubitTerm::SOURCE_NOTE_ID; break; case 'displayNote': $note->typeId = QubitTerm::DISPLAY_NOTE_ID; break; } $this->resource->notes[] = $note; } break; case 'name': if (!$this->resource->isProtected() && $this->resource->name != $this->form->getValue('name')) { $this->resource->name = $this->form->getValue('name'); $this->updatedLabel = true; } break; case 'narrowTerms': foreach ($this->form->getValue('narrowTerms') as $item) { if (1 > strlen($item = trim($item))) { continue; } // Test to make sure term doesn't already exist $criteria = new Criteria(); $criteria->add(QubitTerm::TAXONOMY_ID, $this->resource->taxonomyId); $criteria->addJoin(QubitTerm::ID, QubitTermI18n::ID); $criteria->add(QubitTermI18n::CULTURE, $this->context->user->getCulture()); $criteria->add(QubitTermI18n::NAME, $item); if (0 < count(QubitTermI18n::get($criteria))) { continue; } // Add term as child $term = new QubitTerm(); $term->name = $item; $term->taxonomyId = $this->resource->taxonomyId; $this->resource->termsRelatedByparentId[] = $term; } break; case 'parent': $this->resource->parentId = QubitTerm::ROOT_ID; $value = $this->form->getValue('parent'); if (isset($value)) { $params = $this->context->routing->parse(Qubit::pathInfo($value)); $this->resource->parent = $params['_sf_route']->resource; } break; case 'taxonomy': unset($this->resource->taxonomy); $value = $this->form->getValue('taxonomy'); if (isset($value)) { $params = $this->context->routing->parse(Qubit::pathInfo($value)); $this->resource->taxonomy = $params['_sf_route']->resource; } break; case 'relatedTerms': $value = $filtered = array(); foreach ($this->form->getValue('relatedTerms') as $item) { $params = $this->context->routing->parse(Qubit::pathInfo($item)); $resource = $params['_sf_route']->resource; $value[$resource->id] = $filtered[$resource->id] = $resource; } foreach ($this->relations as $item) { if (isset($value[$item->objectId])) { unset($filtered[$item->objectId]); } else { $item->delete(); } } foreach ($filtered as $item) { $relation = new QubitRelation(); $relation->object = $item; $relation->typeId = QubitTerm::TERM_RELATION_ASSOCIATIVE_ID; $this->resource->relationsRelatedBysubjectId[] = $relation; } break; case 'useFor': $value = $filtered = $this->form->getValue('useFor'); foreach ($this->useFor as $item) { if (isset($value[$item->id])) { $item->name = $value[$item->id]; unset($filtered[$item->id]); } else { $item->delete(); } } foreach ($filtered as $item) { $otherName = new QubitOtherName(); $otherName->name = $item; $otherName->typeId = QubitTerm::ALTERNATIVE_LABEL_ID; $this->resource->otherNames[] = $otherName; } break; default: return parent::processField($field); } }