/** * Returns instance of Tinebase_Config * * @return Tinebase_Config */ public static function getInstance() { if (self::$_instance === NULL) { self::$_instance = new self(); } return self::$_instance; }
/** * init favorites */ protected function _initializeFavorites() { $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Projects')->getId(), 'model' => 'Projects_Model_ProjectFilter'); $closedStatus = Projects_Config::getInstance()->get(Projects_Config::PROJECT_STATUS)->records->filter('is_open', 0); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => Projects_Preference::DEFAULTPERSISTENTFILTER_NAME, 'description' => "All my open projects", 'filters' => array(array('field' => 'contact', 'operator' => 'AND', 'value' => array(array('field' => ':relation_type', 'operator' => 'in', 'value' => Projects_Config::getInstance()->get(Projects_Config::PROJECT_ATTENDEE_ROLE)->records->id), array('field' => ':id', 'operator' => 'equals', 'value' => Addressbook_Model_Contact::CURRENTCONTACT))), array('field' => 'status', 'operator' => 'notin', 'value' => $closedStatus->getId())))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My projects that I'm responsible for", 'description' => "All my open projects that I am responsible for", 'filters' => array(array('field' => 'contact', 'operator' => 'AND', 'value' => array(array('field' => ':relation_type', 'operator' => 'in', 'value' => array('RESPONSIBLE')), array('field' => ':id', 'operator' => 'equals', 'value' => Addressbook_Model_Contact::CURRENTCONTACT))), array('field' => 'status', 'operator' => 'notin', 'value' => $closedStatus->getId())))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My waiting projects", 'description' => "My projects that are on hold", 'filters' => array(array('field' => 'contact', 'operator' => 'AND', 'value' => array(array('field' => ':relation_type', 'operator' => 'in', 'value' => Projects_Config::getInstance()->get(Projects_Config::PROJECT_ATTENDEE_ROLE)->records->id), array('field' => ':id', 'operator' => 'equals', 'value' => Addressbook_Model_Contact::CURRENTCONTACT))), array('field' => 'status', 'operator' => 'in', 'value' => array('NEEDS-ACTION'))))))); }
/** * helper for project relation filter test * * @param array $_contact * @param string * @param array $_project */ protected function _testProjectRelationFilter($_contact, $_operator, $_project) { switch ($_operator) { case 'definedBy': $closedStatus = Projects_Config::getInstance()->get(Projects_Config::PROJECT_STATUS)->records->filter('is_open', 0); $filters = array(array('field' => ":relation_type", "operator" => "equals", "value" => "COWORKER"), array('field' => "status", "operator" => "notin", "value" => $closedStatus->getId()), array('field' => 'id', 'operator' => 'in', 'value' => array($_project['id']))); break; case 'in': $filters = array(array('field' => 'id', 'operator' => $_operator, 'value' => array($_project['id']))); break; case 'equals': $filters = array(array('field' => 'id', 'operator' => $_operator, 'value' => $_project['id'])); break; } $filterId = Tinebase_Record_Abstract::generateUID(); $filter = array(array('field' => 'foreignRecord', 'operator' => 'AND', 'id' => $filterId, 'value' => array('linkType' => 'relation', 'appName' => 'Projects', 'modelName' => 'Project', 'filters' => $filters)), array('field' => 'id', 'operator' => 'in', 'value' => array($_contact['id'], Tinebase_Core::getUser()->contact_id))); $result = $this->_uit->searchContacts($filter, array()); $this->assertEquals('relation', $result['filter'][0]['value']['linkType']); $this->assertTrue(isset($result['filter'][0]['id']), 'id expected'); $this->assertEquals($filterId, $result['filter'][0]['id']); if ($_operator === 'definedBy') { $this->assertEquals(':relation_type', $result['filter'][0]['value']['filters'][0]['field']); $this->assertEquals(1, $result['totalcount'], 'Should find only the COWORKER!'); $this->assertEquals($_contact['org_name'], $result['results'][0]['org_name']); } else { $this->assertEquals(2, $result['totalcount'], 'Should find both contacts!'); } }
/** * testPersistentRelationFilter */ public function testPersistentRelationFilter() { $favoriteId = Tinebase_PersistentFilter::getInstance()->getPreferenceValues('Projects', NULL, 'All my projects'); $favorite = Tinebase_PersistentFilter::getInstance()->getFilterById($favoriteId); $this->assertTrue($favorite instanceof Tinebase_Model_Filter_FilterGroup); $closedStatus = Projects_Config::getInstance()->get(Projects_Config::PROJECT_STATUS)->records->filter('is_open', 0); $this->assertEquals(array(array('field' => 'contact', 'operator' => 'AND', 'value' => array(array('field' => ':relation_type', 'operator' => 'in', 'value' => Projects_Config::getInstance()->get(Projects_Config::PROJECT_ATTENDEE_ROLE)->records->id), array('field' => ':id', 'operator' => 'equals', 'value' => Addressbook_Model_Contact::CURRENTCONTACT))), array('field' => 'status', 'operator' => 'notin', 'value' => $closedStatus->getId())), $favorite->toArray()); }