/** * @param string $name Mnemonic identifier for the object * @param string $icon The icon taken from icon set (file name without extension) */ public function __construct($name, $icon = null) { parent::__construct($name); $this->setIcon($icon); $this->setLabel(P4A_Generate_Default_Label($name)); }
public function getAsCSV($separator = ',', $fields_names = null) { if ($fields_names === true or is_array($fields_names)) { $insert_header = true; } else { $insert_header = false; } if (is_array($fields_names)) { $tmp = array_keys($fields_names); if (is_numeric($tmp[0])) { $tmp = $fields_names; $fields_names = array(); foreach ($tmp as $colname) { $fields_names[$colname] = P4A_Generate_Default_Label($colname); } } } if ($fields_names === null or $fields_names === false or $fields_names === true) { $fields_names = array(); while ($field = $this->fields->nextItem()) { $name = $field->getName(); $fields_names[$name] = $name; } } $csv = ""; $rows = $this->getAll(); if ($insert_header) { array_unshift($rows, $fields_names); } foreach ($rows as $row) { $strrow = ""; foreach ($fields_names as $col => $tmp) { $tmp = str_replace("\n", "", $row[$col]); $tmp = str_replace("\r", "", $tmp); $strrow .= '"' . str_replace('"', '""', $tmp) . "\"{$separator}"; } $csv .= substr($strrow, 0, -1) . "\n"; } return $csv; }
/** * Create from name a default label for the widget * In rendering phase it will be added with ': '. * @see $label * @return P4A_Widget */ public function setDefaultLabel() { $this->setLabel(P4A_Generate_Default_Label($this->getName())); return $this; }