예제 #1
0
 /**
  * Returns info about the usage of a media item as reference to a given table.
  *
  * @param 	string 		$uidList Uid list of tx_dam records the references shall be fetched for
  * @param 	string 		$table Eg tt_content
  * @param	mixed		$MM_ident Array of field/value pairs that should match in MM table. If it is a string, it will be used as value for the field 'ident'.
  * @param	string		$fields The fields to select. Needs to be prepended with table name: tx_dam.uid, tx_dam.title
  * @param	array		$whereClauses WHERE clauses as array with associative keys (which can be used to overwrite 'enableFields') or a single one as string.
  * @param	string		$groupBy: ...
  * @param	string		$orderBy: ...
  * @param	string		$limit: Default: 1000
  * @return array
  */
 function getMediaUsageReferences($uidList, $foreign_table = '', $MM_ident = '', $fields = '', $whereClauses = array(), $groupBy = '', $orderBy = '', $limit = 1000)
 {
     $rows = array();
     // References in tx_dam_mm_ref table
     $fields = $fields ? $fields : 'tx_dam_mm_ref.*';
     $local_table = 'tx_dam';
     $MM_table = 'tx_dam_mm_ref';
     $res = tx_dam_db::referencesQuery($local_table, $uidList, $foreign_table, '', $MM_ident, $MM_table, $fields, $whereClauses, $groupBy, $orderBy, $limit);
     if ($res) {
         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
             $rows[] = $row;
         }
     }
     // References in sys_refindex table
     $softRef_table = 'sys_refindex';
     $fields = $softRef_table . '.tablename AS tablenames, ' . $softRef_table . '.recuid AS uid_foreign, ' . $softRef_table . '.ref_uid AS uid_local, ' . $softRef_table . '.field, ' . $softRef_table . '.softref_key';
     $res = tx_dam_db::softRefIndexQuery($local_table, $uidList, $foreign_table, '', $softRef_ident, $softRef_table, $fields, $whereClauses, $groupBy, $orderBy, $limit);
     if ($res) {
         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
             $rows[] = $row;
         }
     }
     // References in tx_dam_file_tracking table
     $rows = array_merge($rows, tx_dam_db::getMediaUsageUploads($uidList, '', ''));
     return $rows;
 }
 /**
  * Returns an array with reference items + an array with the sorted items
  *
  * @param	string		$selection: reference to a selection object
  * @param	array		$columns: Array of column names required from the entries
  * @return	void
  */
 function read(&$selection, $columns)
 {
     $local_table = 'tx_dam';
     $softRef_table = 'sys_refindex';
     $tracking_table = 'tx_dam_file_tracking';
     // Use the current selection to create a query and count selected records
     $selection->qg->query['DISTINCT'] = false;
     $selection->addSelectionToQuery();
     $countTotal = 0;
     // Save selection where for softRef query
     $queryParts = $selection->qg->getQueryParts();
     $softRefWhere = $queryParts['WHERE'];
     // Look for references in mm table
     $selection->qg->queryAddMM($mm_table = 'tx_dam_mm_ref', $foreign_table = '', $local_table);
     $selection->prepareSelectionQuery(TRUE);
     $queryArr = $selection->qg->getQueryParts();
     $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryArr);
     if ($res) {
         list($countTotal) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
     }
     // If we have a selection...
     if ($selection->sl->hasSelection()) {
         // Look for references in refindex table
         $fields = ' COUNT(' . $local_table . '.uid) as count';
         $res = tx_dam_db::softRefIndexQuery($local_table, '', '', '', '', '', $fields, array($softRefWhere));
         if ($res) {
             list($softRefCountTotal) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
             $countTotal += $softRefCountTotal;
         }
         // Look for references in file tracking table
         $where = array($softRefWhere);
         $where[] = $tracking_table . '.file_hash=' . $local_table . '.file_hash';
         // use index to preselect records
         $where[] = $softRef_table . '.ref_string = CONCAT(' . $tracking_table . '.file_path,' . $tracking_table . '.file_name)';
         $where[] = $softRef_table . '.ref_string LIKE CONCAT(' . $tracking_table . '.file_path,' . $tracking_table . '.file_name)';
         $whereClause = implode(' AND ', $where);
         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $local_table . ',' . $tracking_table . ',' . $softRef_table, $whereClause, '', '', 1000);
         if ($res) {
             list($fileTrackingCountTotal) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
             $countTotal += $fileTrackingCountTotal;
         }
     }
     // If we have references..
     if ($countTotal) {
         $rows = array();
         // Get references from mm table
         $selection->qg->query['FROM'][$local_table] = tx_dam_db::getMetaInfoFieldList();
         $selection->qg->query['FROM']['tx_dam_mm_ref'] = 'tx_dam_mm_ref.uid_foreign,tx_dam_mm_ref.tablenames,tx_dam_mm_ref.ident';
         $selection->qg->addOrderBy('tablenames', 'tx_dam_mm_ref');
         $selection->qg->addLimit($countTotal);
         $selection->prepareSelectionQuery(FALSE);
         $queryArr = $selection->qg->getQueryParts();
         $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryArr);
         if ($res) {
             while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                 $rows[] = $row;
             }
         }
         // Get soft references
         $queryParts = $selection->qg->getQueryParts();
         $fields = tx_dam_db::getMetaInfoFieldList() . ', ' . $softRef_table . '.tablename AS tablenames, ' . $softRef_table . '.recuid AS uid_foreign, ' . $softRef_table . '.ref_uid AS uid_local, ' . $softRef_table . '.field, ' . $softRef_table . '.softref_key';
         $res = tx_dam_db::softRefIndexQuery($local_table, '', '', '', '', '', $fields, array($softRefWhere), $queryParts['GROUPBY'], $queryParts['ORDERBY'], $queryParts['LIMIT']);
         if ($res) {
             while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                 $rows[] = $row;
             }
         }
         // Look for references in file tracking table
         $uids = array();
         $fields = $local_table . '.uid';
         $where = array($softRefWhere);
         $where[] = $tracking_table . '.file_hash=' . $local_table . '.file_hash';
         // use index to preselect records
         $where[] = $softRef_table . '.ref_string = CONCAT(' . $tracking_table . '.file_path,' . $tracking_table . '.file_name)';
         $where[] = $softRef_table . '.ref_string LIKE CONCAT(' . $tracking_table . '.file_path,' . $tracking_table . '.file_name)';
         $whereClause = implode(' AND ', $where);
         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $local_table . ',' . $tracking_table . ',' . $softRef_table, $whereClause, '', '', 1000);
         if ($res) {
             while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                 $uids[] = $row['uid'];
             }
         }
         // Get upload references
         $rows = array_merge($rows, tx_dam_db::getMediaUsageUploads(implode(',', array_unique($uids)), '', ''));
         // Post-process these rows to produce the reference entries array
         $this->processEntries($rows, $columns);
     }
     // Set the pointer
     $selection->pointer->setTotalCount(count($this->entries));
     if (count($this->entries)) {
         $this->sort('page');
         $this->rewind();
     }
 }