Beispiel #1
0
 public function testCreateSourceValues()
 {
     $sourceValues = array('Word of Mouth', 'Outbound', 'Trade Show');
     $sourceFieldData = CustomFieldData::getByName('LeadSources');
     $sourceFieldData->serializedData = serialize($sourceValues);
     $this->assertTrue($sourceFieldData->save());
 }
 public function testLogAuditForOwnedMultipleValuesCustomField()
 {
     Yii::app()->user->userModel = User::getByUsername('jimmy');
     $beforeCount = AuditEvent::getCount();
     $values = array('A', 'B', 'C', 'CC', 'CCC');
     $customFieldData = CustomFieldData::getByName('MultipleIndustries');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     $this->assertTrue($saved);
     $model = new TestOwnedCustomFieldsModel();
     $this->assertTrue($model->save());
     $this->assertEquals($beforeCount + 1, AuditEvent::getCount());
     $model = TestOwnedCustomFieldsModel::getById($model->id);
     $value = new CustomFieldValue();
     $value->value = 'C';
     $model->multipleIndustries->values->removeAll();
     //To remove the blank CustomFieldValue. This mimics
     //setValues($values) in MultipleValuesCustomField.
     $model->multipleIndustries->values->add($value);
     $this->assertTrue($model->save());
     $this->assertEquals($beforeCount + 2, AuditEvent::getCount());
     $model = TestOwnedCustomFieldsModel::getById($model->id);
     $value = new CustomFieldValue();
     $value->value = 'B';
     $model->multipleIndustries->values->add($value);
     $this->assertTrue($model->save());
     $this->assertEquals($beforeCount + 3, AuditEvent::getCount());
     $AuditEventsList = AuditEvent::getTailEvents(3);
     $this->assertRegExp('/[0-9]+\\/[0-9]+\\/[0-9]+ [0-9]+:[0-9]+ [AP]M, ' . 'James Boondog, Item Created, ' . 'TestOwnedCustomFieldsModel\\([0-9]+\\), \\(None\\)/', ZurmoModule::stringifyAuditEvent($AuditEventsList[0]));
     $this->assertRegExp('/[0-9]+\\/[0-9]+\\/[0-9]+ [0-9]+:[0-9]+ [AP]M, ' . 'James Boondog, Item Modified, ' . 'TestOwnedCustomFieldsModel\\([0-9]+\\), \\(None\\), ' . 'Changed Multiple Industries Values from  to C/', ZurmoModule::stringifyAuditEvent($AuditEventsList[1]));
     $this->assertRegExp('/[0-9]+\\/[0-9]+\\/[0-9]+ [0-9]+:[0-9]+ [AP]M, ' . 'James Boondog, Item Modified, ' . 'TestOwnedCustomFieldsModel\\([0-9]+\\), \\(None\\), ' . 'Changed Multiple Industries Values from C to C, B/', ZurmoModule::stringifyAuditEvent($AuditEventsList[2]));
 }
 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());
 }
 /**
  * Render a hidden input, a text input with an auto-complete
  * event, and a select button. These three items together
  * form the Opportunity Editable Element
  * @return The element's content as a string.
  */
 protected function renderControlEditable()
 {
     $content = null;
     $content .= ZurmoHtml::textField('stageToProbabilityMapping_notUsed', null, array('id' => $this->getEditableInputId(), 'style' => "display:none;"));
     $fieldData = CustomFieldData::getByName('SalesStages');
     if ($fieldData->serializedData != null) {
         $values = unserialize($fieldData->serializedData);
         if (!is_array($values)) {
             $values = array();
         }
     } else {
         $values = array();
     }
     $stagesToProbabilities = OpportunitiesModule::getStageToProbabilityMappingData();
     foreach ($values as $value) {
         if (isset($stagesToProbabilities[$value])) {
             $probability = $stagesToProbabilities[$value];
         } else {
             $probability = 0;
         }
         $htmlOptions = array('name' => $this->getNameForInputField($value), 'value' => $probability);
         $element = $this->form->textField($this->model, $this->attribute, $htmlOptions);
         $element .= ZurmoHtml::tag('span', array(), $value);
         $content .= ZurmoHtml::tag('div', array('class' => 'has-lang-label'), $element);
     }
     return $content;
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     ContactsModule::loadStartingData();
     //Need to instantiate a controller so the clipWidget can work properly in elements that utilize it.
     $controller = Yii::app()->createController('reports/default');
     list($controller, $actionId) = $controller;
     Yii::app()->setController($controller);
     $values = array('Test1', 'Test2', 'Test3', 'Sample', 'Demo');
     $customFieldData = CustomFieldData::getByName('ReportTestDropDown');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('Multi 1', 'Multi 2', 'Multi 3');
     $customFieldData = CustomFieldData::getByName('ReportTestMultiDropDown');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('Radio 1', 'Radio 2', 'Radio 3');
     $customFieldData = CustomFieldData::getByName('ReportTestRadioDropDown');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('Cloud 1', 'Cloud 2', 'Cloud 3');
     $customFieldData = CustomFieldData::getByName('ReportTestTagCloud');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     assert($saved);
     // Not Coding Standard
 }
 public static function makeDropDownAttributeUsingAdapter($namePrefix, $valuesPrefix, RedBeanModel $modelTouse)
 {
     $values = array($valuesPrefix . '1', $valuesPrefix . '2', $valuesPrefix . '3', $valuesPrefix . '4');
     $labels = array('fr' => array($valuesPrefix . '1 fr', $valuesPrefix . '1 fr', $valuesPrefix . '1 fr', $valuesPrefix . '1 fr'), 'de' => array($valuesPrefix . '1 de', $valuesPrefix . '1 de', $valuesPrefix . '1 de', $valuesPrefix . '1 de'));
     $airplanesFieldData = CustomFieldData::getByName($namePrefix . 'TheData');
     $airplanesFieldData->serializedData = serialize($values);
     $saved = $airplanesFieldData->save();
     if (!$saved) {
         throw new NotSupportedException();
     }
     $attributeForm = new DropDownAttributeForm();
     $attributeForm->attributeName = $namePrefix;
     $attributeForm->attributeLabels = array('de' => $namePrefix . ' de', 'en' => $namePrefix . ' en', 'es' => $namePrefix . ' es', 'fr' => $namePrefix . ' fr', 'it' => $namePrefix . ' it');
     $attributeForm->isAudited = false;
     $attributeForm->isRequired = false;
     $attributeForm->defaultValueOrder = null;
     $attributeForm->customFieldDataData = $values;
     $attributeForm->customFieldDataName = $namePrefix . 'TheData';
     $attributeForm->customFieldDataLabels = $labels;
     $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
     $adapter = new $modelAttributesAdapterClassName($modelTouse);
     try {
         $adapter->setAttributeMetadataFromForm($attributeForm);
     } catch (FailedDatabaseSchemaChangeException $e) {
         echo $e->getMessage();
         throw new NotSupportedException();
     }
 }
 public function testGetExportValue()
 {
     $values = array('Test1', 'Test2', 'Test3', 'Sample', 'Demo');
     $customFieldData = CustomFieldData::getByName('ExportTestRadioDropDown');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     $this->assertTrue($saved);
     $data = array();
     $model = new ExportTestModelItem();
     $model->radioDropDown->value = $values[1];
     $model->lastName = "Smith";
     $model->string = "Some Test String";
     // We have to save model, to get correct currencyValue id.
     $this->assertTrue($model->save());
     $adapter = new RadioDropDownRedBeanModelAttributeValueToExportValueAdapter($model, 'radioDropDown');
     $adapter->resolveData($data);
     $compareData = array('Test2');
     $this->assertEquals($compareData, $data);
     $data = array();
     $adapter->resolveHeaderData($data);
     $compareData = array($model->getAttributeLabel('radioDropDown'));
     $this->assertEquals($compareData, $data);
     $data = array();
     $model = new ExportTestModelItem();
     $adapter = new RadioDropDownRedBeanModelAttributeValueToExportValueAdapter($model, 'radioDropDown');
     $adapter->resolveData($data);
     $compareData = array('');
     $this->assertEquals($compareData, $data);
     $data = array();
     $adapter->resolveHeaderData($data);
     $compareData = array($model->getAttributeLabel('radioDropDown'));
     $this->assertEquals($compareData, $data);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $super = User::getByUsername('super');
     $bobby = UserTestHelper::createBasicUser('bobby');
     $sarah = UserTestHelper::createBasicUser('sarah');
     self::$superUserId = $super->id;
     self::$bobbyUserId = $bobby->id;
     self::$sarahUserId = $sarah->id;
     $currency = Currency::makeBaseCurrency();
     assert($currency->code == 'USD');
     // Not Coding Standard
     self::$baseCurrencyId = $currency->id;
     $currency = new Currency();
     $currency->code = 'EUR';
     $currency->rateToBase = 2;
     assert($currency->save());
     // Not Coding Standard
     self::$eurCurrencyId = $currency->id;
     $values = array('A1', 'B2', 'C3', 'D4', 'E5', 'F6');
     $fieldData = CustomFieldData::getByName('WorkflowTestDropDown');
     $fieldData->serializedData = serialize($values);
     $saved = $fieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('A1', 'B2', 'C3', 'D4', 'E5', 'F6');
     $fieldData = CustomFieldData::getByName('WorkflowTestRadioDropDown');
     $fieldData->serializedData = serialize($values);
     $saved = $fieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('M1', 'M2', 'M3', 'M4', 'M5', 'M6');
     $fieldData = CustomFieldData::getByName('WorkflowTestMultiDropDown');
     $fieldData->serializedData = serialize($values);
     $saved = $fieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('M1', 'M2', 'M3', 'M4', 'M5', 'M6');
     $fieldData = CustomFieldData::getByName('WorkflowTestTagCloud');
     $fieldData->serializedData = serialize($values);
     $saved = $fieldData->save();
     assert($saved);
     // Not Coding Standard
     $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];
     self::$groupTest = new Group();
     self::$groupTest->name = 'test';
     $saved = self::$groupTest->save();
     assert($saved);
     // Not Coding Standard
     $group = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $saved = $group->save();
     assert($saved);
     // Not Coding Standard
 }
 /**
  * Gets array for stages
  * @return array
  */
 protected function getStageDropDownArray()
 {
     $customFieldData = CustomFieldData::getByName('ProductStages');
     $customFieldIndexedData = CustomFieldDataUtil::getDataIndexedByDataAndTranslatedLabelsByLanguage($customFieldData, Yii::app()->language);
     $data = array_merge(array(ProductsConfigurationForm::FILTERED_BY_ALL_STAGES => Zurmo::t('Core', 'All')), $customFieldIndexedData);
     return $data;
 }
 /**
  * There previously was a problem with a model being created, then a new custom field added, then if you try
  * to access the available CustomFieldData it was not available on that model.  Since performance3 work
  * this has been resolve and this test confirms it works ok
  */
 public function testConstructIncompleteIsNotNeeded()
 {
     //First create AAA model and save
     $aaa = new AAA();
     $aaa->aaaMember = 'test';
     $saved = $aaa->save();
     $this->assertTrue($saved);
     $aaaId = $aaa->id;
     $aaa->forget();
     unset($aaa);
     //Second create customFieldData
     $values = array('Item 1', 'Item 2', 'Item 3');
     $labels = array('fr' => 'Item 1 fr', 'fr' => 'Item 2 fr', 'fr' => 'Item 3 fr');
     $customFieldData = CustomFieldData::getByName('Items');
     $customFieldData->serializedData = serialize($values);
     $customFieldData->serializedLabels = serialize($labels);
     $this->assertTrue($customFieldData->save());
     $id = $customFieldData->id;
     unset($customFieldData);
     //Third create a CustomField on AAA
     $metadata = AAA::getMetadata();
     $metadata['AAA']['customFields']['newCustomField'] = 'Items';
     $metadata['AAA']['relations']['newCustomField'] = array(RedBeanModel::HAS_ONE, 'CustomField');
     AAA::setMetadata($metadata);
     //Fourth make sure AAA can utilize CustomFieldData after being constructed
     $aaa = AAA::GetById($aaaId);
     $this->assertTrue($aaa->isAnAttribute('newCustomField'));
     $dropDownArray = unserialize($aaa->newCustomField->data->serializedData);
     $this->assertCount(3, $dropDownArray);
     //Fifth make sure a new model has the data available
     $aaa = new AAA();
     $this->assertTrue($aaa->isAnAttribute('newCustomField'));
     $dropDownArray = unserialize($aaa->newCustomField->data->serializedData);
     $this->assertCount(3, $dropDownArray);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $super = SecurityTestHelper::createSuperAdmin();
     Yii::app()->user->userModel = $super;
     $jim = UserTestHelper::createBasicUser('jim');
     $values = array('Test1', 'Test2', 'Test3', 'Sample', 'Demo');
     $customFieldData = CustomFieldData::getByName('ImportTestDropDown');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('Multi 1', 'Multi 2', 'Multi 3');
     $customFieldData = CustomFieldData::getByName('ImportTestMultiDropDown');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('Cloud 1', 'Cloud 2', 'Cloud 3');
     $customFieldData = CustomFieldData::getByName('ImportTestTagCloud');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     assert($saved);
     // Not Coding Standard
     //Ensure the external system id column is present.
     $userTableName = User::getTableName();
     ExternalSystemIdUtil::addExternalIdColumnIfMissing($userTableName);
     ExternalSystemIdUtil::updateByModel($super, 'A');
     ExternalSystemIdUtil::updateByModel($jim, 'B');
     ExternalSystemIdUtil::addExternalIdColumnIfMissing(ImportModelTestItem::getTableName());
     ExternalSystemIdUtil::addExternalIdColumnIfMissing(ImportModelTestItem2::getTableName());
     ExternalSystemIdUtil::addExternalIdColumnIfMissing(ImportModelTestItem3::getTableName());
     ExternalSystemIdUtil::addExternalIdColumnIfMissing(ImportModelTestItem4::getTableName());
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $super = SecurityTestHelper::createSuperAdmin();
     Yii::app()->user->userModel = $super;
     $jim = UserTestHelper::createBasicUser('jim');
     $values = array('Test1', 'Test2', 'Test3', 'Sample', 'Demo');
     $customFieldData = CustomFieldData::getByName('ImportTestDropDown');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('Multi 1', 'Multi 2', 'Multi 3');
     $customFieldData = CustomFieldData::getByName('ImportTestMultiDropDown');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('Cloud 1', 'Cloud 2', 'Cloud 3');
     $customFieldData = CustomFieldData::getByName('ImportTestTagCloud');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     assert($saved);
     // Not Coding Standard
     //Ensure the external system id column is present.
     $columnName = ExternalSystemIdUtil::EXTERNAL_SYSTEM_ID_COLUMN_NAME;
     RedBeanColumnTypeOptimizer::externalIdColumn(User::getTableName('User'), $columnName);
     $userTableName = User::getTableName('User');
     R::exec("update " . $userTableName . " set {$columnName} = 'A' where id = {$super->id}");
     R::exec("update " . $userTableName . " set {$columnName} = 'B' where id = {$jim->id}");
     RedBeanColumnTypeOptimizer::externalIdColumn(ImportModelTestItem::getTableName('ImportModelTestItem'), $columnName);
     RedBeanColumnTypeOptimizer::externalIdColumn(ImportModelTestItem2::getTableName('ImportModelTestItem2'), $columnName);
     RedBeanColumnTypeOptimizer::externalIdColumn(ImportModelTestItem3::getTableName('ImportModelTestItem3'), $columnName);
     RedBeanColumnTypeOptimizer::externalIdColumn(ImportModelTestItem4::getTableName('ImportModelTestItem4'), $columnName);
 }
 /**
  * Resolve stage default value
  * @param RedBeanModel $product
  * @return string
  */
 public function resolveStageDefaultValue($product)
 {
     $customFieldData = CustomFieldData::getByName('ProductStages');
     $dropDownArray = unserialize($customFieldData->serializedData);
     if ($product->stage->value == null) {
         $product->stage->value = $dropDownArray[0];
     }
 }
 public static function getTypeValues()
 {
     $values = array('Prospect', 'Customer', 'Vendor');
     $typeFieldData = CustomFieldData::getByName('AccountTypes');
     $typeFieldData->serializedData = serialize($values);
     assert($typeFieldData->save());
     // Not Coding Standard
     return $values;
 }
 public static function createCategories()
 {
     $values = array('Meeting', 'Call', 'Event');
     $typeFieldData = CustomFieldData::getByName('MeetingCategories');
     $typeFieldData->serializedData = serialize($values);
     $saved = $typeFieldData->save();
     if (!$saved) {
         throw new NotSupportedException();
     }
 }
Beispiel #16
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $values = array('Automotive', 'Adult Entertainment', 'Financial Services', 'Mercenaries & Armaments');
     $industryFieldData = CustomFieldData::getByName('Industries');
     $industryFieldData->defaultValue = $values[1];
     $industryFieldData->serializedData = serialize($values);
     if (!$industryFieldData->save()) {
         throw new FailedToSaveRedBeanModelException();
     }
 }
Beispiel #17
0
 protected static function makeCustomFieldDataByValuesAndDefault($name, $values, $defaultValue = null)
 {
     assert('is_string($name)');
     assert('is_array($values)');
     assert('is_string($defaultValue) || $defaultValue == null');
     $fieldData = CustomFieldData::getByName($name);
     $fieldData->serializedData = serialize($values);
     $fieldData->defaultValue = $defaultValue;
     $saved = $fieldData->save();
     assert('$saved');
 }
 /**
  * @return array of values.
  */
 public static function createCustomFieldData($name)
 {
     $customFieldData = CustomFieldData::getByName($name);
     assert('count(unserialize($customFieldData->serializedData)) == 0');
     $values = array($name . '1', $name . '2', $name . '3', $name . '4', $name . '5');
     $customFieldData->defaultValue = null;
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     assert('$saved');
     return $values;
 }
Beispiel #19
0
 public static function createProductStagesIfDoesNotExist()
 {
     $salesStagesFieldData = CustomFieldData::getByName('ProductStages');
     $stageValues = array('Open', 'Lost', 'Won');
     if (count(unserialize($salesStagesFieldData->serializedData)) == 0) {
         $salesStagesFieldData = CustomFieldData::getByName('ProductStages');
         $salesStagesFieldData->defaultValue = $stageValues[0];
         $salesStagesFieldData->serializedData = serialize($stageValues);
         $saved = $salesStagesFieldData->save();
         assert('$saved');
     }
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     ContactsModule::loadStartingData();
     $values = array('AAA', 'BBB', 'CCC');
     $typeFieldData = CustomFieldData::getByName('AccountContactAffiliationRoles');
     $typeFieldData->serializedData = serialize($values);
     if (!$typeFieldData->save()) {
         throw new FailedToSaveModelException();
     }
 }
Beispiel #21
0
 public function testSetTitleValuesAndRetrieveTitleValuesFromUser()
 {
     $titles = array('Mr.', 'Mrs.', 'Ms.', 'Dr.', 'Swami');
     $customFieldData = CustomFieldData::getByName('Titles');
     $customFieldData->serializedData = serialize($titles);
     $this->assertTrue($customFieldData->save());
     $dropDownArray = unserialize($customFieldData->serializedData);
     $this->assertEquals($titles, $dropDownArray);
     $user = new User();
     $dropDownModel = $user->title;
     $dropDownArray = unserialize($dropDownModel->data->serializedData);
     $this->assertEquals($titles, $dropDownArray);
 }
Beispiel #22
0
 /**
  * Given a name, get the custom field data model.  Attempts to retrieve from cache, if it is not available,
  * will attempt to retrieve from persistent storage, cache the model, and return.
  * @param string $name
  */
 public static function getByName($name)
 {
     try {
         return GeneralCache::getEntry('CustomFieldData' . $name);
     } catch (NotFoundException $e) {
         assert('is_string($name)');
         assert('$name != ""');
         $bean = R::findOne('customfielddata', "name = '{$name}'");
         assert('$bean === false || $bean instanceof RedBean_OODBBean');
         if ($bean === false) {
             $customFieldData = new CustomFieldData();
             $customFieldData->name = $name;
             $customFieldData->serializedData = serialize(array());
             // An unused custom field data does not present as needing saving.
             $customFieldData->setNotModified();
             return $customFieldData;
         }
         $model = self::makeModel($bean);
         GeneralCache::cacheEntry('CustomFieldData' . $name, $model);
         return $model;
     }
 }
 /**
  * Given a model class name and an attribute name, get the CustomFieldData object associated with this
  * attribute.  Requires the attribute to be a customField type attribute otherwise it will throw an error.
  * @param string $modelClassName
  * @param string $attributeName
  */
 public static function getDataByModelClassNameAndAttributeName($modelClassName, $attributeName)
 {
     $metadata = $modelClassName::getMetadata();
     foreach ($metadata as $unused => $classMetadata) {
         if (isset($classMetadata['customFields'])) {
             foreach ($classMetadata['customFields'] as $customFieldName => $customFieldDataName) {
                 if ($attributeName == $customFieldName) {
                     return CustomFieldData::getByName($customFieldDataName);
                 }
             }
         }
     }
     throw new NotSupportedException();
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $multiSelectValues = array('Multi 1', 'Multi 2', 'Multi 3');
     $customFieldData = CustomFieldData::getByName('ApiTestMultiDropDown');
     $customFieldData->serializedData = serialize($multiSelectValues);
     $save = $customFieldData->save();
     assert('$save');
     // Not Coding Standard
     $tagCloudValues = array('Cloud 1', 'Cloud 2', 'Cloud 3');
     $customFieldData = CustomFieldData::getByName('ApiTestTagCloud');
     $customFieldData->serializedData = serialize($tagCloudValues);
     $save = $customFieldData->save();
     assert('$save');
     // Not Coding Standard
 }
Beispiel #25
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     global $freeze;
     RedBeanDatabase::setup(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password);
     assert('RedBeanDatabase::isSetup()');
     // Not Coding Standard
     if ($freeze) {
         $schemaFile = sys_get_temp_dir() . '/autobuilt.sql';
         $success = preg_match("/;dbname=([^;]+)/", Yii::app()->db->connectionString, $matches);
         // Not Coding Standard
         assert('$success == 1');
         // Not Coding Standard
         $databaseName = $matches[1];
         if (is_readable($schemaFile) && filesize($schemaFile) > 0) {
             $systemOutput = system('mysql -u' . Yii::app()->db->username . ' -p' . Yii::app()->db->password . ' ' . $databaseName . " < {$schemaFile}");
             if ($systemOutput != null) {
                 echo 'Loading schema using system command. Output: ' . $systemOutput . "\n\n";
             }
         } else {
             echo "The schema file is not readable: {$schemaFile}. \n\n";
             exit;
         }
     }
     CustomFieldData::forgetAllPhpCache();
     GeneralCache::forgetAll();
     BeanModelCache::forgetAll();
     if ($freeze) {
         RedBeanDatabase::freeze();
         TestDatabaseUtil::deleteRowsFromAllTablesExceptLog();
     } else {
         TestDatabaseUtil::deleteAllTablesExceptLog();
     }
     Yii::app()->user->userModel = null;
     Yii::app()->user->clearStates();
     //reset session.
     Yii::app()->language = Yii::app()->getConfigLanguageValue();
     Yii::app()->timeZoneHelper->setTimeZone(Yii::app()->getConfigTimeZoneValue());
     Yii::app()->timeZoneHelper->load();
     //resets timezone
     Yii::app()->languageHelper->flushModuleLabelTranslationParameters();
     if (static::$activateDefaultLanguages) {
         Yii::app()->languageHelper->load();
         Yii::app()->languageHelper->activateLanguagesForTesting();
         Yii::app()->languageHelper->importMessagesForTesting();
     }
 }
 /**
  * @depends testApiServerUrl
  */
 public function testGetCustomFieldData()
 {
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     //Fill some data
     $values = array('Prospect', 'Customer', 'Vendor');
     $typeFieldData = CustomFieldData::getByName('AccountTypes');
     $typeFieldData->serializedData = serialize($values);
     $this->assertTrue($typeFieldData->save());
     CustomFieldData::forgetAll();
     $customFieldData = CustomFieldData::getByName('AccountTypes');
     $compareData = CustomFieldDataUtil::getDataIndexedByDataAndTranslatedLabelsByLanguage($customFieldData, 'en');
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/zurmo/customField/api/read/AccountTypes', 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals($compareData, $response['data']);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $values = array('A', 'B', 'C', 'CC', 'CCC');
     $customFieldData = CustomFieldData::getByName('MultipleIndustries');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('D', 'E', 'F', 'FF', 'FFF');
     $customFieldData = CustomFieldData::getByName('MultipleSomethings');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     assert($saved);
     // Not Coding Standard
 }
 protected function processRead($id)
 {
     assert('is_string($id)');
     try {
         $customFieldData = CustomFieldData::getByName($id);
     } catch (NotFoundException $e) {
         $message = Zurmo::t('ZurmoModule', 'Specified custom field name was invalid.');
         throw new ApiException($message);
     }
     $customFieldData = CustomFieldDataUtil::getDataIndexedByDataAndTranslatedLabelsByLanguage($customFieldData, Yii::app()->language);
     try {
         $result = new ApiResult(ApiResponse::STATUS_SUCCESS, $customFieldData, null, null);
     } catch (Exception $e) {
         $message = $e->getMessage();
         throw new ApiException($message);
     }
     return $result;
 }
 public function testGetSetAndMethods()
 {
     $availableCustomFieldAttributes = array('a', 'test', 'b');
     $mappingData = array('Item 1' => 'parentItem1', 'Item2' => null);
     $customFieldData = CustomFieldData::getByName('Items');
     $mapping = new DropDownDependencyCustomFieldMapping(3, 'test', $availableCustomFieldAttributes, $customFieldData, $mappingData);
     $this->assertEquals(true, $mapping->allowsAttributeSelection());
     $mapping->doNotAllowAttributeSelection();
     $this->assertEquals(false, $mapping->allowsAttributeSelection());
     $this->assertEquals('Level: 4', $mapping->getTitle());
     $this->assertEquals(3, $mapping->getPosition());
     $this->assertEquals('test', $mapping->getAttributeName());
     $this->assertEquals($availableCustomFieldAttributes, $mapping->getAvailableCustomFieldAttributes());
     $this->assertEquals('First select level 3', $mapping->getSelectHigherLevelFirstMessage());
     $this->assertEquals($customFieldData, $mapping->getCustomFieldData());
     $this->assertEquals('parentItem1', $mapping->getMappingDataSelectedParentValueByValue('Item 1'));
     $this->assertEquals(null, $mapping->getMappingDataSelectedParentValueByValue('Item 2'));
 }
 public function testGetCustomFieldDataByPartialName()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $values = array('Automotive', 'Adult Entertainment', 'Financial Services', 'Mercenaries & Armaments', 'autam');
     $industryFieldData = CustomFieldData::getByName('testData');
     $industryFieldData->defaultValue = $values[0];
     $industryFieldData->serializedData = serialize($values);
     $this->assertTrue($industryFieldData->save());
     $results = ModelAutoCompleteUtil::getCustomFieldDataByPartialName('testData', 'a');
     $this->assertEquals(3, count($results));
     $results = ModelAutoCompleteUtil::getCustomFieldDataByPartialName('testData', 'Au');
     $this->assertEquals(2, count($results));
     $results = ModelAutoCompleteUtil::getCustomFieldDataByPartialName('testData', 'Mer');
     $this->assertEquals(1, count($results));
     $results = ModelAutoCompleteUtil::getCustomFieldDataByPartialName('testData', 'sat');
     $this->assertEquals(0, count($results));
     $results = ModelAutoCompleteUtil::getCustomFieldDataByPartialName('testData', 'Aux');
     $this->assertEquals(0, count($results));
 }