/** * Used on first load to install ContactState data * and the startingState for the Contacts module. * @return true/false if data was in fact loaded. */ public static function loadStartingData() { if (count(ContactState::GetAll()) != 0) { return false; } $data = array(Zurmo::t('Core', 'New'), Zurmo::t('Core', 'In Progress'), Zurmo::t('ContactsModule', 'Recycled'), Zurmo::t('ContactsModule', 'Dead'), Zurmo::t('ContactsModule', 'Qualified'), Zurmo::t('ZurmoModule', 'Customer')); $order = 0; $startingStateId = null; foreach ($data as $stateName) { $state = new ContactState(); $state->name = $stateName; $state->order = $order; $saved = $state->save(); assert('$saved'); if ($stateName == Zurmo::t('ContactsModule', 'Qualified')) { $startingStateId = $state->id; } $order++; } if ($startingStateId == null) { throw new NotSupportedException(); } $metadata = ContactsModule::getMetadata(); $metadata['global']['startingStateId'] = $startingStateId; ContactsModule::setMetadata($metadata); assert('count(ContactState::GetAll()) == 6'); return true; }
public static function setStartingStateById($startingStateId) { assert('is_int($startingStateId)'); $metadata = ContactsModule::getMetadata(); $metadata['global']['startingStateId'] = $startingStateId; ContactsModule::setMetadata($metadata); }
public function testLeadsStateMetadataAdapterWithNoStates() { $metadata = ContactsModule::getMetadata(); $metadata['global']['startingStateId'] = LeadsUtil::getStartingState()->id; ContactsModule::setMetadata($metadata); $adapter = new LeadsStateMetadataAdapter(array('clauses' => array(), 'structure' => '')); $adaptedMetadata = $adapter->getAdaptedDataProviderMetadata(); $compareMetadata = array('clauses' => array(1 => array('attributeName' => 'state', 'operatorType' => 'equals', 'value' => '-1')), 'structure' => '(1)'); $this->assertEquals($compareMetadata, $adaptedMetadata); }
public function testContactStateAdapterReturnsCorrectStatesUponStartingStateChange() { $this->assertEquals(7, count(ContactState::GetAll())); $metadata = ContactsModule::getMetadata(); $metadata['global']['startingStateId'] = ContactsUtil::getStartingState()->id; ContactsModule::setMetadata($metadata); $metadata = array('clauses' => array(), 'structure' => ''); $adapter = new ContactsStateMetadataAdapter($metadata); $adaptedMetadata = $adapter->getAdaptedDataProviderMetadata(); $statesToInclude = ContactsUtil::getContactStateDataFromStartingStateOnAndKeyedById(); $this->assertEquals(7, count($statesToInclude)); $compareMetadata['clauses'] = array(); $compareMetadata['structure'] = '(1 or 2 or 3 or 4 or 5 or 6 or 7)'; $index = 1; foreach ($statesToInclude as $stateId => $notUsed) { $compareMetadata['clauses'][$index] = array('attributeName' => 'state', 'operatorType' => 'equals', 'value' => $stateId); $index++; } $this->assertEquals($compareMetadata, $adaptedMetadata); }
public function testUpdateLatestActivityDateTimeMethods() { $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted(); $this->assertTrue($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated(); $this->assertTrue($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived(); $this->assertTrue($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast(); $this->assertTrue($value); $metadata = ContactsModule::getMetadata(); $metadata['global']['updateLatestActivityDateTimeWhenATaskIsCompleted'] = false; ContactsModule::setMetadata($metadata); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted(); $this->assertFalse($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated(); $this->assertTrue($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived(); $this->assertTrue($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast(); $this->assertTrue($value); $metadata = ContactsModule::getMetadata(); $metadata['global']['updateLatestActivityDateTimeWhenANoteIsCreated'] = false; ContactsModule::setMetadata($metadata); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted(); $this->assertFalse($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated(); $this->assertFalse($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived(); $this->assertTrue($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast(); $this->assertTrue($value); $metadata = ContactsModule::getMetadata(); $metadata['global']['updateLatestActivityDateTimeWhenAnEmailIsSentOrArchived'] = false; ContactsModule::setMetadata($metadata); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted(); $this->assertFalse($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated(); $this->assertFalse($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived(); $this->assertFalse($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast(); $this->assertTrue($value); $metadata = ContactsModule::getMetadata(); $metadata['global']['updateLatestActivityDateTimeWhenAMeetingIsInThePast'] = false; ContactsModule::setMetadata($metadata); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted(); $this->assertFalse($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated(); $this->assertFalse($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived(); $this->assertFalse($value); $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast(); $this->assertFalse($value); }