コード例 #1
0
 public function getAttributes()
 {
     $attributes = array();
     $calculatedAttributes = CalculatedDerivedAttributeMetadata::getAllByModelClassName($this->modelClassName);
     foreach ($calculatedAttributes as $attribute) {
         ModelAttributeCollectionUtil::populateCollection($attributes, $attribute->name, $attribute->getLabelByLanguage(Yii::app()->language), DerivedAttributeToMixedTypeUtil::getType($this->modelClassName, $attribute->name));
     }
     $dropdownDependencyAttributes = DropDownDependencyDerivedAttributeMetadata::getAllByModelClassName($this->modelClassName);
     foreach ($dropdownDependencyAttributes as $attribute) {
         ModelAttributeCollectionUtil::populateCollection($attributes, $attribute->name, $attribute->getLabelByLanguage(Yii::app()->language), DerivedAttributeToMixedTypeUtil::getType($this->modelClassName, $attribute->name));
     }
     return $attributes;
 }
 /**
  * @return array|null
  */
 protected function getDerivedAttributesData()
 {
     if ($this->derivedAttributesData == null) {
         $attributes = array();
         $calculatedAttributes = CalculatedDerivedAttributeMetadata::getAllByModelClassName(get_class($this->model));
         foreach ($calculatedAttributes as $attribute) {
             $attributes[$attribute->name] = array('label' => $attribute->getLabelByLanguage(Yii::app()->language), 'derivedAttributeType' => 'CalculatedNumber');
         }
         $this->derivedAttributesData = array_merge($attributes, $this->rules->getDerivedAttributeTypesData($this->model));
     }
     return $this->derivedAttributesData;
 }
 /**
  * @depends testGetAllByModelClassName
  */
 public function testGetFormula()
 {
     $metadata = new CalculatedDerivedAttributeMetadata();
     $metadata->setScenario('nonAutoBuild');
     $metadata->name = 'someName3';
     $metadata->modelClassName = 'Whatever3';
     $metadata->serializedMetadata = serialize(array('stuff', 1, 'attributeLabels' => array(), 'formula' => 'test'));
     $saved = $metadata->save();
     $this->assertTrue($saved);
     $models = CalculatedDerivedAttributeMetadata::getAllByModelClassName('Whatever3');
     $this->assertEquals(1, count($models));
     $this->assertEquals('someName3', $models[0]->name);
     $this->assertEquals('test', $models[0]->getFormula());
 }
 /**
  * @return array|null
  */
 protected function getDerivedAttributesData()
 {
     if (!isset(self::$derivedAttributesData[get_class($this->model)]) || self::$derivedAttributesData[get_class($this->model)] === null) {
         $attributes = array();
         $calculatedAttributes = CalculatedDerivedAttributeMetadata::getAllByModelClassName(get_class($this->model));
         foreach ($calculatedAttributes as $attribute) {
             $attributes[$attribute->name] = array('label' => $attribute->getLabelByLanguage(Yii::app()->language), 'derivedAttributeType' => 'CalculatedNumber');
         }
         self::$derivedAttributesData[get_class($this->model)] = array_merge($attributes, $this->getDerivedAttributesDataByReportRules());
     }
     return self::$derivedAttributesData[get_class($this->model)];
 }