/**
  * the singleton pattern
  *
  * @return Crm_Controller_Lead
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #2
0
 /**
  * the singleton pattern
  *
  * @return Crm_Controller_Lead
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new Crm_Controller_Lead();
     }
     return self::$_instance;
 }
 /**
  * test sorted csv export
  * 
  * @return void
  * 
  * @see 0010790: use current grid sort in exports
  */
 public function testSortedExportCsv()
 {
     $options = array('sortInfo' => array('field' => 'leadstate_id'));
     $this->_instance = new Crm_Export_Csv(new Crm_Model_LeadFilter($this->_getLeadFilter()), Crm_Controller_Lead::getInstance(), $options);
     $this->_filename = $this->_instance->generate();
     $export = file_get_contents($this->_filename);
     $this->assertContains('"Metaways Infosystems GmbH"', $export);
 }
 /**
  * (non-PHPdoc)
  * @see tests/tine20/Crm/AbstractTest::setUp()
  */
 public function setUp()
 {
     parent::setUp();
     $smtpConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::SMTP, new Tinebase_Config_Struct())->toArray();
     if (empty($smtpConfig)) {
         $this->markTestSkipped('No SMTP config found: this is needed to send notifications.');
     }
     $this->_leadController = Crm_Controller_Lead::getInstance();
 }
 /**
  * Tears down the fixture
  * This method is called after a test is executed.
  *
  * @access protected
  */
 protected function tearDown()
 {
     if (isset($this->_objects['paths'])) {
         foreach ($this->_objects['paths'] as $path) {
             try {
                 $this->_fsController->rmdir($path, TRUE);
             } catch (Tinebase_Exception_NotFound $tenf) {
                 // already deleted
             }
         }
     }
     parent::tearDown();
     Crm_Controller_Lead::getInstance()->duplicateCheckFields(array('lead_name'));
 }
 /**
  * constructs a new importer from given config
  *
  * @param array $_options
  */
 public function __construct(array $_options = array())
 {
     parent::__construct($_options);
     // disable lead notifications on import
     Crm_Controller_Lead::getInstance()->sendNotifications(false);
     // get container id from default container if not set
     if (empty($this->_options['container_id'])) {
         $defaultContainer = Tinebase_Container::getInstance()->getDefaultContainer('Crm_Model_Lead');
         $this->_options['container_id'] = $defaultContainer->getId();
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting default container id: ' . $this->_options['container_id']);
         }
     }
 }
 /**
  * tests demo data creation for all applications having demodata prepared
  */
 public function testCreateAllDemoData()
 {
     $adbController = Addressbook_Controller_Contact::getInstance();
     $normalContactsFilter = new Addressbook_Model_ContactFilter(array(array('field' => 'type', 'operator' => 'not', 'value' => 'user')));
     $existingContacts = $adbController->search($normalContactsFilter);
     // skip admin as it will be called before all tests
     $opts = new Zend_Console_Getopt('abp:', array('skipAdmin'));
     ob_start();
     $this->_cli->createAllDemoData($opts);
     ob_end_clean();
     // test addressbook contacts / admin user contacts
     $accountContactsFilter = new Addressbook_Model_ContactFilter(array(array('field' => 'type', 'operator' => 'equals', 'value' => 'user')));
     $normalContactsFilter = new Addressbook_Model_ContactFilter(array(array('field' => 'type', 'operator' => 'equals', 'value' => 'contact')));
     $normalContacts = $adbController->search($normalContactsFilter);
     $accountContacts = $adbController->search($accountContactsFilter);
     // shared should be 700
     $this->assertEquals(700 + $existingContacts->count(), $normalContacts->count(), 'NormalContacts');
     // internal contacts/accounts
     $this->assertEquals(6, $accountContacts->count(), 'AccountContacts');
     // test calendar entries
     $calController = Calendar_Controller_Event::getInstance();
     $allEventsFilter = new Calendar_Model_EventFilter(array());
     $allEvents = $calController->search($allEventsFilter);
     $this->assertEquals(49, $allEvents->count(), 'Events');
     // test crm leads
     $crmController = Crm_Controller_Lead::getInstance();
     $allLeadsFilter = new Crm_Model_LeadFilter(array());
     $allLeads = $crmController->search($allLeadsFilter);
     $this->assertEquals(1, $allLeads->count(), 'One shared lead should have been found');
     // test human resources
     $employeeController = HumanResources_Controller_Employee::getInstance();
     $allEmployeesFilter = new HumanResources_Model_EmployeeFilter(array());
     $allEmployees = $employeeController->search($allEmployeesFilter);
     $this->assertEquals(6, $allEmployees->count());
     // remove employees again
     $employeeController->delete($allEmployees->id);
 }
 /**
  * creates shared leads
  */
 protected function _createSharedLeads()
 {
     $contacts = Addressbook_Controller_Contact::getInstance()->getAll();
     $addresses = $contacts->filter('type', 'contact');
     $pagination = new Tinebase_Model_Pagination();
     $pagination->start = 0;
     $pagination->limit = 100;
     $addresses->limitByPagination($pagination);
     $users = $contacts->filter('type', 'user');
     unset($contacts);
     $userids = $users->getId();
     // remove admin user
     $users->removeRecord($users->getById(Tinebase_Core::getUser()->contact_id));
     $userCount = $users->count();
     $lastOrgName = NULL;
     $lead = NULL;
     $startDate = Tinebase_DateTime::now()->subWeek(10);
     // first day is a monday
     while ($startDate->format('w') != 1) {
         $startDate->subDay(1);
     }
     $this->_createSharedContainer(static::$_de ? 'Gemeinsame Leads' : 'Shared Leads');
     $controller = Crm_Controller_Lead::getInstance();
     $controller->sendNotifications(0);
     $orgNames = array_unique($addresses->org_name);
     shuffle($orgNames);
     $i = 0;
     $userIndex = -1;
     $state = -1;
     $stateIndex = 0;
     foreach ($orgNames as $orgName) {
         if (empty($orgName)) {
             continue;
         }
         $orgAddresses = $addresses->filter('org_name', $orgName);
         if ($orgAddresses->count() < 2) {
             continue;
         }
         $userIndex++;
         while (!($user = $users->getById($userids[$userIndex]))) {
             $userIndex++;
             if ($userIndex >= $userCount - 1) {
                 $userIndex = 0;
             }
         }
         if ($i % 2 == 0) {
             // create more running leads
             if ($state == 0 && $stateIndex < 5) {
                 $stateIndex++;
             } else {
                 $stateIndex = 0;
                 $startDate->addWeek(1);
             }
         }
         // date is the startdate of the lead, always monday, we want friday in a week
         $due = clone $startDate;
         $due->addWeek(1)->addDay(4);
         $this->_getDays($due);
         $now = new Tinebase_DateTime();
         if ($startDate < $now && $due > $now) {
             $state = 0;
         } elseif ($startDate > $now) {
             $state = 1;
         } else {
             $state = -1;
         }
         $lead = $controller->create(new Crm_Model_Lead(array('lead_name' => $orgName, 'leadstate_id' => $state > 0 ? 5 : 1, 'leadtype_id' => rand(1, 3), 'leadsource_id' => rand(1, 4), 'container_id' => $this->_sharedContainer->getId(), 'start' => $startDate, 'end' => $state < 0 ? $due : NULL, 'end_scheduled' => $due, 'probability' => $state > 0 ? 50 + $userIndex * 10 : 100, 'turnover' => ($i + 2 ^ 5) * 1000)));
         $relations = array();
         foreach ($orgAddresses as $address) {
             $relations[] = $this->_getRelationArray($lead, $address, 'sibling', 'CUSTOMER');
         }
         $relations[] = $this->_getRelationArray($lead, $user, 'sibling', 'RESPONSIBLE');
         $tasks = $this->_generateTasks($user, $state, $i);
         foreach ($tasks as $taskArray) {
             $task = $this->_getTask($taskArray);
             $relations[] = $this->_getRelationArray($lead, $task);
         }
         $lead->relations = $relations;
         $controller->update($lead);
         $i++;
     }
 }
Example #9
0
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->_instance = new Crm_Export_Csv(new Crm_Model_LeadFilter($this->_getLeadFilter()), Crm_Controller_Lead::getInstance());
     parent::setUp();
 }
 /**
  * creates and deletes a lead + returns the deleted record
  * 
  * @return Crm_Model_Lead
  */
 protected function _addAndDeleteLead()
 {
     $newLead = new Crm_Model_Lead(array('lead_name' => 'PHPUNIT Lead', 'container_id' => Tinebase_Container::getInstance()->getDefaultContainer('Crm')->getId(), 'leadstate_id' => 1, 'leadtype_id' => 1, 'leadsource_id' => 1, 'start' => Tinebase_DateTime::now()));
     $newLead = Crm_Controller_Lead::getInstance()->create($newLead);
     Crm_Controller_Lead::getInstance()->delete($newLead->getId());
     return $newLead;
 }
Example #11
0
 /**
  * try to create a pdf with a linked task
  *
  */
 public function testLeadPdfLinkedTask()
 {
     // create lead + task + link
     $task = Tasks_Controller_Task::getInstance()->create($this->objects['linkedTask']);
     $lead = Crm_Controller_Lead::getInstance()->get($this->objects['leadWithLink']->getId());
     $lead->relations = array(array('own_model' => 'Crm_Model_Lead', 'own_backend' => 'Sql', 'own_id' => $lead->getId(), 'own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Tasks_Model_Task', 'related_backend' => Tasks_Backend_Factory::SQL, 'related_id' => $task->getId(), 'type' => 'TASK'));
     $lead = Crm_Controller_Lead::getInstance()->update($lead);
     $pdf = new Crm_Export_Pdf();
     $pdf->generate($lead);
     $pdfOutput = $pdf->render();
     //$pdf->save("test.pdf");
     $this->assertEquals(1, preg_match("/^%PDF-1.4/", $pdfOutput), "no pdf generated");
     $this->assertEquals(1, preg_match("/" . $task->summary . "/", $pdfOutput), "no summary found");
     // remove
     Tasks_Controller_Task::getInstance()->delete($task->getId());
     // purge all relations
     $backend = new Tinebase_Relation_Backend_Sql();
     $backend->purgeAllRelations('Crm_Model_Lead', 'Sql', $this->objects['leadWithLink']->getId());
 }
Example #12
0
 /**
  * export lead
  * 
  * @param	string $filter JSON encoded string with lead ids for multi export
  * @param	string $options format or export definition id
  */
 public function exportLead($filter, $options)
 {
     $filter = new Crm_Model_LeadFilter(Zend_Json::decode($filter));
     parent::_export($filter, Zend_Json::decode($options), Crm_Controller_Lead::getInstance());
 }
 /**
  * try to delete a lead
  *
  */
 public function testDeleteLead()
 {
     Crm_Controller_Lead::getInstance()->delete($GLOBALS['Addressbook_ControllerTest']['leadId']);
     // purge all relations
     $backend = new Tinebase_Relation_Backend_Sql();
     $backend->purgeAllRelations('Crm_Model_Lead', 'Sql', $GLOBALS['Addressbook_ControllerTest']['leadId']);
     // delete contact
     Addressbook_Controller_Contact::getInstance()->delete($this->_objects['user']->getId());
     $this->setExpectedException('Tinebase_Exception_NotFound');
     Crm_Controller_Lead::getInstance()->get($GLOBALS['Addressbook_ControllerTest']['leadId']);
 }
Example #14
0
 /**
  * the constructor
  *
  */
 public function __construct()
 {
     $this->_applicationName = 'Crm';
     $this->_controller = Crm_Controller_Lead::getInstance();
 }