/**
  * Override to properly handle retrieving rule information from the model for the attribute name.
  * Will also pull required rules if the scenario calls for it.
  */
 public function rules()
 {
     if ($this->getScenario() == 'extraColumn') {
         $requiredRuleIsApplicable = true;
     } else {
         $requiredRuleIsApplicable = false;
     }
     $defaultValueApplicableModelAttributeRules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName($this->modelClassName, $this->modelAttributeName, static::getAttributeName(), $requiredRuleIsApplicable);
     return array_merge(parent::rules(), $defaultValueApplicableModelAttributeRules);
 }
 /**
  * Override to add an extra rule for the defaultModelStringifiedName. This will ensure if there is an error
  * the message shows up properly in the user interface, since otherwise with the rule being on the
  * defaultModelId, it would not show up because it is a hidden input.
  * @see DefaultModelAttributeMappingRuleForm::rules()
  */
 public function rules()
 {
     if ($this->getScenario() == 'extraColumn') {
         $requiredRuleIsApplicable = true;
     } else {
         $requiredRuleIsApplicable = false;
     }
     $defaultValueApplicableModelAttributeRules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName($this->modelClassName, $this->modelAttributeName, 'defaultModelStringifiedName', $requiredRuleIsApplicable);
     $rules = $defaultValueApplicableModelAttributeRules;
     if (empty($rules)) {
         return array(array('defaultModelStringifiedName, defaultModelId', 'safe'));
     }
     return $rules;
 }
 public function rules()
 {
     if ($this->getScenario() == 'extraColumn') {
         $requiredRuleIsApplicable = true;
     } else {
         $requiredRuleIsApplicable = false;
     }
     $defaultValueApplicableModelAttributeRules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName($this->modelClassName, 'hash', static::getAttributeName(), $requiredRuleIsApplicable);
     //Remove the has length rule
     foreach ($defaultValueApplicableModelAttributeRules as $index => $rule) {
         if ($rule[1] == 'length') {
             unset($defaultValueApplicableModelAttributeRules[$index]);
         }
     }
     return array_merge(parent::rules(), $defaultValueApplicableModelAttributeRules);
 }
 public function testGetFilterRulesByAttribute()
 {
     $model = new ReportModelTestItem();
     $rules = new ReportsTestReportRules();
     $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, Report::TYPE_ROWS_AND_COLUMNS);
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'string', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('string', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'boolean', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('boolean', 'value'));
     $exptected = array(array('value', 'type', 'type' => 'float'));
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('currencyValue', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'date', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('date', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'dateTime', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('dateTime', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'dropDown', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('dropDown', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'float', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('float', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'integer', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('integer', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'multiDropDown', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('multiDropDown', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'owner', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('owner', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'phone', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('phone', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'radioDropDown', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('radioDropDown', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'tagCloud', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('tagCloud', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'textArea', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('textArea', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'url', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('url', 'value'));
     $exptected = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($model), 'likeContactState', 'value', false, true, false);
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('likeContactState', 'value'));
     $model = new ReportModelTestItem12();
     $rules = new ReportsTestReportRules();
     $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, Report::TYPE_ROWS_AND_COLUMNS);
     $exptected = array(array('value', 'type', 'type' => 'string'));
     $this->assertEquals($exptected, $adapter->getFilterRulesByAttribute('emailAddress', 'value'));
 }
 public function testGetApplicableRulesByModelClassNameAndAttributeNameForCustomCreatedTypes()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $import->serializedData = serialize(array('importRulesType' => 'Accounts'));
     $this->assertTrue($import->save());
     ModulesSearchWithDataProviderTestHelper::createDateAttribute(new Account(), 'date');
     ModulesSearchWithDataProviderTestHelper::createDateTimeAttribute(new Account(), 'dateTime');
     ModulesSearchWithDataProviderTestHelper::createCheckBoxAttribute(new Account(), 'checkbox');
     ModulesSearchWithDataProviderTestHelper::createDecimalAttribute(new Account(), 'decimal');
     ModulesSearchWithDataProviderTestHelper::createIntegerAttribute(new Account(), 'integer');
     ModulesSearchWithDataProviderTestHelper::createPhoneAttribute(new Account(), 'phone');
     ModulesSearchWithDataProviderTestHelper::createTextAttribute(new Account(), 'text');
     ModulesSearchWithDataProviderTestHelper::createTextAreaAttribute(new Account(), 'textArea');
     ModulesSearchWithDataProviderTestHelper::createUrlAttribute(new Account(), 'url');
     //Test All custom created types since their rules could vary
     $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'dateCstm', 'defaultValue');
     $compareData = array(array('defaultValue', 'TypeValidator', 'type' => 'date'));
     $this->assertEquals($compareData, $rules);
     $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'dateTimeCstm', 'defaultValue');
     $compareData = array(array('defaultValue', 'TypeValidator', 'type' => 'datetime'));
     $this->assertEquals($compareData, $rules);
     $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'checkboxCstm', 'defaultValue');
     $compareData = array(array('defaultValue', 'boolean'));
     $this->assertEquals($compareData, $rules);
     $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'decimalCstm', 'defaultValue');
     $compareData = array(array('defaultValue', 'length', 'max' => 6), array('defaultValue', 'RedBeanModelNumberValidator', 'precision' => 2), array('defaultValue', 'type', 'type' => 'float'));
     $this->assertEquals($compareData, $rules);
     $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'integerCstm', 'defaultValue');
     $compareData = array(array('defaultValue', 'length', 'max' => 11), array('defaultValue', 'numerical', 'min' => -500000, 'max' => 500000), array('defaultValue', 'type', 'type' => 'integer'));
     $this->assertEquals($compareData, $rules);
     $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'phoneCstm', 'defaultValue');
     $compareData = array(array('defaultValue', 'length', 'max' => 20), array('defaultValue', 'type', 'type' => 'string'));
     $this->assertEquals($compareData, $rules);
     $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'textCstm', 'defaultValue');
     $compareData = array(array('defaultValue', 'length', 'max' => 50), array('defaultValue', 'type', 'type' => 'string'));
     $this->assertEquals($compareData, $rules);
     $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'textAreaCstm', 'defaultValue');
     $compareData = array(array('defaultValue', 'type', 'type' => 'string'));
     $this->assertEquals($compareData, $rules);
     $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'urlCstm', 'defaultValue');
     $compareData = array(array('defaultValue', 'length', 'max' => 50), array('defaultValue', 'url', 'defaultScheme' => 'http'));
     $this->assertEquals($compareData, $rules);
     //todo: add the rest of the custom field types that are importable
 }
 /**
  * @param string $attribute
  * @param string $ruleAttributeName
  * @return array
  */
 public function getTriggerRulesByAttribute($attribute, $ruleAttributeName)
 {
     assert('is_string($attribute)');
     assert('is_string($ruleAttributeName)');
     $rules = array();
     $dynamicallyDerivedAttributes = $this->getDynamicallyDerivedAttributesData();
     if ($this->model->isAttribute($attribute) && $this->model->{$attribute} instanceof CurrencyValue) {
         $rules[] = array($ruleAttributeName, 'type', 'type' => 'float');
     } elseif (in_array($attribute, $dynamicallyDerivedAttributes)) {
         $rules[] = array($ruleAttributeName, 'type' => 'string');
     } elseif ($this->model->isAttribute($attribute)) {
         $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName(get_class($this->model), $attribute, $ruleAttributeName, false, true, false);
     }
     return $rules;
 }