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; }
} if ($http->hasPostVariable('SaveButton')) { 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;
$error = ''; if ($http->hasPostVariable('SaveButton')) { $newKeyword = trim($http->postVariable('TagEditKeyword', '')); if (empty($newKeyword)) { $error = ezpI18n::tr('extension/eztags/errors', 'Name cannot be empty.'); } if (empty($error) && eZTagsObject::exists(0, $newKeyword, $parentTag instanceof eZTagsObject ? $parentTag->attribute('id') : 0)) { $error = ezpI18n::tr('extension/eztags/errors', 'Tag/synonym with that translation already exists in selected location.'); } if (empty($error)) { $db = eZDB::instance(); $db->begin(); $languageMask = eZContentLanguage::maskByLocale(array($language->attribute('locale')), $http->hasPostVariable('AlwaysAvailable')); $tag = new eZTagsObject(array('parent_id' => $parentTagID, 'main_tag_id' => 0, 'depth' => $parentTag instanceof eZTagsObject ? $parentTag->attribute('depth') + 1 : 1, 'path_string' => $parentTag instanceof eZTagsObject ? $parentTag->attribute('path_string') : '/', 'main_language_id' => $language->attribute('id'), 'language_mask' => $languageMask), $language->attribute('locale')); $tag->store(); $translation = new eZTagsKeyword(array('keyword_id' => $tag->attribute('id'), 'language_id' => $language->attribute('id'), 'keyword' => $newKeyword, 'locale' => $language->attribute('locale'), 'status' => eZTagsKeyword::STATUS_PUBLISHED)); if ($http->hasPostVariable('AlwaysAvailable')) { $translation->setAttribute('language_id', $translation->attribute('language_id') + 1); } $translation->store(); $tag->setAttribute('path_string', $tag->attribute('path_string') . $tag->attribute('id') . '/'); $tag->store(); $tag->updateModified(); /* Extended Hook */ if (class_exists('ezpEvent', false)) { ezpEvent::getInstance()->filter('tag/add', array('tag' => $tag, 'parentTag' => $parentTag)); } $db->commit(); return $Module->redirectToView('id', array($tag->attribute('id'))); } }
} } if ($http->hasPostVariable('SaveButton')) { 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, $parentTag instanceof eZTagsObject ? $parentTag->attribute('id') : 0)) { $error = ezpI18n::tr('extension/eztags/errors', 'Tag/synonym with that name already exists in selected location.'); } if (empty($error)) { $db = eZDB::instance(); $db->begin(); $tag = new eZTagsObject(array('parent_id' => $parentTag instanceof eZTagsObject ? $parentTag->attribute('id') : 0, 'main_tag_id' => 0, 'keyword' => $newKeyword, 'depth' => $parentTag instanceof eZTagsObject ? (int) $parentTag->attribute('depth') + 1 : 1, '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(); /* Extended Hook */ if (class_exists('ezpEvent', false)) { $tag = ezpEvent::getInstance()->filter('tag/add', $tag); } $db->commit(); return $Module->redirectToView('id', array($tag->attribute('id'))); } } $tpl = eZTemplate::factory(); $tpl->setVariable('parent_id', $parentTagID); $tpl->setVariable('error', $error); $tpl->setVariable('ui_context', 'edit'); $Result = array();
/** * Moves all children tags of the provided tag to the new location * * @static * @param eZTagsObject $tag * @param eZTagsObject $targetTag */ static function moveChildren($tag, $targetTag) { $currentTime = time(); $children = $tag->getChildren(); foreach ($children as $child) { $childSynonyms = $child->getSynonyms(); foreach ($childSynonyms as $childSynonym) { $childSynonym->setAttribute('parent_id', $targetTag->attribute('id')); $childSynonym->store(); } $child->setAttribute('parent_id', $targetTag->attribute('id')); $child->Modified = $currentTime; $child->store(); $child->updatePathString($targetTag); $child->updateDepth($targetTag); } }
/** * Links the content object attribute and tag * * @static * * @param eZContentObjectAttribute $attribute * @param eZTagsObject $tagObject * @param string $keyword * @param string $locale */ private static function linkTag(eZContentObjectAttribute $attribute, eZTagsObject $tagObject, $keyword, $locale, $priority) { $languageID = eZContentLanguage::idByLocale($locale); if ($languageID === false) { return; } if ($locale == $attribute->attribute('language_code')) { if (!$tagObject->hasTranslation($locale)) { $tagKeywordObject = new eZTagsKeyword(array('keyword_id' => $tagObject->attribute('id'), 'language_id' => $languageID, 'keyword' => $keyword, 'locale' => $locale, 'status' => eZTagsKeyword::STATUS_PUBLISHED)); $tagKeywordObject->store(); $tagObject->updateLanguageMask(); } } $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(); }
/** * Moves all children of this tag below another tag * * @param eZTagsObject $targetTag */ public function moveChildrenBelowAnotherTag(eZTagsObject $targetTag) { $currentTime = time(); $children = $this->getChildren(0, null, true); foreach ($children as $child) { $childSynonyms = $child->getSynonyms(true); foreach ($childSynonyms as $childSynonym) { $childSynonym->setAttribute('parent_id', $targetTag->attribute('id')); $childSynonym->store(); } $child->setAttribute('parent_id', $targetTag->attribute('id')); $child->setAttribute('modified', $currentTime); $child->store(); $child->updatePathString($targetTag); $child->updateDepth($targetTag); } }