Beispiel #1
0
 /**
  * returns all observers of a given observable and event
  * 
  * @param Tinebase_Record_Interface $_observable 
  * @param string _event 
  * @return Tinebase_Record_RecordSet
  */
 protected function getObserversByEvent($_observable, $_event)
 {
     if (!$_observer->getApplication() || !$_observer->getId()) {
         throw new Tinebase_Exception_Record_DefinitionFailure();
     }
     $where = array($this->_db->quoteIdentifier('observable_application') . ' =' . $_observable->getApplication(), $this->_db->quoteIdentifier('observable_identifier') . '  =' . $_observable->getId(), $this->_db->quoteIdentifier('observed_event') . '         =' . $this->_db->getAdapter()->quote($_event));
     return new Tinebase_Record_RecordSet('Tinebase_Model_PersistentObserver', $this->_db->fetchAll($where), true);
 }
Beispiel #2
0
 /**
  * get all note types
  *
  * @param boolean|optional $onlyNonSystemNotes
  * @return Tinebase_Record_RecordSet of Tinebase_Model_NoteType
  */
 public function getNoteTypes($onlyNonSystemNotes = FALSE)
 {
     $types = new Tinebase_Record_RecordSet('Tinebase_Model_NoteType');
     foreach ($this->_noteTypesTable->fetchAll() as $type) {
         if (!$onlyNonSystemNotes || $type->is_user_type) {
             $types->addRecord(new Tinebase_Model_NoteType($type->toArray(), true));
         }
     }
     return $types;
 }
 /**
  * Get multiple groups
  *
  * @param string|array $_ids Ids
  * @return Tinebase_Record_RecordSet
  * 
  * @todo this should return the container_id, too
  */
 public function getMultiple($_ids)
 {
     $result = new Tinebase_Record_RecordSet('Tinebase_Model_Group');
     if (!empty($_ids)) {
         $select = $this->groupsTable->select();
         $select->where($this->_db->quoteIdentifier('id') . ' IN (?)', array_unique((array) $_ids));
         $rows = $this->groupsTable->fetchAll($select);
         foreach ($rows as $row) {
             $result->addRecord(new Tinebase_Model_Group($row->toArray(), TRUE));
         }
     }
     return $result;
 }
Beispiel #4
0
 /**
  * get list of role rights 
  *
  * @param   int $_roleId
  * @return  array of array with application ids & rights
  * @throws  Tinebase_Exception_InvalidArgument
  */
 public function getRoleRights($_roleId)
 {
     $roleId = (int) $_roleId;
     if ($roleId != $_roleId || $roleId <= 0) {
         throw new Tinebase_Exception_InvalidArgument('$_roleId must be integer and greater than 0');
     }
     $rights = array();
     $select = $this->_roleRightsTable->select();
     $select->where($this->_db->quoteInto($this->_db->quoteIdentifier('role_id') . ' = ?', $_roleId));
     $rows = $this->_roleRightsTable->fetchAll($select)->toArray();
     foreach ($rows as $right) {
         $rights[] = array('application_id' => $right['application_id'], 'right' => $right['right']);
     }
     return $rights;
 }
 /**
  * returns all relations of a given record and optionally only of given role
  * 
  * @param  string       $_model         own model to get all relations for
  * @param  string       $_backend       own backend to get all relations for
  * @param  string|array $_id            own id to get all relations for 
  * @param  string       $_degree        only return relations of given degree
  * @param  array        $_type          only return relations of given type
  * @param  boolean      $_returnAll     gets all relations (default: only get not deleted/broken relations)
  * @param  array        $_relatedModels  only return relations having this related model
  * @return Tinebase_Record_RecordSet of Tinebase_Model_Relation
  */
 public function getAllRelations($_model, $_backend, $_id, $_degree = NULL, array $_type = array(), $_returnAll = false, $_relatedModels = NULL)
 {
     $_id = $_id ? (array) $_id : array('');
     $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('own_model') . ' = ?', $_model), $this->_db->quoteInto($this->_db->quoteIdentifier('own_backend') . ' = ?', $_backend), $this->_db->quoteInto($this->_db->quoteIdentifier('own_id') . ' IN (?)', $_id));
     if (is_array($_relatedModels) && !empty($_relatedModels)) {
         $where[] = $this->_db->quoteInto($this->_db->quoteIdentifier('related_model') . ' IN (?)', $_relatedModels);
     }
     if (!$_returnAll) {
         $where[] = $this->_db->quoteIdentifier('is_deleted') . ' = ' . (int) FALSE;
     }
     if ($_degree) {
         $where[] = $this->_db->quoteInto($this->_db->quoteIdentifier('own_degree') . ' = ?', $_degree);
     }
     if (!empty($_type)) {
         $where[] = $this->_db->quoteInto($this->_db->quoteIdentifier('type') . ' IN (?)', $_type);
     }
     $relations = new Tinebase_Record_RecordSet('Tinebase_Model_Relation', array(), true);
     foreach ($this->_dbTable->fetchAll($where) as $relation) {
         $relations->addRecord($this->_rawDataToRecord($relation->toArray(), true));
     }
     return $relations;
 }
Beispiel #6
0
 /**
  * get categories (-> tags)
  *
  * @param string $oldTableName [OPTIONAL]
  * @return  array  categories
  */
 private function getCategories($_oldTableName = NULL)
 {
     $cats = array();
     // get old table data
     $tableName = $_oldTableName != NULL ? $_oldTableName : $this->oldTablePrefix . 'categories';
     $table = new Tinebase_Db_Table(array('name' => $tableName));
     $rows = $table->fetchAll();
     // fill array
     $cats = array();
     foreach ($rows as $row) {
         $cats[$row->cat_id] = $row;
     }
     return $cats;
 }
 /**
  * update to 0.10
  * - migrate old links to relations
  * 
  */
 public function update_9()
 {
     /************* migrate old links to relations *************/
     // get all links
     $linksTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'links'));
     echo "fetching links ... <br/>\n";
     $links = $linksTable->fetchAll();
     // create relations from links
     $relationsByLeadId = array();
     foreach ($links as $link) {
         if ($link->link_app1 === 'crm') {
             switch (strtolower($link->link_app2)) {
                 case 'tasks':
                     $relatedModel = 'Tasks_Model_Task';
                     $backend = Tasks_Backend_Factory::SQL;
                     $degree = Tinebase_Model_Relation::DEGREE_SIBLING;
                     $type = 'TASK';
                     break;
                 case 'addressbook':
                     $relatedModel = 'Addressbook_Model_Contact';
                     $backend = Addressbook_Backend_Factory::SQL;
                     switch ($link->link_remark) {
                         case 'account':
                             $type = 'RESPONSIBLE';
                             $degree = Tinebase_Model_Relation::DEGREE_CHILD;
                             break;
                         case 'customer':
                             $type = 'CUSTOMER';
                             $degree = Tinebase_Model_Relation::DEGREE_SIBLING;
                             break;
                         case 'partner':
                             $type = 'PARTNER';
                             $degree = Tinebase_Model_Relation::DEGREE_SIBLING;
                             break;
                     }
                     break;
                 default:
                     echo 'link type (' . $link->link_app2 . ") not supported<br/>\n";
             }
             if (isset($relatedModel) && isset($backend)) {
                 $relationsByLeadId[$link->link_id1][] = new Tinebase_Model_Relation(array('own_model' => 'Crm_Model_Lead', 'own_backend' => 'SQL', 'own_id' => $link->link_id1, 'related_degree' => $degree, 'related_model' => $relatedModel, 'related_backend' => $backend, 'related_id' => $link->link_id2, 'type' => $type, 'created_by' => $link->link_owner, 'creation_time' => Tinebase_DateTime::now()));
             }
         }
     }
     echo "creating relations ...<br/>\n";
     $relationsBackend = new Tinebase_Relation_Backend_Sql();
     foreach ($relationsByLeadId as $leadId => $relations) {
         foreach ($relations as $relation) {
             try {
                 echo "set relation: " . $relation->type . " " . $relation->related_model . "<br/>\n";
                 $relationsBackend->addRelation($relation);
             } catch (Exception $e) {
                 // cweiss 2008-08-25 this duplicates come from an earlier upgrading failure don't confuse user with verbosity ;-)
                 // echo 'do not add duplicate relation ' . $relation->own_id . '-' . $relation->related_id . "...<br/>\n";
             }
         }
     }
     echo "done<br/>\n";
     $this->setApplicationVersion('Tinebase', '0.10');
 }