示例#1
0
 /**
  * get select for tags query
  *
  * @param string|array $_recordId
  * @param string $_applicationId
  * @param mixed $_cols
  * @return Zend_Db_Select
  */
 protected function _getSelect($_recordId, $_applicationId, $_cols = '*')
 {
     array_walk($_recordId, function (&$value, $index) {
         $value = (string) $value;
     });
     $select = $this->_db->select()->from(array('tagging' => SQL_TABLE_PREFIX . 'tagging'), $_cols)->join(array('tags' => SQL_TABLE_PREFIX . 'tags'), $this->_db->quoteIdentifier('tagging.tag_id') . ' = ' . $this->_db->quoteIdentifier('tags.id'))->where($this->_db->quoteIdentifier('application_id') . ' = ?', $_applicationId)->where($this->_db->quoteIdentifier('record_id') . ' IN (?) ', (array) $_recordId)->where($this->_db->quoteIdentifier('is_deleted') . ' = 0');
     return $select;
 }
示例#2
0
 /**
  * add single role rights 
  *
  * @param   int $_roleId
  * @param   int $_applicationId
  * @param   string $_right
  */
 public function addSingleRight($_roleId, $_applicationId, $_right)
 {
     // check if already in
     $select = $this->_roleRightsTable->select();
     $select->where($this->_db->quoteInto($this->_db->quoteIdentifier('role_id') . ' = ?', $_roleId))->where($this->_db->quoteInto($this->_db->quoteIdentifier('right') . ' = ?', $_right))->where($this->_db->quoteInto($this->_db->quoteIdentifier('application_id') . ' = ?', $_applicationId));
     if (!($row = $this->_roleRightsTable->fetchRow($select))) {
         $data = array('role_id' => $_roleId, 'application_id' => $_applicationId, 'right' => $_right);
         $this->_roleRightsTable->insert($data);
     }
 }
 /**
  * merge duplicate shared tags
  * 
  * @param string $model record model for which tags should be merged
  * @param boolean $deleteObsoleteTags
  * @param boolean $ignoreAcl
  * 
  * @see 0007354: function for merging duplicate tags
  */
 public function mergeDuplicateSharedTags($model, $deleteObsoleteTags = TRUE, $ignoreAcl = FALSE)
 {
     $select = $this->_db->select()->from(array('tags' => SQL_TABLE_PREFIX . 'tags'), 'name')->where($this->_db->quoteIdentifier('type') . ' = ?', Tinebase_Model_Tag::TYPE_SHARED)->where($this->_db->quoteIdentifier('is_deleted') . ' = 0')->group('name')->having('COUNT(' . $this->_db->quoteIdentifier('name') . ') > 1');
     $queryResult = $this->_db->fetchAll($select);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Found ' . count($queryResult) . ' duplicate tag names.');
     }
     $controller = Tinebase_Core::getApplicationInstance($model);
     if ($ignoreAcl) {
         $containerChecks = $controller->doContainerACLChecks(FALSE);
     }
     $recordFilterModel = $model . 'Filter';
     foreach ($queryResult as $duplicateTag) {
         $filter = new Tinebase_Model_TagFilter(array('name' => $duplicateTag['name'], 'type' => Tinebase_Model_Tag::TYPE_SHARED));
         $paging = new Tinebase_Model_Pagination(array('sort' => 'creation_time'));
         $tagsWithSameName = $this->searchTags($filter, $paging);
         $targetTag = $tagsWithSameName->getFirstRecord();
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Merging tag ' . $duplicateTag['name'] . '. Found ' . count($tagsWithSameName) . ' tags with this name.');
         }
         foreach ($tagsWithSameName as $tag) {
             if ($tag->getId() === $targetTag->getId()) {
                 // skip target (oldest) tag
                 continue;
             }
             $recordFilter = new $recordFilterModel(array(array('field' => 'tag', 'operator' => 'in', 'value' => array($tag->getId()))));
             $recordIdsWithTagToMerge = $controller->search($recordFilter, NULL, FALSE, TRUE);
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Found ' . count($recordIdsWithTagToMerge) . ' ' . $model . '(s) with tags to be merged.');
             }
             if (!empty($recordIdsWithTagToMerge)) {
                 $recordFilter = new $recordFilterModel(array(array('field' => 'id', 'operator' => 'in', 'value' => $recordIdsWithTagToMerge)));
                 $this->attachTagToMultipleRecords($recordFilter, $targetTag);
                 $this->detachTagsFromMultipleRecords($recordFilter, $tag->getId());
             }
             // check occurrence of the merged tag and remove it if obsolete
             $tag = $this->get($tag);
             if ($deleteObsoleteTags && $tag->occurrence == 0) {
                 $this->deleteTags($tag->getId(), $ignoreAcl);
             }
         }
     }
     if ($ignoreAcl) {
         /** @noinspection PhpUndefinedVariableInspection */
         $controller->doContainerACLChecks($containerChecks);
     }
 }
示例#4
0
 /**
  * get registration by hash
  *
  * @param string $_hash the hash (md5 coded username) from the registration mail
  * @return Tinebase_Model_Registration the registration object
  *
  */
 public function getRegistrationByHash($_hash)
 {
     $select = $this->_db->select()->from(SQL_TABLE_PREFIX . 'registrations')->where($this->_db->quoteIdentifier('login_hash') . ' = ?', $_hash);
     $stmt = $select->query();
     $row = $stmt->fetch(Zend_Db::FETCH_ASSOC);
     if ($row === false) {
         throw new Tinebase_Exception_Record_NotDefined('registration entry not found error');
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . "Tinebase_Model_Registration::row values: \n" . print_r($row, true));
     }
     try {
         $registration = new Tinebase_Model_Registration();
         $registration->setFromArray($row);
     } catch (Exception $e) {
         $validationErrors = $registration->getValidationErrors();
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . $e->getMessage() . "\n" . "Tinebase_Model_Registration::validation_errors: \n" . print_r($validationErrors, true));
         }
         throw $e;
     }
     return $registration;
 }
 /**
  * delete note type
  *
  * @param integer $_noteTypeId
  */
 public function deleteNoteType($_noteTypeId)
 {
     $this->_noteTypesTable->delete($this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $_noteTypeId));
 }