/**
  * converts category to tag
  * 
  * @param int $catId
  * @return string tagid
  */
 public function getTag($catId)
 {
     if (!(isset($this->_tagMapCache[$catId]) || array_key_exists($catId, $this->_tagMapCache))) {
         $select = $this->_egwDb->select()->from(array('cats' => 'egw_categories'))->where($this->_egwDb->quoteInto($this->_egwDb->quoteIdentifier('cat_id') . ' = ?', $catId));
         $cat = $this->_egwDb->fetchAll($select, NULL, Zend_Db::FETCH_ASSOC);
         $cat = count($cat) === 1 ? $cat[0] : NULL;
         if (!$cat) {
             $this->_log->DEBUG(__METHOD__ . '::' . __LINE__ . " category {$catId} not found in egw, skipping tag");
             return $this->_tagMapCache[$catId] = NULL;
         }
         $tineDb = Tinebase_Core::getDb();
         $select = $tineDb->select()->from(array('tags' => $tineDb->table_prefix . 'tags'))->where($tineDb->quoteInto($tineDb->quoteIdentifier('name') . ' LIKE ?', $cat['cat_name']));
         $tag = $tineDb->fetchAll($select, NULL, Zend_Db::FETCH_ASSOC);
         $tag = count($tag) > 0 ? $tag[0] : NULL;
         if ($tag) {
             return $this->_tagMapCache[$catId] = $tag['id'];
         }
         // create tag
         $catData = unserialize($cat['cat_data']);
         $tagId = Tinebase_Record_Abstract::generateUID();
         $tagType = $cat['cat_access'] == 'public' ? Tinebase_Model_Tag::TYPE_SHARED : Tinebase_Model_Tag::TYPE_PERSONAL;
         $tagOwner = $tagType == Tinebase_Model_Tag::TYPE_SHARED ? 0 : $this->mapAccountIdEgw2Tine($cat['cat_owner']);
         $this->_log->NOTICE(__METHOD__ . '::' . __LINE__ . " creating new {$tagType} tag '{$cat['cat_name']}'");
         $tineDb->insert($tineDb->table_prefix . 'tags', array('id' => $tagId, 'type' => $tagType, 'owner' => $tagOwner, 'name' => $cat['cat_name'], 'description' => $cat['cat_description'], 'color' => $catData['color'], 'created_by' => $tagOwner ? $tagOwner : Tinebase_Core::getUser()->getId(), 'creation_time' => $cat['last_mod'] ? $this->convertDate($cat['last_mod']) : Tinebase_DateTime::now()));
         $right = new Tinebase_Model_TagRight(array('tag_id' => $tagId, 'account_type' => $tagType == Tinebase_Model_Tag::TYPE_SHARED ? Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE : Tinebase_Acl_Rights::ACCOUNT_TYPE_USER, 'account_id' => $tagOwner, 'view_right' => true, 'use_right' => true));
         Tinebase_Tags::getInstance()->setRights($right);
         Tinebase_Tags::getInstance()->setContexts(array(0), $tagId);
         $this->_tagMapCache[$catId] = $tagId;
     }
     return $this->_tagMapCache[$catId];
 }
Exemplo n.º 2
0
 /**
  * generates random challenge 
  * 
  * @return string
  */
 protected function _getChallenge()
 {
     if (!empty($this->_challenge)) {
         return $this->_challenge;
     }
     $session = $this->getSession();
     if (!$session instanceof Zend_Session_Namespace) {
         /**
          * @see Zend_Auth_Adapter_Exception
          */
         require_once 'Zend/Auth/Adapter/Exception.php';
         throw new Zend_Auth_Adapter_Exception('session is not set');
     }
     if (empty($session->ntlmchallenge)) {
         $session->ntlmchallenge = $this->generateChallenge();
     }
     $this->_log->DEBUG("server challenge : {$session->ntlmchallenge}");
     return $session->ntlmchallenge;
 }