public function validateDynamicClauses($attribute, $params)
 {
     if ($this->{$attribute} != null) {
         foreach ($this->{$attribute} as $key => $rowData) {
             $structurePosition = $rowData['structurePosition'];
             if ($rowData['attributeIndexOrDerivedType'] == null) {
                 $this->addError('dynamicClauses', Zurmo::t('Core', 'You must select a field for row {rowNumber}', array('{rowNumber}' => $structurePosition)));
             } else {
                 unset($rowData['attributeIndexOrDerivedType']);
                 unset($rowData['structurePosition']);
                 $dynamicStructure = '';
                 $metadataAdapter = new DynamicSearchDataProviderMetadataAdapter(array('clauses' => array(), 'structure' => ''), $this, Yii::app()->user->userModel->id, array($rowData), $dynamicStructure);
                 $metadata = $metadataAdapter->getAdaptedDataProviderMetadata();
                 if (count($metadata['clauses']) == 0) {
                     $this->addError('dynamicClauses', Zurmo::t('Core', 'You must select a value for row {rowNumber}', array('{rowNumber}' => $structurePosition)));
                 }
             }
         }
     }
 }
 public function testSearchCurrencyValueWithPassingCurrencyidAndANullValue()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $searchAttributes = array(array('structurePosition' => '1', 'attributeIndexOrDerivedType' => 'amount', 'amount' => array('relatedData' => true, 'currency' => array('id' => '1'), 'value' => null)));
     $searchForm = new CurrencyValueTestItemSavedDynamicSearchFormTestModel(new CurrencyValueTestItem());
     $searchForm->dynamicClauses = $searchAttributes;
     $searchForm->dynamicStructure = '1';
     $searchForm->validateDynamicClauses('dynamicClauses', array());
     $this->assertFalse($searchForm->hasErrors());
     $searchForm->clearErrors();
     $dynamicStructure = '1';
     $metadata = array('clauses' => array(), 'structure' => '');
     $metadataAdapter = new DynamicSearchDataProviderMetadataAdapter($metadata, new CurrencyValueTestItemSavedDynamicSearchFormTestModel(new CurrencyValueTestItem(false)), (int) Yii::app()->user->userModel->id, $searchAttributes, $dynamicStructure);
     $metadata = $metadataAdapter->getAdaptedDataProviderMetadata();
     $compareClauses = array(1 => array('attributeName' => 'amount', 'relatedModelData' => array('attributeName' => 'currency', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => '1')));
     $compareStructure = '(1)';
     $this->assertEquals($compareClauses, $metadata['clauses']);
     $this->assertEquals($compareStructure, $metadata['structure']);
 }
示例#3
0
 protected static function resolveDynamicSearchMetadata($searchModel, $metadata, SearchAttributesDataCollection $dataCollection)
 {
     $sanitizedDynamicSearchAttributes = $dataCollection->getSanitizedDynamicSearchAttributes();
     if ($sanitizedDynamicSearchAttributes == null) {
         return $metadata;
     }
     $dynamicStructure = $dataCollection->getDynamicStructure();
     if ($sanitizedDynamicSearchAttributes != null) {
         $dynamicSearchMetadataAdapter = new DynamicSearchDataProviderMetadataAdapter($metadata, $searchModel, Yii::app()->user->userModel->id, $sanitizedDynamicSearchAttributes, $dynamicStructure);
         $metadata = $dynamicSearchMetadataAdapter->getAdaptedDataProviderMetadata();
     }
     return $metadata;
 }
 public function testGetAdaptedDataProviderMetadataForAttributesMappedToRealAttributesMetadata()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $sanitizedDynamicSearchAttributes = array(array('IIIName' => 'IL', 'structurePosition' => 1), array('IIIName' => 'CA', 'structurePosition' => 2));
     $dynamicStructure = '1 OR 2';
     $metadata = array('clauses' => array(), 'structure' => '');
     $metadataAdapter = new DynamicSearchDataProviderMetadataAdapter($metadata, new IIISearchFormTestModel(new III(false)), (int) Yii::app()->user->userModel->id, $sanitizedDynamicSearchAttributes, $dynamicStructure);
     $metadata = $metadataAdapter->getAdaptedDataProviderMetadata();
     $compareClauses = array(1 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'IL'), 2 => array('attributeName' => 'iiiMember2', 'operatorType' => 'startsWith', 'value' => 'IL'), 3 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'CA'), 4 => array('attributeName' => 'iiiMember2', 'operatorType' => 'startsWith', 'value' => 'CA'));
     $compareStructure = '((1 or 2) or (3 or 4))';
     $this->assertEquals($compareClauses, $metadata['clauses']);
     $this->assertEquals($compareStructure, $metadata['structure']);
 }
 /**
  * @depends testMixedClauseCountsOverTenAndDoTheClausesProperlyTranslateCorrectlyToQuery
  */
 public function testMoreThanTenClausesProperlyTranslateCorrectlyToQuery()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $sanitizedDynamicSearchAttributes = array(0 => array('iiiMember' => 'someThing1', 'attributeIndexOrDerivedType' => 'iiiMember', 'structurePosition' => '1'), 1 => array('iiiMember' => 'someThing2', 'attributeIndexOrDerivedType' => 'iiiMember', 'structurePosition' => '2'), 2 => array('iiiMember' => 'someThing3', 'attributeIndexOrDerivedType' => 'iiiMember', 'structurePosition' => '3'), 3 => array('iiiMember' => 'someThing4', 'attributeIndexOrDerivedType' => 'iiiMember', 'structurePosition' => '4'), 4 => array('iiiMember' => 'someThing5', 'attributeIndexOrDerivedType' => 'iiiMember', 'structurePosition' => '5'), 5 => array('iiiMember' => 'someThing6', 'attributeIndexOrDerivedType' => 'iiiMember', 'structurePosition' => '6'), 6 => array('iiiMember' => 'someThing7', 'attributeIndexOrDerivedType' => 'iiiMember', 'structurePosition' => '7'), 7 => array('iiiMember' => 'someThing8', 'attributeIndexOrDerivedType' => 'iiiMember', 'structurePosition' => '8'), 8 => array('iiiMember' => 'someThing9', 'attributeIndexOrDerivedType' => 'iiiMember', 'structurePosition' => '9'), 9 => array('iiiMember' => 'someThing10', 'attributeIndexOrDerivedType' => 'iiiMember', 'structurePosition' => '10'), 10 => array('iiiMember' => 'someThing11', 'attributeIndexOrDerivedType' => 'iiiMember', 'structurePosition' => '11'), 11 => array('iiiMember' => 'someThing12', 'attributeIndexOrDerivedType' => 'iiiMember', 'structurePosition' => '12'), 12 => array('iiiMember' => 'someThing13', 'attributeIndexOrDerivedType' => 'iiiMember', 'structurePosition' => '13'));
     $dynamicStructure = '(1 and 2 and 3 and 4 and 5 and 6 and 7 and 8 and 9 and 10 and 11 and 12 and 13)';
     $metadata = array('clauses' => array(), 'structure' => '');
     $metadataAdapter = new DynamicSearchDataProviderMetadataAdapter($metadata, new IIISearchFormTestModel(new III(false)), (int) Yii::app()->user->userModel->id, $sanitizedDynamicSearchAttributes, $dynamicStructure);
     $metadata = $metadataAdapter->getAdaptedDataProviderMetadata();
     $compareClauses = array(1 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'someThing1'), 2 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'someThing2'), 3 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'someThing3'), 4 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'someThing4'), 5 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'someThing5'), 6 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'someThing6'), 7 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'someThing7'), 8 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'someThing8'), 9 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'someThing9'), 10 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'someThing10'), 11 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'someThing11'), 12 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'someThing12'), 13 => array('attributeName' => 'iiiMember', 'operatorType' => 'startsWith', 'value' => 'someThing13'));
     $compareStructure = '((1 and 2 and 3 and 4 and 5 and 6 and 7 and 8 and 9 and 10 and 11 and 12 and 13))';
     $this->assertEquals($compareClauses, $metadata['clauses']);
     $this->assertEquals($compareStructure, $metadata['structure']);
 }