コード例 #1
0
ファイル: SideReport.php プロジェクト: aaronleslie/aaronunix
 protected function formatValue($record, $source, $info)
 {
     // Field sources
     //if(is_string($source)) {
     $val = Convert::raw2xml($record->{$source});
     //} else {
     //	$val = $record->val($source[0], $source[1]);
     //}
     // Casting, a la TableListField.  We're deep-calling a helper method on TableListField that
     // should probably be pushed elsewhere...
     if (!empty($info['casting'])) {
         $val = TableListField::getCastedValue($val, $info['casting']);
     }
     // Formatting, a la TableListField
     if (!empty($info['formatting'])) {
         $format = str_replace('$value', "__VAL__", $info['formatting']);
         $format = preg_replace('/\\$([A-Za-z0-9-_]+)/', '$record->$1', $format);
         $format = str_replace('__VAL__', '$val', $format);
         $val = eval('return "' . $format . '";');
     }
     $prefix = empty($info['newline']) ? "" : "<br>";
     $classClause = "";
     if (isset($info['title'])) {
         $cssClass = preg_replace('/[^A-Za-z0-9]+/', '', $info['title']);
         $classClause = "class=\"{$cssClass}\"";
     }
     if (isset($info['link']) && $info['link']) {
         $link = $info['link'] === true && $record->hasMethod('CMSEditLink') ? $record->CMSEditLink() : $info['link'];
         return $prefix . "<a {$classClause} href=\"{$link}\">{$val}</a>";
     } else {
         return $prefix . "<span {$classClause}>{$val}</span>";
     }
 }
コード例 #2
0
 function Fields($xmlSafe = true)
 {
     $list = $this->parent->FieldList();
     foreach ($list as $fieldName => $fieldTitle) {
         $value = "";
         // This supports simple FieldName syntax
         if (strpos($fieldName, '.') === false) {
             $value = $this->item->XML_val($fieldName) && $xmlSafe ? $this->item->XML_val($fieldName) : $this->item->RAW_val($fieldName);
             // This support the syntax fieldName = Relation.RelatedField
         } else {
             $fieldNameParts = explode('.', $fieldName);
             $tmpItem = $this->item;
             for ($j = 0; $j < sizeof($fieldNameParts); $j++) {
                 $relationMethod = $fieldNameParts[$j];
                 $idField = $relationMethod . 'ID';
                 if ($j == sizeof($fieldNameParts) - 1) {
                     if ($tmpItem) {
                         $value = $tmpItem->{$relationMethod};
                     }
                 } else {
                     if ($tmpItem) {
                         $tmpItem = $tmpItem->{$relationMethod}();
                     }
                 }
             }
         }
         // casting
         if (array_key_exists($fieldName, $this->parent->fieldCasting)) {
             $value = $this->parent->getCastedValue($value, $this->parent->fieldCasting[$fieldName]);
         } elseif (is_object($value) && method_exists($value, 'Nice')) {
             $value = $value->Nice();
         }
         // formatting
         $item = $this->item;
         if (array_key_exists($fieldName, $this->parent->fieldFormatting)) {
             $format = str_replace('$value', "__VAL__", $this->parent->fieldFormatting[$fieldName]);
             $format = preg_replace('/\\$([A-Za-z0-9-_]+)/', '$item->$1', $format);
             $format = str_replace('__VAL__', '$value', $format);
             eval('$value = "' . $format . '";');
         }
         //escape
         if ($escape = $this->parent->fieldEscape) {
             foreach ($escape as $search => $replace) {
                 $value = str_replace($search, $replace, $value);
             }
         }
         $fields[] = new ArrayData(array("Name" => $fieldName, "Title" => $fieldTitle, "Value" => $value, "CsvSeparator" => $this->parent->getCsvSeparator()));
     }
     return new DataObjectSet($fields);
 }