/**
  * returns a status which is defined as open state
  *
  * @return Tasks_Model_Status
  */
 protected function _getStatus($_open = true)
 {
     foreach (Tasks_Config::getInstance()->get(Tasks_Config::TASK_STATUS)->records as $idx => $status) {
         if (!($status->is_open xor $_open)) {
             return $status;
         }
     }
 }
コード例 #2
0
 /**
  * temporary function to get a default container]
  * 
  * @param string $_referingApplication
  * @return Tinebase_Model_Container container
  * 
  * @todo replace this by Tinebase_Container::getDefaultContainer
  */
 public function getDefaultContainer($_referingApplication = 'tasks')
 {
     $taskConfig = Tasks_Config::getInstance();
     $configString = 'defaultcontainer_' . (empty($_referingApplication) ? 'tasks' : $_referingApplication);
     if (isset($taskConfig->{$configString})) {
         $defaultContainer = Tinebase_Container::getInstance()->getContainerById((int) $taskConfig->{$configString});
     } else {
         $defaultContainer = Tinebase_Container::getInstance()->getDefaultContainer('Tasks');
     }
     return $defaultContainer;
 }
コード例 #3
0
 /**
  * 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' => ''))))));
 }
コード例 #4
0
 /**
  * get resolved records (task status, ...)
  * 
  * @return array
  */
 public static function getResolvedRecords()
 {
     $result = array();
     $result['tasksStatus'] = Tasks_Config::getInstance()->get(Tasks_Config::TASK_STATUS)->records;
     return $result;
 }
コード例 #5
0
 /**
  * test create task with automatic alarm
  *
  */
 public function testCreateTaskWithAutomaticAlarm()
 {
     $task = $this->_getTask();
     // set config for automatic alarms
     Tasks_Config::getInstance()->set(Tinebase_Config::AUTOMATICALARM, array(2 * 24 * 60));
     $persistentTaskData = $this->_backend->saveTask($task->toArray());
     $loadedTaskData = $this->_backend->getTask($persistentTaskData['id']);
     // check if alarms are created / returned
     $this->assertGreaterThan(0, count($loadedTaskData['alarms']));
     $this->assertEquals('Tasks_Model_Task', $loadedTaskData['alarms'][0]['model']);
     $this->assertEquals(Tinebase_Model_Alarm::STATUS_PENDING, $loadedTaskData['alarms'][0]['sent_status']);
     $this->assertTrue(isset($loadedTaskData['alarms'][0]['minutes_before']) || array_key_exists('minutes_before', $loadedTaskData['alarms'][0]), 'minutes_before is missing');
     $this->assertEquals(2 * 24 * 60, $loadedTaskData['alarms'][0]['minutes_before']);
     // reset automatic alarms config
     Tasks_Config::getInstance()->set(Tinebase_Config::AUTOMATICALARM, array());
     $this->_backend->deleteTasks($persistentTaskData['id']);
 }
コード例 #6
0
 /**
  * add automatic alarms to record (if configured)
  * 
  * @param Tinebase_Record_Abstract $_record
  * @return void
  * 
  * @todo    move this to Tinebase_Controller_Record_Abstract
  */
 protected function _addAutomaticAlarms(Tinebase_Record_Abstract $_record)
 {
     $automaticAlarms = Tasks_Config::getInstance()->get(Tinebase_Config::AUTOMATICALARM, new Tinebase_Config_Struct());
     if (!is_object($automaticAlarms)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Invalid ' . Tinebase_Config::AUTOMATICALARM . ' config option');
         }
         return;
     }
     $automaticAlarmsArray = $automaticAlarms->toArray();
     if (count($automaticAlarmsArray) == 0) {
         return;
     }
     if (!$_record->alarms instanceof Tinebase_Record_RecordSet) {
         $_record->alarms = new Tinebase_Record_RecordSet('Tinebase_Model_Alarm');
     }
     if (count($_record->alarms) > 0) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Do not overwrite existing alarm.');
         }
         return;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Add automatic alarms / minutes before: ' . implode(',', $automaticAlarmsArray));
     }
     foreach ($automaticAlarmsArray as $minutesBefore) {
         $_record->alarms->addRecord(new Tinebase_Model_Alarm(array('minutes_before' => $minutesBefore), TRUE));
     }
     $this->_saveAlarms($_record);
 }
コード例 #7
0
 /**
  * get linked objects for lead pdf (contacts, tasks, ...)
  *
  * @param   Crm_Model_Lead $_lead lead data
  * @param   Zend_Locale $_locale the locale
  * @param   Zend_Translate $_translate
  * @return  array  the linked objects
  */
 protected function getLinkedObjects(Crm_Model_Lead $_lead, Zend_Locale $_locale, Zend_Translate $_translate)
 {
     $linkedObjects = array();
     // check relations
     if ($_lead->relations instanceof Tinebase_Record_RecordSet) {
         $_lead->relations->addIndices(array('type'));
         /********************** contacts ******************/
         $linkedObjects[] = array($_translate->_('Contacts'), 'headline');
         $types = array("customer" => "/images/oxygen/32x32/apps/system-users.png", "partner" => "/images/oxygen/32x32/actions/view-process-own.png", "responsible" => "/images/oxygen/32x32/apps/preferences-desktop-user.png");
         foreach ($types as $type => $icon) {
             $contactRelations = $_lead->relations->filter('type', strtoupper($type));
             foreach ($contactRelations as $relation) {
                 try {
                     //$contact = Addressbook_Controller_Contact::getInstance()->getContact($relation->related_id);
                     $contact = $relation->related_record;
                     $contactNameAndCompany = $contact->n_fn;
                     if (!empty($contact->org_name)) {
                         $contactNameAndCompany .= " / " . $contact->org_name;
                     }
                     $linkedObjects[] = array($contactNameAndCompany, 'separator', $icon);
                     $postalcodeLocality = !empty($contact->adr_one_postalcode) ? $contact->adr_one_postalcode . " " . $contact->adr_one_locality : $contact->adr_one_locality;
                     $regionCountry = !empty($contact->adr_one_region) ? $contact->adr_one_region . " " : "";
                     if (!empty($contact->adr_one_countryname)) {
                         $regionCountry .= Zend_Locale::getTranslation($contact->adr_one_countryname, 'country', $_locale);
                     }
                     $linkedObjects[] = array($_translate->_('Address'), array($contact->adr_one_street, $postalcodeLocality, $regionCountry));
                     $linkedObjects[] = array($_translate->_('Telephone'), $contact->tel_work);
                     $linkedObjects[] = array($_translate->_('Email'), $contact->email);
                 } catch (Exception $e) {
                     // do nothing so far
                 }
             }
         }
         /********************** tasks ******************/
         $taskRelations = $_lead->relations->filter('type', strtoupper('task'));
         if (!empty($taskRelations)) {
             $linkedObjects[] = array($_translate->_('Tasks'), 'headline');
             foreach ($taskRelations as $relation) {
                 try {
                     $task = $relation->related_record;
                     $taskTitle = $task->summary . " ( " . $task->percent . " % ) ";
                     // @todo add big icon to db or preg_replace?
                     if (!empty($task->status)) {
                         $status = Tasks_Config::getInstance()->get(Tasks_Config::TASK_STATUS)->records->getById($task->status);
                         $icon = "/" . $status['icon'];
                         $linkedObjects[] = array($taskTitle, 'separator', $icon);
                     } else {
                         $linkedObjects[] = array($taskTitle, 'separator');
                     }
                     // get due date
                     if (!empty($task->due)) {
                         $dueDate = new Tinebase_DateTime($task->due);
                         $linkedObjects[] = array($_translate->_('Due Date'), Tinebase_Translation::dateToStringInTzAndLocaleFormat($dueDate, NULL, NULL, 'date'));
                     }
                     // get task priority
                     $taskPriority = $this->getTaskPriority($task->priority, $_translate);
                     $linkedObjects[] = array($_translate->_('Priority'), $taskPriority);
                 } catch (Exception $e) {
                     // do nothing so far
                     Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' exception caught: ' . $e->__toString());
                 }
             }
         }
         /********************** products ******************/
         $productRelations = $_lead->relations->filter('type', strtoupper('product'));
         if (!empty($productRelations)) {
             $linkedObjects[] = array($_translate->_('Products'), 'headline');
             foreach ($productRelations as $relation) {
                 try {
                     $product = $relation->related_record;
                     $quantity = isset($relation['remark']['quantity']) ? $relation['remark']['quantity'] : 1;
                     $price = isset($relation['remark']['price']) ? $relation['remark']['price'] : $product->price;
                     // @todo set precision for the price ?
                     $price = Zend_Locale_Format::toNumber($price, array('locale' => $_locale)) . " €";
                     $description = isset($relation['remark']['description']) ? $relation['remark']['description'] : $product->description;
                     $linkedObjects[] = array($product->name . ' - ' . $description . ' (' . $price . ') x ' . $quantity, 'separator');
                 } catch (Exception $e) {
                     // do nothing so far
                     Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' exception caught: ' . $e->__toString());
                 }
             }
         }
     }
     return $linkedObjects;
 }
コード例 #8
0
ファイル: Task.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * create notification message for task alarm
  *
  * @return string
  * 
  * @todo should we get the locale pref for each single user here instead of the default?
  * @todo move lead stuff to Crm(_Model_Lead)?
  * @todo add getSummary to Addressbook_Model_Contact for linked contacts?
  */
 public function getNotificationMessage()
 {
     // get locale from prefs
     $localePref = Tinebase_Core::getPreference()->getValue(Tinebase_Preference::LOCALE);
     $locale = Tinebase_Translation::getLocale($localePref);
     $translate = Tinebase_Translation::getTranslation($this->_application, $locale);
     // get date strings
     $timezone = $this->originator_tz ? $this->originator_tz : Tinebase_Core::get(Tinebase_Core::USERTIMEZONE);
     $dueDateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat($this->due, $timezone, $locale);
     // resolve values
     Tinebase_User::getInstance()->resolveUsers($this, 'organizer', true);
     $status = Tasks_Config::getInstance()->get(Tasks_Config::TASK_STATUS)->records->getById($this->status);
     $organizerName = $this->organizer ? $this->organizer->accountDisplayName : '';
     //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($this->toArray(), TRUE));
     $text = $this->summary . "\n\n" . $translate->_('Due') . ': ' . $dueDateString . "\n" . $translate->_('Organizer') . ': ' . $organizerName . "\n" . $translate->_('Description') . ': ' . $this->description . "\n" . $translate->_('Priority') . ': ' . $this->priority . "\n" . $translate->_('Status') . ': ' . $translate->_($status['value']) . "\n" . $translate->_('Percent') . ': ' . $this->percent . "%\n\n";
     // add relations (get with ignore acl)
     $relations = Tinebase_Relations::getInstance()->getRelations(get_class($this), 'Sql', $this->getId(), NULL, array('TASK'), TRUE);
     foreach ($relations as $relation) {
         if ($relation->related_model == 'Crm_Model_Lead') {
             $lead = $relation->related_record;
             $text .= $translate->_('Lead') . ': ' . $lead->lead_name . "\n";
             $leadRelations = Tinebase_Relations::getInstance()->getRelations(get_class($lead), 'Sql', $lead->getId());
             foreach ($leadRelations as $leadRelation) {
                 if ($leadRelation->related_model == 'Addressbook_Model_Contact') {
                     $contact = $leadRelation->related_record;
                     $text .= $leadRelation->type . ': ' . $contact->n_fn . ' (' . $contact->org_name . ')' . "\n" . (!empty($contact->tel_work) ? "\t" . $translate->_('Telephone') . ': ' . $contact->tel_work . "\n" : '') . (!empty($contact->email) ? "\t" . $translate->_('Email') . ': ' . $contact->email . "\n" : '');
                 }
             }
         }
     }
     //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $text);
     return $text;
 }
 /**
  * return contentfilter array
  * 
  * @param  int $_filterType
  * @return Tinebase_Model_Filter_FilterGroup
  */
 protected function _getContentFilter($_filterType)
 {
     $filter = parent::_getContentFilter($_filterType);
     // no persistent filter set -> add default filter
     // @todo what is this good for? I think should be handled in _addContainerFilter. LK
     #if ($filter->isEmpty()) {
     #    $defaultFilter = $filter->createFilter('container_id', 'equals', array(
     #        'path' => '/personal/' . Tinebase_Core::getUser()->getId()
     #    ));
     #
     #    $filter->addFilter($defaultFilter);
     #}
     if (in_array($_filterType, $this->_filterArray)) {
         switch ($_filterType) {
             case Syncroton_Command_Sync::FILTER_INCOMPLETE:
                 $filter->removeFilter('status');
                 $openStatus = Tasks_Config::getInstance()->get(Tasks_Config::TASK_STATUS)->records->filter('is_open', 1);
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " filter by status ids " . print_r($openStatus->getId(), TRUE));
                 }
                 $filter->addFilter(new Tinebase_Model_Filter_Text('status', 'in', $openStatus->getId()));
                 break;
         }
     }
     return $filter;
 }
コード例 #10
0
ファイル: Task.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * handles completed date and sets task to 100%
  * 
  * @param Tasks_Model_Task $_task
  */
 protected function _handleCompleted($_task)
 {
     $allStatus = Tasks_Config::getInstance()->get(Tasks_Config::TASK_STATUS)->records;
     $statusId = $allStatus->getIndexById($_task->status);
     if (is_int($statusId)) {
         $status = $allStatus[$statusId];
         if ($status->is_open) {
             $_task->completed = NULL;
         } elseif (!$_task->completed instanceof DateTime) {
             $_task->completed = Tinebase_DateTime::now();
         }
     }
 }