コード例 #1
0
 public function testIntervalFieldToArray()
 {
     $array = array('Support' => array('default' => true, 'localizedName' => 'Support', 'thresholdType' => '% of all', 'compareType' => 'Greater than or equal', 'explanation' => 'Relative support of the rule', 'fields' => array(array('name' => 'threshold', 'defaultValue' => 0.05, 'localizedName' => 'threshold value', 'minValue' => 0, 'minValueInclusive' => true, 'maxValue' => 1, 'maxValueInclusive' => false, 'dataType' => 'double'))));
     $IM = new InterestMeasure('Support', 'Support', '% of all', 'Greater than or equal', 'Relative support of the rule', true);
     $IM->addIntervalField('threshold', 0.05, 'threshold value', 0, true, 1, false, 'double');
     $this->assertEquals($array, $IM->toArray());
 }
コード例 #2
0
 protected function parseIMTypes()
 {
     $array['types'] = array();
     foreach ($this->XPath->evaluate('BuildingBlocks/InterestMeasures/Types/Type') as $t) {
         $name = $this->XPath->evaluate('Name', $t)->item(0)->nodeValue;
         $localizedName = '';
         if ($LN = $this->XPath->evaluate('LocalizedName[@lang="' . $this->lang . '"]', $t)->item(0)) {
             $localizedName = $LN->nodeValue;
         }
         $thresholdType = $this->XPath->evaluate('ThresholdType', $t)->item(0)->nodeValue;
         $compareType = $this->XPath->evaluate('CompareType', $t)->item(0)->nodeValue;
         $explanation = '';
         $default = $this->XPath->evaluate('Default', $t)->item(0)->nodeValue === 'true';
         if ($EX = $this->XPath->evaluate('Explanation[@lang="' . $this->lang . '"]', $t)->item(0)) {
             $explanation = $EX->nodeValue;
         }
         $IM = new InterestMeasure($name, $localizedName, $thresholdType, $compareType, $explanation, $default);
         foreach ($this->XPath->evaluate('Field', $t) as $f) {
             $name = $this->XPath->evaluate('Name', $f)->item(0)->nodeValue;
             $defaultValue = $this->XPath->evaluate('DefaultValue', $f)->item(0)->nodeValue;
             $localizedName = $this->XPath->evaluate('LocalizedName[@lang="' . $this->lang . '"]', $f)->item(0)->nodeValue;
             $dataType = $this->XPath->evaluate('Validation/Datatype', $f)->item(0)->nodeValue;
             if ($dataType === 'enum') {
                 // enumeration
                 $vals = array();
                 foreach ($this->XPath->evaluate('Validation/Value', $f) as $fv) {
                     array_push($vals, $fv->nodeValue);
                 }
                 sort($vals);
                 $IM->addEnumerationField($name, $defaultValue, $localizedName, $vals, $dataType);
             } else {
                 // interval
                 if ($mv = $this->XPath->evaluate('Validation/MinValue', $f)->item(0)) {
                     $minValue = intval($mv->nodeValue);
                     $minValueInclusive = $mv->getAttribute('inclusive') === 'yes';
                 } else {
                     $minValue = self::$IM_MIN;
                     $minValueInclusive = self::$IM_INCLUSIVE_MIN;
                 }
                 if ($mv = $this->XPath->evaluate('Validation/MaxValue', $f)->item(0)) {
                     $maxValue = intval($mv->nodeValue);
                     $maxValueInclusive = $mv->getAttribute('inclusive') === 'yes';
                 } else {
                     $maxValue = self::$IM_MAX;
                     $maxValueInclusive = self::$IM_INCLUSIVE_MAX;
                 }
                 $IM->addIntervalField($name, $defaultValue, $localizedName, $minValue, $minValueInclusive, $maxValue, $maxValueInclusive, $dataType);
             }
         }
         $array['types'] = array_merge_recursive($array['types'], $IM->toArray());
     }
     return $array;
 }