/** * @param array $array * @return P4A_Array_Source */ public function load(array $array) { $this->_array = array(); $this->_array[-1] = array(); if (empty($array)) { return; } $first_row = $array[0]; if (!is_array($first_row)) { foreach ($array as $value) { $this->_array[] = array('f0' => $value); } $this->setPK('f0'); $first_row = array('f0' => $first_row); } else { foreach ($array as $value) { $this->_array[] = $value; } } foreach ($first_row as $field_name => $value) { if (!isset($this->fields->{$field_name})) { $this->fields->build('P4A_Data_Field', $field_name); } $this->_array[-1][$field_name] = ''; } return $this; }
/** * @return P4A_Field */ protected function buildDeletePreviewDownloadButtons() { if (!isset($this->buttons->button_file_delete)) { $this->buttons->build("p4a_button", "button_file_delete")->setLabel('Delete')->addAjaxAction('onclick')->implement('onclick', $this, 'fileDeleteOnClick'); } if (!isset($this->buttons->button_file_preview)) { $this->buttons->build("p4a_button", "button_file_preview")->setLabel('Preview')->implement('onclick', $this, 'filePreviewOnClick'); } if (!isset($this->buttons->button_file_download)) { $this->buttons->build("p4a_button", "button_file_download")->setLabel('Download')->implement('onclick', $this, 'fileDownloadOnClick'); } return $this; }
/** * Calls the isValid() method for every field. * If a field does not pass validation sets its error message. * @return boolean */ public function validateFields() { $return = true; while ($field = $this->fields->nextItem()) { $validation_results = $field->isValid(); if ($validation_results !== true) { foreach ($validation_results as &$message) { $message = $message; } $field->setError(join('. ', $validation_results) . '.'); $return = false; } } return $return; }
/** * Returns the rendered HTML * @return string */ public function getAsString() { $id = $this->getId(); if (!$this->isVisible()) { return "<div id='{$id}' class='hidden'></div>"; } $height = $this->getHeight(); $this->setHeight(null); $class = $this->composeStringClass(array("ui-tabs", "ui-widget", "ui-widget-content")); $properties = $this->composeStringProperties(); $return = "<div id='{$id}' {$class} {$properties}>"; $return .= "<ul class='tabs ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all'>"; $active_page_name = $this->getActivePageName(); $this->pages->reset(); while ($page = $this->pages->nextItem()) { if (!$page->isVisible()) { continue; } $actions = $page->isEnabled() ? $this->composeStringActions($page->getName()) : ""; $disabled = $page->isEnabled() ? "" : "disabled"; $active = ""; if ($page->getName() == $active_page_name) { $active = "ui-tabs-selected ui-state-active"; } if (!strlen($page->getLabel())) { $page->setDefaultLabel(); } $label = __($page->getLabel()); $tooltip = __($page->getTooltip()); $mouseover = ""; if (strlen($tooltip)) { $tooltip = "<div id='{$page->getId()}tooltip' class='p4a_tooltip'><div class='p4a_tooltip_inner'>{$tooltip}</div></div>"; $mouseover = "onmouseover='p4a_tooltip_show(this)'"; $label .= ' <img src="' . P4A_ICONS_PATH . '/16/status/dialog-information.png" class="p4a_tooltip_icon" alt="" />'; } $return .= "<li class='ui-state-default ui-corner-top {$active} {$disabled}' {$mouseover}><a href='#' {$actions}>{$label}</a>{$tooltip}</li>"; } $return .= "</ul>"; $return .= "<div class='p4a_tab_pane_page ui-tabs-panel ui-widget-content ui-corner-all ui-helper-clearfix' style='height:{$height}'>" . $this->getActivePage()->getAsString() . "</div>"; $return .= "</div>"; $return .= "<script type='text/javascript'>p4a_tabs_load();</script>"; $this->setHeight($height); return $return; }
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; }
/** * Renders HTML * @access public * @return string */ public function getAsString() { $id = $this->getId(); if (!$this->isVisible()) { return "<div id='{$id}' class='hidden'></div>"; } $has_items = $this->hasItems() ? "class='p4a_menu_has_items'" : ''; $properties = $this->composeStringProperties(); if (P4A::singleton()->isHandheld()) { $icon = ''; } else { $icon = $this->getIcon(); if (strlen($icon)) { if (strpos($this->_icon, '.') === false) { $icon_disabled = ''; if (!$this->isEnabled()) { $icon_disabled = '_disabled'; } $icon = P4A_ICONS_PATH . "/16/{$icon}{$icon_disabled}." . P4A_ICONS_EXTENSION; } $icon = "<img src='{$icon}' alt='' />"; } } if (empty($this->_map_actions["onclick"]["method"]) or !$this->isEnabled()) { $sReturn = "<li {$has_items}>" . P4A_Generate_Widget_Layout_Table($icon, "<div {$properties}>" . __($this->getLabel()) . "</div>"); } else { $actions = $this->composeStringActions(); $sReturn = "<li {$has_items}>" . P4A_Generate_Widget_Layout_Table($icon, "<a href='#' {$actions} {$properties}>" . P4A_Highlight_AccessKey(__($this->getLabel()), $this->getAccessKey()) . "</a>"); } if ($has_items) { $sReturn .= "<ul>"; while ($item = $this->items->nextItem()) { $sReturn .= $item->getAsString(); } $sReturn .= "</ul>"; } $sReturn .= "</li>"; return $sReturn; }
/** * @param string $button_name * @param string $icon * @param string $float * @return P4A_Button */ public function addButton($button_name, $icon = null, $float = "left") { $button = $this->buttons->build("p4a_button", $button_name); $button->addAjaxAction('onclick'); if (strlen($icon) > 0) { $button->setIcon($icon); $button->setSize(self::height); } $anchor = "anchor" . $float; $this->{$anchor}($button, "2px"); return $button; }