protected function getJoins($tableAliases)
 {
     $join = '';
     // Hook to append other tables
     tx_rnbase_util_Misc::callHook('rn_base', 'search_generic_getJoins_hook', array('join' => &$join, 'tableAliases' => $tableAliases), $this);
     return $join;
 }
 public static function callHook($bTest = false)
 {
     self::$test = $bTest;
     // hook aufrufen!!
     tx_rnbase_util_Misc::callHook('rn_base', 'searchbase_handleTableMapping', self::$data);
     return self::$test === false;
 }
示例#3
0
 /**
  * It is possible to overwrite this method and return an array of tab functions
  *
  * @return array
  */
 protected function getSubMenuItems()
 {
     $menuItems = tx_t3socials_network_Config::getNewtorkCommunicators();
     array_unshift($menuItems, tx_rnbase::makeInstance('tx_t3socials_mod_handler_Trigger'));
     tx_rnbase_util_Misc::callHook('t3socials', 'modCommunicator_tabItems', array('tabItems' => &$menuItems), $this);
     return $menuItems;
 }
 /**
  * Die Methode kann von Kindklassen verwendet werden.
  * @param string $template das HTML-Template
  * @param Tx_Rnbase_Domain_Model_RecordInterface $item
  * @param tx_rnbase_util_FormatUtil $formatter der zu verwendente Formatter
  * @param string $confId Pfad der TS-Config
  * @param string $marker Name des Markers
  * @return String das geparste Template
  */
 protected function prepareTemplate($template, $item, $formatter, $confId, $marker)
 {
     tx_rnbase_util_Misc::callHook('rn_base', 'mediaMarker_initRecord', array('item' => &$item, 'template' => &$template), $this);
     return $template;
 }
 /**
  * This method is taken from TYPO3\CMS\Frontend\ContentObject\FileContentObject.
  * It is a good tradition in TYPO3 that code can not be re-used. TYPO3 6.x makes
  * no difference...
  *
  * @param tx_rnbase_configurations $conf
  * @param $cObj
  * @param string $confId
  * @return array
  */
 public static function fetchFilesByTS($conf, $cObj, $confId = '')
 {
     /* @var $fileRepository \TYPO3\CMS\Core\Resource\FileRepository */
     $fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
     $fileObjects = array();
     $pics = array();
     tx_rnbase::load('tx_rnbase_util_Strings');
     // Getting the files
     // Try DAM style
     if ($conf->get($confId . 'refTable')) {
         $referencesForeignTable = $conf->getCObj()->stdWrap($conf->get($confId . 'refTable'), $conf->get($confId . 'refTable.'));
         $referencesFieldName = $conf->getCObj()->stdWrap($conf->get($confId . 'refField'), $conf->get($confId . 'refField.'));
         $referencesForeignUid = $conf->getCObj()->stdWrap($conf->get($confId . 'refUid'), $conf->get($confId . 'refUid.'));
         if (!$referencesForeignUid) {
             $referencesForeignUid = isset($cObj->data['_LOCALIZED_UID']) ? $cObj->data['_LOCALIZED_UID'] : $cObj->data['uid'];
         }
         $pics = $fileRepository->findByRelation($referencesForeignTable, $referencesFieldName, $referencesForeignUid);
     } elseif (is_array($conf->get($confId . 'references.'))) {
         $refConfId = $confId . 'references.';
         /*
         			The TypoScript could look like this:# all items related to the page.media field:
         			references {
         			table = pages
         			uid.data = page:uid
         			fieldName = media
         			}# or: sys_file_references with uid 27:
         			references = 27
         */
         // It's important that this always stays "fieldName" and not be renamed to "field" as it would otherwise collide with the stdWrap key of that name
         $referencesFieldName = $conf->getCObj()->stdWrap($conf->get($refConfId . 'fieldName'), $conf->get($refConfId . 'fieldName.'));
         if ($referencesFieldName) {
             $table = $cObj->getCurrentTable();
             if ($table === 'pages' && isset($cObj->data['_LOCALIZED_UID']) && intval($cObj->data['sys_language_uid']) > 0) {
                 $table = 'pages_language_overlay';
             }
             $referencesForeignTable = $conf->getCObj()->stdWrap($conf->get($refConfId . 'table'), $conf->get($refConfId . 'table.'));
             $referencesForeignTable = $referencesForeignTable ? $referencesForeignTable : $table;
             $referencesForeignUid = $conf->getCObj()->stdWrap($conf->get($refConfId . 'uid'), $conf->get($refConfId . 'uid.'));
             $referencesForeignUid = $referencesForeignUid ? $referencesForeignUid : (isset($cObj->data['_LOCALIZED_UID']) ? $cObj->data['_LOCALIZED_UID'] : $cObj->data['uid']);
             // Vermutlich kann hier auch nur ein Objekt geliefert werden...
             $pics = array();
             $referencesForeignUid = tx_rnbase_util_Strings::intExplode(',', $referencesForeignUid);
             foreach ($referencesForeignUid as $refForUid) {
                 if (!$conf->get($refConfId . 'treatIdAsReference')) {
                     $pics[] = $fileRepository->findFileReferenceByUid($refForUid);
                 } else {
                     $pics[] = $fileRepository->findByRelation($referencesForeignTable, $referencesFieldName, $refForUid);
                 }
             }
         } elseif ($refUids = $conf->getCObj()->stdWrap($conf->get($refConfId . 'uid'), $conf->get($refConfId . 'uid.'))) {
             if (!empty($refUids)) {
                 $refUids = tx_rnbase_util_Strings::intExplode(',', $refUids);
                 foreach ($refUids as $refUid) {
                     $pics[] = $fileRepository->findFileReferenceByUid($refUid);
                 }
             }
         }
     }
     // TODO: Hook
     tx_rnbase_util_Misc::callHook('rn_base', 'util_TSFal_fetchFilesByTS_appendMedia_hook', array('conf' => $conf, '$confId' => $confId, 'media' => &$pics), null);
     // gibt es ein Limit/offset
     $offset = intval($conf->get($confId . 'offset'));
     $limit = intval($conf->get($confId . 'limit'));
     if (!empty($pics) && $limit) {
         $pics = array_slice($pics, $offset, $limit);
     } elseif (!empty($pics) && $offset) {
         $pics = array_slice($pics, $offset);
     }
     // Die Bilder sollten jetzt noch in ein
     $fileObjects = self::convertRef2Media($pics);
     return $fileObjects;
 }
示例#6
0
 /**
  * Make a database DELETE
  *
  * @param string $tablename
  * @param string $where
  * @param array $arr
  * @return int number of rows affected
  */
 public function doDelete($tablename, $where, $arr = array())
 {
     // fallback, $arr war früher $debug
     if (!is_array($arr)) {
         $arr = array('debug' => $arr);
     }
     $debug = intval($arr['debug']) > 0;
     $database = $this->getDatabaseConnection($arr);
     tx_rnbase_util_Misc::callHook('rn_base', 'util_db_do_delete_pre', array('tablename' => $tablename, 'where' => $where, 'options' => $arr));
     if ($debug) {
         $sql = $database->DELETEquery($tablename, $where);
         tx_rnbase_util_Debug::debug($sql, 'SQL');
         tx_rnbase_util_Debug::debug(array($tablename, $where));
     }
     $storeLastBuiltQuery = $database->store_lastBuiltQuery;
     $database->store_lastBuiltQuery = TRUE;
     $this->watchOutDB($database->exec_DELETEquery($tablename, $where), $database);
     $database->store_lastBuiltQuery = $storeLastBuiltQuery;
     $affectedRows = $database->sql_affected_rows();
     tx_rnbase_util_Misc::callHook('rn_base', 'util_db_do_delete_post', array('tablename' => $tablename, 'where' => $where, 'affectedRows' => $affectedRows, 'options' => $arr));
     return $affectedRows;
 }
 /**
  * Suchanfrage an die Datenbank
  * Bei den Felder findet ein Mapping auf die eigentlichen DB-Felder statt. Dadurch werden
  * SQL-Injections erschwert und es sind JOINs möglich.
  * Field-Schema: TABLEALIAS.COLNAME
  * Beispiel: TEAM.NAME, TEAM.UID
  *
  * Options: Zusätzliche Bedingungen für Abfrage.
  * LIMIT, ORDERBY
  *
  * Sonderfall Freitextsuche über mehrere Felder:
  * Hierfür gibt es das Sonderfeld SEARCH_FIELD_JOINED. Dieses erwartet ein Array der Form
  * 'value' => 'Suchbegriff'
  * 'operator' => OP_LIKE
  * 'cols' => array(FIELD1, FIELD2,...)
  *
  * Sonderfall SQL Sub-Select:
  * Hierfür gibt es das Sonderfeld SEARCH_FIELD_CUSTOM. Dieses erwartet ein String mit dem
  * Sub-Select. Dieser wird direkt in die Query eingebunden.
  *
  * @param array $fields Felder nach denen gesucht wird
  * @param array $options
  * @return array oder int
  */
 function search($fields, $options)
 {
     if (!is_array($fields)) {
         $fields = array();
     }
     $this->_initSearch($options);
     $tableAliases = array();
     if (isset($fields[SEARCH_FIELD_JOINED])) {
         $joinedFields = $fields[SEARCH_FIELD_JOINED];
         unset($fields[SEARCH_FIELD_JOINED]);
     }
     if (isset($fields[SEARCH_FIELD_CUSTOM])) {
         $customFields = $fields[SEARCH_FIELD_CUSTOM];
         unset($fields[SEARCH_FIELD_CUSTOM]);
     }
     // Die normalen Suchfelder abarbeiten
     foreach ($fields as $field => $data) {
         // Tabelle und Spalte ermitteln
         list($tableAlias, $col) = explode('.', $field);
         $tableAliases[$tableAlias][$col] = $data;
     }
     // Prüfen, ob in orderby noch andere Tabellen liegen
     $orderbyArr = $options['orderby'];
     if (is_array($orderbyArr)) {
         $aliases = array_keys($orderbyArr);
         foreach ($aliases as $alias) {
             if (strstr($alias, SEARCH_FIELD_CUSTOM)) {
                 continue;
             }
             // CUSTOM ignorieren
             list($tableAlias, $col) = explode('.', $alias);
             if (!array_key_exists($tableAlias, $tableAliases)) {
                 $tableAliases[$tableAlias] = array();
             }
         }
     }
     if (is_array($joinedFields)) {
         reset($joinedFields);
         foreach ($joinedFields as $key => $joinedField) {
             // Für die JOINED-Fields müssen die Tabellen gesetzt werden, damit der SQL-JOIN passt
             foreach ($joinedField['cols'] as $field) {
                 list($tableAlias, $col) = explode('.', $field);
                 if (!isset($tableAliases[$tableAlias])) {
                     $tableAliases[$tableAlias] = array();
                 }
                 $joinedFields[$key]['fields'][] = ($this->useAlias() ? $tableAlias : $this->tableMapping[$tableAlias]) . '.' . strtolower($col);
             }
         }
     }
     // Deprecated: Diese Option nicht verwenden. Dafür gibt es den Hook!
     if (is_array($additionalTableAliases = $options['additionalTableAliases'])) {
         foreach ($additionalTableAliases as $additionalTableAlias) {
             if (!isset($tableAliases[$additionalTableAlias])) {
                 $tableAliases[$additionalTableAlias] = array();
             }
         }
     }
     tx_rnbase_util_Misc::callHook('rn_base', 'searchbase_handleTableMapping', array('tableAliases' => &$tableAliases, 'joinedFields' => &$joinedFields, 'customFields' => &$customFields, 'options' => &$options, 'tableMappings' => &$this->tableMapping), $this);
     $what = $this->getWhat($options, $tableAliases);
     $from = $this->getFrom($options, $tableAliases);
     $where = '1=1';
     foreach ($tableAliases as $tableAlias => $colData) {
         foreach ($colData as $col => $data) {
             foreach ($data as $operator => $value) {
                 if (is_array($value)) {
                     // There is more then one value to test against column
                     $joinedValues = $value[SEARCH_FIELD_JOINED];
                     if (!is_array($joinedValues)) {
                         tx_rnbase_util_Misc::mayday('JOINED field required data array. Check up your search config.', 'rn_base');
                     }
                     $joinedValues = array_values($joinedValues);
                     for ($i = 0, $cnt = count($joinedValues); $i < $cnt; $i++) {
                         $wherePart = Tx_Rnbase_Database_Connection::getInstance()->setSingleWhereField($this->useAlias() ? $tableAlias : $this->tableMapping[$tableAlias], $operator, $col, $joinedValues[$i]);
                         if (trim($wherePart) !== '') {
                             $where .= ' AND ' . $wherePart;
                         }
                     }
                 } else {
                     $wherePart = Tx_Rnbase_Database_Connection::getInstance()->setSingleWhereField($this->useAlias() ? $tableAlias : $this->tableMapping[$tableAlias], $operator, $col, $value);
                     if (trim($wherePart) !== '') {
                         $where .= ' AND ' . $wherePart;
                     }
                 }
             }
         }
     }
     // Jetzt die Freitextsuche über mehrere Felder
     if (is_array($joinedFields)) {
         foreach ($joinedFields as $joinedField) {
             // Ignore invalid queries
             if (!isset($joinedField['value']) || !isset($joinedField['operator']) || !isset($joinedField['fields']) || !$joinedField['fields']) {
                 continue;
             }
             if ($joinedField['operator'] == OP_INSET_INT) {
                 // Values splitten und einzelne Abfragen mit OR verbinden
                 $addWhere = Tx_Rnbase_Database_Connection::getInstance()->searchWhere($joinedField['value'], implode(',', $joinedField['fields']), 'FIND_IN_SET_OR');
             } else {
                 $addWhere = Tx_Rnbase_Database_Connection::getInstance()->searchWhere($joinedField['value'], implode(',', $joinedField['fields']), $joinedField['operator']);
             }
             if ($addWhere) {
                 $where .= ' AND ' . $addWhere;
             }
         }
     }
     if (isset($customFields)) {
         $where .= ' AND ' . $customFields;
     }
     if ($options['enableFieldsForAdditionalTableAliases']) {
         $where .= $this->setEnableFieldsForAdditionalTableAliases($tableAliases, $options);
     }
     $sqlOptions = array();
     $sqlOptions['where'] = $where;
     if ($options['pidlist']) {
         $sqlOptions['pidlist'] = $options['pidlist'];
     }
     if ($options['recursive']) {
         $sqlOptions['recursive'] = $options['recursive'];
     }
     if ($options['limit']) {
         $sqlOptions['limit'] = $options['limit'];
     }
     if ($options['offset']) {
         $sqlOptions['offset'] = $options['offset'];
     }
     if ($options['enablefieldsoff']) {
         $sqlOptions['enablefieldsoff'] = $options['enablefieldsoff'];
     }
     if ($options['enablefieldsbe']) {
         $sqlOptions['enablefieldsbe'] = $options['enablefieldsbe'];
     }
     if ($options['enablefieldsfe']) {
         $sqlOptions['enablefieldsfe'] = $options['enablefieldsfe'];
     }
     if ($options['groupby']) {
         $sqlOptions['groupby'] = $options['groupby'];
     }
     if ($options['having']) {
         $sqlOptions['having'] = $options['having'];
     }
     if ($options['callback']) {
         $sqlOptions['callback'] = $options['callback'];
     }
     if ($options['ignorei18n']) {
         $sqlOptions['ignorei18n'] = $options['ignorei18n'];
     }
     if ($options['i18nolmode']) {
         $sqlOptions['i18nolmode'] = $options['i18nolmode'];
     }
     if ($options['i18n']) {
         $sqlOptions['i18n'] = $options['i18n'];
     }
     if ($options['ignoreworkspace']) {
         $sqlOptions['ignoreworkspace'] = $options['ignoreworkspace'];
     }
     if ($options['sqlonly']) {
         $sqlOptions['sqlonly'] = $options['sqlonly'];
     }
     if ($options['union']) {
         $sqlOptions['union'] = $options['union'];
     }
     if ($options['array_object']) {
         $sqlOptions['array_object'] = $options['array_object'];
     }
     if (!isset($options['count']) && is_array($options['orderby'])) {
         // Aus dem Array einen String bauen
         $orderby = array();
         if (array_key_exists('RAND', $options['orderby']) && $options['orderby']['RAND']) {
             $orderby[] = 'RAND()';
         } else {
             if (array_key_exists('RAND', $options['orderby'])) {
                 unset($options['orderby']['RAND']);
             }
             foreach ($options['orderby'] as $field => $order) {
                 // free Order-Clause
                 if (strstr($field, SEARCH_FIELD_CUSTOM)) {
                     $orderby[] = $order;
                     continue;
                 }
                 list($tableAlias, $col) = explode('.', $field);
                 $tableAlias = $this->useAlias() ? $tableAlias : $this->tableMapping[$tableAlias];
                 if ($tableAlias) {
                     $orderby[] = $tableAlias . '.' . strtolower($col) . ' ' . (strtoupper($order) == 'DESC' ? 'DESC' : 'ASC');
                 } else {
                     $orderby[] = $field . ' ' . (strtoupper($order) == 'DESC' ? 'DESC' : 'ASC');
                 }
             }
         }
         $sqlOptions['orderby'] = implode(',', $orderby);
     }
     if (!isset($options['count']) && (!(isset($options['what']) || isset($options['groupby']) || isset($options['sqlonly'])) || isset($options['forcewrapper']))) {
         // der Filter kann ebenfalls eine Klasse setzen. Diese hat Vorrang.
         $sqlOptions['wrapperclass'] = $options['wrapperclass'] ? $options['wrapperclass'] : $this->getGenericWrapperClass();
     }
     // if we have to do a count and there still is a count in the custom what
     // or there is a having or a groupby
     // so we have to wrap the query into a subquery to count the results
     if (!$options['disableCountWrap'] && isset($options['count']) && (isset($options['what']) && strpos(strtoupper($options['what']), 'COUNT(') !== FALSE || $options['groupby'] || $options['having'])) {
         $sqlOptions['sqlonly'] = 1;
         $query = Tx_Rnbase_Database_Connection::getInstance()->doSelect($what, $from, $sqlOptions, $options['debug'] ? 1 : 0);
         $what = 'COUNT(*) AS cnt';
         $from = '(' . $query . ') AS COUNTWRAP';
         $sqlOptions = array('enablefieldsoff' => TRUE, 'sqlonly' => empty($options['sqlonly']) ? 0 : $options['sqlonly']);
     }
     $result = Tx_Rnbase_Database_Connection::getInstance()->doSelect($what, $from, $sqlOptions, $options['debug'] ? 1 : 0);
     if (isset($options['sqlonly'])) {
         return $result;
     }
     // else:
     return isset($options['count']) ? $result[0]['cnt'] : $result;
 }