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']);
 }
 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']);
 }
 /**
  * @returns 6 digit alpha code that can be swapped later for the proper structure.
  * @param Integer $integer
  */
 protected static function getAlphaCodeByInteger($integer)
 {
     assert('is_int($integer)');
     $alphaCode = DynamicSearchDataProviderMetadataAdapter::numberToLetter($integer);
     return str_pad($alphaCode, 6, "z");
 }
예제 #5
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 testNumberToLetter()
 {
     $this->assertEquals('a', DynamicSearchDataProviderMetadataAdapter::numberToLetter(1));
     $this->assertEquals('b', DynamicSearchDataProviderMetadataAdapter::numberToLetter(2));
     $this->assertEquals('c', DynamicSearchDataProviderMetadataAdapter::numberToLetter(3));
     $this->assertEquals('d', DynamicSearchDataProviderMetadataAdapter::numberToLetter(4));
     $this->assertEquals('e', DynamicSearchDataProviderMetadataAdapter::numberToLetter(5));
     $this->assertEquals('o', DynamicSearchDataProviderMetadataAdapter::numberToLetter(15));
     $this->assertEquals('ss', DynamicSearchDataProviderMetadataAdapter::numberToLetter(45));
 }