Пример #1
0
 /**
  * adds a new personal tag
  *
  * @param  array $tag
  * @return array
  */
 public function saveTag($tag)
 {
     $inTag = new Tinebase_Model_Tag($tag);
     if (strlen($inTag->getId()) < 40) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' creating tag: ' . print_r($inTag->toArray(), true));
         }
         $outTag = Tinebase_Tags::getInstance()->createTag($inTag);
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' updating tag: ' . print_r($inTag->toArray(), true));
         }
         $outTag = Tinebase_Tags::getInstance()->updateTag($inTag);
     }
     return $outTag->toArray();
 }
 /**
  * updates a single tag
  *
  * @param   Tinebase_Model_Tag
  * @return  Tinebase_Model_Tag
  * @throws  Tinebase_Exception_AccessDenied
  */
 public function updateTag(Tinebase_Model_Tag $_tag)
 {
     if ($_tag instanceof Tinebase_Model_FullTag) {
         $_tag = new Tinebase_Model_Tag($_tag->toArray(), TRUE);
     }
     $currentAccountId = Tinebase_Core::getUser()->getId();
     $manageSharedTagsRight = Tinebase_Acl_Roles::getInstance()->hasRight('Admin', $currentAccountId, Admin_Acl_Rights::MANAGE_SHARED_TAGS);
     if ($_tag->type == Tinebase_Model_Tag::TYPE_PERSONAL && $_tag->owner == $currentAccountId || $_tag->type == Tinebase_Model_Tag::TYPE_SHARED && $manageSharedTagsRight) {
         $tagId = $_tag->getId();
         if (strlen($tagId) != 40) {
             throw new Tinebase_Exception_AccessDenied('Could not update non-existing tag.');
         }
         $this->_db->update(SQL_TABLE_PREFIX . 'tags', array('type' => $_tag->type, 'owner' => $_tag->owner, 'name' => $_tag->name, 'description' => $_tag->description, 'color' => $_tag->color, 'last_modified_by' => $currentAccountId, 'last_modified_time' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG)), $this->_db->quoteInto($this->_db->quoteIdentifier('id') . '= ?', $tagId));
         $tags = $this->getTagsById($tagId);
         return $tags[0];
     } else {
         throw new Tinebase_Exception_AccessDenied('Your are not allowed to update this tag.');
     }
 }