public function saveToCSV($name = "") { if ($name == "") { $name = $this->_name . ".csv"; } ob_clean(); header("Content-Type: text/csv;"); header("Content-Disposition: attachment; filename={$name}"); $firstRow = true; // Generate XML With Data while ($this->_it->hasNext()) { //com.xmlnuke.anydataset.SingleRow $registro = $this->_it->moveNext(); // Show Header if ($firstRow) { $firstRow = false; $fields = array(); // Insert fields if none is passed. if (sizeof($this->_fields) == 0) { foreach ($registro->getFieldNames() as $fieldname) { $fields[] = $fieldname; $fieldtmp = new EditListField(true); $fieldtmp->editlistName = $fieldname; $fieldtmp->fieldData = $fieldname; $fieldtmp->fieldType = EditListFieldType::TEXT; $this->addEditListField($fieldtmp); } } else { foreach ($this->_fields as $value) { $fields[] = $value->editlistName; } } echo '"' . implode('","', $fields) . '"' . "\n"; } // Show Data $data = array(); foreach ($this->_fields as $chave => $field) { if ($field->fieldType == EditListFieldType::FORMATTER) { $obj = $field->formatter; if (is_null($obj) || !$obj instanceof IEditListFormatter) { throw new InvalidArgumentException("The EditListFieldType::FORMATTER requires a valid IEditListFormatter class"); } else { $result = $obj->Format($registro, $field->fieldData, $registro->getField($field->fieldData)); } } elseif ($field->fieldType == EditListFieldType::LOOKUP) { $value = $registro->getField($field->fieldData); if ($value == "") { $value = "---"; } else { $value = $field->arrayLookup[$value]; } $result = $value; } else { $result = $registro->getField($field->fieldData); } $data[] = str_replace('"', "'", $result); } echo '"' . implode('","', array_values($data)) . '"' . "\n"; } die; }
/** *@desc Generate $page, processing yours childs. *@param DOMNode $current *@return void */ public function generateObject($current) { $submitFunction = "buildDualListField(this, '{$this->_listRightName}', '{$this->_name}');"; $editForm = $current; while ($editForm != null && $editForm->tagName != "editform") { $editForm = $editForm->parentNode; } if ($editForm != null) { if ($editForm->hasAttribute("customsubmit")) { $editForm->getAttributeNode("customsubmit")->value = $editForm->getAttributeNode("customsubmit")->value . " && " . $submitFunction; } else { XmlUtil::AddAttribute($editForm, "customsubmit", $submitFunction); } } else { throw new InvalidArgumentException("XMLDualList must be inside a XmlFormCollection"); } $nodeWorking = XmlUtil::CreateChild($current, "duallist", ""); if ($this->_buttonAllRight instanceof DualListButton && $this->_buttonAllRight->type != DualListButtonType::None) { $this->makeButton($this->_buttonAllRight, "allright", $nodeWorking, $this->_listLeftName, $this->_listRightName, "true"); } if ($this->_buttonOneRight instanceof DualListButton && $this->_buttonOneRight->type != DualListButtonType::None) { $this->makeButton($this->_buttonOneRight, "oneright", $nodeWorking, $this->_listLeftName, $this->_listRightName, "false"); } if ($this->_buttonOneLeft instanceof DualListButton && $this->_buttonOneLeft->type != DualListButtonType::None) { $this->makeButton($this->_buttonOneLeft, "oneleft", $nodeWorking, $this->_listRightName, $this->_listLeftName, "false"); } if ($this->_buttonAllLeft instanceof DualListButton && $this->_buttonAllLeft->type != DualListButtonType::None) { $this->makeButton($this->_buttonAllLeft, "allleft", $nodeWorking, $this->_listRightName, $this->_listLeftName, "true"); } XmlUtil::AddAttribute($nodeWorking, "name", $this->_name); $leftList = XmlUtil::CreateChild($nodeWorking, "leftlist", ""); $rightList = XmlUtil::CreateChild($nodeWorking, "rightlist", ""); XmlUtil::AddAttribute($leftList, "name", $this->_listLeftName); XmlUtil::AddAttribute($leftList, "caption", $this->_listLeftCaption); XmlUtil::AddAttribute($leftList, "size", $this->_listLeftSize); XmlUtil::AddAttribute($rightList, "name", $this->_listRightName); XmlUtil::AddAttribute($rightList, "caption", $this->_listRightCaption); XmlUtil::AddAttribute($rightList, "size", $this->_listRightSize); // Fill Right Side if (!is_array($this->_listRightDataSource)) { $arrRight = array(); if (!is_null($this->_listRightDataSource)) { while ($this->_listRightDataSource->hasNext()) { $row = $this->_listRightDataSource->moveNext(); $arrRight[$row->getField($this->_dataTableFieldId)] = $row->getField($this->_dataTableFieldText); } } } else { $arrRight = $this->_listRightDataSource; } // Fill Left Side if (!is_array($this->_listLeftDataSource)) { $arrLeft = array(); while ($this->_listLeftDataSource->hasNext()) { $row = $this->_listLeftDataSource->moveNext(); if (!array_key_exists($row->getField($this->_dataTableFieldId), $arrRight)) { $arrLeft[$row->getField($this->_dataTableFieldId)] = $row->getField($this->_dataTableFieldText); } } } else { $arrLeft = $this->_listLeftDataSource; } // Fix Data Source foreach ($arrRight as $key => $value) { if (isset($arrLeft[$key])) { $arrRight[$key] = $arrLeft[$key]; unset($arrLeft[$key]); } } $this->buildListItens($leftList, $arrLeft); $this->buildListItens($rightList, $arrRight); return $nodeWorking; }
/** * Get an Array from an existing Iterator * * @param IteratorInterface $it * @param string $key * @param string $value * @param string $firstElement * @return array */ public static function getArrayFromIterator(IteratorInterface $it, $key, $value, $firstElement = "-- Selecione --") { $retArray = array(); if ($firstElement != "") { $retArray[""] = $firstElement; } while ($it->hasNext()) { $sr = $it->moveNext(); $retArray[$sr->getField(strtolower($key))] = $sr->getField(strtolower($value)); } return $retArray; }
/** * @access public * @param IteratorInterface $it * @param string $fieldPK * @param string $fieldName * @return Resource */ public function getArrayField(IteratorInterface $it, $fieldPK, $fieldName) { $result = array(); while ($it->hasNext()) { $registro = $it->moveNext(); $result[$registro->getField($fieldPK)] = $registro->getField($fieldName); } return $result; }