/**
  * detach a single tag from records
  * 
  * @param array $recordIds
  * @param string $dirtyTagId
  * @param string $appId
  * @param Tinebase_Controller_Record_Abstract $controller
  */
 protected function _detachSingleTag($recordIds, $dirtyTagId, $appId, $controller)
 {
     $tag = $this->getTagsById($dirtyTagId, Tinebase_Model_TagRight::USE_RIGHT)->getFirstRecord();
     if (empty($tag)) {
         Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' No use right for tag, detaching not possible.');
         return;
     }
     $tagId = $tag->getId();
     $attachedIds = array();
     $select = $this->_db->select()->from(array('tagging' => SQL_TABLE_PREFIX . 'tagging'), 'record_id')->where($this->_db->quoteIdentifier('application_id') . ' = ?', $appId)->where($this->_db->quoteIdentifier('tag_id') . ' = ? ', $tagId)->where($this->_db->quoteInto($this->_db->quoteIdentifier('record_id') . ' IN (?)', $recordIds));
     Tinebase_Backend_Sql_Abstract::traitGroup($select);
     foreach ($this->_db->fetchAssoc($select) as $tagArray) {
         $attachedIds[] = $tagArray['record_id'];
     }
     if (empty($attachedIds)) {
         Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' There are no records we could detach the tag(s) from');
         return;
     }
     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Detaching 1 Tag from ' . count($attachedIds) . ' records.');
     foreach ($attachedIds as $recordId) {
         $this->_db->delete(SQL_TABLE_PREFIX . 'tagging', array($this->_db->quoteIdentifier('tag_id') . ' = ?' => $tagId, $this->_db->quoteIdentifier('record_id') . ' = ?' => $recordId, $this->_db->quoteIdentifier('application_id') . ' = ?' => $appId));
     }
     $controller->concurrencyManagementAndModlogMultiple($attachedIds, array('tags' => array($tag->toArray())), array('tags' => array()));
     $this->_deleteOccurrence($tagId, count($attachedIds));
 }
Exemplo n.º 2
0
 /**
  * search for notes
  *
  * @param Tinebase_Model_NoteFilter $_filter
  * @param Tinebase_Model_Pagination $_pagination
  * @return Tinebase_Record_RecordSet subtype Tinebase_Model_Note
  */
 public function searchNotes(Tinebase_Model_NoteFilter $_filter, Tinebase_Model_Pagination $_pagination = NULL)
 {
     $select = $this->_db->select()->from(array('notes' => SQL_TABLE_PREFIX . 'notes'));
     Tinebase_Backend_Sql_Filter_FilterGroup::appendFilters($select, $_filter, $this);
     if ($_pagination !== NULL) {
         $_pagination->appendPaginationSql($select);
     }
     //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $select->__toString());
     $rows = $this->_db->fetchAssoc($select);
     $result = new Tinebase_Record_RecordSet('Tinebase_Model_Note', $rows, true);
     return $result;
 }
Exemplo n.º 3
0
 /**
  * detach tag from multiple records identified by a filter
  *
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param mixed                             $_tag       string|array|Tinebase_Model_Tag with existing and non-existing tag
  * @return void
  */
 public function detachTagsFromMultipleRecords($_filter, $_tag)
 {
     list($appName, $i, $modelName) = explode('_', $_filter->getModelName());
     $appId = Tinebase_Application::getInstance()->getApplicationByName($appName)->getId();
     $controller = Tinebase_Core::getApplicationInstance($appName, $modelName);
     if (!is_array($_tag)) {
         $_tag = array($_tag);
     }
     foreach ($_tag as $dirtyTagId) {
         $tag = $this->getTagsById($dirtyTagId, Tinebase_Model_TagRight::USE_RIGHT)->getFirstRecord();
         if (empty($tag)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' No use right for tag, detaching not possible.');
             return;
         }
         $tagId = $tag->getId();
         // only get records user has update rights to
         $controller->checkFilterACL($_filter, 'update');
         $recordIds = $controller->search($_filter, NULL, FALSE, TRUE);
         $recordIdList = '\'' . implode('\',\'', $recordIds) . '\'';
         $attachedIds = array();
         $select = $this->_db->select()->from(array('tagging' => SQL_TABLE_PREFIX . 'tagging'), 'record_id')->where($this->_db->quoteIdentifier('application_id') . ' = ?', $appId)->where($this->_db->quoteIdentifier('tag_id') . ' = ? ', $tagId)->where($this->_db->quoteIdentifier('record_id') . ' IN ( ' . $recordIdList . ' ) ');
         foreach ($this->_db->fetchAssoc($select) as $tagArray) {
             $attachedIds[] = $tagArray['record_id'];
         }
         if (empty($attachedIds)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' There are no records we could detach the tag(s) from');
             return;
         }
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Detaching 1 Tag from ' . count($attachedIds) . ' records.');
         foreach ($attachedIds as $recordId) {
             $this->_db->delete(SQL_TABLE_PREFIX . 'tagging', 'tag_id=\'' . $tagId . '\' AND record_id=\'' . $recordId . '\' AND application_id=\'' . $appId . '\'');
         }
         $controller->concurrencyManagementAndModlogMultiple($attachedIds, array('tags' => array($tag->toArray())), array('tags' => array()));
         $this->_deleteOccurrence($tagId, count($attachedIds));
     }
 }
Exemplo n.º 4
0
 /**
  * Returns roles count
  * 
  * @param Tinebase_Model_RoleFilter $_filter
  * @return int
  */
 public function searchCount($_filter)
 {
     $select = $_filter->getSelect();
     $roles = new Tinebase_Record_RecordSet('Tinebase_Model_Role', $this->_db->fetchAssoc($select));
     return count($roles);
 }