/** * update tag occurrrence * * @param Tinebase_Model_Tag|string $tag * @param integer $toAddOrRemove */ protected function _updateOccurrence($tag, $toAddOrRemove) { if ($toAddOrRemove == 0) { return; } $tagId = $tag instanceof Tinebase_Model_Tag ? $tag->getId() : $tag; if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " de/increasing tag occurrence of {$tagId} by {$toAddOrRemove}"); } $quotedIdentifier = $this->_db->quoteIdentifier('occurrence'); if ($toAddOrRemove > 0) { $toAdd = (int) $toAddOrRemove; $data = array('occurrence' => new Zend_Db_Expr($quotedIdentifier . ' + ' . $toAdd)); } else { $toRemove = abs((int) $toAddOrRemove); $data = array('occurrence' => new Zend_Db_Expr('(CASE WHEN (' . $quotedIdentifier . ' - ' . $toRemove . ') > 0 THEN ' . $quotedIdentifier . ' - ' . $toRemove . ' ELSE 0 END)')); } $this->_db->update(SQL_TABLE_PREFIX . 'tags', $data, $this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $tagId)); }
/** * 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(); }
/** * Creates missing tags on the fly and returns complete list of tags the current * user has use rights for. * Allways respects the current acl of the current user! * * @param array|Tinebase_Record_RecordSet set of string|array|Tinebase_Model_Tag with existing and non-existing tags * @return Tinebase_Record_RecordSet set of all tags * @throws Tinebase_Exception_UnexpectedValue */ protected function _createTagsOnTheFly($_mixedTags) { if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Creating tags on the fly: ' . print_r($_mixedTags, true)); } $tagIds = array(); foreach ($_mixedTags as $tag) { if (is_string($tag)) { $tagIds[] = $tag; continue; } else { if (is_array($tag)) { if (!isset($tag['name']) || empty($tag['name'])) { if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Do not create tag without a name.'); } continue; } $tag = new Tinebase_Model_Tag($tag); } elseif (!$tag instanceof Tinebase_Model_Tag) { throw new Tinebase_Exception_UnexpectedValue('Tag could not be identified.'); } if (!$tag->getId()) { $tag->type = Tinebase_Model_Tag::TYPE_PERSONAL; $tag = $this->createTag($tag); } $tagIds[] = $tag->getId(); } } return $this->getTagsById($tagIds, Tinebase_Model_TagRight::USE_RIGHT); }