protected function processField($field)
 {
     switch ($field->getName()) {
         case 'type':
             $value = $filtered = array();
             foreach ($this->form->getValue('type') 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->term->id])) {
                     unset($filtered[$item->term->id]);
                 } else {
                     $item->delete();
                 }
             }
             foreach ($filtered as $item) {
                 $relation = new QubitObjectTermRelation();
                 $relation->term = $item;
                 $this->resource->objectTermRelationsRelatedByobjectId[] = $relation;
             }
             break;
         default:
             return parent::processField($field);
     }
 }
 public function execute($request)
 {
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     $criteria = new Criteria();
     $criteria->addJoin(QubitActor::ID, QubitActorI18n::ID);
     $criteria->add(QubitActorI18n::CULTURE, $this->context->user->getCulture());
     $criteria->addJoin(QubitActor::ID, QubitObject::ID);
     // Filter out non-authority Actors
     $criteria->add(QubitObject::CLASS_NAME, 'QubitUser', Criteria::NOT_EQUAL);
     $criteria->add(QubitObject::CLASS_NAME, 'QubitDonor', Criteria::NOT_EQUAL);
     // Sort alphabetically by name
     $criteria->addAscendingOrderByColumn('authorized_form_of_name');
     if (isset($request->showOnlyActors) && 'true' == $request->showOnlyActors) {
         $criteria->add(QubitObject::CLASS_NAME, 'QubitActor');
     }
     if (isset($request->query)) {
         $criteria->add(QubitActorI18n::AUTHORIZED_FORM_OF_NAME, "{$request->query}%", Criteria::LIKE);
     }
     // Exclude the calling actor from the list
     $params = $this->context->routing->parse(Qubit::pathInfo($request->getReferer()));
     $resource = $params['_sf_route']->resource;
     if (isset($resource->id)) {
         $criteria->add(QubitActor::ID, $resource->id, Criteria::NOT_EQUAL);
     }
     $this->pager = new QubitPager('QubitActor');
     $this->pager->setCriteria($criteria);
     $this->pager->setMaxPerPage($request->limit);
     $this->pager->setPage($request->page);
     $this->actors = $this->pager->getResults();
     $this->setTemplate('list');
 }
 protected function processField($field)
 {
     switch ($field->getName()) {
         // Override RelationEditComponent
         case 'resource':
             unset($this->relation->object);
             $value = $this->form->getValue('resource');
             if (isset($value)) {
                 $params = $this->context->routing->parse(Qubit::pathInfo($value));
                 $this->relation->object = $params['_sf_route']->resource;
                 if (null === ($this->contactInformation = $this->relation->object->getPrimaryContact())) {
                     $this->contactInformation = new QubitContactInformation();
                 }
             }
             break;
         case 'city':
         case 'contactPerson':
         case 'countryCode':
         case 'email':
         case 'postalCode':
         case 'region':
         case 'streetAddress':
         case 'telephone':
             $this->contactInformation[$field->getName()] = $this->form->getValue($field->getName());
             break;
         default:
             parent::processField($field);
     }
 }
 protected function processField($field)
 {
     switch ($field->getName()) {
         case 'creators':
             $value = $filtered = array();
             foreach ($this->form->getValue('creators') as $item) {
                 $params = $this->context->routing->parse(Qubit::pathInfo($item));
                 $resource = $params['_sf_route']->resource;
                 $value[$resource->id] = $filtered[$resource->id] = $resource;
             }
             foreach ($this->events as $item) {
                 if (isset($value[$item->actor->id])) {
                     unset($filtered[$item->actor->id]);
                 } else {
                     if (!isset($this->request->sourceId)) {
                         $item->delete();
                     }
                 }
             }
             foreach ($filtered as $item) {
                 $event = new QubitEvent();
                 $event->actor = $item;
                 $event->typeId = QubitTerm::CREATION_ID;
                 $this->resource->events[] = $event;
             }
             break;
         default:
             return parent::processField($field);
     }
 }
 protected function processField($field)
 {
     switch ($field->getName()) {
         case 'resource':
             // Update the object of the relation, unless the current resource is
             // the object
             if ($this->resource->id != $this->relation->objectId) {
                 unset($this->relation->object);
             } else {
                 unset($this->relation->subject);
             }
             $value = $this->form->getValue('resource');
             if (isset($value)) {
                 $params = $this->context->routing->parse(Qubit::pathInfo($value));
                 if ($this->resource->id != $this->relation->objectId) {
                     $this->relation->object = $params['_sf_route']->resource;
                 } else {
                     $this->relation->subject = $params['_sf_route']->resource;
                 }
             }
             break;
         default:
             return parent::processField($field);
     }
 }
 protected function processField($field)
 {
     switch ($field->getName()) {
         case 'actor':
             unset($this->event->actor);
             $value = $this->form->getValue('actor');
             if (isset($value)) {
                 $params = $this->context->routing->parse(Qubit::pathInfo($value));
                 $this->event->actor = $params['_sf_route']->resource;
             }
             break;
         case 'place':
             $value = $this->form->getValue('place');
             if (isset($value)) {
                 $params = $this->context->routing->parse(Qubit::pathInfo($value));
             }
             foreach ($this->event->objectTermRelationsRelatedByobjectId as $item) {
                 if (isset($value) && $params['_sf_route']->resource->id == $item->id) {
                     unset($value);
                 } else {
                     $item->delete();
                 }
             }
             if (isset($value)) {
                 $relation = new QubitObjectTermRelation();
                 $relation->term = $params['_sf_route']->resource;
                 $this->event->objectTermRelationsRelatedByobjectId[] = $relation;
             }
             break;
         default:
             return parent::processField($field);
     }
 }
 protected function processForm()
 {
     foreach ($this->request->acl as $key => $value) {
         // If key has an underscore, then we are creating a new permission
         if (1 == preg_match('/([\\w]+)_(.*)/', $key, $matches)) {
             list($action, $uri) = array_slice($matches, 1, 2);
             $params = $this->context->routing->parse(Qubit::pathInfo($uri));
             $resource = $params['_sf_route']->resource;
             if (QubitAcl::INHERIT != $value && isset(QubitAcl::$ACTIONS[$action])) {
                 $aclPermission = new QubitAclPermission();
                 $aclPermission->action = $action;
                 $aclPermission->grantDeny = QubitAcl::GRANT == $value ? 1 : 0;
                 switch ($resource->className) {
                     case 'QubitTaxonomy':
                         // Taxonomy specific rules
                         $aclPermission->objectId = QubitTerm::ROOT_ID;
                         $aclPermission->setTaxonomy($resource);
                         break;
                     default:
                         $aclPermission->objectId = $resource->id;
                 }
                 $this->resource->aclPermissions[] = $aclPermission;
             }
         } else {
             if (null !== ($aclPermission = QubitAclPermission::getById($key))) {
                 if ($value == QubitAcl::INHERIT) {
                     $aclPermission->delete();
                 } else {
                     $aclPermission->grantDeny = QubitAcl::GRANT == $value ? 1 : 0;
                     $this->resource->aclPermissions[] = $aclPermission;
                 }
             }
         }
     }
 }
 protected function earlyExecute()
 {
     parent::earlyExecute();
     $this->isad = new sfEhriIsadPlugin($this->resource);
     if (isset($this->request->repository)) {
         $params = $this->context->routing->parse(Qubit::pathInfo($this->request->repository));
         $this->resource->repository = $params['_sf_route']->resource;
     }
     $title = $this->context->i18n->__('Add new EHRI archival description');
     if (isset($this->getRoute()->resource)) {
         if (1 > strlen($title = $this->resource)) {
             $title = $this->context->i18n->__('Untitled');
         }
         $title = $this->context->i18n->__('Edit %1%', array('%1%' => $title));
     }
     $this->response->setTitle("{$title} - {$this->response->getTitle()}");
     // FIXME: Hack way of setting default values
     if (!$this->resource->levelOfDescription) {
         $this->resource->setLevelOfDescriptionByName("Collection");
     }
     if (!$this->resource->descriptionIdentifier) {
         $this->resource->descriptionIdentifier = "EHRI";
     }
     if (!$this->resource->institutionResponsibleIdentifier) {
         $this->resource->institutionResponsibleIdentifier = "EHRI";
     }
     if (!$this->resource->rules) {
         $this->resource->rules = "ISAD(G)";
     }
     if (!$this->resource->scriptOfDescription) {
         $this->resource->scriptOfDescription = "Latn";
     }
 }
 public function processForm()
 {
     if (isset($this->request->deleteRelations)) {
         foreach ($this->request->deleteRelations as $item) {
             $params = $this->context->routing->parse(Qubit::pathInfo($item));
             $params['_sf_route']->resource->delete();
         }
     }
     return parent::processForm();
 }
 protected function processField($field)
 {
     switch ($field->getName()) {
         case 'type':
             unset($this->resource->type);
             $params = $this->context->routing->parse(Qubit::pathInfo($this->form->getValue('type')));
             $this->resource->type = $params['_sf_route']->resource;
             break;
         default:
             return parent::processField($field);
     }
 }
 public function processForm()
 {
     if ($this->request->hasParameter('csvimport')) {
         if ($this->request->getParameterHolder()->has('datesOfCreation')) {
             $this->request->editEvents = $this->request->getParameterHolder()->get('datesOfCreation');
         }
     }
     $params = array($this->request->editEvent);
     if (isset($this->request->editEvents)) {
         // If dialog JavaScript did it's work, then use array of parameters
         $params = $this->request->editEvents;
     }
     foreach ($params as $item) {
         // Continue only if user typed something
         if (1 > strlen($item['date']) && 1 > strlen($item['endDate']) && 1 > strlen($item['startDate'])) {
             continue;
         }
         // Ignore item if it was removed and it was being duplicated
         if (isset($item['id']) && false !== array_search($item['id'], (array) $this->request->deleteEvents)) {
             continue;
         }
         $this->form->bind($item);
         if ($this->form->isValid()) {
             if (!isset($this->request->sourceId) && isset($item['id'])) {
                 $params = $this->context->routing->parse(Qubit::pathInfo($item['id']));
                 $this->event = $params['_sf_route']->resource;
             } else {
                 $this->resource->events[] = $this->event = new QubitEvent();
             }
             foreach ($this->form as $field) {
                 if (isset($item[$field->getName()])) {
                     $this->processField($field);
                 }
             }
         }
     }
     if (!isset($this->request->sourceId) && isset($this->request->deleteEvents)) {
         foreach ($this->request->deleteEvents as $item) {
             $params = $this->context->routing->parse(Qubit::pathInfo($item));
             $params['_sf_route']->resource->delete();
         }
     }
 }
 protected function processForm()
 {
     foreach ($this->form->getValue('containers') as $item) {
         $params = $this->context->routing->parse(Qubit::pathInfo($item));
         $this->resource->addPhysicalObject($params['_sf_route']->resource);
     }
     if (null !== $this->form->getValue('name') || null !== $this->form->getValue('location')) {
         $physicalObject = new QubitPhysicalObject();
         $physicalObject->name = $this->form->getValue('name');
         $physicalObject->location = $this->form->getValue('location');
         $params = $this->context->routing->parse(Qubit::pathInfo($this->form->getValue('type')));
         $physicalObject->type = $params['_sf_route']->resource;
         $physicalObject->save();
         $this->resource->addPhysicalObject($physicalObject);
     }
     if (isset($this->request->delete_relations)) {
         foreach ($this->request->delete_relations as $item) {
             $params = $this->context->routing->parse(Qubit::pathInfo($item));
             $params['_sf_route']->resource->delete();
         }
     }
 }
 public function execute($request)
 {
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     $criteria = new Criteria();
     $criteria->addJoin(QubitFunction::ID, QubitFunctionI18n::ID);
     $criteria->add(QubitFunctionI18n::CULTURE, $this->context->user->getCulture());
     if (isset($request->query)) {
         $criteria->add(QubitFunctionI18n::AUTHORIZED_FORM_OF_NAME, "{$request->query}%", Criteria::LIKE);
     }
     // Exclude the calling function from the list
     $params = $this->context->routing->parse(Qubit::pathInfo($request->getReferer()));
     $resource = $params['_sf_route']->resource;
     if (isset($resource->id)) {
         $criteria->add(QubitFunction::ID, $resource->id, Criteria::NOT_EQUAL);
     }
     // Page results
     $this->pager = new QubitPager('QubitFunction');
     $this->pager->setCriteria($criteria);
     $this->pager->setMaxPerPage($request->limit);
     $this->pager->setPage(1);
     $this->setTemplate('list');
 }
 protected function processForm()
 {
     $this->relatedAuthorityRecordComponent->processForm();
     $this->relatedFunctionComponent->processForm();
     $this->relatedResourceComponent->processForm();
     if (isset($this->request->deleteRelations)) {
         foreach ($this->request->deleteRelations as $item) {
             $params = $this->context->routing->parse(Qubit::pathInfo($item));
             $params['_sf_route']->resource->delete();
         }
     }
     return parent::processForm();
 }
Example #15
0
 public function getChildYuiNodes($options = array())
 {
     $limit = isset($options['limit']) ? $options['limit'] : 0;
     $offset = isset($options['offset']) ? $options['offset'] : 0;
     $nodes = array();
     $criteria = new Criteria();
     $criteria->add(QubitTerm::PARENT_ID, $this->id);
     if (QubitTerm::ROOT_ID == $this->id) {
         $params = sfContext::getInstance()->routing->parse(Qubit::pathInfo(sfContext::getInstance()->request->getReferer()));
         $refererTerm = $params['_sf_route']->resource;
         if (isset($refererTerm)) {
             $criteria->add(QubitTerm::TAXONOMY_ID, $refererTerm->taxonomyId);
         }
     }
     $criteria = QubitCultureFallback::addFallbackCriteria($criteria, 'QubitTerm');
     $criteria->addAscendingOrderByColumn('name');
     $countCriteria = clone $criteria;
     $totalChildren = intval(BasePeer::doCount($countCriteria)->fetchColumn(0));
     if (0 < $limit) {
         $criteria->setLimit($limit);
     }
     if (0 < $offset) {
         $criteria->setOffset($offset);
     }
     if (0 < count($children = QubitTerm::get($criteria))) {
         foreach ($children as $child) {
             $nodes[] = $child;
         }
     }
     $shownChildren = $offset + count($children);
     if ($totalChildren > $shownChildren) {
         $nodes[] = array('total' => $totalChildren, 'limit' => $limit, 'parentId' => $this->id);
     }
     return self::renderYuiNodes($nodes);
 }
 public function processForm()
 {
     if (isset($this->nameFormat)) {
         $name = preg_replace('/\\[.*\\]/', 's', $this->nameFormat);
         $params = $this->request[$name];
     } else {
         $params = $this->request->editRights;
     }
     foreach ($params as $item) {
         // Continue only if user typed something
         foreach ($item as $value) {
             if (0 < strlen($value)) {
                 break;
             }
         }
         if (1 > strlen($value)) {
             continue;
         }
         $this->form->bind($item);
         if ($this->form->isValid()) {
             if (isset($item['id'])) {
                 $params = $this->context->routing->parse(Qubit::pathInfo($item['id']));
                 $this->right = $params['_sf_route']->resource;
             } else {
                 $this->right = new QubitRights();
             }
             foreach ($this->form as $field) {
                 if (isset($item[$field->getName()])) {
                     $this->processField($field);
                 }
             }
             $this->right->save();
             if (!isset($item['id'])) {
                 $this->relation = new QubitRelation();
                 $this->relation->object = $this->right;
                 $this->relation->typeId = QubitTerm::RIGHT_ID;
                 $this->resource->relationsRelatedBysubjectId[] = $this->relation;
             }
         }
     }
     // Stop here if duplicating
     if (isset($this->request->sourceId)) {
         return;
     }
     if (isset($this->nameFormat)) {
         preg_match('/\\d+/', $this->nameFormat, $usageId);
         $deleteRights = $this->request['deleteRights_' . $usageId[0]];
     } else {
         $deleteRights = $this->request->deleteRights;
     }
     if (isset($deleteRights)) {
         foreach ($deleteRights as $item) {
             $params = $this->context->routing->parse(Qubit::pathInfo($item));
             $params['_sf_route']->resource->delete();
         }
     }
 }
 protected function processField($field)
 {
     switch ($field->getName()) {
         case 'editionStatementOfResponsibility':
         case 'issuingJurisdictionAndDenomination':
         case 'noteOnPublishersSeries':
         case 'numberingWithinPublishersSeries':
         case 'otherTitleInformation':
         case 'otherTitleInformationOfPublishersSeries':
         case 'parallelTitleOfPublishersSeries':
         case 'standardNumber':
         case 'statementOfCoordinates':
         case 'statementOfProjection':
         case 'statementOfResponsibilityRelatingToPublishersSeries':
         case 'statementOfScaleArchitectural':
         case 'statementOfScaleCartographic':
         case 'titleProperOfPublishersSeries':
         case 'titleStatementOfResponsibility':
             $this->rad[$field->getName()] = $this->form->getValue($field->getName());
             break;
         case 'type':
             $value = $filtered = array();
             foreach ($this->form->getValue('type') 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->term->id])) {
                     unset($filtered[$item->term->id]);
                 } else {
                     $item->delete();
                 }
             }
             foreach ($filtered as $item) {
                 $relation = new QubitObjectTermRelation();
                 $relation->term = $item;
                 $this->resource->objectTermRelationsRelatedByobjectId[] = $relation;
             }
             break;
         default:
             return parent::processField($field);
     }
 }
 public function processForm()
 {
     $params = array($this->request->editEvent);
     if (isset($this->request->editEvents)) {
         // If dialog JavaScript did it's work, then use array of parameters
         $params = $this->request->editEvents;
     }
     foreach ($params as $item) {
         // Continue only if user typed something
         foreach ($item as $value) {
             if (0 < strlen($value)) {
                 break;
             }
         }
         if (1 > strlen($value)) {
             continue;
         }
         $this->form->bind($item);
         if ($this->form->isValid()) {
             if (isset($item['id'])) {
                 $params = $this->context->routing->parse(Qubit::pathInfo($item['id']));
                 $this->event = $params['_sf_route']->resource;
             } else {
                 $this->resource->events[] = $this->event = new QubitEvent();
             }
             foreach ($this->form as $field) {
                 if (isset($item[$field->getName()])) {
                     $this->processField($field);
                 }
             }
         }
     }
     // Stop here if duplicating
     if (isset($this->request->sourceId)) {
         return;
     }
     if (isset($this->request->deleteEvents)) {
         foreach ($this->request->deleteEvents as $item) {
             $params = $this->context->routing->parse(Qubit::pathInfo($item));
             $params['_sf_route']->resource->delete();
         }
     }
 }
 public function processForm()
 {
     // HACK For now, parameter name and action name are the same. Should
     // really be configurable, ideally by interpreting
     // $form->getWidgetSchema()->getNameFormat()?
     $params = array($this->request[$this->actionName]);
     if (isset($this->request["{$this->actionName}s"])) {
         // If dialog JavaScript did it's work, then use array of parameters
         $params = $this->request["{$this->actionName}s"];
     }
     foreach ($params as $item) {
         // Continue only if user typed something
         foreach ($item as $value) {
             if (0 < strlen($value)) {
                 break;
             }
         }
         if (1 > strlen($value)) {
             continue;
         }
         $this->form->bind($item);
         if ($this->form->isValid()) {
             if (isset($item['id'])) {
                 $params = $this->context->routing->parse(Qubit::pathInfo($item['id']));
                 $this->relation = $params['_sf_route']->resource;
             } else {
                 $this->resource->relationsRelatedBysubjectId[] = $this->relation = new QubitRelation();
             }
             foreach ($this->form as $field) {
                 if (isset($item[$field->getName()])) {
                     $this->processField($field);
                 }
             }
         }
     }
 }
 protected function processField($field)
 {
     switch ($field->getName()) {
         case 'levelOfDescription':
         case 'parent':
         case 'repository':
             unset($this->resource[$field->getName()]);
             $value = $this->form->getValue($field->getName());
             if (isset($value)) {
                 $params = $this->context->routing->parse(Qubit::pathInfo($value));
                 $this->resource[$field->getName()] = $params['_sf_route']->resource;
             }
             break;
         case 'subjectAccessPoints':
         case 'placeAccessPoints':
             $value = $filtered = array();
             foreach ($this->form->getValue($field->getName()) as $item) {
                 $params = $this->context->routing->parse(Qubit::pathInfo($item));
                 $resource = $params['_sf_route']->resource;
                 $value[$resource->id] = $filtered[$resource->id] = $resource;
             }
             foreach ($this[$field->getName()] as $item) {
                 if (isset($value[$item->term->id])) {
                     unset($filtered[$item->term->id]);
                 } else {
                     $item->delete();
                 }
             }
             foreach ($filtered as $item) {
                 $relation = new QubitObjectTermRelation();
                 $relation->term = $item;
                 $this->resource->objectTermRelationsRelatedByobjectId[] = $relation;
             }
             break;
         case 'nameAccessPoints':
             $value = $filtered = array();
             foreach ($this->form->getValue('nameAccessPoints') as $item) {
                 $params = $this->context->routing->parse(Qubit::pathInfo($item));
                 $resource = $params['_sf_route']->resource;
                 $value[$resource->id] = $filtered[$resource->id] = $resource;
             }
             foreach ($this->nameAccessPoints 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::NAME_ACCESS_POINT_ID;
                 $this->resource->relationsRelatedBysubjectId[] = $relation;
             }
             break;
         default:
             return parent::processField($field);
     }
 }
 public function execute($request)
 {
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     // For term module show only preferred term
     $params = $this->context->routing->parse(Qubit::pathInfo($request->getReferer()));
     if ('term' == $params['module']) {
         $criteria = new Criteria();
         // Exclude the calling object and it's descendants from the list (prevent
         // circular inheritance)
         if (isset($params['id'])) {
             // TODO Self join would be ideal
             $term = QubitTerm::getById($params['id']);
             if (isset($term)) {
                 $criteria->add($criteria->getNewCriterion(QubitTerm::LFT, $term->lft, Criteria::LESS_THAN)->addOr($criteria->getNewCriterion(QubitTerm::RGT, $term->rgt, Criteria::GREATER_THAN)));
             }
         }
         $params = $this->context->routing->parse(Qubit::pathInfo($request->taxonomy));
         $criteria->add(QubitTerm::TAXONOMY_ID, $params['_sf_route']->resource->id);
         $criteria->addJoin(QubitTerm::ID, QubitTermI18n::ID);
         $criteria->add(QubitTermI18n::CULTURE, $this->context->user->getCulture());
         // Narrow results by query
         if (isset($request->query)) {
             $criteria->add(QubitTermI18n::NAME, "{$request->query}%", Criteria::LIKE);
         }
         // Sort by name
         $criteria->addAscendingOrderByColumn(QubitTermI18n::NAME);
         $criteria->setLimit(10);
         $this->terms = QubitTerm::get($criteria);
     } else {
         $s1 = 'SELECT qt.id, null, qti.name
     FROM ' . QubitTerm::TABLE_NAME . ' qt
       LEFT JOIN ' . QubitTermI18n::TABLE_NAME . ' qti
         ON qt.id = qti.id
     WHERE taxonomy_id = :p1
       AND qti.culture = :p2';
         $s2 = 'SELECT qt.id, qon.id as altId, qoni.name
     FROM ' . QubitOtherName::TABLE_NAME . ' qon
       INNER JOIN ' . QubitOtherNameI18n::TABLE_NAME . ' qoni
         ON qon.id = qoni.id
       INNER JOIN ' . QubitTerm::TABLE_NAME . ' qt
         ON qon.object_id = qt.id
     WHERE qt.taxonomy_id = :p1
       AND qoni.culture = :p2';
         // Narrow results by query
         if (isset($request->query)) {
             $s1 .= ' AND qti.name LIKE :p3';
             $s2 .= ' AND qoni.name LIKE :p3';
         }
         $connection = Propel::getConnection();
         $statement = $connection->prepare("({$s1}) UNION ALL ({$s2}) ORDER BY name LIMIT 10");
         $params = $this->context->routing->parse(Qubit::pathInfo($request->taxonomy));
         $statement->bindValue(':p1', $params['_sf_route']->resource->id);
         $statement->bindValue(':p2', $this->context->user->getCulture());
         if (isset($request->query)) {
             $statement->bindValue(':p3', "{$request->query}%");
         }
         $statement->execute();
         $this->terms = array();
         $rows = $statement->fetchAll();
         foreach ($rows as $row) {
             if (isset($row[1])) {
                 // Alternative term
                 $this->terms[] = array(QubitTerm::getById($row[0]), $row[2]);
             } else {
                 // Preferred term
                 $this->terms[] = QubitTerm::getById($row[0]);
             }
         }
     }
 }
 public function execute($request)
 {
     parent::execute($request);
     if ($request->isMethod('post')) {
         $this->form->bind($request->getPostParameters());
         if ($this->form->isValid()) {
             $this->relatedDonorComponent->processForm();
             $this->rightEditComponent->processForm();
             if (isset($this->request->deleteRelations)) {
                 foreach ($this->request->deleteRelations as $item) {
                     $params = $this->context->routing->parse(Qubit::pathInfo($item));
                     $params['_sf_route']->resource->delete();
                 }
             }
             $this->processForm();
             $this->resource->save();
             $this->redirect(array($this->resource, 'module' => 'accession'));
         }
     }
     QubitDescription::addAssets($this->response);
 }
 protected function processField($field)
 {
     switch ($field->getName()) {
         case 'descriptionDetail':
         case 'descriptionStatus':
             unset($this->resource[$field->getName()]);
             $value = $this->form->getValue($field->getName());
             if (isset($value)) {
                 $params = $this->context->routing->parse(Qubit::pathInfo($value));
                 $this->resource[$field->getName()] = $params['_sf_route']->resource;
             }
             break;
         case 'otherName':
         case 'parallelName':
         case 'standardizedName':
             $value = $filtered = $this->form->getValue($field->getName());
             foreach ($this[$field->getName()] 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;
                 switch ($field->getName()) {
                     case 'parallelName':
                         $otherName->typeId = QubitTerm::PARALLEL_FORM_OF_NAME_ID;
                         break;
                     case 'standardizedName':
                         $otherName->typeId = QubitTerm::STANDARDIZED_FORM_OF_NAME_ID;
                         break;
                     default:
                         $otherName->typeId = QubitTerm::OTHER_FORM_OF_NAME_ID;
                 }
                 $this->resource->otherNames[] = $otherName;
             }
             break;
         default:
             $this->resource[$field->getName()] = $this->form->getValue($field->getName());
     }
 }
 /**
  * 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);
     }
 }
 public function execute($request)
 {
     // Default items per page
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     $this->form = new sfForm();
     $this->resource = $this->getRoute()->resource;
     // Check that the object exists and that it is not the root
     if (!isset($this->resource) || !isset($this->resource->parent)) {
         $this->forward404();
     }
     // Check authorization
     if (!QubitAcl::check($this->resource, 'update')) {
         QubitAcl::forwardUnauthorized();
     }
     // "parent" form field
     $this->form->setValidator('parent', new sfValidatorString(array('required' => true)));
     $this->form->setWidget('parent', new sfWidgetFormInputHidden());
     // Root is default parent
     if ($this->resource instanceof QubitInformationObject) {
         $this->form->bind($request->getGetParameters() + array('parent' => $this->context->routing->generate(null, array(QubitInformationObject::getById(QubitInformationObject::ROOT_ID), 'module' => 'informationobject'))));
     } else {
         if ($this->resource instanceof QubitTerm) {
             $this->form->bind($request->getGetParameters() + array('parent' => $this->context->routing->generate(null, array(QubitTerm::getById(QubitTerm::ROOT_ID), 'module' => 'term'))));
         }
     }
     if ($request->isMethod('post')) {
         $this->form->bind($request->getPostParameters());
         if ($this->form->isValid()) {
             $params = $this->context->routing->parse(Qubit::pathInfo($this->form->parent->getValue()));
             // In term treeview, root node links (href) to taxonomy, but it represents the term root object
             if ($this->resource instanceof QubitTerm && QubitObject::getById($params['_sf_route']->resource->id) instanceof QubitTaxonomy) {
                 $this->resource->parentId = QubitTerm::ROOT_ID;
             } else {
                 $this->resource->parentId = $params['_sf_route']->resource->id;
             }
             $this->resource->save();
             if ($request->isXmlHttpRequest()) {
                 return $this->renderText('');
             } else {
                 if ($this->resource instanceof QubitInformationObject) {
                     $this->redirect(array($this->resource, 'module' => 'informationobject'));
                 } else {
                     if ($this->resource instanceof QubitTerm) {
                         $this->redirect(array($this->resource, 'module' => 'term'));
                     }
                 }
             }
         }
     }
     $params = $this->context->routing->parse(Qubit::pathInfo($this->form->parent->getValue()));
     $this->parent = QubitObject::getById($params['_sf_route']->resource->id);
     $query = QubitSearch::getInstance()->addTerm($this->parent->slug, 'parent');
     if (isset($request->query)) {
         $query = $request->query;
     }
     $this->pager = new QubitArrayPager();
     $this->pager->hits = QubitSearch::getInstance()->getEngine()->getIndex()->find($query);
     $this->pager->setMaxPerPage($request->limit);
     $this->pager->setPage($request->page);
     $ids = array();
     foreach ($this->pager->getResults() as $hit) {
         $ids[] = $hit->getDocument()->id;
     }
     $criteria = new Criteria();
     $criteria->add(QubitObject::ID, $ids, Criteria::IN);
     $this->results = QubitObject::get($criteria);
 }
Example #26
0
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Qubit Toolkit is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
 */
require_once dirname(__FILE__) . '/../bootstrap/unit.php';
// Is this the best way to ship path info prefix into ::pathInfo()? I think
// using a real sfWebRequest means including some of its behavior in tests,
// which is possibly not what we want. Should we stub sfContext too? Or ship
// path info prefix into ::pathInfo() some other way?
class sfWebRequestStub
{
    public function getPathInfoPrefix()
    {
        return $this->pathInfoPrefix;
    }
}
$configuration = ProjectConfiguration::getApplicationConfiguration('qubit', 'test', true);
sfContext::createInstance($configuration)->request = new sfWebRequestStub();
$t = new lime_test(2, new lime_output_color());
sfContext::getInstance()->request->pathInfoPrefix = '/aaa/bbb';
$t->is(Qubit::pathInfo('/aaa/bbb/ccc/ddd'), '/ccc/ddd', '"::pathInfo()" with prefix');
sfContext::getInstance()->request->pathInfoPrefix = null;
$t->is(Qubit::pathInfo('/aaa/bbb/ccc/ddd'), '/aaa/bbb/ccc/ddd', '"::pathInfo()" without prefix');