/**
  * Appends the record's header to the XML response.
  *
  * Adds the identifier, datestamp and setSpec to a header element, and
  * appends in to the document.
  *
  * @param DOMElement $parentElement
  */
 public function appendHeader($parentElement)
 {
     $headerData['identifier'] = OaiPmhRepository_OaiIdentifier::itemToOaiId($this->item->id);
     $headerData['datestamp'] = OaiPmhRepository_Date::dbToUtc($this->item->modified);
     $collectionId = $this->item->collection_id;
     if ($collectionId) {
         $headerData['setSpec'] = $collectionId;
     }
     $this->createElementWithChildren($parentElement, 'header', $headerData);
 }
 /**
  * Responds to the two main List verbs, includes resumption and limiting.
  *
  * @param string $verb OAI-PMH verb for the request
  * @param string $metadataPrefix Metadata prefix
  * @param int $cursor Offset in response to begin output at
  * @param mixed $set Optional set argument
  * @param string $from Optional from date argument
  * @param string $until Optional until date argument
  * @uses createResumptionToken()
  */
 private function listResponse($verb, $metadataPrefix, $cursor, $set, $from, $until)
 {
     $listLimit = $this->_listLimit;
     $itemTable = get_db()->getTable('Item');
     $select = $itemTable->getSelect();
     $alias = $itemTable->getTableAlias();
     $itemTable->filterByPublic($select, true);
     if ($set) {
         $itemTable->filterByCollection($select, $set);
     }
     if ($from) {
         $select->where("{$alias}.modified >= ? OR {$alias}.added >= ?", $from);
         $select->group("{$alias}.id");
     }
     if ($until) {
         $select->where("{$alias}.modified <= ? OR {$alias}.added <= ?", $until);
         $select->group("{$alias}.id");
     }
     // Total number of rows that would be returned
     $rows = $select->query()->rowCount();
     // This limit call will form the basis of the flow control
     $select->limit($listLimit, $cursor);
     $items = $itemTable->fetchObjects($select);
     if (count($items) == 0) {
         $this->throwError(self::OAI_ERR_NO_RECORDS_MATCH, 'No records match the given criteria');
     } else {
         if ($verb == 'ListIdentifiers') {
             $method = 'appendHeader';
         } else {
             if ($verb == 'ListRecords') {
                 $method = 'appendRecord';
             }
         }
         $verbElement = $this->document->createElement($verb);
         $this->document->documentElement->appendChild($verbElement);
         foreach ($items as $item) {
             $record = new $this->metadataFormats[$metadataPrefix]($item, $this->document);
             $record->{$method}($verbElement);
             // Drop Item from memory explicitly
             release_object($this->item);
         }
         if ($rows > $cursor + $listLimit) {
             $token = $this->createResumptionToken($verb, $metadataPrefix, $cursor + $listLimit, $set, $from, $until);
             $tokenElement = $this->document->createElement('resumptionToken', $token->id);
             $tokenElement->setAttribute('expirationDate', OaiPmhRepository_Date::dbToUtc($token->expiration));
             $tokenElement->setAttribute('completeListSize', $rows);
             $tokenElement->setAttribute('cursor', $cursor);
             $verbElement->appendChild($tokenElement);
         } else {
             if ($cursor != 0) {
                 $tokenElement = $this->document->createElement('resumptionToken');
                 $verbElement->appendChild($tokenElement);
             }
         }
     }
 }
Example #3
0
 /**
  * Helper to get the earlieast datestamp of the repository.
  *
  * @return string OAI-PMH date stamp.
  */
 private function _getEarliestDatestamp()
 {
     $earliestItem = get_record('Item', array('public' => 1, 'sort_field' => 'added', 'sort_dir' => 'a'));
     return $earliestItem ? OaiPmhRepository_Date::dbToUtc($earliestItem->added) : OaiPmhRepository_Date::unixToUtc(0);
 }