Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 30 additions & 55 deletions apps/qubit/modules/actor/actions/contextMenuComponent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,74 +29,49 @@ class ActorContextMenuComponent extends sfComponent
{
public function execute($request)
{
if (!isset($request->limit))
{
$request->limit = sfConfig::get('app_hits_per_page');
}

$this->resource = $request->getAttribute('sf_route')->resource;
sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url'));

// Arrays used to store all the descriptions related to this resource
// and the paginated results related by the event type
$this->relatedInfoObjects = $this->pagers = array();
$page = 1;
$limit = sfConfig::get('app_hits_per_page', 10);

// Get "subject of" information objects (name access point)
$criteria = new Criteria;
$criteria->add(QubitRelation::OBJECT_ID, $this->resource->id);
$criteria->add(QubitRelation::TYPE_ID, QubitTerm::NAME_ACCESS_POINT_ID);
$criteria->addJoin(QubitRelation::SUBJECT_ID, QubitInformationObject::ID);
// Store related information objects in lists with pagination, lists for
// all event types and for name access point relations (subject of)
$this->lists = array();

// Filter draft descriptions
$criteria = QubitAcl::addFilterDraftsCriteria($criteria);
// Subject of
$resultSet = ActorRelatedInformationObjectsAction::getRelatedInformationObjects($this->resource->id, $page, $limit);

// Paginate results
$pager = new QubitPager('QubitInformationObject');
$pager->setCriteria($criteria);
$pager->setMaxPerPage($request->limit);
$pager->setPage($request->page);

$role = __('Subject');
if (0 < count($pager->getResults()))
if ($resultSet->getTotalHits() > 0)
{
// Add pager only if needed
if ($pager->getNbResults() > $request->limit)
{
$this->pagers[$role] = $pager;
}
$pager = new QubitSearchPager($resultSet);
$pager->setPage($page);
$pager->setMaxPerPage($limit);
$pager->init();

$this->relatedInfoObjects[$role] = $pager->getResults();
$this->lists[] = array(
Copy link

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.

'label' => $this->context->i18n->__('Subject'),
'pager' => $pager,
'dataUrl' => url_for(array('module' => 'actor', 'action' => 'relatedInformationObjects', 'actorId' => $this->resource->id)),
'moreUrl' => url_for(array('module' => 'informationobject', 'action' => 'browse', 'topLod' => 0, 'names' => $this->resource->id)));
}

// Iterate over event types to get the related descriptions for each type of event
// All event types
foreach (QubitTerm::getEventTypes() as $eventType)
{
$criteria = new Criteria;
$criteria->add(QubitEvent::ACTOR_ID, $this->resource->id);
$criteria->add(QubitEvent::TYPE_ID, $eventType->id);
$criteria->addJoin(QubitEvent::OBJECT_ID, QubitInformationObject::ID);

// Sort info objects alphabetically (w/ fallback)
$criteria->addAscendingOrderByColumn('title');
$criteria = QubitCultureFallback::addFallbackCriteria($criteria, 'QubitInformationObject');

// Filter draft descriptions
$criteria = QubitAcl::addFilterDraftsCriteria($criteria);

// Paginate results
$pager = new QubitPager('QubitInformationObject');
$pager->setCriteria($criteria);
$pager->setMaxPerPage($request->limit);
$pager->setPage($request->page);
$resultSet = ActorRelatedInformationObjectsAction::getRelatedInformationObjects($this->resource->id, $page, $limit, $eventType->id);

if (0 < count($pager->getResults()))
if ($resultSet->getTotalHits() > 0)
{
// Add pager only if needed
if ($pager->getNbResults() > $request->limit)
{
$this->pagers[$eventType->getRole()] = $pager;
}
$pager = new QubitSearchPager($resultSet);
$pager->setPage($page);
$pager->setMaxPerPage($limit);
$pager->init();

$this->relatedInfoObjects[$eventType->getRole()] = $pager->getResults();
$this->lists[] = array(
'label' => $eventType->getRole(),
'pager' => $pager,
'dataUrl' => url_for(array('module' => 'actor', 'action' => 'relatedInformationObjects', 'actorId' => $this->resource->id, 'eventTypeId' => $eventType->id)),
'moreUrl' => url_for(array('module' => 'informationobject', 'action' => 'browse', 'topLod' => 0, 'actorId' => $this->resource->id, 'eventTypeId' => $eventType->id)));
}
}
}
Expand Down
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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this generate a notice or warning for referring to undefined $request->eventTypeId though, if error_reporting(E_ALL) is set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link

Choose a reason for hiding this comment

The 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;
}
}
39 changes: 19 additions & 20 deletions apps/qubit/modules/actor/templates/_contextMenu.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
<div class="sidebar-lowering">

<?php if (isset($subjectInfoObjects)): ?>
<?php foreach ($lists as $list): ?>

<section class="list-menu">
<section class="sidebar-paginated-list list-menu"
data-total-pages="<?php echo $list['pager']->getLastPage() ?>"
data-url="<?php echo $list['dataUrl'] ?>">

<h2><?php echo __('Subject of') ?></h2>
<h3>
<?php echo __('%1% of', array('%1%' => $list['label'])) ?>
<?php echo image_tag('loading.small.gif', array('class' => 'hidden', 'id' => 'spinner', 'alt' => __('Loading ...'))) ?>
</h3>

<ul>
<?php foreach ($subjectInfoObjects as $item): ?>
<li><?php echo link_to(render_title($item), array($item, 'module' => 'informationobject')) ?></li>
<?php endforeach; ?>
</ul>

</section>

<?php endif; ?>

<?php foreach ($relatedInfoObjects as $role => $informationObjects): ?>

<section class="list-menu">

<h2><?php echo __('%1% of', array('%1%' => $role)) ?></h2>
<div class="more">
<a href="<?php echo $list['moreUrl'] ?>">
<i class="fa fa-search"></i>
<?php echo __('Browse %1% results', array('%1%' => $list['pager']->getNbResults())) ?>
</a>
</div>

<ul>
<?php foreach ($informationObjects as $informationObject): ?>
<li><?php echo link_to(render_title($informationObject), array($informationObject, 'module' => 'informationobject')) ?><?php if (QubitTerm::PUBLICATION_STATUS_DRAFT_ID == $informationObject->getPublicationStatus()->status->id): ?> <span class="publicationStatus"><?php echo $informationObject->getPublicationStatus()->status ?></span><?php endif; ?></li>
<?php foreach ($list['pager']->getResults() as $hit): ?>
<?php $doc = $hit->getData() ?>
<li><?php echo link_to(get_search_i18n($doc, 'title', array('allowEmpty' => false)), array('module' => 'informationobject', 'slug' => $doc['slug'])) ?></li>
<?php endforeach; ?>
</ul>

<?php echo get_partial('default/sidebarPager', array('pager' => $list['pager'])) ?>

</section>

<?php endforeach; ?>
Expand Down
18 changes: 7 additions & 11 deletions apps/qubit/modules/repository/actions/holdingsAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ public function execute($request)
{
$this->response->setHttpHeader('Content-Type', 'application/json; charset=utf-8');

if (empty($request->id) || !ctype_digit($request->id))
{
$this->forward404();
}

if (!empty($request->page) && !ctype_digit($request->page))
if ((empty($request->id) || !ctype_digit($request->id))
|| (empty($request->page) || !ctype_digit($request->page)))
{
$this->forward404();
}
Expand All @@ -45,25 +41,25 @@ public function execute($request)

sfContext::getInstance()->getConfiguration()->loadHelpers(array('Qubit', 'Url'));

$holdings = array();
$results = array();
foreach ($pager->getResults() as $item)
{
$doc = $item->getData();
$holdings[] = array(
$results[] = array(
'url' => url_for(array('module' => 'informationobject', 'slug' => $doc['slug'])),
'title' => get_search_i18n($doc, 'title', array('allowEmpty' => false, 'culture' => $culture, 'cultureFallback' => true))
);
}

$results = array(
'holdings' => $holdings,
$data = array(
'results' => $results,
'start' => $pager->getFirstIndice(),
'end' => $pager->getLastIndice(),
'currentPage' => $pager->getPage(),
'lastPage' => $pager->getLastPage()
);

return $this->renderText(json_encode($results));
return $this->renderText(json_encode($data));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/qubit/modules/repository/templates/_holdings.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<section id="repo-holdings" class="list-menu"
<section class="sidebar-paginated-list list-menu"
data-total-pages="<?php echo $pager->getLastPage() ?>"
data-url="<?php echo url_for(array('module' => 'repository', 'action' => 'holdings', 'id' => $resource->id)) ?>">

Expand Down
Loading