示例#1
0
    public static function create($remoteID, $keyword, eZTagsObject $parentTag=null)
    {
        // Vérification de l'existance
        if ($remoteID)
        {
            $tag = eZTagsObject::fetchByRemoteID($remoteID);

            if ($tag)
            {
                if ($parentTag && $tag->attribute( 'parent_id' ) != $parentTag->attribute('id'))
                {
                    $tag->setAttribute('parent_id', $parentTag->attribute('id'));
                    $tag->updatePathString($parentTag);
                    $tag->updateDepth($parentTag);
                }

                return $tag;
            }
        }
        else
        {
            $tags = eZTagsObject::fetchList(array(
                'keyword' => array( 'like', trim( $keyword ) ),
                'parent_id' => $parentTag ? $parentTag->attribute('id') : 0,
            ));

            if (count($tags))
                return $tags[0];
        }

        $db = eZDB::instance();
        $db->begin();

        // Création du tag
        $tag = new eZTagsObject(array(
            'remote_id'   => $remoteID,
            'parent_id'   => $parentTag ? $parentTag->attribute( 'id' ) : null,
            'main_tag_id' => null,
            'keyword'     => $keyword,
            'depth'       => $parentTag ? $parentTag->attribute( 'depth' ) + 1 : 1
        ));

        $tag->store();

        // Mise a jour du path string
        $tag->setAttribute( 'path_string', ($parentTag ? $parentTag->attribute( 'path_string' ) : '/') . $tag->attribute( 'id' ) . '/' );
        $tag->store();
        $tag->updateModified();

        $db->commit();

        /* Extended Hook */
        if ( class_exists( 'ezpEvent', false ) )
            ezpEvent::getInstance()->filter( 'tag/add', array( 'tag' => $tag, 'parentTag' => $parentTag ) );

        return $tag;
    }
示例#2
0
    if (!($http->hasPostVariable('TagEditKeyword') && strlen(trim($http->postVariable('TagEditKeyword'))) > 0)) {
        $error = ezpI18n::tr('extension/eztags/errors', 'Name cannot be empty.');
    }
    $newKeyword = trim($http->postVariable('TagEditKeyword'));
    if (empty($error) && eZTagsObject::exists(0, $newKeyword, $mainTag->attribute('parent_id'))) {
        $error = ezpI18n::tr('extension/eztags/errors', 'Tag/synonym with that name already exists in selected location.');
    }
    if (empty($error)) {
        $parentTag = eZTagsObject::fetch($mainTag->attribute('parent_id'));
        $db = eZDB::instance();
        $db->begin();
        $tag = new eZTagsObject(array('parent_id' => $mainTag->attribute('parent_id'), 'main_tag_id' => $mainTagID, 'keyword' => $newKeyword, 'depth' => $mainTag->attribute('depth'), 'path_string' => $parentTag instanceof eZTagsObject ? $parentTag->attribute('path_string') : '/'));
        $tag->store();
        $tag->setAttribute('path_string', $tag->attribute('path_string') . $tag->attribute('id') . '/');
        $tag->store();
        $tag->updateModified();
        $db->commit();
        return $Module->redirectToView('id', array($tag->attribute('id')));
    }
}
$tpl = eZTemplate::factory();
$tpl->setVariable('main_tag', $mainTag);
$tpl->setVariable('error', $error);
$tpl->setVariable('ui_context', 'edit');
$Result = array();
$Result['content'] = $tpl->fetch('design:tags/addsynonym.tpl');
$Result['ui_context'] = 'edit';
$Result['path'] = array();
$tempTag = $mainTag;
while ($tempTag->hasParent()) {
    $Result['path'][] = array('tag_id' => $tempTag->attribute('id'), 'text' => $tempTag->attribute('keyword'), 'url' => false);
示例#3
0
文件: eztags.php 项目: oki34/eztags
 /**
  * Creates a new tag and links it to provided content object attribute
  *
  * @static
  *
  * @param eZContentObjectAttribute $attribute
  * @param int $parentID
  * @param string $parentPathString
  * @param int $parentDepth
  * @param string $keyword
  * @param string $locale
  */
 private static function createAndLinkTag(eZContentObjectAttribute $attribute, $parentID, $parentPathString, $parentDepth, $keyword, $locale, $priority)
 {
     $languageID = eZContentLanguage::idByLocale($locale);
     if ($languageID === false) {
         return;
     }
     $ini = eZINI::instance('eztags.ini');
     $alwaysAvailable = $ini->variable('GeneralSettings', 'DefaultAlwaysAvailable');
     $alwaysAvailable = $alwaysAvailable === 'true' ? 1 : 0;
     $tagObject = new eZTagsObject(array('parent_id' => $parentID, 'main_tag_id' => 0, 'depth' => $parentDepth + 1, 'path_string' => $parentPathString, 'main_language_id' => $languageID, 'language_mask' => $languageID + $alwaysAvailable), $locale);
     $tagObject->store();
     $tagKeywordObject = new eZTagsKeyword(array('keyword_id' => $tagObject->attribute('id'), 'language_id' => $languageID + $alwaysAvailable, 'keyword' => $keyword, 'locale' => $locale, 'status' => eZTagsKeyword::STATUS_PUBLISHED));
     $tagKeywordObject->store();
     $tagObject->setAttribute('path_string', $tagObject->attribute('path_string') . $tagObject->attribute('id') . '/');
     $tagObject->store();
     $tagObject->updateModified();
     $linkObject = new eZTagsAttributeLinkObject(array('keyword_id' => $tagObject->attribute('id'), 'objectattribute_id' => $attribute->attribute('id'), 'objectattribute_version' => $attribute->attribute('version'), 'object_id' => $attribute->attribute('contentobject_id'), 'priority' => $priority));
     $linkObject->store();
     if (class_exists('ezpEvent', false)) {
         ezpEvent::getInstance()->filter('tag/add', array('tag' => $tagObject, 'parentTag' => $tagObject->getParent(true)));
     }
 }