Пример #1
0
 /**
  * Generates output for use with autocomplete and suggest methods
  *
  * @static
  *
  * @param array $params
  * @param int $subTreeLimit
  * @param bool $hideRootTag
  * @param string $locale
  *
  * @return array
  */
 private static function generateOutput(array $params, $subTreeLimit, $hideRootTag, $locale)
 {
     $subTreeLimit = (int) $subTreeLimit;
     $hideRootTag = (bool) $hideRootTag;
     $locale = (string) $locale;
     if (empty($locale)) {
         return array('status' => 'success', 'message' => '', 'tags' => array());
     }
     // @TODO Fix synonyms not showing up in autocomplete
     // when subtree limit is defined in class attribute
     if ($subTreeLimit > 0) {
         if ($hideRootTag) {
             $params['id'] = array('<>', $subTreeLimit);
         }
         $params['path_string'] = array('like', '%/' . $subTreeLimit . '/%');
     }
     // first fetch tags that exist in selected locale
     /** @var eZTagsObject[] $tags */
     $tags = eZTagsObject::fetchList($params, null, null, false, $locale);
     if (!is_array($tags)) {
         $tags = array();
     }
     $tagsIDsToExclude = array_map(function ($tag) {
         /** @var eZTagsObject $tag */
         return (int) $tag->attribute('id');
     }, $tags);
     // then fetch the rest of tags, but exclude already fetched ones
     // fetch with main translation to be consistent with eztags attribute content
     $customConds = eZTagsObject::fetchCustomCondsSQL($params, true);
     if (!empty($tagsIDsToExclude)) {
         $customConds .= " AND " . eZDB::instance()->generateSQLINStatement($tagsIDsToExclude, 'eztags.id', true, true, 'int') . " ";
     }
     $tagsRest = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), array(), $params, null, null, true, false, array('DISTINCT eztags.*', array('operation' => 'eztags_keyword.keyword', 'name' => 'keyword'), array('operation' => 'eztags_keyword.locale', 'name' => 'locale')), array('eztags_keyword'), $customConds);
     if (!is_array($tagsRest)) {
         $tagsRest = array();
     }
     // finally, return both set of tags as one list
     $tags = array_merge($tags, $tagsRest);
     $returnArray = array('status' => 'success', 'message' => '', 'tags' => array());
     foreach ($tags as $tag) {
         $returnArrayChild = array();
         $returnArrayChild['tag_parent_id'] = $tag->attribute('parent_id');
         $returnArrayChild['tag_parent_name'] = $tag->hasParent(true) ? $tag->getParent(true)->attribute('keyword') : '';
         $returnArrayChild['tag_name'] = $tag->attribute('keyword');
         $returnArrayChild['tag_id'] = $tag->attribute('id');
         $returnArrayChild['tag_locale'] = $tag->attribute('current_language');
         $returnArray['tags'][] = $returnArrayChild;
     }
     return $returnArray;
 }
Пример #2
0
    $params = array('keyword' => array('like', '%' . $tagsSearchText . '%'));
    $customFields = array(array('operation' => 'COUNT( * )', 'name' => 'row_count'));
    $customConds = null;
    if ($tagsSearchSubTree > 0) {
        if ($tagsIncludeSynonyms) {
            $customConds = ' AND ( path_string LIKE "%/' . $tagsSearchSubTree . '/%" OR main_tag_id = ' . $tagsSearchSubTree . ' ) ';
        } else {
            $params['path_string'] = array('like', '%/' . $tagsSearchSubTree . '/%');
        }
    } else {
        if (!$tagsIncludeSynonyms) {
            $params['main_tag_id'] = 0;
        }
    }
    $tagsSearchResults = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), null, $params, null, $limits, true, false, null, null, $customConds);
    $tagsSearchCount = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), array(), $params, array(), null, false, false, $customFields, null, $customConds);
    $tagsSearchCount = $tagsSearchCount[0]['row_count'];
}
$tpl = eZTemplate::factory();
$tpl->setVariable('tags_search_text', $tagsSearchText);
$tpl->setVariable('tags_search_subtree', $tagsSearchSubTree);
$tpl->setVariable('tags_include_synonyms', $tagsIncludeSynonyms);
$tpl->setVariable('tags_search_count', $tagsSearchCount);
$tpl->setVariable('tags_search_results', $tagsSearchResults);
$tpl->setVariable('view_parameters', $viewParameters);
$tpl->setVariable('persistent_variable', false);
$Result = array();
$Result['content'] = $tpl->fetch('design:tags/search.tpl');
$Result['path'] = array(array('text' => ezpI18n::tr('extension/eztags/tags/search', 'Tags search'), 'url' => false));
$contentInfoArray = array();
$contentInfoArray['persistent_variable'] = false;
Пример #3
0
    public static function fetchByPathName($path)
    {
        if (!is_array($path) && is_string($path))
            $path = array($path);

        if (count($path) == 0)
            return false;

        $db         = eZDB::instance();
        $definition = eZTagsObject::definition();
        $table      = $definition['name'];
        $from       = array();
        $where      = array();
        $lastIndex  = 0;

        reset($path);

        while(list($index, $keyword) = each($path))
        {
            if ($index == 0)
            {
                $from[]     = sprintf('%1$s as t%2$d', $table, $index);
                $where[]    = sprintf('t%1$d.keyword like "%2$s" AND t%1$d.depth = 1', $index, $db->escapeString($keyword));
            }
            else
            {
                $from[]     = sprintf('INNER JOIN %1$s as t%3$d ON t%2$d.id = t%3$d.parent_id', $table, $index - 1, $index);
                $where[]    = sprintf('t%d.keyword like "%s"', $index, $db->escapeString($keyword));
            }

            $lastIndex = $index;
        }

        $query = sprintf(
            'SELECT t%d.id From %s Where %s;',
            $lastIndex,
            implode(' ', $from),
            implode(' AND ', $where)
        );

        $result = $db->arrayQuery($query);

        if (is_array($result) && count($result))
            return eZTagsObject::fetch($result[0]['id']);

        return false;
    }
Пример #4
0
 /**
  * Fetches latest modified tags by specified parameters
  *
  * @static
  * @param integer $parentTagID
  * @param integer $limit
  * @return array
  */
 public static function fetchLatestTags($parentTagID = false, $limit = 0)
 {
     $filterArray = array('main_tag_id' => 0);
     if ($parentTagID !== false) {
         $filterArray['parent_id'] = (int) $parentTagID;
     }
     $result = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), null, $filterArray, array('modified' => 'desc'), array('offset' => 0, 'limit' => $limit));
     if (is_array($result) && !empty($result)) {
         return array('result' => $result);
     } else {
         return array('result' => false);
     }
 }
Пример #5
0
#!/usr/bin/env php
<?php 
require 'autoload.php';
$cli = eZCLI::instance();
$script = eZScript::instance(array('description' => '\\nUpdates depth of all the tags.\\n', 'use-session' => false, 'use-modules' => false, 'use-extensions' => true));
$script->startup();
$options = $script->getOptions('', '', array());
$script->initialize();
$limit = 20;
$offset = 0;
$db = eZDB::instance();
$script->setIterationData('.', '~');
while ($firstLevelTags = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), null, array('parent_id' => 0, 'main_tag_id' => 0), null, array('offset' => $offset, 'limit' => $limit))) {
    foreach ($firstLevelTags as $tag) {
        $tagID = $tag->attribute('id');
        $db->begin();
        $tag->updateDepth(false);
        $db->commit();
        $script->iterate($cli, true, "Updated depth of tag ID = {$tagID} and all its children.");
    }
    $offset += $limit;
}
$script->shutdown();
Пример #6
0
$tagsIncludeSynonyms = $http->hasVariable('TagsIncludeSynonyms');
if (!empty($tagsSearchText)) {
    $sorts = array('eztags_keyword.keyword' => 'asc');
    $limits = array('offset' => $offset, 'limit' => $limit);
    $params = array('eztags_keyword.keyword' => array('like', '%' . $tagsSearchText . '%'));
    $customConds = eZTagsObject::fetchCustomCondsSQL($params);
    if ($tagsSearchSubTree > 0) {
        if ($tagsIncludeSynonyms) {
            $customConds .= ' AND ( path_string LIKE "%/' . $tagsSearchSubTree . '/%" OR main_tag_id = ' . $tagsSearchSubTree . ' ) ';
        } else {
            $params['path_string'] = array('like', '%/' . $tagsSearchSubTree . '/%');
        }
    } else {
        if (!$tagsIncludeSynonyms) {
            $params['main_tag_id'] = 0;
        }
    }
    $tagsSearchResults = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), array(), $params, $sorts, $limits, true, false, array('DISTINCT eztags.*', array('operation' => 'eztags_keyword.keyword', 'name' => 'keyword'), array('operation' => 'eztags_keyword.locale', 'name' => 'locale')), array('eztags_keyword'), $customConds);
    $tagsSearchCount = eZPersistentObject::fetchObjectList(eZTagsObject::definition(), array(), $params, array(), null, false, false, array(array('operation' => 'COUNT( * )', 'name' => 'row_count')), array('eztags_keyword'), $customConds);
    $tagsSearchCount = $tagsSearchCount[0]['row_count'];
}
$tpl = eZTemplate::factory();
$tpl->setVariable('tags_search_text', $tagsSearchText);
$tpl->setVariable('tags_search_subtree', $tagsSearchSubTree);
$tpl->setVariable('tags_include_synonyms', $tagsIncludeSynonyms);
$tpl->setVariable('tags_search_count', $tagsSearchCount);
$tpl->setVariable('tags_search_results', $tagsSearchResults);
$tpl->setVariable('view_parameters', $viewParameters);
$Result = array();
$Result['content'] = $tpl->fetch('design:tags/search.tpl');
$Result['path'] = eZTagsObject::generateModuleResultPath(false, null, ezpI18n::tr('extension/eztags/tags/search', 'Tags search'));
 /**
  * Returns array of eZTagsObject objects for given parent ID
  *
  * @static
  * @param integer $parentID
  * @param integer $offset
  * @param integer $limit
  * @return array
  */
 static function fetchByParentID($parentID, $offset = 0, $limit = null)
 {
     return eZPersistentObject::fetchObjectList(eZTagsObject::definition(), null, array('parent_id' => $parentID, 'main_tag_id' => 0), null, array('offset' => $offset, 'length' => $limit));
 }
 /**
  * Returns $limit latest tags
  *
  * @static
  * @param integer $limit
  * @return array
  */
 static function fetchLatestTags($limit)
 {
     return eZPersistentObject::fetchObjectList(eZTagsObject::definition(), null, array('main_tag_id' => 0), array('modified' => 'desc'), array('limit' => $limit));
 }