-
Notifications
You must be signed in to change notification settings - Fork 144
Improve navigation in actor IO lists, refs #10048 #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1e680cc
3feb947
8168ca2
c660a40
aed9b45
43531d3
3e70f01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Access to Memory (AtoM) software. | ||
* | ||
* Access to Memory (AtoM) is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
*names.id | ||
* Access to Memory (AtoM) 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 Access to Memory (AtoM). If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
class ActorRelatedInformationObjectsAction extends sfAction | ||
{ | ||
public function execute($request) | ||
{ | ||
$this->response->setHttpHeader('Content-Type', 'application/json; charset=utf-8'); | ||
|
||
if ((empty($request->actorId) || !ctype_digit($request->actorId)) | ||
|| (empty($request->page) || !ctype_digit($request->page)) | ||
|| (isset($request->eventTypeId) && !ctype_digit($request->eventTypeId))) | ||
{ | ||
$this->forward404(); | ||
} | ||
|
||
$limit = sfConfig::get('app_hits_per_page', 10); | ||
$culture = $this->context->user->getCulture(); | ||
|
||
$resultSet = self::getRelatedInformationObjects($request->actorId, $request->page, $limit, $request->eventTypeId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this generate a notice or warning for referring to undefined There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what do you mean with undefined, it's forwarding to a 404 page if the value of that parameter is not a digit and, if it's not a event type id, it will return no results. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, my bad! I still need my morning tea :) |
||
|
||
$pager = new QubitSearchPager($resultSet); | ||
$pager->setMaxPerPage($limit); | ||
$pager->setPage($request->page); | ||
$pager->init(); | ||
|
||
sfContext::getInstance()->getConfiguration()->loadHelpers(array('Qubit', 'Url')); | ||
|
||
$results = array(); | ||
foreach ($pager->getResults() as $item) | ||
{ | ||
$doc = $item->getData(); | ||
$results[] = array( | ||
'url' => url_for(array('module' => 'informationobject', 'slug' => $doc['slug'])), | ||
'title' => get_search_i18n($doc, 'title', array('allowEmpty' => false, 'culture' => $culture, 'cultureFallback' => true)) | ||
); | ||
} | ||
|
||
$data = array( | ||
'results' => $results, | ||
'start' => $pager->getFirstIndice(), | ||
'end' => $pager->getLastIndice(), | ||
'currentPage' => $pager->getPage(), | ||
'lastPage' => $pager->getLastPage() | ||
); | ||
|
||
return $this->renderText(json_encode($data)); | ||
} | ||
|
||
/** | ||
* Get related IOs by event type. If no event type id | ||
* is provided, 'Subject of' IOs are returned | ||
*/ | ||
public static function getRelatedInformationObjects($actorId, $page, $limit, $eventTypeId = null) | ||
{ | ||
$query = new \Elastica\Query; | ||
|
||
if (!isset($eventTypeId)) | ||
{ | ||
// Get subject of IOs (name access points) | ||
$queryTerm = new \Elastica\Query\Term(array('names.id' => $actorId)); | ||
|
||
$query->setQuery($queryTerm); | ||
} | ||
else | ||
{ | ||
// Get related by event IOs | ||
$queryBool = new \Elastica\Query\BoolQuery; | ||
$queryBool->addMust(new \Elastica\Query\Term(array('dates.actorId' => $actorId))); | ||
$queryBool->addMust(new \Elastica\Query\Term(array('dates.typeId' => $eventTypeId))); | ||
|
||
// Use nested query and mapping object to allow querying | ||
// over the actor and event ids from the same event | ||
$queryNested = new \Elastica\Query\Nested(); | ||
$queryNested->setPath('dates'); | ||
$queryNested->setQuery($queryBool); | ||
|
||
$query->setQuery($queryNested); | ||
} | ||
|
||
$query->setLimit($limit); | ||
$query->setFrom($limit * ($page - 1)); | ||
|
||
$title = sprintf('i18n.%s.title.untouched', sfContext::getInstance()->user->getCulture()); | ||
$query->setSort(array($title => array('order' => 'asc', 'ignore_unmapped' => true))); | ||
|
||
$filter = new \Elastica\Filter\BoolFilter; | ||
QubitAclSearch::filterDrafts($filter); | ||
|
||
if (0 < count($filter->toArray())) | ||
{ | ||
$query->setPostFilter($filter); | ||
} | ||
|
||
$resultSet = QubitSearch::getInstance()->index->getType('QubitInformationObject')->search($query); | ||
|
||
return $resultSet; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment here about what $this->lists is for. It isn't immediately obvious what it's for if you're just looking at the one file and not the entire PR for context.