public function execute($request)
 {
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     $this->resource = $this->getRoute()->resource;
     // Check that this isn't the root
     if (!isset($this->resource->parent)) {
         $this->forward404();
     }
     $query = QubitSearch::getInstance()->addTerm($this->resource->id, 'parentId');
     if (isset($request->query)) {
         $query = $request->query;
     }
     $query = QubitAcl::searchFilterByRepository($query, 'read');
     $query = QubitAcl::searchFilterDrafts($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(QubitInformationObject::ID, $ids, Criteria::IN);
     $this->informationObjects = QubitInformationObject::get($criteria);
 }
 public function execute($request)
 {
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     $this->resource = $this->getRoute()->resource;
     $criteria = new Criteria();
     $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
     $criteria->add(QubitRelation::TYPE_ID, QubitTerm::HAS_PHYSICAL_OBJECT_ID);
     $criteria->addJoin(QubitRelation::OBJECT_ID, QubitInformationObject::ID);
     $this->informationObjects = QubitInformationObject::get($criteria);
     $c2 = clone $criteria;
     $this->foundcount = BasePeer::doCount($c2)->fetchColumn(0);
 }
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $conn = $databaseManager->getDatabase('propel')->getConnection();
     $criteria = new Criteria();
     $criteria->add(QubitSlug::SLUG, $arguments['slug']);
     $criteria->addJoin(QubitSlug::OBJECT_ID, QubitObject::ID);
     $resource = QubitInformationObject::get($criteria)->__get(0);
     $publicationStatus = QubitTerm::getById($arguments['publicationStatusId']);
     // Check if the resource exists
     if (!isset($resource)) {
         throw new sfException('Resource not found');
     }
     // Check if the given status is correct and exists
     if (!isset($publicationStatus)) {
         throw new sfException('Publication status not found');
     }
     if (QubitTaxonomy::PUBLICATION_STATUS_ID != $publicationStatus->taxonomyId) {
         throw new sfException('Given term is not part of the publication status taxonomy');
     }
     // Final confirmation
     if (!$options['no-confirm']) {
         if (!$this->askConfirmation(array('Please, confirm that you want to change', 'the publication status of "' . $resource . '"', 'to "' . $publicationStatus . '" (y/N)'), 'QUESTION_LARGE', false)) {
             $this->logSection('tools', 'Bye!');
             return 1;
         }
     }
     // Start work
     $resource->setPublicationStatus($publicationStatus->id);
     $resource->save();
     echo '+';
     // Update pub status of descendants
     if (!$options['ignore-descendants']) {
         foreach ($resource->descendants as $descendant) {
             if (null === ($descendantPubStatus = $descendant->getPublicationStatus())) {
                 $descendantPubStatus = new QubitStatus();
                 $descendantPubStatus->typeId = QubitTerm::STATUS_TYPE_PUBLICATION_ID;
                 $descendantPubStatus->objectId = $descendant->id;
             }
             if ($options['force'] || $publicationStatus->id != $descendantPubStatus->statusId) {
                 $descendantPubStatus->statusId = $publicationStatus->id;
                 $descendantPubStatus->save();
                 echo '^';
             }
         }
     }
     echo "\n";
 }
 public function execute($request)
 {
     $this->form = new sfForm();
     $this->resource = $this->getRoute()->resource;
     $criteria = new Criteria();
     $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
     $criteria->addJoin(QubitRelation::OBJECT_ID, QubitInformationObject::ID);
     $this->informationObjects = QubitInformationObject::get($criteria);
     $this->form->setValidator('next', new sfValidatorString());
     $this->form->setWidget('next', new sfWidgetFormInputHidden());
     if ($request->isMethod('delete')) {
         $this->form->bind($request->getPostParameters());
         $this->resource->delete();
         $next = $this->form->getValue('next');
         if (isset($next)) {
             $this->redirect($next);
         }
         $this->redirect('@homepage');
     }
 }
 public function execute($request)
 {
     $this->version = '1.3';
     $this->verbose = 'false';
     $this->noOp = 'false';
     $this->maxUploadSize = QubitDigitalObject::getMaxUploadSize() / 1024;
     // From bytes to kilobytes
     $this->mediation = 'false';
     // Should be based in auth + X-On-Behalf-Of
     if (isset($request->getAttribute('sf_route')->resource)) {
         $this->resource = $this->getRoute()->resource;
         $this->title = $this->resource->__toString();
         $this->workspaces = $this->resource->getChildren();
     } else {
         $this->title = sfConfig::get('app_siteTitle');
         $criteria = new Criteria();
         $criteria->add(QubitInformationObject::PARENT_ID, QubitInformationObject::ROOT_ID, Criteria::IN);
         $criteria = QubitAcl::addFilterDraftsCriteria($criteria);
         $this->workspaces = QubitInformationObject::get($criteria);
     }
     $this->response->setHttpHeader('Content-Type', 'application/atom+xml; charset="utf-8"');
     $request->setRequestFormat('xml');
 }
Пример #6
0
 /**
  * Get a new criterion to filter a SQL query by ACL rules
  *
  * @param Criteria $criteria
  * @param mixed $root - root object for list
  * @return Criterion
  */
 public static function getFilterCriterion($criteria, $root, $action)
 {
     $user = sfContext::getInstance()->user;
     $rootClass = get_class($root);
     if ('createTerm' != $action) {
         $permissions = self::getUserPermissionsByAction($user, $rootClass, $action);
     } else {
         $permissions = self::getUserPermissionsByAction($user, 'QubitTerm', 'create');
     }
     // Build access control list
     $allows = $bans = $ids = array();
     $forceBan = false;
     if (0 < count($permissions)) {
         foreach ($permissions as $permission) {
             switch ($action) {
                 case 'createTerm':
                     if (null === ($id = $permission->getConstants(array('name' => 'taxonomyId')))) {
                         $ids[] = QubitTaxonomy::ROOT_ID;
                     }
                     break;
                 case 'viewDraft':
                     if (null !== ($repoId = $permission->getConstants(array('name' => 'repositoryId')))) {
                         $criteria2 = new Criteria();
                         $criteria2->add(QubitInformationObject::REPOSITORY_ID, $repoId);
                         if (0 < count($results = QubitInformationObject::get($criteria2))) {
                             foreach ($results as $item) {
                                 $ids[] = $item->id;
                             }
                             // Special case because isAllowed() on ROOT will return true if
                             // user has grant permission on ANY repository. This will force
                             // showing ONLY resources in allowed repositories
                             $forceBan = true;
                         }
                     }
                     break;
                 default:
                     $ids[] = $permission->objectId;
             }
         }
         foreach ($ids as $id) {
             if (!isset($resourceAccess[$id])) {
                 $resource = call_user_func(array($rootClass, 'getById'), $id);
                 $resourceAccess[$id] = self::isAllowed($user, $resource, $action);
                 if ($resourceAccess[$id]) {
                     $allows[] = $id;
                 } else {
                     $bans[] = $id;
                 }
             }
         }
     }
     // Special cases - avoid adding unnecessary criteria
     if (0 == count($allows) && !QubitAcl::isAllowed($user, $root, $action)) {
         return false;
         // No allows, always false
     } else {
         if (!$forceBan && 0 == count($bans) && QubitAcl::isAllowed($user, $root, $action)) {
             return true;
             // No bans, always true
         }
     }
     // If more allows then bans, then add list of allowed resources
     $criterion = null;
     if (count($allows) >= count($bans)) {
         while ($resourceId = array_shift($allows)) {
             $resource = call_user_func(array($rootClass, 'getById'), $resourceId);
             // If object has no children include it by id
             if (1 == $resource->rgt - $resource->lft) {
                 $subCriterion = $criteria->getNewCriterion(constant("{$rootClass}::ID"), $resourceId);
             } else {
                 $subCriterion = $criteria->getNewCriterion(constant("{$rootClass}::LFT"), $resource->lft, Criteria::GREATER_EQUAL);
                 $subCriterion2 = $criteria->getNewCriterion(constant("{$rootClass}::RGT"), $resource->rgt, Criteria::LESS_EQUAL);
                 $subCriterion->addAnd($subCriterion2);
             }
             if (isset($criterion)) {
                 $criterion->addOr($subCriterion);
             } else {
                 $criterion = $subCriterion;
             }
         }
     } else {
         while ($resourceId = array_shift($bans)) {
             $resource = call_user_func(array($rootClass, 'getById'), $resourceId);
             // If object has no children, remove it by id
             if (1 == $resource->rgt - $resource->lft) {
                 $subCriterion = $criteria->getNewCriterion(constant("{$rootClass}::ID"), $resourceId, Criteria::NOT_EQUAL);
             } else {
                 $subCriterion = $criteria->getNewCriterion(constant("{$rootClass}::LFT"), $resource->lft, Criteria::LESS_THAN);
                 $subCriterion2 = $criteria->getNewCriterion(constant("{$rootClass}::RGT"), $resource->rgt, Criteria::GREATER_THAN);
                 $subCriterion->addOr($subCriterion2);
             }
             if (isset($criterion)) {
                 $criterion->addAnd($subCriterion);
             } else {
                 $criterion = $subCriterion;
             }
         }
     }
     return $criterion;
 }
 public function generateReport($request)
 {
     // Get "file" term in "level of description" taxonomy
     $c2 = new Criteria();
     $c2->addJoin(QubitTerm::ID, QubitTermI18n::ID, Criteria::INNER_JOIN);
     $c2->add(QubitTermI18n::NAME, 'file');
     $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 "file" 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;
     $informationObjects = QubitInformationObject::get($criteria);
     foreach ($informationObjects 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) : '&nbsp;', '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]);
         });
     }
 }
Пример #8
0
 public function getResourceRelations()
 {
     $criteria = new Criteria();
     $criteria->addJoin(QubitInformationObject::ID, QubitEvent::INFORMATION_OBJECT_ID);
     $criteria->addGroupByColumn(QubitInformationObject::ID);
     $criteria->add(QubitEvent::ACTOR_ID, $this->id);
     return QubitInformationObject::get($criteria);
 }
 private static function getFullTree($currentNode, $limit)
 {
     $tree = array();
     // Get direct ancestors
     $ancestors = $currentNode->getAncestors()->orderBy('lft');
     foreach ($ancestors as $ancestor) {
         if (QubitInformationObject::ROOT_ID != $ancestor->id) {
             $tree[$ancestor->id] = $ancestor;
         }
     }
     // Get siblings (with limit) - but don't show sibling collection roots
     $totalSiblings = 0;
     if (QubitInformationObject::ROOT_ID != $currentNode->parentId) {
         $criteria = new Criteria();
         $criteria->add(QubitInformationObject::PARENT_ID, $currentNode->parentId);
         $criteria = self::addTreeViewSortCriteria($criteria);
         if (0 < $limit) {
             $criteria->setLimit($limit);
         }
         foreach (QubitInformationObject::get($criteria) as $item) {
             // Keep track of position of $currentNode in array
             if ($item === $currentNode) {
                 $curIndex = count($tree);
             }
             $tree[] = $item;
         }
         $totalSiblings = intval(BasePeer::doCount($criteria->setLimit(0))->fetchColumn(0));
     }
     // Add current object to $tree if it wasn't added as a sibling
     if (!isset($curIndex)) {
         if ($totalSiblings >= $limit) {
             // replace last sibling with current object
             array_splice($tree, -1, 1, array($currentNode));
         } else {
             $tree[] = $currentNode;
         }
         $curIndex = count($tree) - 1;
     }
     if ($totalSiblings > $limit) {
         $tree[] = array('total' => $totalSiblings, 'limit' => $limit, 'parentId' => $currentNode->parentId);
     }
     // Get children (with limit)
     $totalChildren = 0;
     $criteria = new Criteria();
     $criteria->add(QubitInformationObject::PARENT_ID, $currentNode->id);
     $criteria = self::addTreeViewSortCriteria($criteria);
     if (0 < $limit) {
         $criteria->setLimit($limit);
     }
     if (0 < count($children = QubitInformationObject::get($criteria))) {
         foreach ($children as $item) {
             $childs[] = $item;
         }
         $totalChildren = intval(BasePeer::doCount($criteria->setLimit(0))->fetchColumn(0));
         if ($totalChildren > $limit) {
             $childs[] = array('total' => $totalChildren, 'limit' => $limit, 'parentId' => $currentNode->id);
         }
         // Insert children right AFTER current info object in array
         if ($curIndex == count($tree) - 1) {
             $tree = array_merge($tree, $childs);
         } else {
             array_splice($tree, $curIndex + 1, 0, $childs);
         }
     }
     return $tree;
 }
 public static function getinformationObjectsRelatedByparentIdById($id, array $options = array())
 {
     $criteria = new Criteria();
     self::addinformationObjectsRelatedByparentIdCriteriaById($criteria, $id);
     return QubitInformationObject::get($criteria, $options);
 }
 /**
  * @see xfIndex
  */
 public function qubitPopulate($options)
 {
     $conn = Propel::getConnection();
     $start = microtime(true);
     $this->getLogger()->log('Populating index...', $this->getName());
     // if we are using an offset to resume from a segfault, optimize the index instead of deleting
     if (!isset($options['actorOffset']) && !isset($options['ioOffset'])) {
         $this->getEngine()->erase();
         $this->getLogger()->log('Index erased.', $this->getName());
     } else {
         $this->optimize();
     }
     // set buffering and updates to be batched for better performance
     // NB: not sure why this doesn't work in object scope
     self::getInstance()->getEngine()->enableBatchMode();
     $actorOffset = intval($options['actorOffset']);
     $ioOffset = intval($options['ioOffset']);
     // index actors
     if (-1 < $actorOffset) {
         // Get count of all actors
         $sql = 'SELECT COUNT(*) from ' . QubitActor::TABLE_NAME;
         $rs = $conn->query($sql);
         $rowcount = $rs->fetchColumn(0);
         // Get actors (with offset)
         $criteria = new Criteria();
         QubitActor::addSelectColumns($criteria);
         if (0 < $actorOffset) {
             $criteria->setOffset($actorOffset);
         }
         $actors = QubitActor::get($criteria);
         // Loop through results, and add to search index
         foreach ($actors as $key => $actor) {
             if ($key == 0 && 0 < $actorOffset) {
                 $this->getLogger()->log('Ignoring first ' . $actorOffset . ' actors.');
             }
             self::addActorIndex($actor);
             $this->getLogger()->log('"' . $actor->__toString() . '" inserted (' . round(microtime(true) - $start, 2) . 's) (' . ($key + $actorOffset + 1) . '/' . $rowcount . ')', $this->getName());
         }
     } else {
         $this->getLogger()->log('Actors are ignored.');
     }
     // index information objects
     if (-1 < $ioOffset) {
         // Get count of all information objects
         $sql = 'SELECT COUNT(*) from ' . QubitInformationObject::TABLE_NAME;
         $rs = $conn->query($sql);
         $rowcount = $rs->fetchColumn(0);
         // Get info objects (with offset)
         $criteria = new Criteria();
         QubitInformationObject::addSelectColumns($criteria);
         if (0 < $ioOffset) {
             $criteria->setOffset($ioOffset);
         }
         $informationObjects = QubitInformationObject::get($criteria);
         // Loop through results, and add to search index
         foreach ($informationObjects as $key => $informationObject) {
             if ($key == 0 && 0 < $ioOffset) {
                 $this->getLogger()->log('Ignoring first ' . $ioOffset . ' information objects.');
             }
             if (0 < count($languages = $this->getTranslatedLanguages($informationObject))) {
                 foreach ($languages as $language) {
                     self::addInformationObjectIndex($informationObject, $language, $options);
                 }
             }
             $this->getLogger()->log('"' . $informationObject->__toString() . '" inserted (' . round(microtime(true) - $start, 2) . 's) (' . ($key + $ioOffset + 1) . '/' . $rowcount . ')', $this->getName());
         }
     } else {
         $this->getLogger()->log('Information objects are ignored.');
     }
     $this->getLogger()->log('Index populated in "' . round(microtime(true) - $start, 2) . '" seconds.', $this->getName());
 }