/** * init the default persistentfilters */ protected function _initializeFavorites() { $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Inventory')->getId(), 'model' => 'Inventory_Model_InventoryItemFilter'); // default persistent filter for all records $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "All Inventory Items", 'description' => "All existing Inventory Items", 'filters' => array())))); }
/** * update to 5.1 * @return void */ public function update_0() { $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Courses')->getId(), 'model' => 'Courses_Model_CourseFilter'); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => Courses_Preference::DEFAULTPERSISTENTFILTER_NAME, 'description' => "All courses", 'filters' => array(array('field' => 'is_deleted', 'operator' => 'equals', 'value' => '0')))))); $this->setApplicationVersion('Courses', '5.1'); }
/** * init favorites */ protected function _initializeFavorites() { $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('SimpleFAQ')->getId(), 'model' => 'SimpleFAQ_Model_FaqFilter'); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => SimpleFAQ_Preference::DEFAULTPERSISTENTFILTER_NAME, 'description' => "All FAQs of my FAQ Lists", 'filters' => array(array('field' => 'container_id', 'operator' => 'equals', 'value' => '/personal/' . Tinebase_Model_User::CURRENTACCOUNT)))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Last modified by me", 'description' => "All FAQs that I have last modified", 'filters' => array(array('field' => 'last_modified_by', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT)))))); }
/** * 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'))))))); }
/** * init favorites */ protected function _initializeFavorites() { $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Phone')->getId(), 'model' => 'Phone_Model_CallFilter'); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Calls this week", 'description' => "Incoming and outgoing calls of this week", 'filters' => array(array('field' => 'start', 'operator' => 'within', 'value' => 'weekThis')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Calls last week", 'description' => "Incoming and outgoing calls of last week", 'filters' => array(array('field' => 'start', 'operator' => 'within', 'value' => 'weekLast')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Calls this month", 'description' => "Incoming and outgoing calls of this month", 'filters' => array(array('field' => 'start', 'operator' => 'within', 'value' => 'monthThis')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Calls last month", 'description' => "Incoming and outgoing calls of last month", 'filters' => array(array('field' => 'start', 'operator' => 'within', 'value' => 'monthLast')))))); }
/** * init favorites */ protected function _initializeFavorites() { $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Felamimail')->getId(), 'model' => 'Felamimail_Model_MessageFilter'); $myInboxPFilter = $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => Felamimail_Preference::DEFAULTPERSISTENTFILTER_NAME, 'description' => 'All inboxes of my email accounts', 'filters' => array(array('field' => 'path', 'operator' => 'in', 'value' => Felamimail_Model_MessageFilter::PATH_ALLINBOXES)))))); $myUnseenPFilter = $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => 'All unread mail', 'description' => 'All unread mail of my email accounts', 'filters' => array(array('field' => 'flags', 'operator' => 'notin', 'value' => Zend_Mail_Storage::FLAG_SEEN)))))); $myHighlightedPFilter = $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => 'All highlighted mail', 'description' => 'All highlighted mail of my email accounts', 'filters' => array(array('field' => 'flags', 'operator' => 'in', 'value' => Zend_Mail_Storage::FLAG_FLAGGED)))))); $myDraftsPFilter = $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => 'All drafts', 'description' => 'All mails with the draft flag', 'filters' => array(array('field' => 'flags', 'operator' => 'in', 'value' => Zend_Mail_Storage::FLAG_DRAFT)))))); }
/** * init favorites */ protected function _initializeFavorites() { $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), 'model' => 'Calendar_Model_EventFilter'); $myEventsPFilter = $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => Calendar_Preference::DEFAULTPERSISTENTFILTER_NAME, 'description' => "All events I attend", 'filters' => array(array('field' => 'attender', 'operator' => 'equals', 'value' => array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => Addressbook_Model_Contact::CURRENTCONTACT)), array('field' => 'attender_status', 'operator' => 'notin', 'value' => array('DECLINED'))))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Awaiting response", 'description' => "Events I have not yet responded to", 'filters' => array(array('field' => 'attender', 'operator' => 'equals', 'value' => array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => Addressbook_Model_Contact::CURRENTCONTACT)), array('field' => 'attender_status', 'operator' => 'in', 'value' => array(Calendar_Model_Attender::STATUS_NEEDSACTION, Calendar_Model_Attender::STATUS_TENTATIVE))))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Declined events", 'description' => "Events I have declined", 'filters' => array(array('field' => 'attender', 'operator' => 'equals', 'value' => array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => Addressbook_Model_Contact::CURRENTCONTACT)), array('field' => 'attender_status', 'operator' => 'in', 'value' => array(Calendar_Model_Attender::STATUS_DECLINED))))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "I'm organizer", 'description' => "Events I'm the organizer of", 'filters' => array(array('field' => 'organizer', 'operator' => 'equals', 'value' => Addressbook_Model_Contact::CURRENTCONTACT)))))); }
/** * add more default favorites */ public function update_3() { $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Crm')->getId(), 'model' => 'Crm_Model_LeadFilter'); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Last modified by me", 'description' => "All leads that I have last modified", 'filters' => array(array('field' => 'last_modified_by', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT)))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My leads", 'description' => "All leads that I am responsible for", 'filters' => array(array('field' => 'contact', 'operator' => 'AND', 'value' => array(array('field' => 'id', 'operator' => 'equals', 'value' => Addressbook_Model_Contact::CURRENTCONTACT)))))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Leads with overdue tasks", 'description' => "Leads with overdue tasks", 'filters' => array(array('field' => 'task', 'operator' => 'AND', 'value' => array(array('field' => 'due', 'operator' => 'before', 'value' => 'dayThis')))))))); $this->setApplicationVersion('Crm', '3.4'); }
/** * create default favorites and update to 5.3 * * @return void */ public function update_2() { // Timeaccounts $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Timetracker')->getId(), 'model' => 'Timetracker_Model_TimeaccountFilter'); $pfe = Tinebase_PersistentFilter::getInstance(); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Timeaccounts to bill", 'description' => "Timeaccounts to bill", 'filters' => array(array('field' => 'status', 'operator' => 'equals', 'value' => 'to bill')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Timeaccounts not yet billed", 'description' => "Timeaccounts not yet billed", 'filters' => array(array('field' => 'status', 'operator' => 'equals', 'value' => 'not yet billed')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Timeaccounts already billed", 'description' => "Timeaccounts already billed", 'filters' => array(array('field' => 'status', 'operator' => 'equals', 'value' => 'billed')))))); $this->setApplicationVersion('Timetracker', '5.3'); }
/** * init favorites */ protected function _initializeFavorites() { $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Crm')->getId(), 'model' => 'Crm_Model_LeadFilter'); $closedStatus = Crm_Controller::getInstance()->getConfigSettings()->getEndedLeadstates(TRUE); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => Crm_Preference::DEFAULTPERSISTENTFILTER_NAME, 'description' => "All leads I have read grants for", 'filters' => array(array('field' => 'leadstate_id', 'operator' => 'notin', 'value' => $closedStatus)))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Last modified by me", 'description' => "All leads that I have last modified", 'filters' => array(array('field' => 'last_modified_by', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT)))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My leads", 'description' => "All leads that I am responsible for", 'filters' => array(array('field' => 'contact', 'operator' => 'AND', 'value' => array(array('field' => 'id', 'operator' => 'equals', 'value' => Addressbook_Model_Contact::CURRENTCONTACT)))))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Leads with overdue tasks", 'description' => "Leads with overdue tasks", 'filters' => array(array('field' => 'task', 'operator' => 'AND', 'value' => array(array('field' => 'due', 'operator' => 'before', 'value' => 'dayThis')))))))); }
/** * create favorites */ protected function _initializeFavorites() { $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('HumanResources')->getId(), 'model' => 'HumanResources_Model_EmployeeFilter'); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Currently employed employees", 'description' => "Employees which are currently employed", 'filters' => array(array('field' => 'is_employed', 'operator' => 'equals', 'value' => 1)))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "All employees", 'description' => "All available employees", 'filters' => array())))); // Accounts $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('HumanResources')->getId(), 'model' => 'HumanResources_Model_AccountFilter'); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "All accounts", 'description' => "All available accounts", 'filters' => array())))); }
/** * added more default favorites * * @return void */ public function update_2() { $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Timetracker')->getId(), 'model' => 'Timetracker_Model_TimesheetFilter'); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Timesheets today", 'description' => "Timesheets today", 'filters' => array(array('field' => 'account_id', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'start_date', 'operator' => 'within', 'value' => 'dayThis')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Timesheets this week", 'description' => "Timesheets this week", 'filters' => array(array('field' => 'account_id', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'start_date', 'operator' => 'within', 'value' => 'weekThis')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Timesheets last week", 'description' => "Timesheets last week", 'filters' => array(array('field' => 'account_id', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'start_date', 'operator' => 'within', 'value' => 'weekLast')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Timesheets this month", 'description' => "Timesheets this month", 'filters' => array(array('field' => 'account_id', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'start_date', 'operator' => 'within', 'value' => 'monthThis')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Timesheets last month", 'description' => "Timesheets last month", 'filters' => array(array('field' => 'account_id', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'start_date', 'operator' => 'within', 'value' => 'monthLast')))))); $this->setApplicationVersion('Timetracker', '3.3'); }
/** * test remove all grants (should not be possible) */ public function testAddGrants() { $defaultUserGroup = Tinebase_Group::getInstance()->getDefaultGroup(); $filter = $this->testSaveSharedFavorite(); $filter->grants->addRecord(new Tinebase_Model_PersistentFilterGrant(array('account_id' => $defaultUserGroup->getId(), 'account_type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP, 'record_id' => $filter->getId(), Tinebase_Model_Grants::GRANT_READ => true))); $updatedFilter = $this->_instance->update($filter); $this->assertEquals(3, count($updatedFilter->grants)); $grant = $updatedFilter->grants->filter('account_id', $defaultUserGroup->getId())->getFirstRecord(); $this->assertTrue($grant !== null); $this->assertTrue($grant->userHasGrant(Tinebase_Model_PersistentFilterGrant::GRANT_READ)); }
/** * update from 5.1 -> 5.2 * - default contracts & products * * @return void */ public function update_1() { // Products $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Sales')->getId(), 'model' => 'Sales_Model_ProductFilter'); $pfe = Tinebase_PersistentFilter::getInstance(); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My Products", 'description' => "Products created by me", 'filters' => array(array('field' => 'created_by', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT)))))); // Contracts $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Sales')->getId(), 'model' => 'Sales_Model_ContractFilter'); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My Contracts", 'description' => "Contracts created by me", 'filters' => array(array('field' => 'created_by', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT)))))); $this->setApplicationVersion('Sales', '5.2'); }
/** * init favorites */ protected function _initializeFavorites() { $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Tasks')->getId(), 'model' => 'Tasks_Model_TaskFilter'); $closedStatus = Tasks_Config::getInstance()->get(Tasks_Config::TASK_STATUS)->records->filter('is_open', 0); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => Tasks_Preference::DEFAULTPERSISTENTFILTER_NAME, 'description' => "All tasks of my taskslists", 'filters' => array(array('field' => 'container_id', 'operator' => 'equals', 'value' => '/personal/' . Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'status', 'operator' => 'notin', 'value' => $closedStatus->getId())))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My open tasks", 'description' => "My open tasks", 'filters' => array(array('field' => 'organizer', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'status', 'operator' => 'notin', 'value' => $closedStatus->getId())))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My open tasks this week", 'description' => "My open tasks this week", 'filters' => array(array('field' => 'organizer', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'due', 'operator' => 'within', 'value' => 'weekThis'), array('field' => 'status', 'operator' => 'notin', 'value' => $closedStatus->getId())))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "All tasks for me", 'description' => "All tasks that I am responsible for", 'filters' => array(array('field' => 'organizer', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT)))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Last modified by me", 'description' => "All tasks that I have last modified", 'filters' => array(array('field' => 'last_modified_by', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT)))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Tasks without responsible", 'description' => "Tasks without responsible", 'filters' => array(array('field' => 'organizer', 'operator' => 'equals', 'value' => '')))))); }
/** * get special options * * @param string $_value * @return array */ protected function _getSpecialOptions($_value) { $result = array(); switch ($_value) { case self::DEFAULTPERSISTENTFILTER: $result = Tinebase_PersistentFilter::getPreferenceValues('Projects'); break; default: $result = parent::_getSpecialOptions($_value); } return $result; }
/** * get preference defaults if no default is found in the database * * @param string $_preferenceName * @return Tinebase_Model_Preference */ public function getApplicationPreferenceDefaults($_preferenceName, $_accountId = NULL, $_accountType = Tinebase_Acl_Rights::ACCOUNT_TYPE_USER) { $preference = $this->_getDefaultBasePreference($_preferenceName); switch ($_preferenceName) { case self::DEFAULTPERSISTENTFILTER: $preference->value = Tinebase_PersistentFilter::getPreferenceValues('Courses', $_accountId, self::DEFAULTPERSISTENTFILTER_NAME); break; default: throw new Tinebase_Exception_NotFound('Default preference with name ' . $_preferenceName . ' not found.'); } return $preference; }
/** * init favorites */ protected function _initializeFavorites() { $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Timetracker')->getId(), 'model' => 'Timetracker_Model_TimesheetFilter'); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My Timesheets today", 'description' => "My Timesheets today", 'filters' => array(array('field' => 'account_id', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'start_date', 'operator' => 'within', 'value' => 'dayThis')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My Timesheets this week", 'description' => "My Timesheets this week", 'filters' => array(array('field' => 'account_id', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'start_date', 'operator' => 'within', 'value' => 'weekThis')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My Timesheets last week", 'description' => "My Timesheets last week", 'filters' => array(array('field' => 'account_id', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'start_date', 'operator' => 'within', 'value' => 'weekLast')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My Timesheets this month", 'description' => "My Timesheets this month", 'filters' => array(array('field' => 'account_id', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'start_date', 'operator' => 'within', 'value' => 'monthThis')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My Timesheets last month", 'description' => "My Timesheets last month", 'filters' => array(array('field' => 'account_id', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'start_date', 'operator' => 'within', 'value' => 'monthLast')))))); // Timeaccounts $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Timetracker')->getId(), 'model' => 'Timetracker_Model_TimeaccountFilter'); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Timeaccounts to bill", 'description' => "Timeaccounts to bill", 'filters' => array(array('field' => 'status', 'operator' => 'equals', 'value' => 'to bill')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Timeaccounts not yet billed", 'description' => "Timeaccounts not yet billed", 'filters' => array(array('field' => 'status', 'operator' => 'equals', 'value' => 'not yet billed')))))); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Timeaccounts already billed", 'description' => "Timeaccounts already billed", 'filters' => array(array('field' => 'status', 'operator' => 'equals', 'value' => 'billed')))))); }
private function prepareFilter($filter) { $decodedFilter = is_array($_filter) || strlen($_filter) == 40 ? $_filter : Zend_Json::decode($_filter); if (is_array($decodedFilter)) { $filter = new Billing_Model_ReceiptFilter(array()); $filter->setFromArrayInUsersTimezone($decodedFilter); } else { if (!empty($decodedFilter) && strlen($decodedFilter) == 40) { $filter = Tinebase_PersistentFilter::getFilterById($decodedFilter); } else { if (!$filter instanceof Tinebase_Model_Filter_FilterGroup) { // filter is empty $filter = new Billing_Model_ReceiptFilter(array()); } } } return $filter; }
/** * init favorites */ protected function _initializeFavorites() { // Products $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Sales')->getId(), 'model' => 'Sales_Model_ProductFilter'); $pfe = Tinebase_PersistentFilter::getInstance(); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My Products", 'description' => "Products created by me", 'filters' => array(array('field' => 'created_by', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT)))))); // Contracts $commonValues['model'] = 'Sales_Model_ContractFilter'; $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "My Contracts", 'description' => "Contracts created by me", 'filters' => array(array('field' => 'created_by', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT)))))); // Customers $commonValues['model'] = 'Sales_Model_CustomerFilter'; $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "All Customers", 'description' => "All customer records", 'filters' => array())))); // Offers $commonValues['model'] = 'Sales_Model_OfferFilter'; $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "All Offers", 'description' => "All offer records", 'filters' => array())))); Sales_Setup_Update_Release8::createDefaultFavoritesForSub20(); Sales_Setup_Update_Release8::createDefaultFavoritesForSub22(); Sales_Setup_Update_Release8::createDefaultFavoritesForSub24(); }
/** * get preference defaults if no default is found in the database * * @param string $_preferenceName * @param string|Tinebase_Model_User $_accountId * @param string $_accountType * @return Tinebase_Model_Preference */ public function getApplicationPreferenceDefaults($_preferenceName, $_accountId = NULL, $_accountType = Tinebase_Acl_Rights::ACCOUNT_TYPE_USER) { $preference = $this->_getDefaultBasePreference($_preferenceName); switch ($_preferenceName) { case self::DEFAULTADDRESSBOOK: $this->_getDefaultContainerPreferenceDefaults($preference, $_accountId); break; case self::DEFAULTPERSISTENTFILTER: $preference->value = Tinebase_PersistentFilter::getPreferenceValues('Addressbook', $_accountId, self::DEFAULTPERSISTENTFILTER_NAME); break; case self::DEFAULT_CONTACT_ODS_EXPORTCONFIG: $preference->value = 'adb_default_ods'; break; case self::DEFAULT_CONTACT_XLS_EXPORTCONFIG: $preference->value = 'adb_default_xls'; break; default: throw new Tinebase_Exception_NotFound('Default preference with name ' . $_preferenceName . ' not found.'); } return $preference; }
/** * update favorites to new filter syntax and update to 5.2 * * @return void */ public function update_1() { $filters = Tinebase_PersistentFilter::getInstance()->getAll(); $timetrackerFilters = $filters->filter('application_id', Tinebase_Application::getInstance()->getApplicationByName('Timetracker')->getId()); $pfBackend = new Tinebase_PersistentFilter_Backend_Sql(); foreach ($timetrackerFilters as $pfilter) { foreach ($pfilter->filters as $filter) { if (in_array($filter->getField(), array('timeaccount_id')) && $filter instanceof Tinebase_Model_Filter_ForeignId) { $values = array(); foreach ($filter->getValue() as $idx => $subfilter) { $values[$idx] = $subfilter; if (in_array($subfilter['field'], array('id'))) { $values[$idx]['field'] = ':' . $subfilter['field']; } } $filter->setValue($values); $pfBackend->update($pfilter); } } } $this->setApplicationVersion('Timetracker', '5.2'); }
/** * update favorites to new filter syntax and update to 5.0 * * @return void */ public function update_0() { $filters = Tinebase_PersistentFilter::getInstance()->getAll(); $crmFilters = $filters->filter('application_id', Tinebase_Application::getInstance()->getApplicationByName('Crm')->getId()); $pfBackend = new Tinebase_PersistentFilter_Backend_Sql(); foreach ($crmFilters as $pfilter) { foreach ($pfilter->filters as $filter) { if (in_array($filter->getField(), array('contact', 'product', 'task')) && $filter instanceof Tinebase_Model_Filter_Relation) { $values = array(); foreach ($filter->getValue() as $idx => $subfilter) { $values[$idx] = $subfilter; if (in_array($subfilter['field'], array('relation_type', 'id'))) { $values[$idx]['field'] = ':' . $subfilter['field']; } } $filter->setValue($values); $pfBackend->update($pfilter); } } } $this->setApplicationVersion('Crm', '5.1'); }
/** * decodes the filter string * * @param string|array $_filter * @param string $_filterModel the class name of the filter model to use * @param boolean $_throwExceptionIfEmpty * @return Tinebase_Model_Filter_FilterGroup */ protected function _decodeFilter($_filter, $_filterModel, $_throwExceptionIfEmpty = FALSE) { $filterModel = $this->_getPluginForFilterModel($_filterModel); $decodedFilter = is_array($_filter) || strlen($_filter) == 40 ? $_filter : Zend_Json::decode($_filter); if (is_array($decodedFilter)) { $filter = new $filterModel(array()); $filter->setFromArrayInUsersTimezone($decodedFilter); } else { if (!empty($decodedFilter) && strlen($decodedFilter) == 40) { $filter = Tinebase_PersistentFilter::getFilterById($decodedFilter); } else { if ($_throwExceptionIfEmpty) { throw new Tinebase_Exception_InvalidArgument('Filter must not be empty!'); } else { $filter = new $filterModel(array()); } } } return $filter; }
/** * repair function for persistent filters (favorites) without grants: this adds default grants for those filters. * * @return int */ public function setDefaultGrantsOfPersistentFilters() { if (!$this->_checkAdminRight()) { return -1; } $this->_addOutputLogWriter(6); // get all persistent filters without grants // TODO this could be enhanced by allowing to set default grants for other filters, too Tinebase_PersistentFilter::getInstance()->doContainerACLChecks(false); $filters = Tinebase_PersistentFilter::getInstance()->search(new Tinebase_Model_PersistentFilterFilter(array(), '', array('ignoreAcl' => true))); $filtersWithoutGrants = 0; foreach ($filters as $filter) { if (count($filter->grants) == 0) { // update to set default grants $filter = Tinebase_PersistentFilter::getInstance()->update($filter); $filtersWithoutGrants++; if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Updated filter: ' . print_r($filter->toArray(), true)); } } } if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Set default grants for ' . $filtersWithoutGrants . ' filters' . ' (checked ' . count($filters) . ' in total).'); } return 0; }
/** * create default favorite for teacher * * @param Tinebase_Model_FullUser $account * @param Courses_Model_Course $course */ protected function _createDefaultFilterForTeacher($account, $course) { $pfe = Tinebase_PersistentFilter::getInstance(); $filter = $pfe->create(new Tinebase_Model_PersistentFilter(array('account_id' => $account->getId(), 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Courses')->getId(), 'model' => 'Courses_Model_CourseFilter', 'name' => "My course", 'description' => "My course", 'filters' => array(array('field' => 'is_deleted', 'operator' => 'equals', 'value' => '0'), array('field' => 'name', 'operator' => 'equals', 'value' => $course->name))))); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Created default filter for teacher ' . $account->accountLoginName . ': ' . print_r($filter->toArray(), true)); } // set as default $pref = new Courses_Preference(); $pref->setValueForUser(Courses_Preference::DEFAULTPERSISTENTFILTER, $filter->getId(), $account->getId(), TRUE); }
/** * calendar has different grant handling * @see 0007450: shared calendars of other users (iOS) */ public function testGetAllFoldersWithContainerSyncFilter() { $device = $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE); $controller = Syncroton_Data_Factory::factory($this->_class, $device, new Tinebase_DateTime(null, null, 'de_DE')); $folderA = $this->testCreateFolder(); // personal of test user $sclever = Tinebase_Helper::array_value('sclever', Zend_Registry::get('personas')); $folderB = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::DEFAULTCALENDAR, $sclever->getId()); // have syncGerant for sclever Tinebase_Container::getInstance()->setGrants($folderB, new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array(array('account_id' => $sclever->getId(), 'account_type' => 'user', Tinebase_Model_Grants::GRANT_ADMIN => true), array('account_id' => Tinebase_Core::getUser()->getId(), 'account_type' => 'user', Tinebase_Model_Grants::GRANT_READ => true, Tinebase_Model_Grants::GRANT_SYNC => true))), TRUE); $syncFilter = new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'in', 'value' => array($folderA->serverId, $folderB)))); $syncFavorite = Tinebase_PersistentFilter::getInstance()->create(new Tinebase_Model_PersistentFilter(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), 'account_id' => Tinebase_Core::getUser()->getId(), 'model' => 'Calendar_Model_EventFilter', 'filters' => $syncFilter, 'name' => 'testSyncFilter', 'description' => 'test two folders'))); $device->calendarfilterId = $syncFavorite->getId(); $allSyncrotonFolders = $controller->getAllFolders(); $defaultFolderId = Tinebase_Core::getPreference('Calendar')->{Calendar_Preference::DEFAULTCALENDAR}; foreach ($allSyncrotonFolders as $syncrotonFolder) { $this->assertTrue($syncrotonFolder->serverId == $defaultFolderId ? $syncrotonFolder->type === Syncroton_Command_FolderSync::FOLDERTYPE_CALENDAR : $syncrotonFolder->type === Syncroton_Command_FolderSync::FOLDERTYPE_CALENDAR_USER_CREATED); } $this->assertEquals(2, count($allSyncrotonFolders)); $this->assertArrayHasKey($folderA->serverId, $allSyncrotonFolders); $this->assertArrayHasKey($folderB, $allSyncrotonFolders); }
/** * get preference defaults if no default is found in the database * * @param string $_preferenceName * @param string|Tinebase_Model_User $_accountId * @param string $_accountType * @return Tinebase_Model_Preference */ public function getApplicationPreferenceDefaults($_preferenceName, $_accountId = NULL, $_accountType = Tinebase_Acl_Rights::ACCOUNT_TYPE_USER) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Get default value for ' . $_preferenceName . ' of account id ' . $_accountId); } $preference = $this->_getDefaultBasePreference($_preferenceName); switch ($_preferenceName) { case self::DAYSVIEW_STARTTIME: $preference->value = '08:00'; $preference->options = $this->_createTimespanDataXML(0, 23); break; case self::DAYSVIEW_ENDTIME: $preference->value = '18:00'; $preference->options = $this->_createTimespanDataXML(1, 24); break; case self::DAYSVIEW_DEFAULT_STARTTIME: $preference->value = '08:00'; $preference->options = $this->_createTimespanDataXML(0, 23); break; case self::DEFAULTCALENDAR: $this->_getDefaultContainerPreferenceDefaults($preference, $_accountId); break; case self::DEFAULTPERSISTENTFILTER: $preference->value = Tinebase_PersistentFilter::getPreferenceValues('Calendar', $_accountId, "All my events"); break; case self::NOTIFICATION_LEVEL: $translate = Tinebase_Translation::getTranslation($this->_application); // need to put the translations strings here because they were not found in the xml below :/ // _('Never') _('On invitation and cancellation only') _('On time changes') _('On all updates but attendee responses') _('On attendee responses too') $preference->value = Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_EVENT_RESCHEDULE; $preference->options = '<?xml version="1.0" encoding="UTF-8"?> <options> <option> <value>' . Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_NONE . '</value> <label>' . $translate->_('Never') . '</label> </option> <option> <value>' . Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_INVITE_CANCEL . '</value> <label>' . $translate->_('On invitation and cancellation only') . '</label> </option> <option> <value>' . Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_EVENT_RESCHEDULE . '</value> <label>' . $translate->_('On time changes') . '</label> </option> <option> <value>' . Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_EVENT_UPDATE . '</value> <label>' . $translate->_('On all updates but attendee responses') . '</label> </option> <option> <value>' . Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_ATTENDEE_STATUS_UPDATE . '</value> <label>' . $translate->_('On attendee responses too') . '</label> </option> </options>'; break; case self::SEND_NOTIFICATION_OF_OWN_ACTIONS: $preference->value = 0; $preference->options = '<?xml version="1.0" encoding="UTF-8"?> <options> <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special> </options>'; break; case self::SEND_ALARM_NOTIFICATIONS: $preference->value = 1; $preference->options = '<?xml version="1.0" encoding="UTF-8"?> <options> <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special> </options>'; break; case self::DEFAULTALARM_ENABLED: $preference->value = 0; $preference->options = '<?xml version="1.0" encoding="UTF-8"?> <options> <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special> </options>'; break; case self::DEFAULTALARM_MINUTESBEFORE: $preference->value = 15; $preference->options = ''; break; case self::DEFAULTATTENDEE_STRATEGY: $preference->value = 'me'; $preference->options = '<?xml version="1.0" encoding="UTF-8"?> <options> <option> <label>Me</label> <value>me</value> </option> <option> <label>Intelligent</label> <value>intelligent</value> </option> <option> <label>Calendar owner</label> <value>calendarOwner</value> </option> <option> <label>Filtered attendee</label> <value>filteredAttendee</value> </option> </options>'; break; case self::DEFAULT_TIMEINCREMENT: $preference->value = 15; $preference->options = '<?xml version="1.0" encoding="UTF-8"?> <options> <option> <label>5</label> <value>5</value> </option> <option> <label>10</label> <value>10</value> </option> <option> <label>15</label> <value>15</value> </option> <option> <label>20</label> <value>20</value> </option> <option> <label>30</label> <value>30</value> </option> <option> <label>60</label> <value>60</value> </option> </options>'; break; case self::DEFAULT_EVENTS_RRIVATE: $preference->value = 0; $preference->options = '<?xml version="1.0" encoding="UTF-8"?> <options> <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special> </options>'; break; case self::FIRSTDAYOFWEEK: $preference->value = 1; $preference->options = '<?xml version="1.0" encoding="UTF-8"?> <options> <option> <label>Sunday</label> <value>0</value> </option> <option> <label>Monday</label> <value>1</value> </option> </options>'; break; default: throw new Tinebase_Exception_NotFound('Default preference with name ' . $_preferenceName . ' not found.'); } return $preference; }
/** * testTeacherDefaultFavorite * * @see 0006876: create "my course" default favorite for new teachers */ public function testTeacherDefaultFavorite() { $course = $this->_getCourseData(); $courseData = $this->_json->saveCourse($course); $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id'])); $teacher = Tinebase_User::getInstance()->getFullUserById($courseData['members'][0]['id']); $filter = Tinebase_PersistentFilter::getInstance()->getFilterById(Tinebase_Core::getPreference('Courses')->getValueForUser(Courses_Preference::DEFAULTPERSISTENTFILTER, $teacher->getId())); $this->assertEquals(array(array('field' => 'name', 'operator' => 'equals', 'value' => $course['name'])), $filter->toArray()); }
/** /** * return (outer) contentfilter array * * @param int $_filterType * @return Tinebase_Model_Filter_FilterGroup */ protected function _getContentFilter($_filterType) { $filter = new $this->_contentFilterClass(); try { $persistentFilterId = $this->_device->{$this->_filterProperty}; if ($persistentFilterId) { $filter = Tinebase_PersistentFilter::getFilterById($persistentFilterId); } } catch (Tinebase_Exception_NotFound $tenf) { // filter got deleted already } return $filter; }