本文整理汇总了PHP中ContactState类的典型用法代码示例。如果您正苦于以下问题:PHP ContactState类的具体用法?PHP ContactState怎么用?PHP ContactState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContactState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadStartingData
/**
* 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;
}
示例2: testLoad
public function testLoad()
{
$customFieldData = CustomFieldData::getByName('Titles');
$this->assertEquals(0, count(unserialize($customFieldData->serializedData)));
$customFieldData = CustomFieldData::getByName('AccountTypes');
$this->assertEquals(0, count(unserialize($customFieldData->serializedData)));
$customFieldData = CustomFieldData::getByName('LeadSources');
$this->assertEquals(0, count(unserialize($customFieldData->serializedData)));
$customFieldData = CustomFieldData::getByName('Industries');
$this->assertEquals(0, count(unserialize($customFieldData->serializedData)));
$customFieldData = CustomFieldData::getByName('MeetingCategories');
$this->assertEquals(0, count(unserialize($customFieldData->serializedData)));
$this->assertEquals(0, ContactState::getCount());
// do a getAll to ensure we create base currency
$baseCurrency = Currency::getAll();
$this->assertCount(1, $baseCurrency);
$this->assertEquals(1, Currency::getCount());
$messageLogger = new MessageLogger();
DefaultDataUtil::load($messageLogger);
$customFieldData = CustomFieldData::getByName('Titles');
$this->assertEquals(4, count(unserialize($customFieldData->serializedData)));
$customFieldData = CustomFieldData::getByName('AccountTypes');
$this->assertEquals(3, count(unserialize($customFieldData->serializedData)));
$customFieldData = CustomFieldData::getByName('LeadSources');
$this->assertEquals(4, count(unserialize($customFieldData->serializedData)));
$customFieldData = CustomFieldData::getByName('Industries');
$this->assertEquals(9, count(unserialize($customFieldData->serializedData)));
$customFieldData = CustomFieldData::getByName('MeetingCategories');
$this->assertEquals(2, count(unserialize($customFieldData->serializedData)));
$this->assertEquals(6, ContactState::getCount());
$this->assertEquals(1, Currency::getCount());
}
示例3: sanitizeValue
/**
* Given a contact state id, attempt to get and return a contact state object. If the id is invalid, then an
* InvalidValueToSanitizeException will be thrown.
* @param mixed $value
* @return sanitized value
* @throws InvalidValueToSanitizeException
* @throws NotFoundException
*/
public function sanitizeValue($value)
{
assert('$this->attributeName == null');
if ($value == null) {
return $value;
}
try {
if ((int) $value <= 0) {
$states = ContactState::getByName($value);
if (count($states) > 1) {
throw new InvalidValueToSanitizeException(Zurmo::t('ContactsModule', 'Status specified is not unique and is invalid.'));
} elseif (count($states) == 0) {
throw new NotFoundException();
}
$state = $states[0];
} else {
$state = ContactState::getById($value);
}
$startingState = ContactsUtil::getStartingState();
if (!static::resolvesValidStateByOrder($state->order, $startingState->order)) {
throw new InvalidValueToSanitizeException(Zurmo::t('ZurmoModule', 'Status specified is invalid.'));
}
return $state;
} catch (NotFoundException $e) {
throw new InvalidValueToSanitizeException(Zurmo::t('ContactsModule', 'Status specified does not exist.'));
}
}
示例4: testGetExportValue
public function testGetExportValue()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$data = array();
$contactStates = ContactState::getByName('Qualified');
$contact = new Contact();
$contact->owner = $super;
$contact->firstName = 'Super';
$contact->lastName = 'Man';
$contact->jobTitle = 'Superhero';
$contact->description = 'Some Description';
$contact->department = 'Red Tape';
$contact->officePhone = '1234567890';
$contact->mobilePhone = '0987654321';
$contact->officeFax = '1222222222';
$contact->state = $contactStates[0];
$this->assertTrue($contact->save());
$adapter = new ContactStateRedBeanModelAttributeValueToExportValueAdapter($contact, 'state');
$adapter->resolveData($data);
$compareData = array($contactStates[0]->name);
$this->assertEquals($compareData, $data);
$data = array();
$adapter->resolveHeaderData($data);
$compareData = array($contact->getAttributeLabel('state'));
$this->assertEquals($compareData, $data);
}
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:27,代码来源:ContactStateRedBeanModelAttributeValueToExportValueAdapterTest.php
示例5: testCreateAndGetContactWebFormById
public function testCreateAndGetContactWebFormById()
{
$allAttributes = ContactWebFormsUtil::getAllAttributes();
$placedAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle');
$contactFormAttributes = ContactWebFormsUtil::getAllPlacedAttributes($allAttributes, $placedAttributes);
$attributes = array_keys($contactFormAttributes);
$this->assertTrue(ContactsModule::loadStartingData());
$contactStates = ContactState::getByName('New');
$contactWebForm = new ContactWebForm();
$contactWebForm->name = 'Test Form';
$contactWebForm->redirectUrl = 'http://google.com';
$contactWebForm->submitButtonLabel = 'Save';
$contactWebForm->defaultState = $contactStates[0];
$contactWebForm->serializedData = serialize($attributes);
$contactWebForm->defaultOwner = Yii::app()->user->userModel;
$this->assertTrue($contactWebForm->save());
$id = $contactWebForm->id;
unset($contactWebForm);
$contactWebForm = ContactWebForm::getById($id);
$this->assertEquals('Test Form', $contactWebForm->name);
$this->assertEquals('http://google.com', $contactWebForm->redirectUrl);
$this->assertEquals('Save', $contactWebForm->submitButtonLabel);
$this->assertEquals('New', $contactWebForm->defaultState->name);
$this->assertEquals($attributes, unserialize($contactWebForm->serializedData));
}
示例6: setAttributeMetadataFromForm
public function setAttributeMetadataFromForm(AttributeForm $attributeForm)
{
$modelClassName = get_class($this->model);
$attributeName = $attributeForm->attributeName;
$attributeLabels = $attributeForm->attributeLabels;
$elementType = $attributeForm->getAttributeTypeName();
$isRequired = (bool) $attributeForm->isRequired;
$isAudited = (bool) $attributeForm->isAudited;
$contactStatesData = $attributeForm->contactStatesData;
$contactStatesLabels = $attributeForm->contactStatesLabels;
$startingStateOrder = (int) $attributeForm->startingStateOrder;
$contactStatesDataExistingValues = $attributeForm->contactStatesDataExistingValues;
if ($contactStatesDataExistingValues == null) {
$contactStatesDataExistingValues = array();
}
if ($attributeForm instanceof ContactStateAttributeForm) {
//update order on existing states.
//delete removed states
$states = ContactState::getAll('order');
$stateNames = array();
foreach ($states as $state) {
if (in_array($state->name, $contactStatesDataExistingValues)) {
//todo: just don't match up the swap
$order = array_search($state->name, $contactStatesDataExistingValues);
$state->name = $contactStatesData[$order];
$state->order = $order;
$state->serializedLabels = $this->makeSerializedLabelsByLabelsAndOrder($contactStatesLabels, (int) $state->order);
$saved = $state->save();
assert('$saved');
$stateNames[] = $state->name;
} elseif (in_array($state->name, $contactStatesData)) {
$stateNames[] = $state->name;
$state->order = array_search($state->name, $contactStatesData);
$state->serializedLabels = $this->makeSerializedLabelsByLabelsAndOrder($contactStatesLabels, (int) $state->order);
$saved = $state->save();
assert('$saved');
} else {
$stateNames[] = $state->name;
$state->delete();
}
}
//add new states with correct order.
foreach ($contactStatesData as $order => $name) {
if (!in_array($name, $stateNames)) {
$state = new ContactState();
$state->name = $name;
$state->order = $order;
$state->serializedLabels = $this->makeSerializedLabelsByLabelsAndOrder($contactStatesLabels, (int) $order);
$saved = $state->save();
assert('$saved');
}
}
//Set starting state by order.
ContactsUtil::setStartingStateByOrder($startingStateOrder);
ModelMetadataUtil::addOrUpdateRelation($modelClassName, $attributeName, $attributeLabels, $elementType, $isRequired, $isAudited, 'ContactState');
} else {
throw new NotSupportedException();
}
}
示例7: resolveValueAndSetToModel
/**
* Utilized to create or update model attribute values after a workflow's triggers are fired as true.
* @param WorkflowActionProcessingModelAdapter $adapter
* @param string $attribute
* @throws NotSupportedException
*/
public function resolveValueAndSetToModel(WorkflowActionProcessingModelAdapter $adapter, $attribute)
{
assert('is_string($attribute)');
if ($this->type == WorkflowActionAttributeForm::TYPE_STATIC) {
$adapter->getModel()->{$attribute} = ContactState::getById((int) $this->value);
//todo: what if it doesn't exist anymore?
} else {
throw new NotSupportedException();
}
}
示例8: testCreateAndGetContactWebFormEntryById
public function testCreateAndGetContactWebFormEntryById()
{
$allAttributes = ContactWebFormsUtil::getAllAttributes();
$placedAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle');
$contactFormAttributes = ContactWebFormsUtil::getAllPlacedAttributes($allAttributes, $placedAttributes);
$attributes = array_keys($contactFormAttributes);
$this->assertTrue(ContactsModule::loadStartingData());
$contactStates = ContactState::getByName('New');
$contactWebForm = new ContactWebForm();
$contactWebForm->name = 'Test Form';
$contactWebForm->redirectUrl = 'http://google.com';
$contactWebForm->submitButtonLabel = 'Save';
$contactWebForm->defaultState = $contactStates[0];
$contactWebForm->defaultOwner = Yii::app()->user->userModel;
$contactWebForm->serializedData = serialize($attributes);
$contactWebForm->save();
$contact = new Contact();
$contact->owner = $contactWebForm->defaultOwner;
$contact->state = $contactWebForm->defaultState;
$contact->firstName = 'Super';
$contact->lastName = 'Man';
$contact->jobTitle = 'Superhero';
$contact->companyName = 'Test Inc.';
if ($contact->validate()) {
$contactWebFormEntryStatus = ContactWebFormEntry::STATUS_SUCCESS;
$contactWebFormEntryMessage = ContactWebFormEntry::STATUS_SUCCESS_MESSAGE;
} else {
$contactWebFormEntryStatus = ContactWebFormEntry::STATUS_ERROR;
$contactWebFormEntryMessage = ContactWebFormEntry::STATUS_ERROR_MESSAGE;
}
$contact->save();
foreach ($contactFormAttributes as $attributeName => $attributeValue) {
$contactFormAttributes[$attributeName] = $contact->{$attributeName};
}
$contactFormAttributes['owner'] = $contactWebForm->defaultOwner->id;
$contactFormAttributes['state'] = $contactWebForm->defaultState->id;
$contactWebFormEntry = new ContactWebFormEntry();
$contactWebFormEntry->serializedData = serialize($contactFormAttributes);
$contactWebFormEntry->status = $contactWebFormEntryStatus;
$contactWebFormEntry->message = $contactWebFormEntryMessage;
$contactWebFormEntry->contactWebForm = $contactWebForm;
$contactWebFormEntry->contact = $contact;
$this->assertTrue($contactWebFormEntry->save());
$contactWebFormEntryId = $contactWebFormEntry->id;
unset($contactWebFormEntry);
$contactWebFormEntry = ContactWebFormEntry::getById($contactWebFormEntryId);
$this->assertEquals('Test Form', $contactWebFormEntry->contactWebForm->name);
$this->assertEquals('Super', $contactWebFormEntry->contact->firstName);
$this->assertEquals('Man', $contactWebFormEntry->contact->lastName);
$contactFormAttributes = unserialize($contactWebFormEntry->serializedData);
$this->assertEquals('Super', $contactFormAttributes['firstName']);
$this->assertEquals('Man', $contactFormAttributes['lastName']);
$this->assertEquals('Superhero', $contactFormAttributes['jobTitle']);
$this->assertEquals('Test Inc.', $contactFormAttributes['companyName']);
}
示例9: testSanitizeValueBySanitizerTypesForContactStateTypeThatIsRequired
public function testSanitizeValueBySanitizerTypesForContactStateTypeThatIsRequired()
{
$contactStates = ContactState::getAll();
$this->assertEquals(6, count($contactStates));
//Test a required contact state with no value or default value.
$importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
$columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultStateId' => null)));
$sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
$sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, null, 'column_0', $columnMappingData, $importSanitizeResultsUtil);
$this->assertNull($sanitizedValue);
$this->assertFalse($importSanitizeResultsUtil->shouldSaveModel());
$messages = $importSanitizeResultsUtil->getMessages();
$this->assertEquals(1, count($messages));
$compareMessage = 'Contact - The status is required. Neither a value nor a default was specified.';
$this->assertEquals($compareMessage, $messages[0]);
//Test a required contact state with a valid value, and a default value. The valid value should come through.
$importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
$columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultStateId' => $contactStates[4]->id)));
$sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
$sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, $contactStates[5]->id, 'column_0', $columnMappingData, $importSanitizeResultsUtil);
$this->assertEquals($contactStates[5], $sanitizedValue);
$this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
$messages = $importSanitizeResultsUtil->getMessages();
$this->assertEquals(0, count($messages));
//Test a required contact state with no value, and a default value.
$importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
$columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultStateId' => $contactStates[4]->id)));
$sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
$sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, null, 'column_0', $columnMappingData, $importSanitizeResultsUtil);
$this->assertEquals($contactStates[4], $sanitizedValue);
$this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
$messages = $importSanitizeResultsUtil->getMessages();
$this->assertEquals(0, count($messages));
//Test a required contact state with a value that is invalid
$importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
$columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultValue' => null)));
$sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
$sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, 'somethingnotright', 'column_0', $columnMappingData, $importSanitizeResultsUtil);
$this->assertFalse($importSanitizeResultsUtil->shouldSaveModel());
$messages = $importSanitizeResultsUtil->getMessages();
$this->assertEquals(1, count($messages));
$compareMessage = 'Contact - Status specified does not exist.';
$this->assertEquals($compareMessage, $messages[0]);
//Test a required contact state with a state that is for leads, not contacts.
$importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
$columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultValue' => null)));
$sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
$sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, $contactStates[1]->id, 'column_0', $columnMappingData, $importSanitizeResultsUtil);
$this->assertFalse($importSanitizeResultsUtil->shouldSaveModel());
$messages = $importSanitizeResultsUtil->getMessages();
$this->assertEquals(1, count($messages));
$compareMessage = 'Contact - Status specified is invalid.';
$this->assertEquals($compareMessage, $messages[0]);
}
示例10: getStateIds
public function getStateIds()
{
$states = ContactState::getAll('order');
$startingStateOrder = ContactsUtil::getStartingStateOrder($states);
$stateIds = array();
foreach ($states as $state) {
if ($this->shouldIncludeState($state->order, $startingStateOrder)) {
$stateIds[] = $state->id;
}
}
return $stateIds;
}
示例11: testCasingInsensitivity
/**
* @depends testGetModelsByFullName
*/
public function testCasingInsensitivity()
{
Yii::app()->user->userModel = User::getByUsername('super');
$user = User::getByUsername('billy');
ContactsModule::loadStartingData();
$states = ContactState::GetAll();
$contact = new Contact();
$contact->owner = $user;
$contact->title->value = 'Mr.';
$contact->firstName = 'super';
$contact->lastName = 'man';
$contact->state = $states[0];
$this->assertTrue($contact->save());
$id = $contact->id;
$this->assertNotEmpty($id);
unset($contact);
$contacts = ZurmoModelSearch::getModelsByFullName('Contact', 'Super Man');
$this->assertEquals(2, count($contacts));
}
示例12: makeAll
public function makeAll(&$demoDataHelper)
{
assert('$demoDataHelper instanceof DemoDataHelper');
assert('$demoDataHelper->isSetRange("User")');
$contactStates = ContactState::getAll();
$statesBeginningWithStartingState = $this->getStatesBeforeOrStartingWithStartingState($contactStates);
$contacts = array();
for ($i = 0; $i < $this->resolveQuantityToLoad(); $i++) {
$contact = new Contact();
$contact->owner = $demoDataHelper->getRandomByModelName('User');
$contact->state = RandomDataUtil::getRandomValueFromArray($statesBeginningWithStartingState);
$this->populateModel($contact);
$saved = $contact->save();
assert('$saved');
$contacts[] = $contact->id;
}
//We can use dummy model name here ContactsThatAreLeads, so we can distinct between contacts are leads
$demoDataHelper->setRangeByModelName('ContactsThatAreLeads', $contacts[0], $contacts[count($contacts) - 1]);
}
示例13: createContactWebFormByName
public static function createContactWebFormByName($name, $owner = null)
{
if ($owner === null) {
$owner = Yii::app()->user->userModel;
}
$placedAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle');
ContactsModule::loadStartingData();
$contactStates = ContactState::getByName('New');
$contactWebForm = new ContactWebForm();
$contactWebForm->name = $name;
$contactWebForm->redirectUrl = 'http://www.zurmo.com/';
$contactWebForm->submitButtonLabel = 'Save';
$contactWebForm->defaultState = $contactStates[0];
$contactWebForm->serializedData = serialize($placedAttributes);
$contactWebForm->defaultOwner = $owner;
$saved = $contactWebForm->save();
assert('$saved');
return $contactWebForm;
}
示例14: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
$loaded = ContactsModule::loadStartingData();
assert($loaded);
// Not Coding Standard
$contactStates = ContactState::getByName('New');
self::$newState = $contactStates[0];
$contactStates = ContactState::getByName('In progress');
self::$inProgressState = $contactStates[0];
$contactStates = ContactState::getByName('Recycled');
self::$recycledState = $contactStates[0];
$contactStates = ContactState::getByName('Dead');
self::$deadState = $contactStates[0];
$contactStates = ContactState::getByName('Qualified');
self::$qualifiedState = $contactStates[0];
$contactStates = ContactState::getByName('Customer');
self::$customerState = $contactStates[0];
}
示例15: makeAll
public function makeAll(&$demoDataHelper)
{
assert('$demoDataHelper instanceof DemoDataHelper');
assert('$demoDataHelper->isSetRange("User")');
assert('$demoDataHelper->isSetRange("Account")');
$contactStates = ContactState::getAll();
$statesBeginningWithStartingState = $this->getStatesBeforeOrStartingWithStartingState($contactStates);
$contacts = array();
for ($i = 0; $i < $this->resolveQuantityToLoad(); $i++) {
$contact = new Contact();
$contact->account = $demoDataHelper->getRandomByModelName('Account');
$contact->state = RandomDataUtil::getRandomValueFromArray($statesBeginningWithStartingState);
$contact->owner = $contact->account->owner;
$this->populateModel($contact);
$saved = $contact->save();
assert('$saved');
$contacts[] = $contact->id;
}
$demoDataHelper->setRangeByModelName('Contact', $contacts[0], $contacts[count($contacts) - 1]);
}