function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters) { $parentNodeID = $namedParameters['parent_node_id']; switch ($operatorName) { case 'ezkeywordlist': include_once 'lib/ezdb/classes/ezdb.php'; $db = eZDB::instance(); if ($parentNodeID) { $node = eZContentObjectTreeNode::fetch($parentNodeID); if ($node) { $pathString = "AND ezcontentobject_tree.path_string like '" . $node->attribute('path_string') . "%'"; } $parentNodeIDSQL = "AND ezcontentobject_tree.node_id != " . (int) $parentNodeID; } $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(true, false); $limitation = false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); $versionNameJoins = " AND ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id AND\n ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version AND "; $languageFilter = " AND " . eZContentLanguage::languagesSQLFilter('ezcontentobject'); $versionNameJoins .= eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject'); $quotedClassIdentifiers = array(); foreach ((array) $namedParameters['class_identifier'] as $classIdentifier) { $quotedClassIdentifiers[] = "'" . $db->escapeString($classIdentifier) . "'"; } $rs = $db->arrayQuery("SELECT DISTINCT ezkeyword.keyword\n FROM ezkeyword_attribute_link,\n ezkeyword,\n ezcontentobject,\n ezcontentobject_name,\n ezcontentobject_attribute,\n ezcontentobject_tree,\n ezcontentclass\n {$sqlPermissionChecking['from']}\n WHERE ezkeyword.id = ezkeyword_attribute_link.keyword_id\n AND ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id\n AND ezcontentobject_tree.contentobject_id = ezcontentobject_attribute.contentobject_id\n AND ezkeyword.class_id = ezcontentclass.id\n AND " . $db->generateSQLINStatement($quotedClassIdentifiers, 'ezcontentclass.identifier') . "\n {$pathString}\n {$parentNodeIDSQL} " . ($namedParameters['depth'] > 0 ? "AND ezcontentobject_tree.depth=" . (int) $namedParameters['depth'] : '') . "\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}\n {$languageFilter}\n {$versionNameJoins}\n ORDER BY ezkeyword.keyword ASC"); $operatorValue = $rs; break; } }
static function sqlAppendFilter($languageTable = 'ezcontentclass') { $def = eZContentClassName::definition(); $languageListTable = $def['name']; $sqlFilter = array('nameField' => ", {$languageListTable}.name", 'from' => ", {$languageListTable}", 'where' => "AND {$languageTable}.id = {$languageListTable}.contentclass_id AND\n {$languageTable}.version = {$languageListTable}.contentclass_version AND " . eZContentLanguage::sqlFilter($languageListTable, $languageTable), 'orderBy' => "{$languageListTable}.name"); return $sqlFilter; }
/** * Fetches content object states by conditions. * * The content object states are fetched in the right language, depending on the list of prioritized languages * of the site access. * * @param $conditions * @param $limit * @param $offset * @return array */ private static function fetchByConditions($conditions, $limit, $offset) { $db = eZDB::instance(); $defaultConditions = array('ezcobj_state.group_id=ezcobj_state_group.id', 'ezcobj_state_language.contentobject_state_id=ezcobj_state.id', eZContentLanguage::languagesSQLFilter('ezcobj_state'), eZContentLanguage::sqlFilter('ezcobj_state_language', 'ezcobj_state')); $conditions = array_merge($conditions, $defaultConditions); $conditionsSQL = implode(' AND ', $conditions); $sql = "SELECT ezcobj_state.*, ezcobj_state_language.* " . "FROM ezcobj_state, ezcobj_state_group, ezcobj_state_language " . "WHERE {$conditionsSQL} " . "ORDER BY ezcobj_state.priority"; $rows = $db->arrayQuery($sql, array('limit' => $limit, 'offset' => $offset)); $states = array(); foreach ($rows as $row) { $state = new eZContentObjectState($row); $stateLanguage = new eZContentObjectStateLanguage($row); $state->setLanguageObject($stateLanguage); $states[] = $state; } return $states; }
function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters) { $parentNodeID = $namedParameters['parent_node_id']; switch ($operatorName) { case 'ezkeywordlist': include_once 'lib/ezdb/classes/ezdb.php'; $db = eZDB::instance(); if ($parentNodeID) { $node = eZContentObjectTreeNode::fetch($parentNodeID); if ($node) { $pathString = "AND ezcontentobject_tree.path_string like '" . $node->attribute('path_string') . "%'"; } $parentNodeIDSQL = "AND ezcontentobject_tree.node_id != " . (int) $parentNodeID; } $limitation = false; $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL(eZContentObjectTreeNode::getLimitationList($limitation)); // eZContentObjectTreeNode::classIDByIdentifier() might need to be used for eZ Publish < 4.1 $classIDs = eZContentClass::classIDByIdentifier($namedParameters['class_identifier']); $operatorValue = $db->arrayQuery("SELECT DISTINCT ezkeyword.keyword\n FROM ezkeyword\n JOIN ezkeyword_attribute_link ON ezkeyword.id = ezkeyword_attribute_link.keyword_id\n JOIN ezcontentobject_attribute ON ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id\n JOIN ezcontentobject ON ezcontentobject_attribute.contentobject_id = ezcontentobject.id\n JOIN ezcontentobject_name ON ezcontentobject.id = ezcontentobject_name.contentobject_id\n JOIN ezcontentobject_tree ON ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version\n {$sqlPermissionChecking['from']}\n WHERE " . eZContentLanguage::languagesSQLFilter('ezcontentobject') . "\n AND " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject') . (empty($classIDs) ? '' : ' AND ' . $db->generateSQLINStatement($classIDs, 'ezkeyword.class_id')) . "\n {$pathString}\n {$parentNodeIDSQL} " . ($namedParameters['depth'] > 0 ? "AND ezcontentobject_tree.depth=" . (int) $namedParameters['depth'] : '') . "\n " . eZContentObjectTreeNode::createShowInvisibleSQLString(true, false) . "\n {$sqlPermissionChecking['where']}\n ORDER BY ezkeyword.keyword ASC"); break; } }
/** * Returns the SQL for custom fetching of tags with eZPersistentObject * * @static * * @param mixed $params * @param bool $mainTranslation * @param mixed $locale * * @return string */ public static function fetchCustomCondsSQL($params, $mainTranslation = false, $locale = false) { $customConds = is_array($params) && !empty($params) ? " AND " : " WHERE "; $customConds .= " eztags.id = eztags_keyword.keyword_id "; if ($mainTranslation !== false) { $customConds .= " AND eztags.main_language_id + MOD( eztags.language_mask, 2 ) = eztags_keyword.language_id "; } else { if (is_string($locale)) { $db = eZDB::instance(); $customConds .= " AND " . eZContentLanguage::languagesSQLFilter('eztags') . " "; $customConds .= " AND eztags_keyword.locale = '" . $db->escapeString($locale) . "' "; } else { $customConds .= " AND " . eZContentLanguage::languagesSQLFilter('eztags') . " "; $customConds .= " AND " . eZContentLanguage::sqlFilter('eztags_keyword', 'eztags') . " "; } } return $customConds; }
public function search($searchText, $params = array(), $searchTypes = array()) { if (count($searchTypes) == 0) { $searchTypes['general'] = array(); $searchTypes['subtype'] = array(); $searchTypes['and'] = array(); } else { if (!isset($searchTypes['general'])) { $searchTypes['general'] = array(); } } $allowSearch = true; if (trim($searchText) == '') { $ini = eZINI::instance(); if ($ini->variable('SearchSettings', 'AllowEmptySearch') != 'enabled') { $allowSearch = false; } if (isset($params['AllowEmptySearch'])) { $allowSearch = $params['AllowEmptySearch']; } } if ($allowSearch) { $searchText = $this->normalizeText($searchText, false); $db = eZDB::instance(); $nonExistingWordArray = array(); $searchTypeMap = array('class' => 'SearchContentClassID', 'publishdate' => 'SearchDate', 'subtree' => 'SearchSubTreeArray'); foreach ($searchTypes['general'] as $searchType) { $params[$searchTypeMap[$searchType['subtype']]] = $searchType['value']; } if (isset($params['SearchOffset'])) { $searchOffset = $params['SearchOffset']; } else { $searchOffset = 0; } if (isset($params['SearchLimit'])) { $searchLimit = $params['SearchLimit']; } else { $searchLimit = 10; } if (isset($params['SearchContentClassID'])) { $searchContentClassID = $params['SearchContentClassID']; } else { $searchContentClassID = -1; } if (isset($params['SearchSectionID'])) { $searchSectionID = $params['SearchSectionID']; } else { $searchSectionID = -1; } if (isset($params['SearchDate'])) { $searchDate = $params['SearchDate']; } else { $searchDate = -1; } if (isset($params['SearchTimestamp'])) { $searchTimestamp = $params['SearchTimestamp']; } else { $searchTimestamp = false; } if (isset($params['SearchContentClassAttributeID'])) { $searchContentClassAttributeID = $params['SearchContentClassAttributeID']; } else { $searchContentClassAttributeID = -1; } if (isset($params['SearchSubTreeArray'])) { $subTreeArray = $params['SearchSubTreeArray']; } else { $subTreeArray = array(); } if (isset($params['SortArray'])) { $sortArray = $params['SortArray']; } else { $sortArray = array(); } $ignoreVisibility = isset($params['IgnoreVisibility']) ? $params['IgnoreVisibility'] : false; // strip multiple spaces $searchText = preg_replace("(\\s+)", " ", $searchText); // find the phrases /* $numQuotes = substr_count( $searchText, "\"" ); $phraseTextArray = array(); $fullText = $searchText; $nonPhraseText =''; // $fullText = ''; $postPhraseText = $fullText; $pos = 0; if ( ( $numQuotes > 0 ) and ( ( $numQuotes % 2 ) == 0 ) ) { for ( $i = 0; $i < ( $numQuotes / 2 ); $i ++ ) { $quotePosStart = strpos( $searchText, '"', $pos ); $quotePosEnd = strpos( $searchText, '"', $quotePosStart + 1 ); $prePhraseText = substr( $searchText, $pos, $quotePosStart - $pos ); $postPhraseText = substr( $searchText, $quotePosEnd +1 ); $phraseText = substr( $searchText, $quotePosStart + 1, $quotePosEnd - $quotePosStart - 1 ); $phraseTextArray[] = $phraseText; // $fullText .= $prePhraseText; $nonPhraseText .= $prePhraseText; $pos = $quotePosEnd + 1; } } $nonPhraseText .= $postPhraseText; */ $phrasesResult = $this->getPhrases($searchText); $phraseTextArray = $phrasesResult['phrases']; $nonPhraseText = $phrasesResult['nonPhraseText']; $fullText = $phrasesResult['fullText']; $sectionQuery = ''; if (is_numeric($searchSectionID) and $searchSectionID > 0) { $sectionQuery = "ezsearch_object_word_link.section_id = '{$searchSectionID}' AND "; } else { if (is_array($searchSectionID)) { // Build query for searching in an array of sections $sectionQuery = $db->generateSQLINStatement($searchSectionID, 'ezsearch_object_word_link.section_id', false, false, 'int') . " AND "; } } $searchDateQuery = ''; if (is_numeric($searchDate) and $searchDate > 0 or $searchTimestamp) { $date = new eZDateTime(); $timestamp = $date->timeStamp(); $day = $date->attribute('day'); $month = $date->attribute('month'); $year = $date->attribute('year'); $publishedDateStop = false; if ($searchTimestamp) { if (is_array($searchTimestamp)) { $publishedDate = (int) $searchTimestamp[0]; $publishedDateStop = (int) $searchTimestamp[1]; } else { $publishedDate = (int) $searchTimestamp; } } else { switch ($searchDate) { case 1: $adjustment = 24 * 60 * 60; //seconds for one day $publishedDate = $timestamp - $adjustment; break; case 2: $adjustment = 7 * 24 * 60 * 60; //seconds for one week $publishedDate = $timestamp - $adjustment; break; case 3: $adjustment = 31 * 24 * 60 * 60; //seconds for one month $publishedDate = $timestamp - $adjustment; break; case 4: $adjustment = 3 * 31 * 24 * 60 * 60; //seconds for three months $publishedDate = $timestamp - $adjustment; break; case 5: $adjustment = 365 * 24 * 60 * 60; //seconds for one year $publishedDate = $timestamp - $adjustment; break; default: $publishedDate = $date->timeStamp(); } } $searchDateQuery = "ezsearch_object_word_link.published >= '{$publishedDate}' AND "; if ($publishedDateStop) { $searchDateQuery .= "ezsearch_object_word_link.published <= '{$publishedDateStop}' AND "; } $this->GeneralFilter['searchDateQuery'] = $searchDateQuery; } $classQuery = ""; if (is_numeric($searchContentClassID) and $searchContentClassID > 0) { // Build query for searching in one class $classQuery = "ezsearch_object_word_link.contentclass_id = '{$searchContentClassID}' AND "; $this->GeneralFilter['classAttributeQuery'] = $classQuery; } else { if (is_array($searchContentClassID)) { // Build query for searching in a number of classes $classString = $db->generateSQLINStatement($searchContentClassID, 'ezsearch_object_word_link.contentclass_id', false, false, 'int'); $classQuery = "{$classString} AND "; $this->GeneralFilter['classAttributeQuery'] = $classQuery; } } $classAttributeQuery = ""; if (is_numeric($searchContentClassAttributeID) and $searchContentClassAttributeID > 0) { $classAttributeQuery = "ezsearch_object_word_link.contentclass_attribute_id = '{$searchContentClassAttributeID}' AND "; } else { if (is_array($searchContentClassAttributeID)) { // Build query for searching in a number of attributes $classAttributeQuery = $db->generateSQLINStatement($searchContentClassAttributeID, 'ezsearch_object_word_link.contentclass_attribute_id', false, false, 'int') . ' AND '; } } // Get the total number of objects $totalObjectCount = $this->fetchTotalObjectCount(); $searchPartsArray = array(); $wordIDHash = array(); $wildCardCount = 0; if (trim($searchText) != '') { $wordIDArrays = $this->prepareWordIDArrays($searchText); $wordIDArray = $wordIDArrays['wordIDArray']; $wordIDHash = $wordIDArrays['wordIDHash']; $wildIDArray = $wordIDArrays['wildIDArray']; $wildCardCount = $wordIDArrays['wildCardCount']; $searchPartsArray = $this->buildSearchPartArray($phraseTextArray, $nonPhraseText, $wordIDHash, $wildIDArray); } /// OR search, not used in this version $doOrSearch = false; if ($doOrSearch == true) { // build fulltext search SQL part $searchWordArray = $this->splitString($fullText); $fullTextSQL = ""; if (count($searchWordArray) > 0) { $i = 0; // Build the word query string foreach ($searchWordArray as $searchWord) { $wordID = null; if (isset($wordIDHash[$searchWord])) { $wordID = $wordIDHash[$searchWord]['id']; } if (is_numeric($wordID) and $wordID > 0) { if ($i == 0) { $fullTextSQL .= "ezsearch_object_word_link.word_id='{$wordID}' "; } else { $fullTextSQL .= " OR ezsearch_object_word_link.word_id='{$wordID}' "; } } else { $nonExistingWordArray[] = $searchWord; } $i++; } $fullTextSQL = " ( {$fullTextSQL} ) AND "; } } // Search only in specific sub trees $subTreeSQL = ""; $subTreeTable = ""; if (count($subTreeArray) > 0) { // Fetch path_string value to use when searching subtrees $i = 0; $doSubTreeSearch = false; $subTreeNodeSQL = ''; foreach ($subTreeArray as $nodeID) { if (is_numeric($nodeID) and $nodeID > 0) { $subTreeNodeSQL .= " {$nodeID}"; if (isset($subTreeArray[$i + 1]) and is_numeric($subTreeArray[$i + 1])) { $subTreeNodeSQL .= ", "; } $doSubTreeSearch = true; } $i++; } if ($doSubTreeSearch == true) { $subTreeNodeSQL = "( " . $subTreeNodeSQL; // $subTreeTable = ", ezcontentobject_tree "; $subTreeTable = ''; $subTreeNodeSQL .= " ) "; $nodeQuery = "SELECT node_id, path_string FROM ezcontentobject_tree WHERE node_id IN {$subTreeNodeSQL}"; // Build SQL subtre search query $subTreeSQL = " ( "; $nodeArray = $db->arrayQuery($nodeQuery); $i = 0; foreach ($nodeArray as $node) { $pathString = $node['path_string']; $subTreeSQL .= " ezcontentobject_tree.path_string like '{$pathString}%' "; if ($i < count($nodeArray) - 1) { $subTreeSQL .= " OR "; } $i++; } $subTreeSQL .= " ) AND "; $this->GeneralFilter['subTreeTable'] = $subTreeTable; $this->GeneralFilter['subTreeSQL'] = $subTreeSQL; } } $limitation = false; if (isset($params['Limitation'])) { $limitation = $params['Limitation']; } $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); $this->GeneralFilter['sqlPermissionChecking'] = $sqlPermissionChecking; $versionNameJoins = " AND " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject'); /// Only support AND search at this time // build fulltext search SQL part $searchWordArray = $this->splitString($fullText); $searchWordCount = count($searchWordArray); $fullTextSQL = ""; $stopWordArray = array(); $ini = eZINI::instance(); $tmpTableCount = 0; $i = 0; foreach ($searchTypes['and'] as $searchType) { $methodName = $this->constructMethodName($searchType); $intermediateResult = $this->callMethod($methodName, array($searchType)); if ($intermediateResult == false) { // cleanup temp tables $db->dropTempTableList($sqlPermissionChecking['temp_tables']); return array("SearchResult" => array(), "SearchCount" => 0, "StopWordArray" => array()); } } // Do not execute search if site.ini:[SearchSettings]->AllowEmptySearch is enabled, but no conditions are set. if (!$searchDateQuery && !$sectionQuery && !$classQuery && !$classAttributeQuery && !$searchPartsArray && !$subTreeSQL) { // cleanup temp tables $db->dropTempTableList($sqlPermissionChecking['temp_tables']); return array("SearchResult" => array(), "SearchCount" => 0, "StopWordArray" => array()); } $i = $this->TempTablesCount; // Loop every word and insert result in temporary table // Determine whether we should search invisible nodes. $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(!$ignoreVisibility); foreach ($searchPartsArray as $searchPart) { $stopWordThresholdValue = 100; if ($ini->hasVariable('SearchSettings', 'StopWordThresholdValue')) { $stopWordThresholdValue = $ini->variable('SearchSettings', 'StopWordThresholdValue'); } $stopWordThresholdPercent = 60; if ($ini->hasVariable('SearchSettings', 'StopWordThresholdPercent')) { $stopWordThresholdPercent = $ini->variable('SearchSettings', 'StopWordThresholdPercent'); } $searchThresholdValue = $totalObjectCount; if ($totalObjectCount > $stopWordThresholdValue) { $searchThresholdValue = (int) ($totalObjectCount * ($stopWordThresholdPercent / 100)); } // do not search words that are too frequent if ($searchPart['object_count'] < $searchThresholdValue) { $tmpTableCount++; $searchPartText = $searchPart['sql_part']; if ($i == 0) { $table = $db->generateUniqueTempTableName('ezsearch_tmp_%', 0); $this->saveCreatedTempTableName(0, $table); $db->createTempTable("CREATE TEMPORARY TABLE {$table} ( contentobject_id int primary key not null, published int )"); $db->query("INSERT INTO {$table} SELECT DISTINCT ezsearch_object_word_link.contentobject_id, ezsearch_object_word_link.published\n FROM ezcontentobject\n INNER JOIN ezsearch_object_word_link ON (ezsearch_object_word_link.contentobject_id = ezcontentobject.id)\n {$subTreeTable}\n INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n {$sqlPermissionChecking['from']}\n WHERE\n {$searchDateQuery}\n {$sectionQuery}\n {$classQuery}\n {$classAttributeQuery}\n {$searchPartText}\n {$subTreeSQL}\n ezcontentclass.version = '0' AND\n ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}", eZDBInterface::SERVER_SLAVE); } else { $table = $db->generateUniqueTempTableName('ezsearch_tmp_%', $i); $this->saveCreatedTempTableName($i, $table); $tmpTable0 = $this->getSavedTempTableName(0); $db->createTempTable("CREATE TEMPORARY TABLE {$table} ( contentobject_id int primary key not null, published int )"); $db->query("INSERT INTO {$table} SELECT DISTINCT ezsearch_object_word_link.contentobject_id, ezsearch_object_word_link.published\n FROM\n ezcontentobject\n INNER JOIN ezsearch_object_word_link ON (ezsearch_object_word_link.contentobject_id = ezcontentobject.id)\n {$subTreeTable}\n INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n INNER JOIN {$tmpTable0} ON ({$tmpTable0}.contentobject_id = ezsearch_object_word_link.contentobject_id)\n {$sqlPermissionChecking['from']}\n WHERE\n {$searchDateQuery}\n {$sectionQuery}\n {$classQuery}\n {$classAttributeQuery}\n {$searchPartText}\n {$subTreeSQL}\n ezcontentclass.version = '0' AND\n ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}", eZDBInterface::SERVER_SLAVE); } $i++; } else { $stopWordArray[] = array('word' => $searchPart['text']); } } if (count($searchPartsArray) === 0 && $this->TempTablesCount == 0) { $table = $db->generateUniqueTempTableName('ezsearch_tmp_%', 0); $this->saveCreatedTempTableName(0, $table); $db->createTempTable("CREATE TEMPORARY TABLE {$table} ( contentobject_id int primary key not null, published int )"); $db->query("INSERT INTO {$table} SELECT DISTINCT ezsearch_object_word_link.contentobject_id, ezsearch_object_word_link.published\n FROM ezcontentobject\n INNER JOIN ezsearch_object_word_link ON (ezsearch_object_word_link.contentobject_id = ezcontentobject.id)\n {$subTreeTable}\n INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n {$sqlPermissionChecking['from']}\n WHERE\n {$searchDateQuery}\n {$sectionQuery}\n {$classQuery}\n {$classAttributeQuery}\n {$subTreeSQL}\n ezcontentclass.version = '0' AND\n ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}", eZDBInterface::SERVER_SLAVE); $this->TempTablesCount = 1; $i = $this->TempTablesCount; } $nonExistingWordCount = count(array_unique($searchWordArray)) - count($wordIDHash) - $wildCardCount; $excludeWordCount = $searchWordCount - count($stopWordArray); if (count($stopWordArray) + $nonExistingWordCount == $searchWordCount && $this->TempTablesCount == 0) { // No words to search for, return empty result // cleanup temp tables $db->dropTempTableList($sqlPermissionChecking['temp_tables']); $db->dropTempTableList($this->getSavedTempTablesList()); return array("SearchResult" => array(), "SearchCount" => 0, "StopWordArray" => $stopWordArray); } $tmpTablesFrom = ""; $tmpTablesWhere = ""; /// tmp tables $tmpTableCount = $i; for ($i = 0; $i < $tmpTableCount; $i++) { $tmpTablesFrom .= $this->getSavedTempTableName($i); if ($i < $tmpTableCount - 1) { $tmpTablesFrom .= ", "; } } $tmpTablesSeparator = ''; if ($tmpTableCount > 0) { $tmpTablesSeparator = ', '; } $tmpTable0 = $this->getSavedTempTableName(0); for ($i = 1; $i < $tmpTableCount; $i++) { $tmpTableI = $this->getSavedTempTableName($i); $tmpTablesWhere .= " {$tmpTable0}.contentobject_id={$tmpTableI}.contentobject_id "; if ($i < $tmpTableCount - 1) { $tmpTablesWhere .= " AND "; } } $tmpTablesWhereExtra = ''; if ($tmpTableCount > 0) { $tmpTablesWhereExtra = "ezcontentobject.id={$tmpTable0}.contentobject_id AND"; } $and = ""; if ($tmpTableCount > 1) { $and = " AND "; } // Generate ORDER BY SQL $orderBySQLArray = $this->buildSortSQL($sortArray); $orderByFieldsSQL = $orderBySQLArray['sortingFields']; $sortWhereSQL = $orderBySQLArray['whereSQL']; $sortFromSQL = $orderBySQLArray['fromSQL']; $sortSelectSQL = $orderBySQLArray['selectSQL']; // Fetch data from table $searchQuery = ''; $searchQuery = "SELECT DISTINCT ezcontentobject.*, ezcontentclass.serialized_name_list as class_serialized_name_list,\n ezcontentobject_tree.*, ezcontentobject_name.name as name,\n ezcontentobject_name.real_translation {$sortSelectSQL}\n FROM\n {$tmpTablesFrom} {$tmpTablesSeparator}\n ezcontentobject\n INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id )\n INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n INNER JOIN ezcontentobject_name ON (\n ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND\n ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version\n )\n {$sortFromSQL}\n WHERE\n {$tmpTablesWhere} {$and}\n {$tmpTablesWhereExtra}\n ezcontentclass.version = '0' AND\n ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id AND\n " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject') . "\n {$showInvisibleNodesCond}\n {$sortWhereSQL}\n ORDER BY {$orderByFieldsSQL}"; // Count query $languageCond = eZContentLanguage::languagesSQLFilter('ezcontentobject'); if ($tmpTableCount == 0) { $searchCountQuery = "SELECT count( DISTINCT ezcontentobject.id ) AS count\n FROM\n ezcontentobject,\n ezcontentobject_tree\n WHERE\n ezcontentobject.id = ezcontentobject_tree.contentobject_id and\n ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id\n AND {$languageCond}\n {$showInvisibleNodesCond}"; } else { $searchCountQuery = "SELECT count( DISTINCT ezcontentobject.id ) AS count\n FROM {$tmpTablesFrom} {$tmpTablesSeparator}\n ezcontentobject\n WHERE {$tmpTablesWhere} {$and}\n {$tmpTablesWhereExtra}\n {$languageCond}"; } $objectRes = array(); $searchCount = 0; if ($nonExistingWordCount <= 0) { // execute search query $objectResArray = $db->arrayQuery($searchQuery, array("limit" => $searchLimit, "offset" => $searchOffset), eZDBInterface::SERVER_SLAVE); // execute search count query $objectCountRes = $db->arrayQuery($searchCountQuery, array(), eZDBInterface::SERVER_SLAVE); $objectRes = eZContentObjectTreeNode::makeObjectsArray($objectResArray); $searchCount = $objectCountRes[0]['count']; } else { $objectRes = array(); } // Drop tmp tables $db->dropTempTableList($sqlPermissionChecking['temp_tables']); $db->dropTempTableList($this->getSavedTempTablesList()); return array("SearchResult" => $objectRes, "SearchCount" => $searchCount, "StopWordArray" => $stopWordArray); } else { return array("SearchResult" => array(), "SearchCount" => 0, "StopWordArray" => array()); } }
/** * Returns a list or the number of nodes from the trash * * @see eZContentObjectTreeNode::subTreeByNodeID() * * @param array|bool $params * @param bool $asCount If true, returns the number of items in the trash * @return array|int|null */ static function trashList($params = false, $asCount = false) { if ($params === false) { $params = array('Offset' => false, 'Limit' => false, 'SortBy' => false, 'AttributeFilter' => false); } $offset = isset($params['Offset']) && is_numeric($params['Offset']) ? $params['Offset'] : false; $limit = isset($params['Limit']) && is_numeric($params['Limit']) ? $params['Limit'] : false; $asObject = isset($params['AsObject']) ? $params['AsObject'] : true; $objectNameFilter = isset($params['ObjectNameFilter']) ? $params['ObjectNameFilter'] : false; $sortBy = isset($params['SortBy']) && is_array($params['SortBy']) ? $params['SortBy'] : array(array('name')); if ($asCount) { $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings(false); } else { $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings($sortBy, 'ezcot'); } $attributeFilter = eZContentObjectTreeNode::createAttributeFilterSQLStrings($params['AttributeFilter'], $sortingInfo); if ($attributeFilter === false) { return null; } $objectNameFilterSQL = eZContentObjectTreeNode::createObjectNameFilterConditionSQLString($objectNameFilter); $limitation = isset($params['Limitation']) && is_array($params['Limitation']) ? $params['Limitation'] : false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList, 'ezcontentobject_trash', 'ezcot'); if ($asCount) { $query = "SELECT count(*) as count "; } else { $query = "SELECT\n ezcontentobject.*,\n ezcot.*,\n ezcontentclass.serialized_name_list as class_serialized_name_list,\n ezcontentclass.identifier as class_identifier,\n ezcontentobject_name.name as name,\n ezcontentobject_name.real_translation\n {$sortingInfo['attributeTargetSQL']} "; } $query .= "FROM\n ezcontentobject_trash ezcot\n INNER JOIN ezcontentobject ON ezcot.contentobject_id = ezcontentobject.id\n INNER JOIN ezcontentclass ON ezcontentclass.version = 0 AND ezcontentclass.id = ezcontentobject.contentclass_id\n INNER JOIN ezcontentobject_name ON (\n ezcot.contentobject_id = ezcontentobject_name.contentobject_id AND\n ezcot.contentobject_version = ezcontentobject_name.content_version\n )\n {$sortingInfo['attributeFromSQL']}\n {$attributeFilter['from']}\n {$sqlPermissionChecking['from']}\n WHERE\n {$sortingInfo['attributeWhereSQL']}\n {$attributeFilter['where']}\n " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject') . "\n {$sqlPermissionChecking['where']}\n {$objectNameFilterSQL}\n AND " . eZContentLanguage::languagesSQLFilter('ezcontentobject'); if (!$asCount && $sortingInfo['sortingFields'] && strlen($sortingInfo['sortingFields']) > 5) { $query .= " ORDER BY {$sortingInfo['sortingFields']}"; } $db = eZDB::instance(); if (!$offset && !$limit) { $trashRowsArray = $db->arrayQuery($query); } else { $trashRowsArray = $db->arrayQuery($query, array('offset' => $offset, 'limit' => $limit)); } // cleanup temp tables $db->dropTempTableList($sqlPermissionChecking['temp_tables']); if ($asCount) { return $trashRowsArray[0]['count']; } else { if ($asObject) { $retTrashNodes = array(); foreach (array_keys($trashRowsArray) as $key) { $trashRow =& $trashRowsArray[$key]; $retTrashNodes[] = new eZContentObjectTrashNode($trashRow); } return $retTrashNodes; } else { return $trashRowsArray; } } }
static function fetchNodesByPathString($nodePath, $withLastNode = false, $asObjects = true, $limit = false) { $nodesListArray = array(); $pathString = eZContentObjectTreeNode::createNodesConditionSQLStringFromPath($nodePath, $withLastNode, $limit); if ($pathString) { $nodesListArray = eZDB::instance()->arrayQuery("SELECT " . "ezcontentobject.contentclass_id, ezcontentobject.current_version, ezcontentobject.id, ezcontentobject.initial_language_id, ezcontentobject.language_mask, " . "ezcontentobject.modified, ezcontentobject.owner_id, ezcontentobject.published, ezcontentobject.remote_id AS object_remote_id, ezcontentobject.section_id, " . "ezcontentobject.status, ezcontentobject_tree.contentobject_is_published, ezcontentobject_tree.contentobject_version, ezcontentobject_tree.depth, " . "ezcontentobject_tree.is_hidden, ezcontentobject_tree.is_invisible, ezcontentobject_tree.main_node_id, ezcontentobject_tree.modified_subnode, ezcontentobject_tree.node_id, " . "ezcontentobject_tree.parent_node_id, ezcontentobject_tree.path_identification_string, ezcontentobject_tree.path_string, ezcontentobject_tree.priority, ezcontentobject_tree.remote_id, " . "ezcontentobject_tree.sort_field, ezcontentobject_tree.sort_order, ezcontentclass.serialized_name_list as class_serialized_name_list, ezcontentclass.identifier as class_identifier, " . "ezcontentclass.is_container as is_container, ezcontentobject_name.name, ezcontentobject_name.real_translation " . "FROM ezcontentobject_tree " . "INNER JOIN ezcontentobject ON (ezcontentobject.id = ezcontentobject_tree.contentobject_id) " . "INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id) " . "INNER JOIN ezcontentobject_name ON ( " . " ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND " . " ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version " . ") " . "WHERE {$pathString} ezcontentclass.version = 0 AND " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject') . " " . "ORDER BY path_string"); } if ($asObjects) { return eZContentObjectTreeNode::makeObjectsArray($nodesListArray); } return $nodesListArray; }
/** * Fetches a node by ID * * @param int|array $nodeID Either a node ID or array of node IDs * @param string $lang language code to fetch the node in. If not provided, the prioritized language list is used * @param bool $asObject True to fetch the node as an eZContentObjectTreeNode, false to fetch its attributes as an array * @param array $conditions An associative array (field => value) of fetch conditions. Will be applied as is to the SQL query * * @return eZContentObjectTreeNode */ static function fetch($nodeID = false, $lang = false, $asObject = true, $conditions = false) { $returnValue = null; $db = eZDB::instance(); if (is_numeric($nodeID) && $nodeID == 1 || is_array($nodeID) && count($nodeID) === 1 && $nodeID[0] == 1) { $query = "SELECT *\n FROM ezcontentobject_tree\n WHERE node_id = 1"; } else { $versionNameTables = ', ezcontentobject_name '; $versionNameTargets = ', ezcontentobject_name.name as name, ezcontentobject_name.real_translation '; $versionNameJoins = " and ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id and\n ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version and "; if ($lang) { $lang = $db->escapeString($lang); $versionNameJoins .= " ezcontentobject_name.content_translation = '{$lang}' "; } else { $versionNameJoins .= eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject'); } $languageFilter = ' AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject'); $sqlCondition = ''; if ($nodeID !== false) { if (is_array($nodeID)) { if (count($nodeID) === 1) { $sqlCondition = 'node_id = ' . (int) $nodeID[0] . ' AND '; } else { $sqlCondition = $db->generateSQLINStatement($nodeID, 'node_id', false, true, 'int') . ' AND '; } } else { $sqlCondition = 'node_id = ' . (int) $nodeID . ' AND '; } } if (is_array($conditions)) { foreach ($conditions as $key => $condition) { if (is_string($condition)) { $condition = $db->escapeString($condition); $condition = "'{$condition}'"; } $sqlCondition .= "ezcontentobject_tree." . $db->escapeString($key) . "={$condition} AND "; } } if ($sqlCondition == '') { eZDebug::writeWarning('Cannot fetch node, emtpy ID or no conditions given', __METHOD__); return $returnValue; } $query = "SELECT ezcontentobject.*,\n ezcontentobject_tree.*,\n ezcontentclass.serialized_name_list as class_serialized_name_list,\n ezcontentclass.identifier as class_identifier,\n ezcontentclass.is_container as is_container\n {$versionNameTargets}\n FROM ezcontentobject_tree,\n ezcontentobject,\n ezcontentclass\n {$versionNameTables}\n WHERE {$sqlCondition}\n ezcontentobject_tree.contentobject_id=ezcontentobject.id AND\n ezcontentclass.version=0 AND\n ezcontentclass.id = ezcontentobject.contentclass_id\n {$languageFilter}\n {$versionNameJoins}"; } $nodeListArray = $db->arrayQuery($query); if (is_array($nodeListArray) && count($nodeListArray) > 0) { if ($asObject) { $returnValue = eZContentObjectTreeNode::makeObjectsArray($nodeListArray); if (count($returnValue) === 1) { $returnValue = $returnValue[0]; } } else { if (count($nodeListArray) === 1) { $returnValue = $nodeListArray[0]; } else { $returnValue = $nodeListArray; } } } return $returnValue; }
/** * Returns related or reverse related objects * * @param int|bool $fromObjectVersion If omitted, the current version will be used * @param int|bool $objectID If omitted, the current object will be used * @param int|bool $attributeID makes sense only when $params['AllRelations'] not set or eZContentObject::RELATION_ATTRIBUTE * $attributeID = 0|false ( $params['AllRelations'] is eZContentObject::RELATION_ATTRIBUTE ) * - return relations made with any attributes * $attributeID > 0 * - return relations made with attribute ID ( "related object(s)" datatype ) * $attributeID = false ( $params['AllRelations'] not set ) * - return ALL relations (deprecated, use "$params['AllRelations'] = true" instead) * @param bool $groupByAttribute This parameter makes sense only when $attributeID == false or $params['AllRelations'] = true * $groupByAttribute = false * - return all relations as an array of content objects * $groupByAttribute = true * - return all relations groupped by attribute ID * @param array|bool $params Other parameters from template fetch function * $params['AllRelations'] = true * - return ALL relations, including attribute-level * $params['AllRelations'] = false * - return objec level relations only * $params['AllRelations'] = int > 0 * - bit mask of EZ_CONTENT_OBJECT_RELATION_* values * $params['SortBy'] * - Possible values: * "class_identifier", "class_name", "modified", * "name", "published", "section" * $params['IgnoreVisibility'] = true * - Include related objects with a 'hidden' state * $params['IgnoreVisibility'] = false * - Exclude related objects with a 'hidden' state * $params['RelatedClassIdentifiers'] = array * - limit returned relations to objects of the specified class identifiers * @param bool $reverseRelatedObjects true -> returns reverse related objects * false -> returns related objects * @return eZContentObject[]|array eZContentObject[], if $params['AsObject'] is set to true (default), array otherwise */ function relatedObjects( $fromObjectVersion = false, $objectID = false, $attributeID = 0, $groupByAttribute = false, $params = false, $reverseRelatedObjects = false ) { if ( $fromObjectVersion == false ) $fromObjectVersion = isset( $this->CurrentVersion ) ? $this->CurrentVersion : false; $fromObjectVersion =(int) $fromObjectVersion; if( !$objectID ) $objectID = $this->ID; $objectID =(int) $objectID; $limit = ( isset( $params['Limit'] ) && is_numeric( $params['Limit'] ) ) ? $params['Limit'] : false; $offset = ( isset( $params['Offset'] ) && is_numeric( $params['Offset'] ) ) ? $params['Offset'] : false; $asObject = ( isset( $params['AsObject'] ) ) ? $params['AsObject'] : true; $loadDataMap = ( isset( $params['LoadDataMap'] ) ) ? $params['LoadDataMap'] : false; $db = eZDB::instance(); $sortingString = ''; $sortingInfo = array( 'attributeFromSQL' => '', 'attributeWhereSQL' => '', 'attributeTargetSQL' => '' ); $relatedClassIdentifiersSQL = ''; $showInvisibleNodesCond = ''; // process params (only SortBy and IgnoreVisibility currently supported): // Supported sort_by modes: // class_identifier, class_name, modified, name, published, section if ( is_array( $params ) ) { if ( isset( $params['SortBy'] ) ) { $validSortBy = array( 'class_identifier', 'class_name', 'modified', 'name', 'published', 'section' ); $sortByParam = array(); if ( is_array( $params['SortBy'] ) ) { // only one SortBy, as a simple array if ( !is_array( $params['SortBy'][0] ) ) { if ( !in_array( $params['SortBy'][0], $validSortBy ) ) eZDebug::writeWarning( "Unsupported sort_by parameter {$params['SortBy'][0]}; check the online documentation for the list of supported sort types", __METHOD__ ); else $sortByParam[] = $params['SortBy']; } // multiple SortBy, check each of them one by one, and keep valid ones else { $invalidSortBy = array(); foreach( $params['SortBy'] as $sortByTuple ) { if ( !in_array( $sortByTuple[0], $validSortBy ) ) $invalidSortBy[] = $sortByTuple[0]; else $sortByParam[] = $sortByTuple; } if ( count( $invalidSortBy ) > 0 ) { eZDebug::writeWarning( "Unsupported sort_by parameter(s) " . implode( ', ', $invalidSortBy ) . "; check the online documentation for the list of supported sort types", __METHOD__ ); } } } if ( count( $sortByParam ) > 0 ) { $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( $sortByParam ); $sortingString = ' ORDER BY ' . $sortingInfo['sortingFields']; } } if ( isset( $params['IgnoreVisibility'] ) ) { $showInvisibleNodesCond = self::createFilterByVisibilitySQLString( $params['IgnoreVisibility'] ); } // related class identifier filter $relatedClassIdentifiersSQL = ''; if ( isset( $params['RelatedClassIdentifiers'] ) && is_array( $params['RelatedClassIdentifiers'] ) ) { $relatedClassIdentifiers = array(); foreach( $params['RelatedClassIdentifiers'] as $classIdentifier ) { $relatedClassIdentifiers[] = "'" . $db->escapeString( $classIdentifier ) . "'"; } $relatedClassIdentifiersSQL = $db->generateSQLINStatement( $relatedClassIdentifiers, 'ezcontentclass.identifier', false, true, 'string' ). " AND"; unset( $classIdentifier, $relatedClassIdentifiers ); } } $relationTypeMasking = ''; $relationTypeMask = isset( $params['AllRelations'] ) ? $params['AllRelations'] : ( $attributeID === false ); if ( $attributeID && ( $relationTypeMask === false || $relationTypeMask === eZContentObject::RELATION_ATTRIBUTE ) ) { $attributeID =(int) $attributeID; $relationTypeMasking .= " contentclassattribute_id=$attributeID AND "; $relationTypeMask = eZContentObject::RELATION_ATTRIBUTE; } elseif ( is_bool( $relationTypeMask ) ) { $relationTypeMask = eZContentObject::relationTypeMask( $relationTypeMask ); } if ( $db->databaseName() == 'oracle' ) { $relationTypeMasking .= " bitand( relation_type, $relationTypeMask ) <> 0 "; } else { $relationTypeMasking .= " ( relation_type & $relationTypeMask ) <> 0 "; } // Create SQL $fromOrToContentObjectID = $reverseRelatedObjects == false ? " AND ezcontentobject.id=ezcontentobject_link.to_contentobject_id AND ezcontentobject_link.from_contentobject_id='$objectID' AND ezcontentobject_link.from_contentobject_version='$fromObjectVersion' " : " AND ezcontentobject.id=ezcontentobject_link.from_contentobject_id AND ezcontentobject_link.to_contentobject_id=$objectID AND ezcontentobject_link.from_contentobject_version=ezcontentobject.current_version "; $query = "SELECT "; if ( $groupByAttribute ) { $query .= "ezcontentobject_link.contentclassattribute_id, "; } $query .= " ezcontentclass.serialized_name_list AS class_serialized_name_list, ezcontentclass.identifier as contentclass_identifier, ezcontentclass.is_container as is_container, ezcontentobject.*, ezcontentobject_name.name as name, ezcontentobject_name.real_translation $sortingInfo[attributeTargetSQL] FROM ezcontentclass, ezcontentobject, ezcontentobject_link, ezcontentobject_name $sortingInfo[attributeFromSQL] WHERE ezcontentclass.id=ezcontentobject.contentclass_id AND ezcontentclass.version=0 AND ezcontentobject.status=" . eZContentObject::STATUS_PUBLISHED . " AND $sortingInfo[attributeWhereSQL] $relatedClassIdentifiersSQL $relationTypeMasking $fromOrToContentObjectID $showInvisibleNodesCond AND ezcontentobject.id = ezcontentobject_name.contentobject_id AND ezcontentobject.current_version = ezcontentobject_name.content_version AND " . eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' ) . " $sortingString"; if ( !$offset && !$limit ) { $relatedObjects = $db->arrayQuery( $query ); } else { $relatedObjects = $db->arrayQuery( $query, array( 'offset' => $offset, 'limit' => $limit ) ); } $ret = array(); $tmp = array(); foreach ( $relatedObjects as $object ) { if ( $asObject ) { $obj = new eZContentObject( $object ); $obj->ClassName = eZContentClass::nameFromSerializedString( $object['class_serialized_name_list'] ); } else { $obj = $object; } $tmp[] = $obj; if ( !$groupByAttribute ) { $ret[] = $obj; } else { $classAttrID = $object['contentclassattribute_id']; if ( !isset( $ret[$classAttrID] ) ) $ret[$classAttrID] = array(); $ret[$classAttrID][] = $obj; } } if ( $loadDataMap && $asObject ) eZContentObject::fillNodeListAttributes( $tmp ); return $ret; }
function relatedObjects($fromObjectVersion = false, $objectID = false, $attributeID = 0, $groupByAttribute = false, $params = false, $reverseRelatedObjects = false) { if ($fromObjectVersion == false) { $fromObjectVersion = isset($this->CurrentVersion) ? $this->CurrentVersion : false; } $fromObjectVersion = (int) $fromObjectVersion; if (!$objectID) { $objectID = $this->ID; } $objectID = (int) $objectID; $limit = isset($params['Limit']) && is_numeric($params['Limit']) ? $params['Limit'] : false; $offset = isset($params['Offset']) && is_numeric($params['Offset']) ? $params['Offset'] : false; $asObject = isset($params['AsObject']) ? $params['AsObject'] : true; $loadDataMap = isset($params['LoadDataMap']) ? $params['LoadDataMap'] : false; $db = eZDB::instance(); $sortingString = ''; $sortingInfo = array('attributeFromSQL' => '', 'attributeWhereSQL' => ''); $showInvisibleNodesCond = ''; // process params (only SortBy and IgnoreVisibility currently supported): // Supported sort_by modes: // class_identifier, class_name, modified, name, published, section if (is_array($params)) { if (isset($params['SortBy'])) { if (!in_array($params['SortBy'], array('class_identifier', 'class_name', 'modified', 'name', 'published', 'section'))) { eZDebug::writeWarning("Unsupported sort_by parameter {$params['SortBy']}; check the online documentation for the list of supported sort types", __METHOD__); } else { $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings($params['SortBy']); $sortingString = ' ORDER BY ' . $sortingInfo['sortingFields']; } } if (isset($params['IgnoreVisibility'])) { $showInvisibleNodesCond = self::createFilterByVisibilitySQLString($params['IgnoreVisibility']); } } $relationTypeMasking = ''; $relationTypeMask = isset($params['AllRelations']) ? $params['AllRelations'] : $attributeID === false; if ($attributeID && ($relationTypeMask === false || $relationTypeMask === eZContentObject::RELATION_ATTRIBUTE)) { $attributeID = (int) $attributeID; $relationTypeMasking .= " AND contentclassattribute_id={$attributeID} "; $relationTypeMask = eZContentObject::RELATION_ATTRIBUTE; } elseif (is_bool($relationTypeMask)) { $relationTypeMask = eZContentObject::relationTypeMask($relationTypeMask); } if ($db->databaseName() == 'oracle') { $relationTypeMasking .= " AND bitand( relation_type, {$relationTypeMask} ) <> 0 "; } else { $relationTypeMasking .= " AND ( relation_type & {$relationTypeMask} ) <> 0 "; } // Create SQL $versionNameTables = ', ezcontentobject_name '; $versionNameTargets = ', ezcontentobject_name.name as name, ezcontentobject_name.real_translation '; $versionNameJoins = " AND ezcontentobject.id = ezcontentobject_name.contentobject_id AND\n ezcontentobject.current_version = ezcontentobject_name.content_version AND "; $versionNameJoins .= eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject'); $fromOrToContentObjectID = $reverseRelatedObjects == false ? " AND ezcontentobject.id=ezcontentobject_link.to_contentobject_id AND\n ezcontentobject_link.from_contentobject_id='{$objectID}' AND\n ezcontentobject_link.from_contentobject_version='{$fromObjectVersion}' " : " AND ezcontentobject.id=ezcontentobject_link.from_contentobject_id AND\n ezcontentobject_link.to_contentobject_id={$objectID} AND\n ezcontentobject_link.from_contentobject_version=ezcontentobject.current_version "; $query = "SELECT "; if ($groupByAttribute) { $query .= "ezcontentobject_link.contentclassattribute_id, "; } $query .= "\n ezcontentclass.serialized_name_list AS class_serialized_name_list,\n ezcontentclass.identifier as contentclass_identifier,\n ezcontentclass.is_container as is_container,\n ezcontentobject.* {$versionNameTargets}\n FROM\n ezcontentclass,\n ezcontentobject,\n ezcontentobject_link\n {$versionNameTables}\n {$sortingInfo['attributeFromSQL']}\n WHERE\n ezcontentclass.id=ezcontentobject.contentclass_id AND\n ezcontentclass.version=0 AND\n ezcontentobject.status=" . eZContentObject::STATUS_PUBLISHED . " AND\n {$sortingInfo['attributeWhereSQL']}\n ezcontentobject_link.op_code='0'\n {$relationTypeMasking}\n {$fromOrToContentObjectID}\n {$showInvisibleNodesCond}\n {$versionNameJoins}\n {$sortingString}"; if (!$offset && !$limit) { $relatedObjects = $db->arrayQuery($query); } else { $relatedObjects = $db->arrayQuery($query, array('offset' => $offset, 'limit' => $limit)); } $ret = array(); $tmp = array(); foreach ($relatedObjects as $object) { if ($asObject) { $obj = new eZContentObject($object); $obj->ClassName = eZContentClass::nameFromSerializedString($object['class_serialized_name_list']); } else { $obj = $object; } $tmp[] = $obj; if (!$groupByAttribute) { $ret[] = $obj; } else { $classAttrID = $object['contentclassattribute_id']; if (!isset($ret[$classAttrID])) { $ret[$classAttrID] = array(); } $ret[$classAttrID][] = $obj; } } if ($loadDataMap && $asObject) { eZContentObject::fillNodeListAttributes($tmp); } return $ret; }
function subTree($params, $nodeID, $countChildren = false) { $nodeListArray = array(); // sorting params $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings($params['SortBy']); // node params $notEqParentString = ''; $pathStringCond = ''; eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings($pathStringCond, $notEqParentString, $nodeID, 1, false); // class filter $classCondition = eZContentObjectTreeNode::createClassFilteringSQLString($params['ClassFilterType'], $params['ClassFilterArray']); if ($classCondition === false) { return $nodeListArray; } // permissions $limitationParams = false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitationParams); if ($limitationList === false) { return $nodeListArray; } $permissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); // invisible nodes. $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(false, $params['FetchHidden']); $query = ''; if ($countChildren) { $query = "SELECT count(*) as count\n FROM\n ezcontentobject_tree\n INNER JOIN ezcontentobject ON (ezcontentobject.id = ezcontentobject_tree.contentobject_id)\n INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n INNER JOIN ezcontentobject_name ON (\n ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND\n ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version\n )\n {$permissionChecking['from']}\n WHERE {$pathStringCond}\n {$classCondition}\n ezcontentclass.version=0 AND\n {$notEqParentString}\n " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject') . "\n {$permissionChecking['where']} "; } else { $query = "SELECT ezcontentobject.*,\n ezcontentobject_tree.*,\n ezcontentclass.serialized_name_list as class_serialized_name_list,\n ezcontentclass.identifier as class_identifier,\n ezcontentclass.is_container as is_container,\n ezcontentobject_name.name as name,\n ezcontentobject_name.real_translation\n FROM\n ezcontentobject_tree\n INNER JOIN ezcontentobject ON (ezcontentobject.id = ezcontentobject_tree.contentobject_id)\n INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n INNER JOIN ezcontentobject_name ON (\n ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND\n ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version\n )\n {$sortingInfo['attributeFromSQL']}\n {$permissionChecking['from']}\n WHERE\n {$pathStringCond}\n {$sortingInfo['attributeWhereSQL']}\n ezcontentclass.version=0 AND\n {$notEqParentString}\n {$classCondition}\n ezcontentobject_tree.contentobject_is_published = 1\n " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject') . "\n {$showInvisibleNodesCond}\n {$permissionChecking['where']}\n ORDER BY {$sortingInfo['sortingFields']}"; } $db = eZDB::instance(); $nodeListArray = $db->arrayQuery($query); // cleanup temp tables $db->dropTempTableList($permissionChecking['temp_tables']); if ($countChildren) { return $nodeListArray[0]['count']; } else { foreach ($nodeListArray as $key => $row) { $nodeListArray[$key]['path_identification_string'] = eZContentObjectTreeNode::fetch($row['node_id'])->pathWithNames(); } return $nodeListArray; } }
static function fetchNodesByPathString($nodePath, $withLastNode = false, $asObjects = true, $limit = false) { $nodesListArray = array(); $pathString = eZContentObjectTreeNode::createNodesConditionSQLStringFromPath($nodePath, $withLastNode, $limit); if ($pathString) { $query = "SELECT ezcontentobject.*,\n ezcontentobject_tree.*,\n ezcontentclass.serialized_name_list as class_serialized_name_list,\n ezcontentclass.identifier as class_identifier,\n ezcontentclass.is_container as is_container,\n ezcontentobject_name.name as name,\n ezcontentobject_name.real_translation\n FROM ezcontentobject_tree\n INNER JOIN ezcontentobject ON (ezcontentobject.id = ezcontentobject_tree.contentobject_id)\n INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n INNER JOIN ezcontentobject_name ON (\n ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND\n ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version\n )\n WHERE {$pathString}\n ezcontentclass.version = 0 AND\n " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject') . "\n ORDER BY path_string"; $db = eZDB::instance(); $nodesListArray = $db->arrayQuery($query); } if ($asObjects) { return eZContentObjectTreeNode::makeObjectsArray($nodesListArray); } return $nodesListArray; }
static function fetchAttributes( $version, $contentObjectID, $language = false, $asObject = true ) { $db = eZDB::instance(); $language = $db->escapeString( $language ); $contentObjectID = (int) $contentObjectID; $version =(int) $version; $query = "SELECT ezcontentobject_attribute.*, ezcontentclass_attribute.identifier as classattribute_identifier, ezcontentclass_attribute.can_translate, ezcontentclass_attribute.serialized_name_list as attribute_serialized_name_list FROM ezcontentobject_attribute, ezcontentclass_attribute, ezcontentobject_version WHERE ezcontentclass_attribute.version = '0' AND ezcontentclass_attribute.id = ezcontentobject_attribute.contentclassattribute_id AND ezcontentobject_attribute.version = '$version' AND ezcontentobject_attribute.contentobject_id = '$contentObjectID' AND ezcontentobject_version.contentobject_id = '$contentObjectID' AND ezcontentobject_version.version = '$version' AND ". ( ( $language )? "ezcontentobject_attribute.language_code = '$language'": eZContentLanguage::sqlFilter( 'ezcontentobject_attribute', 'ezcontentobject_version' ) ). " ORDER by ezcontentclass_attribute.placement ASC"; $attributeArray = $db->arrayQuery( $query ); $returnAttributeArray = array(); foreach ( $attributeArray as $attribute ) { $attr = new eZContentObjectAttribute( $attribute ); $attr->setContentClassAttributeIdentifier( $attribute['classattribute_identifier'] ); $dataType = $attr->dataType(); if ( is_object( $dataType ) && $dataType->Attributes["properties"]["translation_allowed"] && $attribute['can_translate'] ) $attr->setContentClassAttributeCanTranslate( 1 ); else $attr->setContentClassAttributeCanTranslate( 0 ); $attr->setContentClassAttributeName( eZContentClassAttribute::nameFromSerializedString( $attribute['attribute_serialized_name_list'] ) ); $returnAttributeArray[] = $attr; } return $returnAttributeArray; }
/** * Returns the tag cloud for specified parameters using eZ Publish database * * @param array $params * * @return array */ private function tagCloud($params) { $parentNodeID = 0; $classIdentifier = ''; $classIdentifierSQL = ''; $pathString = ''; $parentNodeIDSQL = ''; $dbParams = array(); $orderBySql = 'ORDER BY eztags.keyword ASC'; if (isset($params['class_identifier'])) { $classIdentifier = $params['class_identifier']; } if (isset($params['parent_node_id'])) { $parentNodeID = $params['parent_node_id']; } if (isset($params['limit'])) { $dbParams['limit'] = $params['limit']; } if (isset($params['offset'])) { $dbParams['offset'] = $params['offset']; } if (isset($params['sort_by']) && is_array($params['sort_by']) && !empty($params['sort_by'])) { $orderBySql = 'ORDER BY '; $orderArr = is_string($params['sort_by'][0]) ? array($params['sort_by']) : $params['sort_by']; foreach ($orderArr as $key => $order) { if ($key !== 0) { $orderBySql .= ', '; } $direction = isset($order[1]) ? $order[1] : false; switch ($order[0]) { case 'keyword': $orderBySql .= 'eztags.keyword ' . ($direction ? 'ASC' : 'DESC'); break; case 'count': $orderBySql .= 'keyword_count ' . ($direction ? 'ASC' : 'DESC'); break; } } } $db = eZDB::instance(); if ($classIdentifier) { $classID = eZContentObjectTreeNode::classIDByIdentifier($classIdentifier); $classIdentifierSQL = "AND ezcontentobject.contentclass_id = '" . $classID . "'"; } if ($parentNodeID) { $node = eZContentObjectTreeNode::fetch($parentNodeID); if ($node) { $pathString = "AND ezcontentobject_tree.path_string like '" . $node->attribute('path_string') . "%'"; } $parentNodeIDSQL = "AND ezcontentobject_tree.node_id != " . (int) $parentNodeID; } $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(true, false); $limitation = false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); $languageFilter = 'AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject'); $languageFilter .= 'AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject_attribute', 'language_id'); $rs = $db->arrayQuery("SELECT eztags.id, eztags.keyword, COUNT(DISTINCT ezcontentobject.id) AS keyword_count\n FROM eztags_attribute_link\n LEFT JOIN ezcontentobject_attribute\n ON eztags_attribute_link.objectattribute_id = ezcontentobject_attribute.id\n AND eztags_attribute_link.objectattribute_version = ezcontentobject_attribute.version\n LEFT JOIN ezcontentobject\n ON ezcontentobject_attribute.contentobject_id = ezcontentobject.id\n LEFT JOIN ezcontentobject_tree\n ON ezcontentobject_attribute.contentobject_id = ezcontentobject_tree.contentobject_id\n LEFT JOIN eztags\n ON eztags.id = eztags_attribute_link.keyword_id\n LEFT JOIN eztags_keyword\n ON eztags.id = eztags_keyword.keyword_id\n {$sqlPermissionChecking['from']}\n WHERE " . eZContentLanguage::languagesSQLFilter('eztags') . "\n AND " . eZContentLanguage::sqlFilter('eztags_keyword', 'eztags') . "\n AND ezcontentobject.status = " . eZContentObject::STATUS_PUBLISHED . "\n AND ezcontentobject_attribute.version = ezcontentobject.current_version\n AND ezcontentobject_tree.main_node_id = ezcontentobject_tree.node_id\n {$pathString}\n {$parentNodeIDSQL}\n {$classIdentifierSQL}\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}\n {$languageFilter}\n GROUP BY eztags.id, eztags.keyword\n {$orderBySql}", $dbParams); $tagsCountList = array(); foreach ($rs as $row) { $tagsCountList[$row['id']] = $row['keyword_count']; } /** @var eZTagsObject[] $tagObjects */ $tagObjects = eZTagsObject::fetchList(array('id' => array(array_keys($tagsCountList)))); if (!is_array($tagObjects) || empty($tagObjects)) { return array(); } $tagSortArray = array(); $tagKeywords = array(); $tagCounts = array(); foreach ($tagObjects as $tag) { $tagKeyword = $tag->attribute('keyword'); $tagCount = $tagsCountList[$tag->attribute('id')]; $tagSortArray[] = array('keyword' => $tagKeyword, 'count' => $tagCount, 'tag' => $tag); $tagKeywords[] = $tagKeyword; $tagCounts[] = $tagCount; } if (isset($params['post_sort_by'])) { if ($params['post_sort_by'] === 'keyword') { array_multisort($tagKeywords, SORT_ASC, SORT_LOCALE_STRING, $tagSortArray); } else { if ($params['post_sort_by'] === 'keyword_reverse') { array_multisort($tagKeywords, SORT_DESC, SORT_LOCALE_STRING, $tagSortArray); } else { if ($params['post_sort_by'] === 'count') { array_multisort($tagCounts, SORT_ASC, SORT_NUMERIC, $tagSortArray); } else { if ($params['post_sort_by'] === 'count_reverse') { array_multisort($tagCounts, SORT_DESC, SORT_NUMERIC, $tagSortArray); } } } } } $this->normalizeTagCounts($tagSortArray, $tagCounts); return $tagSortArray; }
/** * Creates and returns SQL parts used in fetch functions * * @param array $params where 'tag_id' is an array of arrays; at least one tag ID from each array must match * * @return array */ public function createAndMultipleFilterSqlParts($params) { $returnArray = array('tables' => '', 'joins' => '', 'columns' => ''); if (!isset($params['tag_id'])) { return $returnArray; } if (is_array($params['tag_id'])) { $tagIDsArray = $params['tag_id']; } else { return $returnArray; } $returnArray['tables'] = " INNER JOIN eztags_attribute_link i1 ON (i1.object_id = ezcontentobject.id AND i1.objectattribute_version = ezcontentobject.current_version)\n INNER JOIN eztags i2 ON (i1.keyword_id = i2.id)\n INNER JOIN eztags_keyword i3 ON (i2.id = i3.keyword_id)"; $dbStrings = array(); $db = eZDB::instance(); foreach ($tagIDsArray as $tagIDGroup) { $tagIDGroup = (array) $tagIDGroup; if (!isset($params['include_synonyms']) || isset($params['include_synonyms']) && (bool) $params['include_synonyms'] == true) { /** @var eZTagsObject[] $tags */ $tags = eZTagsObject::fetchList(array('main_tag_id' => array($tagIDGroup))); if (is_array($tags)) { foreach ($tags as $tag) { $tagIDGroup[] = $tag->attribute('id'); } } } $dbStrings[] = "EXISTS (\n SELECT 1\n FROM\n eztags_attribute_link j1,\n ezcontentobject j2\n WHERE " . $db->generateSQLINStatement($tagIDGroup, 'j1.keyword_id', false, true, 'int') . " AND j1.object_id = j2.id\n AND j2.id = ezcontentobject.id\n AND j1.objectattribute_version = j2.current_version\n )"; } $dbString = implode(" AND ", $dbStrings); if (isset($params['language'])) { $language = $params['language']; if (!is_array($language)) { $language = array($language); } eZContentLanguage::setPrioritizedLanguages($language); } $returnArray['joins'] = " {$dbString}\n AND " . eZContentLanguage::languagesSQLFilter('i2') . " AND " . eZContentLanguage::sqlFilter('i3', 'i2') . " AND "; if (isset($params['language'])) { eZContentLanguage::clearPrioritizedLanguages(); } return $returnArray; }
public static function keyword($params) { $sqlTables = ''; $sqlJoins = ''; $keyword = isset($params['keyword']) ? $params['keyword'] : false; $attribute = isset($params['attribute']) ? $params['attribute'] : false; if ($keyword === false && is_string($keyword) && $keyword != '') { return array(); } $db = eZDB::instance(); $sqlKeyword = $db->escapeString($keyword); $sqlJoins .= 'coa_related_by_keyword' . $params['index'] . '.contentobject_id = ezcontentobject.id AND ' . 'coa_related_by_keyword' . $params['index'] . '.version = ezcontentobject.current_version AND '; $sqlJoins .= eZContentLanguage::sqlFilter('coa_related_by_keyword' . $params['index'], 'ezcontentobject') . ' AND '; if ($attribute !== false) { $attributeID = eZContentClassAttribute::classAttributeIDByIdentifier($attribute); if ($attributeID) { $sqlJoins .= 'coa_related_by_keyword' . $params['index'] . '.contentclassattribute_id = ' . $attributeID . ' AND '; } } $sqlJoins .= 'coa_related_by_keyword' . $params['index'] . '.id = kal_related_by_keyword' . $params['index'] . '.objectattribute_id AND ' . 'kal_related_by_keyword' . $params['index'] . '.keyword_id = k_related_by_keyword' . $params['index'] . '.id AND '; $sqlJoins .= 'k_related_by_keyword' . $params['index'] . ".keyword = '" . $sqlKeyword . "' AND"; $sqlTables .= ', ezcontentobject_attribute coa_related_by_keyword' . $params['index'] . ', ' . 'ezkeyword_attribute_link kal_related_by_keyword' . $params['index'] . ', ' . 'ezkeyword k_related_by_keyword' . $params['index']; return array('tables' => $sqlTables, 'joins' => $sqlJoins); }