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;
     }
 }
 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;
     }
 }
Beispiel #3
0
 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;
     }
 }
 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());
     }
 }
 /**
 * Retourne une liste de noeuds associés à un mot clé
 * @param string $keyword le mot clés associé
 * @param array $classIDArray filtre éventuel sur des IDs numériques de classes    
 * @param integer $parentNodeID filtre éventuel sur un noeud parent
 * @param string $subtreePathString filtre éventuel sur une sous arborescence (définie par un path_string du type "/1/2/214/" )
 * @return une liste de tableaux associatifs {'node_id'=>$nodeID}
 *
 */
 private static function fetchKeyword( $keyword, 
                                      $classIDArray,
                                      $parentNodeID,
                                      $subtreePathString)
 {
     
     $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString( true, false );
     $limitation = false;
     $limitationList = eZContentObjectTreeNode::getLimitationList( $limitation );
     $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList );
     $sqlKeyword = 'ezkeyword.keyword';
     $db = eZDB::instance();
     
     $alphabet = $db->escapeString( $keyword );
     
     $sortingInfo = array();
     $sortingInfo['attributeFromSQL'] = ', ezcontentobject_attribute a1';
     $sortingInfo['attributeWhereSQL'] = '';
     $sqlTarget = 'DISTINCT ezcontentobject_tree.node_id';
     
     $sortingInfo['attributeWhereSQL'] .= " a1.version=ezcontentobject.current_version
     AND a1.contentobject_id=ezcontentobject.id AND";
     
     $parentNodeIDString = is_numeric( $parentNodeID ) ? "AND ezcontentobject_tree.parent_node_id = '$parentNodeID'" : '';
     $subtreeString = empty( $subtreePathString ) ? '' : "AND ezcontentobject_tree.path_string like '$subtreePathString%'";
     $sqlClassIDString = '';
     
     if ( is_array( $classIDArray ) && ! empty( $classIDArray ) )
     {
         $sqlClassIDString = 'AND ezkeyword.class_id IN (' . $db->implodeWithTypeCast( ',', $classIDArray, 'int' ) . ')';
     }
     
     $sqlMatching = "ezkeyword.keyword = '$alphabet'";
     
     $query = "SELECT $sqlTarget
     FROM ezkeyword, ezkeyword_attribute_link,ezcontentobject_tree,ezcontentobject,ezcontentclass
     $sortingInfo[attributeFromSQL]
     $sqlPermissionChecking[from]
     WHERE
     $sortingInfo[attributeWhereSQL]
     $sqlMatching
     $showInvisibleNodesCond
     $sqlPermissionChecking[where]
     $sqlClassIDString
     $parentNodeIDString
     $subtreeString
     AND ezcontentclass.version=0
     AND ezcontentobject.status=".eZContentObject::STATUS_PUBLISHED."
     AND ezcontentobject_tree.main_node_id=ezcontentobject_tree.node_id
     AND ezcontentobject_tree.contentobject_id = ezcontentobject.id
     AND ezcontentclass.id = ezcontentobject.contentclass_id
     AND a1.id=ezkeyword_attribute_link.objectattribute_id
     AND ezkeyword_attribute_link.keyword_id = ezkeyword.id";
     $db_params = array();
     $keywordNodeArray = $db->arrayQuery( $query, $db_params );
     return $keywordNodeArray;
 }
 public static function fetchKeyword($alphabet, $classid, $offset, $limit, $owner = false, $sortBy = array(), $parentNodeID = false, $includeDuplicates = true, $strictMatching = false, $depth = 1)
 {
     $classIDArray = array();
     if (is_numeric($classid)) {
         $classIDArray = array($classid);
     } else {
         if (is_array($classid)) {
             $classIDArray = $classid;
         }
     }
     $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(true, false);
     $limitation = false;
     $limitationList = eZContentObjectTreeNode::getLimitationList($limitation);
     $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList);
     $db_params = array();
     $db_params['offset'] = $offset;
     $db_params['limit'] = $limit;
     $keywordNodeArray = array();
     $lastKeyword = '';
     $db = eZDB::instance();
     //in SELECT clause below we will use a full keyword value
     //or just a part of ezkeyword.keyword matched to $alphabet respective to $includeDuplicates parameter.
     //In the case $includeDuplicates = ture we need only a part
     //of ezkeyword.keyword to be fetched in field to allow DISTINCT to remove rows with the same node id's
     $sqlKeyword = 'ezkeyword.keyword';
     if (!$includeDuplicates) {
         $sqlKeyword = $db->subString('ezkeyword.keyword', 1, strlen($alphabet)) . ' AS keyword ';
     }
     $alphabet = $db->escapeString($alphabet);
     $sortingInfo = array();
     $sortingInfo['attributeFromSQL'] = '';
     $sqlTarget = $sqlKeyword . ',ezcontentobject_tree.node_id';
     if (is_array($sortBy) && count($sortBy) > 0) {
         switch ($sortBy[0]) {
             case 'keyword':
             case 'name':
                 $sortingString = '';
                 if ($sortBy[0] == 'name') {
                     $sortingString = 'ezcontentobject.name';
                 } elseif ($sortBy[0] == 'keyword') {
                     if ($includeDuplicates) {
                         $sortingString = 'ezkeyword.keyword';
                     } else {
                         $sortingString = 'keyword';
                     }
                 }
                 $sortOrder = true;
                 // true is ascending
                 if (isset($sortBy[1])) {
                     $sortOrder = $sortBy[1];
                 }
                 $sortingOrder = $sortOrder ? ' ASC' : ' DESC';
                 $sortingInfo['sortingFields'] = $sortingString . $sortingOrder;
                 break;
             default:
                 $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings($sortBy);
         }
         // Fixing the attributeTargetSQL
         switch ($sortBy[0]) {
             case 'keyword':
                 $sortingInfo['attributeTargetSQL'] = '';
                 break;
             case 'name':
                 $sortingInfo['attributeTargetSQL'] = ', ezcontentobject.name';
                 break;
             case 'attribute':
             case 'class_name':
                 break;
             default:
                 $sortingInfo['attributeTargetSQL'] .= ', ' . strtok($sortingInfo["sortingFields"], " ");
         }
         $sqlTarget .= $sortingInfo['attributeTargetSQL'];
     } else {
         $sortingInfo['sortingFields'] = 'ezkeyword.keyword ASC';
     }
     //Adding DISTINCT to avoid duplicates,
     //check if DISTINCT keyword was added before providing clauses for sorting.
     if (!$includeDuplicates && substr($sqlTarget, 0, 9) != 'DISTINCT ') {
         $sqlTarget = 'DISTINCT ' . $sqlTarget;
     }
     $sqlOwnerString = is_numeric($owner) ? "AND ezcontentobject.owner_id = '{$owner}'" : '';
     $parentNodeIDString = '';
     if (is_numeric($parentNodeID)) {
         $notEqParentString = '';
         // If the node(s) doesn't exist we return null.
         if (!eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings($parentNodeIDString, $notEqParentString, $parentNodeID, $depth)) {
             return null;
         }
     }
     $sqlClassIDString = '';
     if (is_array($classIDArray) and count($classIDArray)) {
         $sqlClassIDString = 'AND ' . $db->generateSQLINStatement($classIDArray, 'ezkeyword.class_id', false, false, 'int') . ' ';
     }
     // composing sql for matching tag word, it could be strict equiality or LIKE clause
     // dependent of $strictMatching parameter.
     $sqlMatching = "ezkeyword.keyword LIKE '{$alphabet}%'";
     if ($strictMatching) {
         $sqlMatching = "ezkeyword.keyword = '{$alphabet}'";
     }
     $query = "SELECT {$sqlTarget}\n                  FROM ezkeyword\n                       INNER JOIN ezkeyword_attribute_link ON (ezkeyword_attribute_link.keyword_id = ezkeyword.id)\n                       INNER JOIN ezcontentobject_attribute ON (ezcontentobject_attribute.id = ezkeyword_attribute_link.objectattribute_id)\n                       INNER JOIN ezcontentobject ON (ezcontentobject_attribute.version = ezcontentobject.current_version AND ezcontentobject_attribute.contentobject_id = ezcontentobject.id)\n                       INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n                       INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n                       {$sortingInfo['attributeFromSQL']}\n                       {$sqlPermissionChecking['from']}\n                  WHERE\n                  {$parentNodeIDString}\n                  {$sqlMatching}\n                  {$showInvisibleNodesCond}\n                  {$sqlPermissionChecking['where']}\n                  {$sqlClassIDString}\n                  {$sqlOwnerString}\n                  AND ezcontentclass.version = 0\n                  AND ezcontentobject.status = " . eZContentObject::STATUS_PUBLISHED . "\n                  AND ezcontentobject_tree.main_node_id = ezcontentobject_tree.node_id\n                  ORDER BY {$sortingInfo['sortingFields']}";
     $keyWords = $db->arrayQuery($query, $db_params);
     $trans = eZCharTransform::instance();
     foreach ($keyWords as $keywordArray) {
         $keyword = $keywordArray['keyword'];
         $nodeID = $keywordArray['node_id'];
         $nodeObject = eZContentObjectTreeNode::fetch($nodeID);
         if ($nodeObject != null) {
             $keywordLC = $trans->transformByGroup($keyword, 'lowercase');
             if ($lastKeyword == $keywordLC) {
                 $keywordNodeArray[] = array('keyword' => '', 'link_object' => $nodeObject);
             } else {
                 $keywordNodeArray[] = array('keyword' => $keyword, 'link_object' => $nodeObject);
             }
             $lastKeyword = $keywordLC;
         } else {
             $lastKeyword = $trans->transformByGroup($keyword, 'lowercase');
         }
     }
     return array('result' => $keywordNodeArray);
 }
    static public function fetchKeyword( $alphabet,
                           $classid,
                           $offset,
                           $limit,
                           $owner = false,
                           $sortBy = array(),
                           $parentNodeID = false,
                           $includeDuplicates = true,
                           $strictMatching = false )
    {
        $classIDArray = array();
        if ( is_numeric( $classid ) )
        {
            $classIDArray = array( $classid );
        }
        else if ( is_array( $classid ) )
        {
            $classIDArray = $classid;
        }

        $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString( true, false );
        $limitation = false;
        $limitationList = eZContentObjectTreeNode::getLimitationList( $limitation );
        $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList );

        $db_params = array();
        $db_params['offset'] = $offset;
        $db_params['limit'] = $limit;

        $keywordNodeArray = array();
        $lastKeyword = '';

        $db = eZDB::instance();

        //in SELECT clause below we will use a full keyword value
        //or just a part of ezkeyword.keyword matched to $alphabet respective to $includeDuplicates parameter.
        //In the case $includeDuplicates = ture we need only a part
        //of ezkeyword.keyword to be fetched in field to allow DISTINCT to remove rows with the same node id's
        $sqlKeyword = 'ezkeyword.keyword';
        if ( !$includeDuplicates )
        {
            $sqlKeyword = $db->subString('ezkeyword.keyword', 1, strlen( $alphabet ) ) . ' AS keyword ';
        }

        $alphabet = $db->escapeString( $alphabet );

        $sortingInfo = array();
        $sortingInfo['attributeFromSQL'] = ', ezcontentobject_attribute a1';
        $sortingInfo['attributeWhereSQL'] = '';
        $sqlTarget = $sqlKeyword.',ezcontentobject_tree.node_id';

        if ( is_array( $sortBy ) && count ( $sortBy ) > 0 )
        {
            switch ( $sortBy[0] )
            {
                case 'keyword':
                case 'name':
                {
                    $sortingString = '';
                    if ( $sortBy[0] == 'name' )
                    {
                        $sortingString = 'ezcontentobject.name';
                        $sortingInfo['attributeTargetSQL'] = ', ' . $sortingString;
                    }
                    elseif ( $sortBy[0] == 'keyword' )
                    {
                        if ( $includeDuplicates )
                            $sortingString = 'ezkeyword.keyword';
                        else
                            $sortingString = 'keyword';
                        $sortingInfo['attributeTargetSQL'] = '';
                    }

                    $sortOrder = true; // true is ascending
                    if ( isset( $sortBy[1] ) )
                        $sortOrder = $sortBy[1];
                    $sortingOrder = $sortOrder ? ' ASC' : ' DESC';
                    $sortingInfo['sortingFields'] = $sortingString . $sortingOrder;
                } break;
                default:
                {
                    $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( $sortBy );

                    if ( $sortBy[0] == 'attribute' )
                    {
                        // if sort_by is 'attribute' we should add ezcontentobject_name to "FromSQL" and link to ezcontentobject
                        $sortingInfo['attributeFromSQL']  .= ', ezcontentobject_name, ezcontentobject_attribute a1';
                        $sortingInfo['attributeWhereSQL'] .= ' ezcontentobject.id = ezcontentobject_name.contentobject_id AND';
                        $sqlTarget = 'DISTINCT ezcontentobject_tree.node_id, '.$sqlKeyword;
                    }
                    else // for unique declaration
                    {
                        $sortByArray = explode( ' ', $sortingInfo['sortingFields'] );
                        $sortingInfo['attributeTargetSQL'] .= ', ' . $sortByArray[0];

                        $sortingInfo['attributeFromSQL']  .= ', ezcontentobject_attribute a1';
                    }

                } break;
            }

            $sqlTarget .= $sortingInfo['attributeTargetSQL'];
        }
        else
        {
            $sortingInfo['sortingFields'] = 'ezkeyword.keyword ASC';
        }
        $sortingInfo['attributeWhereSQL'] .= " a1.version=ezcontentobject.current_version
                                             AND a1.contentobject_id=ezcontentobject.id AND";

        //Adding DISTINCT to avoid duplicates,
        //check if DISTINCT keyword was added before providing clauses for sorting.
        if ( !$includeDuplicates && substr( $sqlTarget, 0, 9) != 'DISTINCT ' )
        {
            $sqlTarget = 'DISTINCT ' . $sqlTarget;
        }

        $sqlOwnerString = is_numeric( $owner ) ? "AND ezcontentobject.owner_id = '$owner'" : '';
        $parentNodeIDString = is_numeric( $parentNodeID ) ? "AND ezcontentobject_tree.parent_node_id = '$parentNodeID'" : '';

        $sqlClassIDString = '';
        if ( is_array( $classIDArray ) and count( $classIDArray ) )
        {
            $sqlClassIDString = 'AND ' . $db->generateSQLINStatement( $classIDArray, 'ezkeyword.class_id', false, false, 'int' ) . ' ';
        }

        // composing sql for matching tag word, it could be strict equiality or LIKE clause
        // dependent of $strictMatching parameter.
        $sqlMatching = "ezkeyword.keyword LIKE '$alphabet%'";
        if ( $strictMatching )
        {
            $sqlMatching = "ezkeyword.keyword = '$alphabet'";
        }

        $query = "SELECT $sqlTarget
                  FROM ezkeyword, ezkeyword_attribute_link,ezcontentobject_tree,ezcontentobject,ezcontentclass
                       $sortingInfo[attributeFromSQL]
                       $sqlPermissionChecking[from]
                  WHERE
                  $sortingInfo[attributeWhereSQL]
                  $sqlMatching
                  $showInvisibleNodesCond
                  $sqlPermissionChecking[where]
                  $sqlClassIDString
                  $sqlOwnerString
                  $parentNodeIDString
                  AND ezcontentclass.version=0
                  AND ezcontentobject.status=".eZContentObject::STATUS_PUBLISHED."
                  AND ezcontentobject_tree.main_node_id=ezcontentobject_tree.node_id
                  AND ezcontentobject_tree.contentobject_id = ezcontentobject.id
                  AND ezcontentclass.id = ezcontentobject.contentclass_id
                  AND a1.id=ezkeyword_attribute_link.objectattribute_id
                  AND ezkeyword_attribute_link.keyword_id = ezkeyword.id ORDER BY {$sortingInfo['sortingFields']}";

        $keyWords = $db->arrayQuery( $query, $db_params );

        $trans = eZCharTransform::instance();

        foreach ( $keyWords as $keywordArray )
        {
            $keyword = $keywordArray['keyword'];
            $nodeID = $keywordArray['node_id'];
            $nodeObject = eZContentObjectTreeNode::fetch( $nodeID );

            if ( $nodeObject != null )
            {
                $keywordLC = $trans->transformByGroup( $keyword, 'lowercase' );
                if ( $lastKeyword == $keywordLC )
                    $keywordNodeArray[] = array( 'keyword' => '', 'link_object' => $nodeObject );
                else
                    $keywordNodeArray[] = array( 'keyword' => $keyword, 'link_object' => $nodeObject );

                $lastKeyword = $keywordLC;
            }
            else
            {
                $lastKeyword = $trans->transformByGroup( $keyword, 'lowercase' );
            }
        }
        return array( 'result' => $keywordNodeArray );
    }
 static function calendar($params = false, $nodeID = 0)
 {
     if (!is_numeric($nodeID) and !is_array($nodeID)) {
         return array();
     }
     if ($params === false) {
         $params = array('Depth' => false, 'Offset' => false, 'Limit' => false, 'AttributeFilter' => false, 'ExtendedAttributeFilter' => false, 'ClassFilterType' => false, 'ClassFilterArray' => false, 'GroupBy' => false);
     }
     $offset = isset($params['Offset']) && is_numeric($params['Offset']) ? $params['Offset'] : false;
     $limit = isset($params['Limit']) && is_numeric($params['Limit']) ? $params['Limit'] : false;
     $depth = isset($params['Depth']) && is_numeric($params['Depth']) ? $params['Depth'] : false;
     $depthOperator = isset($params['DepthOperator']) ? $params['DepthOperator'] : false;
     $groupBy = isset($params['GroupBy']) ? $params['GroupBy'] : false;
     $mainNodeOnly = isset($params['MainNodeOnly']) ? $params['MainNodeOnly'] : false;
     $ignoreVisibility = isset($params['IgnoreVisibility']) ? $params['IgnoreVisibility'] : false;
     if (!isset($params['ClassFilterType'])) {
         $params['ClassFilterType'] = false;
     }
     $classCondition = eZContentObjectTreeNode::createClassFilteringSQLString($params['ClassFilterType'], $params['ClassFilterArray']);
     $attributeFilter = eZContentObjectTreeNode::createAttributeFilterSQLStrings($params['AttributeFilter'], $sortingInfo);
     $extendedAttributeFilter = eZContentObjectTreeNode::createExtendedAttributeFilterSQLStrings($params['ExtendedAttributeFilter']);
     $mainNodeOnlyCond = eZContentObjectTreeNode::createMainNodeConditionSQLString($mainNodeOnly);
     $pathStringCond = '';
     $notEqParentString = '';
     eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings($pathStringCond, $notEqParentString, $nodeID, $depth, $depthOperator);
     $groupBySelectText = '';
     $groupBySQL = $extendedAttributeFilter['group_by'];
     if (!$groupBySQL) {
         eZContentObjectTreeNode::createGroupBySQLStrings($groupBySelectText, $groupBySQL, $groupBy);
     } else {
         if ($groupBy) {
             eZDebug::writeError("Cannot use group_by parameter together with extended attribute filter which sets group_by!", __METHOD__);
         }
     }
     $limitation = isset($params['Limitation']) && is_array($params['Limitation']) ? $params['Limitation'] : false;
     $limitationList = eZContentObjectTreeNode::getLimitationList($limitation);
     $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList);
     // Determine whether we should show invisible nodes.
     $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(!$ignoreVisibility);
     $query = "SELECT DISTINCT\n                         ezcontentobject.published as published\n                         {$groupBySelectText}\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\n                      {$attributeFilter['from']}\n                      {$extendedAttributeFilter['tables']}\n                      {$sqlPermissionChecking['from']}\n                   WHERE\n                      {$pathStringCond}\n                      {$extendedAttributeFilter['joins']}\n                      {$attributeFilter['where']}\n                      ezcontentclass.version = 0 AND\n                      {$notEqParentString}\n                      {$mainNodeOnlyCond}\n                      {$classCondition}\n                      " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject') . "\n                      {$showInvisibleNodesCond}\n                      {$sqlPermissionChecking['where']}\n                {$groupBySQL}";
     $db = eZDB::instance();
     $server = count($sqlPermissionChecking['temp_tables']) > 0 ? eZDBInterface::SERVER_SLAVE : false;
     if (!$offset && !$limit) {
         $nodeListArray = $db->arrayQuery($query, array(), $server);
     } else {
         $nodeListArray = $db->arrayQuery($query, array('offset' => $offset, 'limit' => $limit), $server);
     }
     // cleanup temp tables
     $db->dropTempTableList($sqlPermissionChecking['temp_tables']);
     return $nodeListArray;
 }
 function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters)
 {
     switch ($operatorName) {
         case 'eztagcloud':
             $tags = array();
             $tagCloud = array();
             $parentNodeID = 0;
             $classIdentifier = '';
             $classIdentifierSQL = '';
             $pathString = '';
             $parentNodeIDSQL = '';
             $dbParams = array();
             $params = $namedParameters['params'];
             $orderBySql = 'ORDER BY ezkeyword.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']) && count($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 .= 'ezkeyword.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 ezkeyword.keyword, count(ezkeyword.keyword) AS keyword_count\n                                        FROM ezkeyword_attribute_link\n                                        LEFT JOIN ezcontentobject_attribute\n                                            ON ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id\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 ezkeyword\n                                            ON ezkeyword.id = ezkeyword_attribute_link.keyword_id\n                                        {$sqlPermissionChecking['from']}\n                                        WHERE\n                                            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 ezkeyword.id, ezkeyword.keyword\n                                        {$orderBySql}", $dbParams);
             foreach ($rs as $row) {
                 $tags[$row['keyword']] = $row['keyword_count'];
             }
             // To be able to combine count sorting with keyword sorting
             // without being limited by sql LIMIT result clipping
             if (isset($params['post_sort_by'])) {
                 if ($params['post_sort_by'] === 'keyword') {
                     ksort($tags, SORT_LOCALE_STRING);
                 } else {
                     if ($params['post_sort_by'] === 'keyword_reverse') {
                         krsort($tags, SORT_LOCALE_STRING);
                     } else {
                         if ($params['post_sort_by'] === 'count') {
                             asort($tags, SORT_NUMERIC);
                         } else {
                             if ($params['post_sort_by'] === 'count_reverse') {
                                 arsort($tags, SORT_NUMERIC);
                             }
                         }
                     }
                 }
             }
             $maxFontSize = 200;
             $minFontSize = 100;
             $maxCount = 0;
             $minCount = 0;
             if (count($tags) != 0) {
                 $maxCount = max(array_values($tags));
                 $minCount = min(array_values($tags));
             }
             $spread = $maxCount - $minCount;
             if ($spread == 0) {
                 $spread = 1;
             }
             $step = ($maxFontSize - $minFontSize) / $spread;
             foreach ($tags as $key => $value) {
                 $size = $minFontSize + ($value - $minCount) * $step;
                 $tagCloud[] = array('font_size' => $size, 'count' => $value, 'tag' => $key);
             }
             $tpl = eZTemplate::factory();
             $tpl->setVariable('tag_cloud', $tagCloud);
             $operatorValue = $tpl->fetch('design:tagcloud/tagcloud.tpl');
             break;
     }
 }
    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 );

        // version
        $useVersionName = true;
        $versionNameTables = eZContentObjectTreeNode::createVersionNameTablesSQLString( $useVersionName );
        $versionNameTargets = eZContentObjectTreeNode::createVersionNameTargetsSQLString( $useVersionName );
        $versionNameJoins = eZContentObjectTreeNode::createVersionNameJoinsSQLString( $useVersionName );

        // invisible nodes.
        $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString( false, $params['FetchHidden'] );

        $query = '';
        if ( $countChildren )
        {
            $query = "SELECT count(*) as count
                          FROM
                               ezcontentobject_tree,
                               ezcontentobject,ezcontentclass
                               $versionNameTables
                               $permissionChecking[from]
                          WHERE $pathStringCond
                                $classCondition
                                ezcontentclass.version=0 AND
                                $notEqParentString
                                ezcontentobject_tree.contentobject_id = ezcontentobject.id  AND
                                ezcontentclass.id = ezcontentobject.contentclass_id
                                $versionNameJoins
                                $permissionChecking[where] ";
        }
        else
        {
            $query = "SELECT ezcontentobject.*,
                             ezcontentobject_tree.*,
                             ezcontentclass.serialized_name_list as class_serialized_name_list,
                             ezcontentclass.identifier as class_identifier,
                             ezcontentclass.is_container as is_container
                             $versionNameTargets
                      FROM
                             ezcontentobject_tree,
                             ezcontentobject,ezcontentclass
                             $versionNameTables
                             $sortingInfo[attributeFromSQL]
                             $permissionChecking[from]
                      WHERE
                             $pathStringCond
                             $sortingInfo[attributeWhereSQL]
                             ezcontentclass.version=0 AND
                             $notEqParentString
                             ezcontentobject_tree.contentobject_id = ezcontentobject.id  AND
                             ezcontentclass.id = ezcontentobject.contentclass_id AND
                             $classCondition
                             ezcontentobject_tree.contentobject_is_published = 1
                             $versionNameJoins
                             $showInvisibleNodesCond
                             $permissionChecking[where]
                      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;
        }
    }
 /**
  * Fetch top/bottom content (nodes) by rating++
  * 
  * @param array $params (see inline doc for details)
  * @return array Returs array of nodes (either objects or raw db output based on as_object param)
  */
 static function fetchNodeByRating($params)
 {
     /**
      * Works like fetch list/tree, except:
      * 1. Attribute filter is not supported (because of dependency on normal sort_by param)
      * 2. Supported sorting: rating, rating_count, object_count, published, modified and view_count.
      * 3. parent_node_id only works for list fetch, if you want tree fetch use 
      *    parent_node_path (format is like $node.path_string, as in '/1/2/144/256/').
      * 4. depth and depth_operator are not supported (so parent_node_path gives you unlimited depth).
      * 5. There are additional advance params to see rating, rating_count, object_count pr user / group
      *    see group_by_owner, owner_parent_node_id, owner_parent_node_path and owner_id.
      * 6. param 'include_not_rated' when set to true will use left join to also include unrated content
      */
     $ret = array();
     $whereSql = array();
     $offset = false;
     $limit = false;
     $fromSql = '';
     $asObject = isset($params['as_object']) ? $params['as_object'] : true;
     $loadDataMap = isset($params['load_data_map']) ? $params['load_data_map'] : false;
     $mainNodeOnly = isset($params['main_node_only']) ? $params['main_node_only'] : false;
     $ignoreVisibility = isset($params['ignore_visibility']) ? $params['ignore_visibility'] : false;
     $classFilterType = isset($params['class_filter_type']) ? $params['class_filter_type'] : false;
     $classFilterArray = isset($params['class_filter_array']) ? $params['class_filter_array'] : false;
     $includeNotRated = isset($params['include_not_rated']) ? $params['include_not_rated'] : false;
     $selectSql = 'ezcontentobject.*, ezcontentobject_tree.*,';
     $groupBySql = 'GROUP BY ezcontentobject_tree.node_id';
     $orderBySql = 'ORDER BY rating DESC, rating_count DESC';
     // default sorting
     // WARNING: group_by_owner only works as intended if user is owner of him self..
     if (isset($params['group_by_owner']) && $params['group_by_owner']) {
         // group by owner instead of content object and fetch users instead of content objects
         $selectSql = 'ezcontentobject.*, owner_tree.*,';
         $groupBySql = 'GROUP BY owner_tree.node_id';
     }
     if (isset($params['owner_parent_node_id']) and is_numeric($params['owner_parent_node_id'])) {
         // filter by parent node of owner (main user group)
         $parentNodeId = $params['owner_parent_node_id'];
         $whereSql[] = 'owner_tree.parent_node_id = ' . $parentNodeId;
     } else {
         if (isset($params['owner_parent_node_path']) and is_string($params['owner_parent_node_path'])) {
             // filter recursivly by parent node id
             // supported format is /1/2/144/256/ ( $node.path_string )
             $parentNodePath = $params['owner_parent_node_path'];
             $whereSql[] = "owner_tree.path_string != '{$parentNodePath}'";
             $whereSql[] = "owner_tree.path_string like '{$parentNodePath}%'";
         } else {
             if (isset($params['owner_id']) and is_numeric($params['owner_id'])) {
                 // filter by owner_id ( user / contentobject id)
                 $ownerId = $params['owner_id'];
                 $whereSql[] = 'ezcontentobject.owner_id = ' . $ownerId;
             }
         }
     }
     if (isset($params['parent_node_id']) and is_numeric($params['parent_node_id'])) {
         // filter by main parent node id
         $parentNodeId = $params['parent_node_id'];
         $whereSql[] = 'ezcontentobject_tree.parent_node_id = ' . $parentNodeId;
     } else {
         if (isset($params['parent_node_path'])) {
             if (is_string($params['parent_node_path'])) {
                 // filter recursivly by main parent node id
                 // supported format is /1/2/144/256/ ( $node.path_string )
                 $parentNodePath = $params['parent_node_path'];
                 $whereSql[] = "ezcontentobject_tree.path_string != '{$parentNodePath}'";
                 $whereSql[] = "ezcontentobject_tree.path_string like '{$parentNodePath}%'";
             } else {
                 eZDebug::writeError("Parameter 'parent_node_path' needs to be node path_string, was '{$params['parent_node_path']}'.", __METHOD__);
             }
         }
     }
     $classCondition = eZContentObjectTreeNode::createClassFilteringSQLString($classFilterType, $classFilterArray);
     if ($classCondition === false) {
         eZDebug::writeNotice("Class filter returned false", __MEHOD__);
         return null;
     }
     if (isset($params['limit'])) {
         $limit = (int) $params['limit'];
     }
     if (isset($params['offset'])) {
         $offset = (int) $params['offset'];
     }
     if ($includeNotRated) {
         $ratingFromSql = 'LEFT JOIN ezstarrating
                          ON ezstarrating.contentobject_id = ezcontentobject.id';
         $ratingWhereSql = '';
     } else {
         $ratingFromSql = ', ezstarrating';
         $ratingWhereSql = 'ezstarrating.contentobject_id = ezcontentobject.id AND';
     }
     if (isset($params['sort_by']) && is_array($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) {
             $orderBySqlPart = false;
             $direction = isset($order[1]) ? $order[1] : false;
             switch ($order[0]) {
                 case 'rating':
                     $orderBySqlPart = 'rating ' . ($direction ? 'ASC' : 'DESC');
                     break;
                 case 'rating_count':
                     $orderBySqlPart = 'rating_count ' . ($direction ? 'ASC' : 'DESC');
                     break;
                 case 'object_count':
                     $selectSql .= 'COUNT( ezcontentobject.id ) as object_count,';
                     $orderBySqlPart = 'object_count ' . ($direction ? 'ASC' : 'DESC');
                     break;
                 case 'published':
                     $orderBySqlPart = 'ezcontentobject.published ' . ($direction ? 'ASC' : 'DESC');
                     break;
                 case 'modified':
                     $orderBySqlPart = 'ezcontentobject.modified ' . ($direction ? 'ASC' : 'DESC');
                     break;
                 case 'view_count':
                     // notice: will only fetch nodes that HAVE a entry in the ezview_counter table!!!
                     $selectSql .= 'ezview_counter.count as view_count,';
                     $fromSql .= ', ezview_counter';
                     $whereSql[] = 'ezcontentobject_tree.node_id = ezview_counter.node_id';
                     $orderBySqlPart = 'view_count ' . ($direction ? 'ASC' : 'DESC');
                     break;
                 default:
                     if (isset($params['extended_attribute_filter'])) {
                         $orderBySqlPart = $order[0] . ' ' . ($direction ? 'ASC' : 'DESC');
                     } else {
                         eZDebug::writeError("Unsuported sort type '{$order['0']}', for fetch_by_starrating().", __METHOD__);
                     }
                     break;
             }
             if ($orderBySqlPart) {
                 if ($key !== 0) {
                     $orderBySql .= ',';
                 }
                 $orderBySql .= $orderBySqlPart;
             }
         }
     }
     $whereSql = $whereSql ? implode($whereSql, ' AND ') . ' AND ' : '';
     $extendedAttributeFilter = eZContentObjectTreeNode::createExtendedAttributeFilterSQLStrings($params['extended_attribute_filter']);
     $limitation = isset($params['limitation']) && is_array($params['limitation']) ? $params['limitation'] : false;
     $limitationList = eZContentObjectTreeNode::getLimitationList($limitation);
     $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList);
     $languageFilter = ' AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject');
     $useVersionName = true;
     $versionNameTables = eZContentObjectTreeNode::createVersionNameTablesSQLString($useVersionName);
     $versionNameTargets = eZContentObjectTreeNode::createVersionNameTargetsSQLString($useVersionName);
     $versionNameJoins = eZContentObjectTreeNode::createVersionNameJoinsSQLString($useVersionName, false);
     $mainNodeOnlyCond = eZContentObjectTreeNode::createMainNodeConditionSQLString($mainNodeOnly);
     $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(!$ignoreVisibility);
     $db = eZDB::instance();
     $sql = "SELECT\n                             {$selectSql}\n                             AVG( ezstarrating.rating_average ) as rating,\n                             SUM( ezstarrating.rating_count ) as rating_count,\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                             {$extendedAttributeFilter['columns']}\n                            FROM\n                             ezcontentobject_tree,\n                             ezcontentobject_tree owner_tree,\n                             ezcontentclass\n                             {$fromSql}\n                             {$versionNameTables}\n                             {$extendedAttributeFilter['tables']}\n                             {$sqlPermissionChecking['from']}\n                             ,ezcontentobject\n                             {$ratingFromSql}\n                            WHERE\n                             {$extendedAttributeFilter['joins']}\n                             {$ratingWhereSql}\n                             ezcontentobject.id = ezcontentobject_tree.contentobject_id AND\n                             ezcontentobject.owner_id = owner_tree.contentobject_id AND\n                             owner_tree.node_id = owner_tree.main_node_id AND\n                             ezcontentclass.version=0 AND\n                             ezcontentclass.id = ezcontentobject.contentclass_id AND\n                             {$mainNodeOnlyCond}\n                             {$classCondition}\n                             {$whereSql}\n\t                         {$versionNameJoins}\n\t                         {$showInvisibleNodesCond}\n\t                         {$sqlPermissionChecking['where']}\n\t                         {$languageFilter}\n                            {$groupBySql}\n                            {$orderBySql}";
     $server = isset($sqlPermissionChecking['temp_tables'][0]) ? eZDBInterface::SERVER_SLAVE : false;
     if ($offset !== false || $limit !== false) {
         $rows = $db->arrayQuery($sql, array('offset' => $offset, 'limit' => $limit), $server);
     } else {
         $rows = $db->arrayQuery($sql, null, $server);
     }
     $db->dropTempTableList($sqlPermissionChecking['temp_tables']);
     unset($db);
     if (isset($rows[0]) && is_array($rows)) {
         if ($asObject) {
             $ret = ezsrRatingObjectTreeNode::makeObjectsArray($rows);
             if ($loadDataMap) {
                 eZContentObject::fillNodeListAttributes($ret);
             }
         } else {
             $ret = $rows;
         }
     } else {
         if ($rows === false) {
             eZDebug::writeError('The ezstarrating table seems to be missing,
                       contact your administrator', __METHOD__);
             $ret = array();
         } else {
             $ret = array();
         }
     }
     return $ret;
 }
Beispiel #12
0
 /**
  * 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;
 }
 function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters)
 {
     switch ($operatorName) {
         case 'eztagcloud':
             /*
             $tags = array();
             $tagCloud = array();
             $parentNodeID = 0;
             $classID = '';
             $classIdentifier = '';
             $classIdentifierSQL = '';
             $pathString = '';
             $parentNodeIDSQL = '';
             
             if ( isset( $namedParameters['params']['class_identifier'] ) )
                 $classIdentifier = $namedParameters['params']['class_identifier'];
             
             if ( isset( $namedParameters['params']['parent_node_id'] ) )
                 $parentNodeID = $namedParameters['params']['parent_node_id'];
             
             if ( isset( $namedParameters['params']['limit'] ) )
                 $tagCloudLimit = $namedParameters['params']['limit'];
             else
                 $tagCloudLimit = 25;
             
             include_once( 'lib/ezdb/classes/ezdb.php' );
             $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 );
             
             $versionNameJoins = " AND ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id AND
                                         ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version AND ";
             $languageFilter = " AND " . eZContentLanguage::languagesSQLFilter( 'ezcontentobject' );
             $versionNameJoins .= eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' );
             
             $rs = $db->arrayQuery( "SELECT DISTINCT ezkeyword.keyword
                                     FROM ezkeyword,
                                         ezkeyword_attribute_link,
                                         ezcontentobject,
                                         ezcontentobject_name,
                                         ezcontentobject_attribute,
                                         ezcontentobject_tree
                                         $sqlPermissionChecking[from]
                                     WHERE ezkeyword.id = ezkeyword_attribute_link.keyword_id
                                         AND ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id
                                         AND ezcontentobject_attribute.contentobject_id = ezcontentobject_tree.contentobject_id
                                         AND ezcontentobject.status = '".eZContentObject::STATUS_PUBLISHED."'
                                         AND ezcontentobject_attribute.version = ezcontentobject.current_version
                                         AND ezcontentobject_tree.main_node_id = ezcontentobject_tree.node_id
                                         $pathString
                                         $parentNodeIDSQL
                                         $classIdentifierSQL
                                         $showInvisibleNodesCond
                                         $sqlPermissionChecking[where]
                                         $languageFilter
                                         $versionNameJoins
                                     ORDER BY ezkeyword.keyword ASC" );
             
             include_once ('lib/ezutils/classes/ezfunctionhandler.php');
             
             foreach( $rs as $row )
             {
                 $tags[$row['keyword']] = eZFunctionHandler::execute( 'content', 'keyword_count', array( 'alphabet' => $row['keyword'],
                                                                                                         'strict_matching' => true,
                                                                                                         'classid' => $classID  ) );
             }
             
             $maxFontSize = 180;
             $minFontSize = 90;
             
             $maxCount = 0;
             $minCount = 0;
             
             if( count( $tags ) != 0 )
             {
                 $maxCount = max( array_values( $tags ) );
                 $minCount = min( array_values($tags ) );
             }
             
             $spread = $maxCount - $minCount;
             if ( $spread == 0 )
             $spread = 1;
             
             $step = ( $maxFontSize - $minFontSize )/( $spread );
             
             foreach ($tags as $key => $value)
             {
                 $size = $minFontSize + ( ( $value - $minCount ) * $step );
                 $tagCloud[] = array( 'font_size' => $size,
                                      'count' => $value,
                                      'tag' => $key );
             }
             
             // Now sort and truncate the tag cloud results
             usort($tagCloud, array("eZTagCloud","tagCountSort"));
             array_splice($tagCloud, $tagCloudLimit);
             shuffle($tagCloud);
             
             $tpl = eZTemplate::factory();
             $tpl->setVariable( 'tag_cloud', $tagCloud );
             
             $operatorValue = $tpl->fetch( 'design:tagcloud/tagcloud.tpl' );
             */
             // End original version
             // Start trunk version of ezwebin:
             $tags = array();
             $tagCloud = array();
             $parentNodeID = 0;
             $classIdentifier = '';
             $classIdentifierSQL = '';
             $pathString = '';
             $parentNodeIDSQL = '';
             $dbParams = array();
             $params = $namedParameters['params'];
             $orderBySql = 'ORDER BY ezkeyword.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']) && count($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 .= 'ezkeyword.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');
             $rs = $db->arrayQuery("SELECT ezkeyword.keyword, count(*) as keyword_count\n                                            FROM ezkeyword,\n                                                ezkeyword_attribute_link,\n                                                ezcontentobject,\n                                                ezcontentobject_attribute,\n                                                ezcontentobject_tree\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_attribute.contentobject_id = ezcontentobject_tree.contentobject_id\n                                                AND ezcontentobject_attribute.contentobject_id = ezcontentobject.id\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 ezkeyword.id, ezkeyword.keyword\n                                            {$orderBySql}", $dbParams);
             foreach ($rs as $row) {
                 $tags[$row['keyword']] = $row['keyword_count'];
             }
             // To be able to combine count sorting with keyword sorting
             // without being limited by sql LIMIT result clipping
             if (isset($params['post_sort_by'])) {
                 if ($params['post_sort_by'] === 'keyword') {
                     ksort($tags, SORT_LOCALE_STRING);
                 } else {
                     if ($params['post_sort_by'] === 'keyword_reverse') {
                         krsort($tags, SORT_LOCALE_STRING);
                     } else {
                         if ($params['post_sort_by'] === 'count') {
                             asort($tags, SORT_NUMERIC);
                         } else {
                             if ($params['post_sort_by'] === 'count_reverse') {
                                 arsort($tags, SORT_NUMERIC);
                             }
                         }
                     }
                 }
             }
             // $maxFontSize = 10;
             // $minFontSize = 1;
             $maxFontSize = 200;
             $minFontSize = 100;
             $maxCount = 0;
             $minCount = 0;
             if (count($tags) != 0) {
                 $maxCount = max(array_values($tags));
                 $minCount = min(array_values($tags));
             }
             $spread = $maxCount - $minCount;
             if ($spread == 0) {
                 $spread = 1;
             }
             $step = ($maxFontSize - $minFontSize) / $spread;
             foreach ($tags as $key => $value) {
                 // $size = round( log( $value ) / ( log( $maxCount ) / ( $maxFontSize - $minFontSize ) )  + $minFontSize );
                 $size = $minFontSize + ($value - $minCount) * $step;
                 $tagCloud[] = array('font_size' => $size, 'count' => $value, 'tag' => $key);
             }
             $tpl = eZTemplate::factory();
             $tpl->setVariable('tag_cloud', $tagCloud);
             $operatorValue = $tpl->fetch('design:tagcloud/tagcloud.tpl');
             break;
         case 'eztagcloud_new':
             // Start trunk version of ezwebin:
             $tags = array();
             $tagCloud = array();
             $parentNodeID = 0;
             $classIdentifier = '';
             $classIdentifierSQL = '';
             $pathString = '';
             $parentNodeIDSQL = '';
             $dbParams = array();
             $params = $namedParameters['params'];
             $orderBySql = 'ORDER BY ezkeyword.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']) && count($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 .= 'ezkeyword.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');
             $rs = $db->arrayQuery("SELECT ezkeyword.keyword, count(*) as keyword_count\n                                            FROM ezkeyword,\n                                                ezkeyword_attribute_link,\n                                                ezcontentobject,\n                                                ezcontentobject_attribute,\n                                                ezcontentobject_tree\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_attribute.contentobject_id = ezcontentobject_tree.contentobject_id\n                                                AND ezcontentobject_attribute.contentobject_id = ezcontentobject.id\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 ezkeyword.id, ezkeyword.keyword\n                                            {$orderBySql}", $dbParams);
             foreach ($rs as $row) {
                 $tags[$row['keyword']] = $row['keyword_count'];
             }
             // To be able to combine count sorting with keyword sorting
             // without being limited by sql LIMIT result clipping
             if (isset($params['post_sort_by'])) {
                 if ($params['post_sort_by'] === 'keyword') {
                     ksort($tags, SORT_LOCALE_STRING);
                 } else {
                     if ($params['post_sort_by'] === 'keyword_reverse') {
                         krsort($tags, SORT_LOCALE_STRING);
                     } else {
                         if ($params['post_sort_by'] === 'count') {
                             asort($tags, SORT_NUMERIC);
                         } else {
                             if ($params['post_sort_by'] === 'count_reverse') {
                                 arsort($tags, SORT_NUMERIC);
                             }
                         }
                     }
                 }
             }
             $maxFontSize = 10;
             $minFontSize = 4;
             $maxCount = 0;
             $minCount = 0;
             if (count($tags) != 0) {
                 $maxCount = max(array_values($tags));
                 $minCount = min(array_values($tags));
             }
             $spread = $maxCount - $minCount;
             if ($spread == 0) {
                 $spread = 1;
             }
             $step = ($maxFontSize - $minFontSize) / $spread;
             foreach ($tags as $key => $value) {
                 $weight = (log($value) - log($minCount)) / (log($maxCount) - log($minCount));
                 $size = $minFontSize + round(($maxFontSize - $minFontSize) * $weight);
                 $tagCloud[] = array('font_size' => $size, 'count' => $value, 'tag' => $key);
             }
             $tpl = eZTemplate::factory();
             $tpl->setVariable('tag_cloud', $tagCloud);
             $tpl->setVariable('tag_cloud_exclude', $params['exclude_tags']);
             $tpl->setVariable('tag_cloud_strings', $params['exclude_strings']);
             $operatorValue = $tpl->fetch('design:tagcloud/tagcloud.tpl');
             break;
     }
 }
    static function calendar( $params = false, $nodeID = 0 )
    {
        if ( !is_numeric( $nodeID ) and !is_array( $nodeID ) )
        {
            return array();
        }

        if ( $params === false )
        {
            $params = array( 'Depth'                    => false,
                             'Offset'                   => false,
                             'Limit'                    => false,
                             'AttributeFilter'          => false,
                             'ExtendedAttributeFilter'  => false,
                             'ClassFilterType'          => false,
                             'ClassFilterArray'         => false,
                             'GroupBy'                  => false );
        }

        $offset           = ( isset( $params['Offset'] ) && is_numeric( $params['Offset'] ) ) ? $params['Offset']             : false;
        $limit            = ( isset( $params['Limit']  ) && is_numeric( $params['Limit']  ) ) ? $params['Limit']              : false;
        $depth            = ( isset( $params['Depth']  ) && is_numeric( $params['Depth']  ) ) ? $params['Depth']              : false;
        $depthOperator    = ( isset( $params['DepthOperator']     ) )                         ? $params['DepthOperator']      : false;
        $groupBy          = ( isset( $params['GroupBy']           ) )                         ? $params['GroupBy']            : false;
        $mainNodeOnly     = ( isset( $params['MainNodeOnly']      ) )                         ? $params['MainNodeOnly']       : false;
        $ignoreVisibility = ( isset( $params['IgnoreVisibility']  ) )                         ? $params['IgnoreVisibility']   : false;
        if ( !isset( $params['ClassFilterType'] ) )
            $params['ClassFilterType'] = false;

        $classCondition          = eZContentObjectTreeNode::createClassFilteringSQLString( $params['ClassFilterType'], $params['ClassFilterArray'] );
        $attributeFilter         = eZContentObjectTreeNode::createAttributeFilterSQLStrings( $params['AttributeFilter'], $sortingInfo );
        $extendedAttributeFilter = eZContentObjectTreeNode::createExtendedAttributeFilterSQLStrings( $params['ExtendedAttributeFilter'] );
        $mainNodeOnlyCond        = eZContentObjectTreeNode::createMainNodeConditionSQLString( $mainNodeOnly );

        $pathStringCond     = '';
        $notEqParentString  = '';
        eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings( $pathStringCond, $notEqParentString, $nodeID, $depth, $depthOperator );

        $groupBySelectText  = '';
        $groupBySQL         = $extendedAttributeFilter['group_by'];
        if ( !$groupBySQL )
        {
            eZContentObjectTreeNode::createGroupBySQLStrings( $groupBySelectText, $groupBySQL, $groupBy );
        }
        else if ( $groupBy )
        {
            eZDebug::writeError( "Cannot use group_by parameter together with extended attribute filter which sets group_by!", __METHOD__ );
        }

        $useVersionName     = true;
        $versionNameTables  = eZContentObjectTreeNode::createVersionNameTablesSQLString( $useVersionName );
        $versionNameJoins   = eZContentObjectTreeNode::createVersionNameJoinsSQLString( $useVersionName, false );

        $limitation = ( isset( $params['Limitation']  ) && is_array( $params['Limitation']  ) ) ? $params['Limitation']: false;
        $limitationList = eZContentObjectTreeNode::getLimitationList( $limitation );
        $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList );

        // Determine whether we should show invisible nodes.
        $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString( !$ignoreVisibility );

        $query = "SELECT DISTINCT
                         ezcontentobject.published as published
                         $groupBySelectText
                   FROM
                      ezcontentobject_tree,
                      ezcontentobject,ezcontentclass
                      $versionNameTables
                      $attributeFilter[from]
                      $extendedAttributeFilter[tables]
                      $sqlPermissionChecking[from]
                   WHERE
                      $pathStringCond
                      $extendedAttributeFilter[joins]
                      $attributeFilter[where]
                      ezcontentclass.version=0
                      AND
                      $notEqParentString
                      $mainNodeOnlyCond
                      ezcontentobject_tree.contentobject_id = ezcontentobject.id AND
                      ezcontentclass.id = ezcontentobject.contentclass_id AND
                      $classCondition
                      $versionNameJoins
                      $showInvisibleNodesCond
                      $sqlPermissionChecking[where]
                $groupBySQL";


        $db = eZDB::instance();

        $server = count( $sqlPermissionChecking['temp_tables'] ) > 0 ? eZDBInterface::SERVER_SLAVE : false;

        if ( !$offset && !$limit )
        {
            $nodeListArray = $db->arrayQuery( $query, array(), $server );
        }
        else
        {
            $nodeListArray = $db->arrayQuery( $query, array( 'offset' => $offset,
                                                              'limit'  => $limit ),
                                                      $server );
        }

        // cleanup temp tables
        $db->dropTempTableList( $sqlPermissionChecking['temp_tables'] );

        return $nodeListArray;
    }
Beispiel #15
0
 function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters)
 {
     switch ($operatorName) {
         case 'eztagcloud':
             $tags = array();
             $tagCloud = array();
             $parentNodeID = 0;
             $classIdentifier = '';
             $classIdentifierSQL = '';
             $pathString = '';
             $parentNodeIDSQL = '';
             $dbParams = array();
             $params = $namedParameters['params'];
             $orderBySql = 'ORDER BY ezkeyword.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']) && count($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 .= 'ezkeyword.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');
             $rs = $db->arrayQuery("SELECT ezkeyword.keyword, count(*) as keyword_count\n                                        FROM ezkeyword,\n                                            ezkeyword_attribute_link,\n                                            ezcontentobject,\n                                            ezcontentobject_attribute,\n                                            ezcontentobject_tree\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_attribute.contentobject_id = ezcontentobject_tree.contentobject_id\n                                            AND ezcontentobject_attribute.contentobject_id = ezcontentobject.id\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 ezkeyword.id, ezkeyword.keyword\n                                        {$orderBySql}", $dbParams);
             foreach ($rs as $row) {
                 $tags[$row['keyword']] = $row['keyword_count'];
             }
             $maxFontSize = 200;
             $minFontSize = 100;
             $maxCount = 0;
             $minCount = 0;
             if (count($tags) != 0) {
                 $maxCount = max(array_values($tags));
                 $minCount = min(array_values($tags));
             }
             $spread = $maxCount - $minCount;
             if ($spread == 0) {
                 $spread = 1;
             }
             $step = ($maxFontSize - $minFontSize) / $spread;
             // stevo - combine lower/upper case
             $realTags = array();
             $realkey = '';
             foreach ($tags as $key => $value) {
                 $key = strtolower($key);
                 if (isset($realTags[$key])) {
                     $realTags[$key] += $value;
                 } else {
                     $realTags[$key] = $value;
                 }
             }
             // stevo - add minimum tag count option
             $min = isset($params['min']) ? $params['min'] : 0;
             //$minCount -= $min;
             foreach ($realTags as $key => $value) {
                 if ($value > $min) {
                     $size = $minFontSize + ($value - $minCount) * $step;
                     $tagCloud[] = array('font_size' => $size, 'count' => $value, 'tag' => $key);
                 }
             }
             require_once 'kernel/common/template.php';
             $tpl = templateInit();
             $tpl->setVariable('tag_cloud', $tagCloud);
             $operatorValue = $tpl->fetch('design:tagcloud/tagcloud.tpl');
             break;
     }
 }