示例#1
0
 /**
  * Delete stored object attribute
  *
  * @param eZContentObjectAttribute $contentObjectAttribute
  * @param eZContentObjectVersion $version
  */
 public function deleteStoredObjectAttribute($contentObjectAttribute, $version = null)
 {
     $contentObjectAttributeID = $contentObjectAttribute->attribute('id');
     eZTagsAttributeLinkObject::removeByAttribute($contentObjectAttributeID, $version);
 }
示例#2
0
文件: eztags.php 项目: oki34/eztags
 /**
  * Stores the tags to database
  *
  * @param eZContentObjectAttribute $attribute
  */
 public function store(eZContentObjectAttribute $attribute)
 {
     $this->Attribute = $attribute;
     if (!is_numeric($this->Attribute->attribute('id')) || !is_numeric($this->Attribute->attribute('version'))) {
         return;
     }
     $db = eZDB::instance();
     $db->begin();
     // first remove all links in this version, allows emptying the attribute and storing
     eZTagsAttributeLinkObject::removeByAttribute($this->Attribute->attribute('id'), $this->Attribute->attribute('version'));
     if (empty($this->IDArray)) {
         $db->commit();
         return;
     }
     // if for some reason already existing tags are added with ID = 0 with fromString
     // check to see if they really exist, so we can link to them
     // locale doesn't matter here, since we don't allow storing tags under the same
     // parent that have any of translations same as any other translation from another tag
     foreach (array_keys($this->IDArray) as $key) {
         if ($this->IDArray[$key] == 0) {
             $results = $db->arrayQuery("SELECT eztags.id\n                                             FROM eztags, eztags_keyword\n                                             WHERE eztags.id = eztags_keyword.keyword_id AND\n                                                 eztags.parent_id = " . (int) $this->ParentArray[$key] . " AND\n                                                 eztags_keyword.keyword LIKE '" . $db->escapeString($this->KeywordArray[$key]) . "'", array('offset' => 0, 'limit' => 1));
             if (is_array($results) && !empty($results)) {
                 $this->IDArray[$key] = (int) $results[0]['id'];
             }
         }
     }
     // first check if user can really add tags, considering policies
     // and subtree limits
     $permissionArray = $this->getPermissionArray();
     $priority = 0;
     foreach (array_keys($this->IDArray) as $key) {
         if ($this->IDArray[$key] == 0 && $permissionArray['can_add']) {
             $pathString = '/';
             $depth = 0;
             $parentTag = eZTagsObject::fetchWithMainTranslation($this->ParentArray[$key]);
             if ($parentTag instanceof eZTagsObject) {
                 $pathString = $parentTag->attribute('path_string');
                 $depth = (int) $parentTag->attribute('depth');
             }
             //and then for each tag check if user can save in one of the allowed locations
             if (self::canSave($pathString, $permissionArray['allowed_locations'])) {
                 self::createAndLinkTag($this->Attribute, $this->ParentArray[$key], $pathString, $depth, $this->KeywordArray[$key], $this->LocaleArray[$key], $priority);
                 $priority++;
             }
         } else {
             if ($this->IDArray[$key] > 0) {
                 $tagObject = eZTagsObject::fetchWithMainTranslation($this->IDArray[$key]);
                 if (!$tagObject instanceof eZTagsObject) {
                     continue;
                 }
                 if ($permissionArray['subtree_limit'] == 0 || $permissionArray['subtree_limit'] > 0 && strpos($tagObject->attribute('path_string'), '/' . $permissionArray['subtree_limit'] . '/') !== false) {
                     self::linkTag($this->Attribute, $tagObject, $this->KeywordArray[$key], $this->LocaleArray[$key], $priority);
                     $priority++;
                 }
             }
         }
     }
     $db->commit();
 }