Respect database relations when selecting documents and collections

This commit is contained in:
Sebastian Meyer 2013-05-31 18:53:23 +02:00
parent 21e81c7ed4
commit 39f56a29cd
9 changed files with 139 additions and 62 deletions

View File

@ -107,23 +107,6 @@ final class tx_dlf_document {
*/
protected $formatsLoaded = FALSE;
/**
* This holds the hook objects for this class
*
* @var array
* @access protected
*/
protected $hookObjects = array ();
/**
* Is the hook objects array loaded?
* @see $hookObjects
*
* @var boolean
* @access protected
*/
protected $hookObjectsLoaded = FALSE;
/**
* This holds the logical units
*
@ -334,29 +317,6 @@ final class tx_dlf_document {
}
/**
* This gets the registered hook objects for this class.
*
* @access protected
*
* @return void
*/
protected function getHookObjects() {
if (!$this->hookObjectsLoaded && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/common/class.tx_dlf_document.php']['hookClass'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/common/class.tx_dlf_document.php']['hookClass'] as $classRef) {
$this->hookObjects[] = t3lib_div::getUserObj($classRef);
}
$this->hookObjectsLoaded = TRUE;
}
}
/**
* This is a singleton class, thus instances must be created by this method
*
@ -916,9 +876,6 @@ final class tx_dlf_document {
*/
protected function init() {
// Get hook objects for this class.
$this->getHookObjects();
// Get METS node from XML file.
$this->registerNamespaces($this->xml);
@ -1316,7 +1273,7 @@ final class tx_dlf_document {
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_documents.pid='.intval($pid).' AND tx_dlf_collections.pid='.intval($pid).' AND tx_dlf_documents.uid='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->uid, 'tx_dlf_documents').' AND NOT (tx_dlf_collections.cruser_id='.intval($be_user).' AND tx_dlf_collections.fe_cruser_id=0)',
'AND tx_dlf_documents.pid='.intval($pid).' AND tx_dlf_collections.pid='.intval($pid).' AND tx_dlf_documents.uid='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->uid, 'tx_dlf_documents').' AND NOT (tx_dlf_collections.cruser_id='.intval($be_user).' AND tx_dlf_collections.fe_cruser_id=0) AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations'),
'',
'',
''
@ -2161,8 +2118,11 @@ final class tx_dlf_document {
}
// Get hook objects.
$hookObjects = tx_dlf_helper::getHookObjects('common/class.tx_dlf_document.php');
// Apply hooks.
foreach($this->hookObjects as $hookObj) {
foreach($hookObjects as $hookObj) {
if (method_exists($hookObj, 'construct_postProcessRecordId')) {

View File

@ -366,6 +366,69 @@ class tx_dlf_helper {
}
/**
* Get the current frontend user object
*
* @access public
*
* @return tslib_feUserAuth Instance of tslib_feUserAuth or NULL on failure
*/
public static function getFeUser() {
if (TYPO3_MODE === 'FE') {
// Check if a user is currently logged in.
if (!empty($GLOBALS['TSFE']->loginUser)) {
return $GLOBALS['TSFE']->fe_user;
} elseif (!empty(t3lib_div::_GP('eID'))) {
return tslib_eidtools::initFeUser();
}
} else {
if (TYPO3_DLOG) {
t3lib_div::devLog('[tx_dlf_helper->getFeUser()] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::extKey, SYSLOG_SEVERITY_ERROR);
}
}
return;
}
/**
* Get the registered hook objects for a class
*
* @access public
*
* @param string $scriptRelPath: The path to the class file
*
* @return array Array of hook objects for the class
*/
public static function getHookObjects($scriptRelPath) {
$hookObjects = array ();
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][tx_dlf_helper::$extKey.'/'.$scriptRelPath]['hookClass'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][tx_dlf_helper::$extKey.'/'.$scriptRelPath]['hookClass'] as $classRef) {
$hookObjects[] = t3lib_div::getUserObj($classRef);
}
}
return $hookObjects;
}
/**
* Get the "index_name" for an UID
*
@ -742,6 +805,50 @@ class tx_dlf_helper {
}
/**
* Adds "t3jquery" extension's library to page header.
*
* @access public
*
* @return boolean TRUE on success or FALSE on error
*/
public static function loadJQuery() {
// Was jQuery already loaded before?
if (T3JQUERY === TRUE) {
return TRUE;
}
// Ensure extension "t3jquery" is available.
if (t3lib_extMgm::isLoaded('t3jquery')) {
require_once(t3lib_extMgm::extPath('t3jquery').'class.tx_t3jquery.php');
}
// Is "t3jquery" loaded?
if (T3JQUERY === TRUE) {
tx_t3jquery::addJqJS();
return TRUE;
} else {
if (TYPO3_DLOG) {
t3lib_div::devLog('[tx_dlf_helper->loadJQuery()] JQuery not available', $this->extKey, SYSLOG_SEVERITY_ERROR);
}
return FALSE;
}
}
/**
* Process a data and/or command map with TYPO3 core engine.
*

View File

@ -496,6 +496,7 @@ class tx_dlf_solr {
'options' => array (
'source' => 'search',
'select' => $query,
'userid' => 0,
'params' => $this->params,
'order' => 'relevance',
'order.asc' => TRUE,

View File

@ -44,11 +44,11 @@ $EM_CONF[$_EXTKEY] = array(
'depends' => array(
'php' => '5.3.0-',
'typo3' => '4.5.0-',
't3jquery' => '2.6.0-',
),
'conflicts' => array(
),
'suggests' => array(
't3jquery' => '',
),
),
'_md5_values_when_last_written' => '',

View File

@ -272,7 +272,7 @@ class tx_dlf_modIndexing extends tx_dlf_module {
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_documents.pid='.intval($this->id).' AND tx_dlf_collections.uid='.intval($this->data['collection']).tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_documents.pid='.intval($this->id).' AND tx_dlf_collections.uid='.intval($this->data['collection']).' AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'tx_dlf_documents.uid',
'',
''

View File

@ -122,14 +122,22 @@ class tx_dlf_collection extends tx_dlf_plugin {
}
// Should user-defined collections be shown?
// Should user-defined collections be shown?
if (empty($this->conf['show_userdefined'])) {
$additionalWhere .= ' AND tx_dlf_collections.fe_cruser_id=0';
} elseif ($this->conf['show_userdefined'] > 0) {
$additionalWhere .= ' AND NOT tx_dlf_collections.fe_cruser_id=0';
if (!empty($GLOBALS['TSFE']->fe_user->user['uid'])) {
$additionalWhere .= ' AND tx_dlf_collections.fe_cruser_id='.intval($GLOBALS['TSFE']->fe_user->user['uid']);
} else {
$additionalWhere .= ' AND NOT tx_dlf_collections.fe_cruser_id=0';
}
}
@ -139,7 +147,7 @@ class tx_dlf_collection extends tx_dlf_plugin {
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND tx_dlf_documents.partof=0'.$additionalWhere.tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND tx_dlf_documents.partof=0 AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').$additionalWhere.tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'tx_dlf_collections.uid',
$orderBy,
''
@ -163,7 +171,7 @@ class tx_dlf_collection extends tx_dlf_plugin {
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND NOT tx_dlf_documents.uid IN (SELECT DISTINCT tx_dlf_documents.partof FROM tx_dlf_documents WHERE NOT tx_dlf_documents.partof=0'.tx_dlf_helper::whereClause('tx_dlf_documents').')'.$additionalWhere.tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND NOT tx_dlf_documents.uid IN (SELECT DISTINCT tx_dlf_documents.partof FROM tx_dlf_documents WHERE NOT tx_dlf_documents.partof=0'.tx_dlf_helper::whereClause('tx_dlf_documents').') AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').$additionalWhere.tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'tx_dlf_collections.uid',
'',
''
@ -270,11 +278,11 @@ class tx_dlf_collection extends tx_dlf_plugin {
// Get all documents in collection.
$result = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
'tx_dlf_collections.index_name AS index_name,tx_dlf_collections.label AS collLabel,tx_dlf_collections.description AS collDesc,tx_dlf_documents.uid AS uid,tx_dlf_documents.thumbnail AS thumbnail,tx_dlf_documents.metadata AS metadata,tx_dlf_documents.metadata_sorting AS metadata_sorting,tx_dlf_documents.volume_sorting AS volume_sorting,tx_dlf_documents.partof AS partof',
'tx_dlf_collections.index_name AS index_name,tx_dlf_collections.label AS collLabel,tx_dlf_collections.description AS collDesc,tx_dlf_collections.fe_cruser_id AS userid,tx_dlf_documents.uid AS uid,tx_dlf_documents.thumbnail AS thumbnail,tx_dlf_documents.metadata AS metadata,tx_dlf_documents.metadata_sorting AS metadata_sorting,tx_dlf_documents.volume_sorting AS volume_sorting,tx_dlf_documents.partof AS partof',
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_collections.uid='.intval($id).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).$additionalWhere.tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_collections.uid='.intval($id).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').$additionalWhere.tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'',
'tx_dlf_documents.title_sorting ASC',
''
@ -297,6 +305,7 @@ class tx_dlf_collection extends tx_dlf_plugin {
'options' => array (
'source' => 'collection',
'select' => $id,
'userid' => $resArray['userid'],
'params' => array ('fq' => array ('collection_faceting:"'.$resArray['index_name'].'"')),
'order' => 'title',
'order.asc' => TRUE

View File

@ -119,7 +119,7 @@ class tx_dlf_feeds extends tx_dlf_plugin {
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).$additionalWhere.tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').' AND tx_dlf_collections.pid='.intval($this->conf['pages']).$additionalWhere.tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'tx_dlf_documents.uid',
'tx_dlf_documents.tstamp DESC',
intval($this->conf['limit'])

View File

@ -608,7 +608,7 @@ class tx_dlf_oai extends tx_dlf_plugin {
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_documents.uid IN ('.implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($todo)).') AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).$where.tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_documents.uid IN ('.implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($todo)).') AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').$where.tx_dlf_helper::whereClause('tx_dlf_collections'),
'tx_dlf_documents.uid',
'tx_dlf_documents.tstamp',
$this->conf['limit']
@ -790,7 +790,7 @@ class tx_dlf_oai extends tx_dlf_plugin {
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_documents.record_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->piVars['identifier'], 'tx_dlf_documents').' AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).$where.tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_documents.record_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->piVars['identifier'], 'tx_dlf_documents').' AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').$where.tx_dlf_helper::whereClause('tx_dlf_collections'),
'tx_dlf_documents.uid',
'tx_dlf_documents.tstamp',
'1'
@ -1128,7 +1128,7 @@ class tx_dlf_oai extends tx_dlf_plugin {
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).$where.tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').$where.tx_dlf_helper::whereClause('tx_dlf_collections'),
'tx_dlf_documents.uid',
'tx_dlf_documents.tstamp',
''
@ -1181,7 +1181,7 @@ class tx_dlf_oai extends tx_dlf_plugin {
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_documents.uid IN ('.implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($todo)).') AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).$where.tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_documents.uid IN ('.implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($todo)).') AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').$where.tx_dlf_helper::whereClause('tx_dlf_collections'),
'tx_dlf_documents.uid',
'tx_dlf_documents.tstamp',
$this->conf['limit']
@ -1504,7 +1504,7 @@ class tx_dlf_oai extends tx_dlf_plugin {
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).$where.tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').$where.tx_dlf_helper::whereClause('tx_dlf_collections'),
'tx_dlf_documents.uid',
'tx_dlf_documents.tstamp',
''
@ -1551,7 +1551,7 @@ class tx_dlf_oai extends tx_dlf_plugin {
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_documents.uid IN ('.implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($todo)).') AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).$where.tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_documents.uid IN ('.implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($todo)).') AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').$where.tx_dlf_helper::whereClause('tx_dlf_collections'),
'tx_dlf_documents.uid',
'tx_dlf_documents.tstamp',
$this->conf['limit']

View File

@ -81,7 +81,7 @@ class tx_dlf_statistics extends tx_dlf_plugin {
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND tx_dlf_documents.partof=0 AND tx_dlf_collections.uid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($this->conf['collections']).')'.tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND tx_dlf_documents.partof=0 AND tx_dlf_collections.uid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($this->conf['collections']).') AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'tx_dlf_documents.uid',
'',
''
@ -92,7 +92,7 @@ class tx_dlf_statistics extends tx_dlf_plugin {
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND NOT tx_dlf_documents.uid IN (SELECT DISTINCT tx_dlf_documents.partof FROM tx_dlf_documents WHERE NOT tx_dlf_documents.partof=0'.tx_dlf_helper::whereClause('tx_dlf_documents').') AND tx_dlf_collections.uid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($this->conf['collections']).')'.tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND NOT tx_dlf_documents.uid IN (SELECT DISTINCT tx_dlf_documents.partof FROM tx_dlf_documents WHERE NOT tx_dlf_documents.partof=0'.tx_dlf_helper::whereClause('tx_dlf_documents').') AND tx_dlf_collections.uid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($this->conf['collections']).') AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'tx_dlf_documents.uid',
'',
''