Esempio n. 1
0
 /**
  * Factory that tries to create a series with the given id.
  * Note that the series is *not* persisted to the database.
  * You need to explicitly call store() on the corresponding model instance
  * of Opus_Series.
  *
  * @param integer $id
  * @return Opus_Db_TableGateway
  */
 public static function createRowWithCustomId($id)
 {
     $tableGatewayModel = Opus_Db_TableGateway::getInstance(self::$_tableGatewayClass);
     $row = $tableGatewayModel->createRow();
     $row->id = $id;
     return $row;
 }
Esempio n. 2
0
 public function preDelete(Opus_Model_AbstractDb $model)
 {
     if ($model->isNewRecord()) {
         return;
     }
     $this->updateDocuments($model);
     $collections = Opus_Db_TableGateway::getInstance('Opus_Db_Collections');
     $collections->deleteSubTree($model->getId());
 }
Esempio n. 3
0
 /**
  * Returns a list of organisational units that act as (thesis) publishers.
  *
  * @return array A list of Opus_DnbInstitutes that act as publishers.
  */
 public static function getPublishers()
 {
     $table = Opus_Db_TableGateway::getInstance('Opus_Db_DnbInstitutes');
     $select = $table->select()->where('is_publisher = ?', 1);
     $rows = $table->fetchAll($select);
     $result = array();
     foreach ($rows as $row) {
         $result[] = new Opus_DnbInstitute($row);
     }
     return $result;
 }
Esempio n. 4
0
 /**
  * Updates documents and deletes collections of CollectionRole.
  * @param Opus_Model_AbstractDb $model
  */
 public function preDelete(Opus_Model_AbstractDb $model)
 {
     if ($model->isNewRecord()) {
         return;
     }
     // Update documents, incl. ServerDateModified
     if ($model instanceof Opus_CollectionRole) {
         $rootCollection = $model->getRootCollection();
         if (!is_null($rootCollection)) {
             $this->updateDocuments($rootCollection);
         }
     }
     // Delete collections belonging to CollectionRole
     $collections = Opus_Db_TableGateway::getInstance('Opus_Db_Collections');
     $collections->deleteTree($model->getId());
 }
Esempio n. 5
0
 /**
  * make sure documents related to Collection[Role|]s in subtree are updated 
  * (XML-Cache and server_date_published)
  *
  * @param Opus_Collection Starting point for recursive update to documents
  */
 protected function updateDocuments($model)
 {
     if (is_null($model) || is_null($model->getId())) {
         // TODO explain why this is right
         return;
     }
     $collections = Opus_Db_TableGateway::getInstance('Opus_Db_Collections');
     $collectionIdSelect = $collections->selectSubtreeById($model->getId(), 'id');
     $documentFinder = new Opus_DocumentFinder();
     $documentFinder->setCollectionId($collectionIdSelect);
     // clear affected documents from cache
     $xmlCache = new Opus_Model_Xml_Cache();
     $xmlCache->removeAllEntriesWhereSubSelect($documentFinder->getSelectIds());
     // update ServerDateModified for affected documents
     $date = new Opus_Date();
     $date->setNow();
     Opus_Document::setServerDateModifiedByIds($date, $documentFinder->ids());
 }
Esempio n. 6
0
 /**
  * Get a list of IDs for Persons that have the specified role for
  * certain documents.
  *
  * @param string $role Role name.
  * @return array List of Opus_Person Ids for Person models assigned to the specified Role.
  */
 public static function getAllIdsByRole($role)
 {
     // $documentsLinkTable = new Opus_Db_LinkPersonsDocuments();
     $documentsLinkTable = Opus_Db_TableGateway::getInstance('Opus_Db_LinkPersonsDocuments');
     $tablename = $documentsLinkTable->info(Zend_Db_Table::NAME);
     $db = $documentsLinkTable->getAdapter();
     $select = $db->select()->from($tablename, array('person_id'))->where('role = ? ', $role);
     $personIds = $documentsLinkTable->getAdapter()->fetchCol($select);
     if (is_null($personIds) === true) {
         $personIds = array();
     }
     return $personIds;
 }
Esempio n. 7
0
 /**
  * Flush all pending AccessModule actions.
  */
 private function _flushAccessResourceQueue()
 {
     $resource_tables = array('document_id' => Opus_Db_TableGateway::getInstance("Opus_Db_AccessDocuments"), 'file_id' => Opus_Db_TableGateway::getInstance("Opus_Db_AccessFiles"), 'module_name' => Opus_Db_TableGateway::getInstance("Opus_Db_AccessModules"));
     $role_id = $this->getId();
     foreach ($this->_pendingAccessResources as $entry) {
         $action = $entry[0];
         $resource_name = $entry[1];
         $resource_id = $entry[2];
         $table = $resource_tables[$resource_name];
         $data = array('role_id' => $role_id, $resource_name => $resource_id);
         if ($action == 'append') {
             $table->insertIgnoreDuplicate($data);
         } else {
             if ($action == 'remove') {
                 $table->deleteWhereArray($data);
             }
         }
     }
     $this->_pendingAccessResources = array();
 }
Esempio n. 8
0
 /**
  * 
  * Add instance of dependent model as constraint.
  * 
  * @param Opus_Model_AbstractDb $model Instance of dependent model.
  * 
  * @return Opus_DocumentFinder Fluent interface.
  */
 public function setDependentModel($model)
 {
     if (!$model instanceof Opus_Model_AbstractDb) {
         throw new Opus_DocumentFinder_Exception('Expected instance of Opus_Model_AbstractDb.');
     }
     $id = null;
     if ($model instanceof Opus_Model_Dependent_Link_Abstract) {
         $id = $model->getModel()->getId();
     } else {
         $id = $model->getId();
     }
     if (empty($id)) {
         throw new Opus_DocumentFinder_Exception('Id not set for model ' . get_class($model));
     }
     // workaround for Opus_Collection[|Role] which are implemented differently
     if ($model instanceof Opus_Collection) {
         return $this->setCollectionId($id);
     }
     if ($model instanceof Opus_CollectionRole) {
         return $this->setCollectionRoleId($id);
     }
     if (!($model instanceof Opus_Model_Dependent_Abstract || $model instanceof Opus_Model_Dependent_Link_Abstract)) {
         $linkModelClass = $this->_getLinkModelClass($model);
         if (is_null($linkModelClass)) {
             throw new Opus_DocumentFinder_Exception('link model class unknown for model ' . get_class($model));
         }
         $model = new $linkModelClass();
     }
     if (!is_null($id)) {
         $id = $this->db->quote($id);
     }
     $idCol = $model->getParentIdColumn();
     $tableGatewayClass = $model->getTableGatewayClass();
     if (empty($tableGatewayClass)) {
         throw new Opus_DocumentFinder_Exception('No table gateway class provided for ' . get_class($model));
     }
     $table = Opus_Db_TableGateway::getInstance($tableGatewayClass)->info('name');
     if (empty($idCol) || empty($table)) {
         throw new Opus_DocumentFinder_Exception('Cannot create subquery from dependent model ' . get_class($model));
     }
     $idCol = $this->db->quoteIdentifier($idCol);
     $table = $this->db->quoteIdentifier($table);
     if ($model instanceof Opus_Model_Dependent_Link_Abstract) {
         $linkedModelKey = $model->getModelKey();
         if (empty($linkedModelKey)) {
             throw new Opus_DocumentFinder_Exception('Cannot create subquery from dependent model ' . get_class($model));
         }
         $linkedModelKey = $this->db->quoteIdentifier($linkedModelKey);
         $subselect = "SELECT {$idCol}\n                FROM {$table} AS l\n                WHERE l.{$idCol} = d.id\n                AND l.{$linkedModelKey} = {$id}";
     } else {
         if ($model instanceof Opus_Model_Dependent_Abstract) {
             $subselect = "SELECT {$idCol}\n                FROM {$table} AS l\n                WHERE l.{$idCol} = d.id\n                AND l.id = {$id}";
         } else {
             throw new Opus_DocumentFinder_Exception('Cannot create constraint for Model ' . get_class($model));
         }
     }
     $this->select->where("EXISTS ({$subselect})");
     return $this;
 }
Esempio n. 9
0
 /**
  * 
  * Get properties of language object as array for a specific terminology code
  * @param string $code ISO639-2 terminology code to retrieve properties for
  * @return array|null Array of properties or null if object not found in database
  */
 public static function getPropertiesByPart2T($code)
 {
     $table = Opus_Db_TableGateway::getInstance(self::$_tableGatewayClass);
     $rows = $table->fetchAll($table->select()->where('part2_t = ?', $code))->toArray();
     return isset($rows[0]) ? $rows[0] : null;
 }
Esempio n. 10
0
 /**
  * Helper method to fetch account-rows by login name.
  */
 private static function fetchAccountRowByLogin($login)
 {
     if (false === isset($login) or false === is_string($login)) {
         return;
     }
     $accounts = Opus_Db_TableGateway::getInstance(self::$_tableGatewayClass);
     $select = $accounts->select()->where('login = ?', $login);
     return $accounts->fetchRow($select);
 }
Esempio n. 11
0
 /**
  * Fetch-method for field "RootCollection".
  *
  * @return Opus_Collection
  */
 protected function _fetchRootCollection()
 {
     if ($this->isNewRecord()) {
         return;
     }
     $collections = Opus_Db_TableGateway::getInstance('Opus_Db_Collections');
     $root = $collections->getRootNode($this->getId());
     if (!isset($root)) {
         return;
     }
     return new Opus_Collection($root);
 }
Esempio n. 12
0
 /**
  * Returns all collection_ids for a given document_id.
  *
  * @param  int    $document_id
  * @return array  Array of collection Ids.
  *
  * FIXME: This method belongs to Opus_Db_Link_Documents_Collections
  */
 public static function fetchCollectionIdsByDocumentId($document_id)
 {
     if (!isset($document_id)) {
         return array();
     }
     // FIXME: self::$_tableGatewayClass not possible in static methods.
     $table = Opus_Db_TableGateway::getInstance('Opus_Db_Collections');
     // FIXME: Don't use internal knowledge of foreign models/tables.
     // FIXME: Don't return documents if collection is hidden.
     $select = $table->getAdapter()->select()->from("link_documents_collections AS ldc", "collection_id")->where('ldc.document_id = ?', $document_id)->distinct();
     $ids = $table->getAdapter()->fetchCol($select);
     return $ids;
 }
Esempio n. 13
0
 public function readTotal($documentId, $datatype = 'files')
 {
     if ($datatype != 'files' && $datatype != 'frontdoor') {
         $datatype = 'files';
     }
     $ods = Opus_Db_TableGateway::getInstance('Opus_Db_DocumentStatistics');
     $select = $ods->select()->from(array('stat' => 'document_statistics'), array('count' => 'SUM(stat.count)'))->where('stat.type = ?', $datatype)->where('stat.document_id = ?', $documentId);
     $queryResult = $ods->fetchAll($select);
     unset($result);
     foreach ($queryResult as $row) {
         $result = $row->count;
     }
     if (isset($result) === false) {
         $result = 0;
     }
     return $result;
 }
Esempio n. 14
0
 /**
  * Small helper method to fetch next sequence number from database.
  */
 protected function _fetchNextSequenceNumber($sequence_type)
 {
     $id_table = Opus_Db_TableGateway::getInstance('Opus_Db_DocumentIdentifiers');
     $select = $id_table->select()->from($id_table, '')->columns(new Zend_Db_Expr('MAX(CAST(value AS SIGNED))'))->where("type = ?", $sequence_type)->where("value REGEXP '^[[:digit:]]+\$'");
     $last_sequence_id = (int) $id_table->getAdapter()->fetchOne($select);
     if (is_null($last_sequence_id) or $last_sequence_id <= 0) {
         return 1;
     }
     return $last_sequence_id + 1;
 }
Esempio n. 15
0
 /**
  * Checks, if the logged user is allowed to access (module_name).
  *
  * @param string $module_name Name of the module to check
  * @return boolean  Returns true only if access is granted.
  */
 public function checkModule($module_name = null)
 {
     if ($this->skipSecurityChecks()) {
         return true;
     }
     if (empty($module_name)) {
         return false;
     }
     $db = Opus_Db_TableGateway::getInstance('Opus_Db_UserRoles')->getAdapter();
     $results = $db->fetchAll($db->select()->from(array('am' => 'access_modules'), array('module_name'))->join(array('r' => 'user_roles'), 'am.role_id = r.id', '')->where('r.name IN (?)', $this->_roles)->where('am.module_name = ?', $module_name));
     return 1 <= count($results) ? true : false;
 }
Esempio n. 16
0
 /**
  * Bulk update of ServerDateModified for documents matching selection
  * 
  * @param Opus_Date $date Opus_Date-Object holding the date to be set
  * @param array $ids array of document ids
  */
 public static function setServerDateModifiedByIds($date, $ids)
 {
     // Update wird nur ausgeführt, wenn IDs übergeben werden
     if (is_null($ids) || count($ids) == 0) {
         return;
     }
     $table = Opus_Db_TableGateway::getInstance(self::$_tableGatewayClass);
     $where = $table->getAdapter()->quoteInto('id IN (?)', $ids);
     try {
         $table->update(array('server_date_modified' => "{$date}"), $where);
     } catch (Exception $e) {
         $logger = Zend_Registry::get('Zend_Log');
         if (!is_null($logger)) {
             $logger->err(__METHOD__ . ' ' . $e);
         }
     }
 }
Esempio n. 17
0
 /**
  * Retrieve all instances of a particular Opus_Model that are known
  * to the database.
  *
  * @param string $modelClassName        Name of the model class.
  * @param string $tableGatewayClass     Name of the table gateway class
  *                                      to determine the table entities shall
  *                                      be fetched from.
  * @param array  $ids                   A list of ids to fetch.
  * @param string $orderBy               A column name to order by.
  *
  * @return array List of all known model entities.
  * @throws InvalidArgumentException When not passing class names.
  *
  * TODO: Include options array to parametrize query.
  */
 public static function getAllFrom($modelClassName = null, $tableGatewayClass = null, array $ids = null, $orderBy = null)
 {
     // As we are in static context, we have no chance to retrieve
     // those class names.
     if (is_null($modelClassName) === true or is_null($tableGatewayClass) === true) {
         throw new InvalidArgumentException('Both model class and table gateway class must be given.');
     }
     // As this is calling from static context we cannot
     // use the instance variable $_tableGateway here.
     $table = Opus_Db_TableGateway::getInstance($tableGatewayClass);
     // Fetch all entries in one query and pass result table rows
     // directly to models.
     $rows = array();
     if (is_null($ids) === true) {
         $rows = $table->fetchAll(null, $orderBy);
     } else {
         if (empty($ids) === false) {
             $rowset = $table->find($ids);
             if (false === is_null($orderBy)) {
                 // Sort manually, since find() does not support order by clause.
                 $vals = array();
                 foreach ($rowset as $key => $row) {
                     $vals[$key] = $row->{$orderBy};
                     $rows[] = $row;
                 }
                 array_multisort($vals, SORT_ASC, $rows);
             } else {
                 $rows = $rowset;
             }
         }
     }
     $result = array();
     foreach ($rows as $row) {
         $model = new $modelClassName($row);
         $result[] = $model;
     }
     return $result;
 }
Esempio n. 18
0
 /**
  * Retrieve all Opus_EnrichmentKeys referenced by document from the database.
  *
  * @return array Array of Opus_EnrichmentKeys objects.
  */
 public static function getAllReferenced()
 {
     $table = Opus_Db_TableGateway::getInstance('Opus_Db_DocumentEnrichments');
     $db = $table->getAdapter();
     $select = $db->select()->from(array('document_enrichments'));
     $select->reset('columns');
     $select->columns("key_name")->distinct(true);
     return $db->fetchCol($select);
 }
Esempio n. 19
0
 */
// file to import
$input_file = '../workspace/tmp/ddc_dnb.txt';
// visibility status of imported collections
$visible = true;
$fieldSeparator = '	';
if (!file_exists($input_file)) {
    echo "Error: input file {$input_file} does not exist\n";
    exit;
}
if (!is_readable($input_file)) {
    echo "Error: input file {$input_file} is not readable\n";
    exit;
}
// find next valid position for collection role
$table = Opus_Db_TableGateway::getInstance(Opus_CollectionRole::getTableGatewayClass());
$select = $table->select()->from($table, array('MAX(position) AS max_position'));
$row = $table->fetchRow($select);
$position = $row->max_position + 1;
// create root collection
$collectionRole = new Opus_CollectionRole();
$collectionRole->setPosition($position);
$collectionRole->setName('ddc_dnb');
$collectionRole->setOaiName('ddc_dnb');
$collectionRole->setVisible(true);
$collectionRole->setVisibleBrowsingStart(true);
$collectionRole->setDisplayBrowsing('Number,Name');
$collectionRole->setDisplayFrontdoor('Number,Name');
$collectionRole->setVisibleFrontdoor(true);
$collectionRole->setVisibleOai(true);
$collectionRoleId = $collectionRole->store();
Esempio n. 20
0
 /**
  * Tells whether the Job is unique amongst all other jobs
  * in the queue.
  *
  * @return boolean True if job is unique, False otherwise.
  */
 public function isUniqueInQueue()
 {
     $table = Opus_Db_TableGateway::getInstance(self::$_tableGatewayClass);
     $select = $table->select();
     $select->from($table, array('count(sha1_id) as count'))->where('sha1_id = ?', $this->getSha1Id());
     $row = $table->fetchRow($select);
     return (int) $row->count === 0;
 }
Esempio n. 21
0
 public static function fetchByDocIdPathName($docId, $pathName)
 {
     $files = Opus_Db_TableGateway::getInstance(self::$_tableGatewayClass);
     $select = $files->select()->where('document_id = ?', $docId)->where('path_name = ?', $pathName);
     $row = $files->fetchRow($select);
     if (!is_null($row)) {
         return new Opus_File($row);
     }
     return null;
 }