Example #1
0
	/** 
	 * Each row contains a dataobject with any number of attributes
	 * @param $ID int The ID of the record
	 * @param $form Form A Form object containing all of the fields for this item.  The data should be loaded in
	 * @param $fieldTypes array An array of name => fieldtype for use when creating a new field
	 * @param $parent TableListField The parent table for quick reference of names, and id's for storing values.
	 */
	function __construct($item = null, $parent, $form, $fieldTypes, $isAddRow = false) {
		$this->data = $form;
		$this->fieldTypes = $fieldTypes;
		$this->isAddRow = $isAddRow;
		$this->item = $item;

		parent::__construct(($this->item) ? $this->item : new DataObject(), $parent);
		
		$this->fields = $this->createFields();
	}
 function __construct(DataObject $item, ComplexTableField $parent, $start)
 {
     $this->start = $start;
     parent::__construct($item, $parent);
 }
Example #3
0
 function generateExportFileData(&$numColumns, &$numRows)
 {
     $separator = $this->csvSeparator;
     $csvColumns = $this->fieldListCsv ? $this->fieldListCsv : $this->fieldList;
     $fileData = '';
     $columnData = array();
     $fieldItems = new DataObjectSet();
     if ($this->csvHasHeader) {
         $fileData .= "\"" . implode("\"{$separator}\"", array_values($csvColumns)) . "\"";
         $fileData .= "\n";
     }
     if (isset($this->customSourceItems)) {
         $items = $this->customSourceItems;
     } else {
         $dataQuery = $this->getCsvQuery();
         $items = $dataQuery->execute();
     }
     // temporary override to adjust TableListField_Item behaviour
     $this->setFieldFormatting(array());
     $this->fieldList = $csvColumns;
     if ($items) {
         foreach ($items as $item) {
             if (is_array($item)) {
                 $className = isset($item['RecordClassName']) ? $item['RecordClassName'] : $item['ClassName'];
                 $item = new $className($item);
             }
             $fieldItem = new TableListField_Item($item, $this);
             $fields = $fieldItem->Fields();
             $columnData = array();
             if ($fields) {
                 foreach ($fields as $field) {
                     $value = $field->Value;
                     // TODO This should be replaced with casting
                     if (array_key_exists($field->Name, $this->csvFieldFormatting)) {
                         $format = str_replace('$value', "__VAL__", $this->csvFieldFormatting[$field->Name]);
                         $format = preg_replace('/\\$([A-Za-z0-9-_]+)/', '$item->$1', $format);
                         $format = str_replace('__VAL__', '$value', $format);
                         eval('$value = "' . $format . '";');
                     }
                     $value = str_replace(array("\r", "\n"), "\n", $value);
                     $tmpColumnData = "\"" . str_replace("\"", "\"\"", $value) . "\"";
                     $columnData[] = $tmpColumnData;
                 }
             }
             $fileData .= implode($separator, $columnData);
             $fileData .= "\n";
             $item->destroy();
             unset($item);
             unset($fieldItem);
         }
         $numColumns = count($columnData);
         $numRows = $fieldItems->count();
         return $fileData;
     } else {
         return null;
     }
 }