public function __viewIndex() { // This is the 'correct' way to append a string containing an entity $title = $this->createElement('title'); $title->appendChild($this->createTextNode(__('Symphony') . ' ')); $title->appendChild($this->createEntityReference('ndash')); $title->appendChild($this->createTextNode(' ' . __('Data Sources'))); $this->insertNodeIntoHead($title); $this->appendSubheading(__('Data Sources'), Widget::Anchor(__('Create New'), Administration::instance()->getCurrentPageURL() . '/new/', array('title' => __('Create a new data source'), 'class' => 'create button'))); $datasources = new DatasourceIterator(); $dsTableHead = array(array(__('Name'), 'col'), array(__('Source'), 'col'), array(__('Type'), 'col'), array(__('Used By'), 'col')); $dsTableBody = array(); $colspan = count($dsTableHead); if ($datasources->length() <= 0) { $dsTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), array('class' => 'inactive', 'colspan' => $colspan))), array('class' => 'odd'))); } else { // Load Views so we can determine what Datasources are attached if (!self::$_loaded_views) { foreach (new ViewIterator() as $view) { self::$_loaded_views[$view->guid] = array('title' => $view->title, 'handle' => $view->handle, 'data-sources' => $view->{'data-sources'}); } } foreach ($datasources as $pathname) { $ds = DataSource::load($pathname); $view_mode = $ds->allowEditorToParse() == true ? 'edit' : 'info'; $handle = DataSource::getHandleFromFilename($pathname); // Name $col_name = Widget::TableData(Widget::Anchor($ds->about()->name, ADMIN_URL . "/blueprints/datasources/{$view_mode}/{$handle}/", array('title' => $ds->parameters()->pathname))); $col_name->appendChild(Widget::Input("items[{$handle}]", NULL, 'checkbox')); // Source try { $col_source = $ds->prepareSourceColumnValue(); } catch (Exception $e) { $col_source = Widget::TableData(__('None'), array('class' => 'inactive')); } // Used By $fragment_views = $this->createDocumentFragment(); foreach (self::$_loaded_views as $view) { if (is_array($view['data-sources']) && in_array($handle, $view['data-sources'])) { if ($fragment_views->hasChildNodes()) { $fragment_views->appendChild(new DOMText(', ')); } $fragment_views->appendChild(Widget::Anchor($view['title'], ADMIN_URL . "/blueprints/views/edit/{$view['handle']}/")); } } if (!$fragment_views->hasChildNodes()) { $col_views = Widget::TableData(__('None'), array('class' => 'inactive')); } else { $col_views = Widget::TableData($fragment_views); } // Type if (is_null($ds->getType())) { $col_type = Widget::TableData(__('Unknown'), array('class' => 'inactive')); } else { $col_type = Widget::TableData($this->types[$ds->getType()]->name); } $dsTableBody[] = Widget::TableRow(array($col_name, $col_source, $col_type, $col_views)); } } $table = Widget::Table(Widget::TableHead($dsTableHead), NULL, Widget::TableBody($dsTableBody), array('id' => 'datasources-list')); $this->Form->appendChild($table); $tableActions = $this->createElement('div'); $tableActions->setAttribute('class', 'actions'); $options = array(array(NULL, false, __('With Selected...')), array('delete', false, __('Delete'))); $tableActions->appendChild(Widget::Select('with-selected', $options)); $tableActions->appendChild(Widget::Input('action[apply]', __('Apply'), 'submit')); $this->Form->appendChild($tableActions); }
public function __form() { $layout = new Layout(); $left = $layout->createColumn(Layout::LARGE); $center = $layout->createColumn(Layout::LARGE); $right = $layout->createColumn(Layout::LARGE); $existing = null; $fields = array(); // Verify view exists: if ($this->_context[0] == 'edit') { if (!isset($this->_context[1]) || strlen(trim($this->_context[1])) == 0) { redirect(ADMIN_URL . '/blueprints/views/'); } $context = $this->_context; array_shift($context); $view_pathname = implode('/', $context); $existing = self::__loadExistingView($view_pathname); } // Status message: $callback = Administration::instance()->getPageCallback(); if (isset($callback['flag']) && !is_null($callback['flag'])) { switch ($callback['flag']) { case 'saved': $this->alerts()->append(__('View updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/views/new/', ADMIN_URL . '/blueprints/views/')), AlertStack::SUCCESS); break; case 'created': $this->alerts()->append(__('View created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/views/new/', ADMIN_URL . '/blueprints/views/')), AlertStack::SUCCESS); break; } } // Find values: if (isset($_POST['fields'])) { $fields = $_POST['fields']; } elseif ($this->_context[0] == 'edit') { $fields = (array) $existing->about(); // Flatten the types array: $fields['types'] = (isset($fields['types']) and is_array($fields['types'])) ? implode(', ', $fields['types']) : null; // Flatten the url-parameters array: $fields['url-parameters'] = (isset($fields['url-parameters']) and is_array($fields['url-parameters'])) ? implode('/', $fields['url-parameters']) : null; $fields['parent'] = $existing->parent() instanceof View ? $existing->parent()->path : NULL; $fields['handle'] = $existing->handle; } $title = null; if (isset($fields['title'])) { $title = $fields['title']; } if (strlen(trim($title)) == 0) { $title = $existing instanceof View ? $existing->title : 'New View'; } $this->setTitle(__($title ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Views'), $title))); if ($existing instanceof View) { $template_name = $fields['handle']; $this->appendSubheading(__($title ? $title : __('New View'))); $viewoptions = array(__('Configuration') => Administration::instance()->getCurrentPageURL(), __('Template') => sprintf('%s/blueprints/views/template/%s/', ADMIN_URL, $view_pathname)); $this->appendViewOptions($viewoptions); } else { $this->appendSubheading($title ? $title : __('Untitled')); } // Fieldset ----------------------------------------------------------- $fieldset = Widget::Fieldset(__('Essentials')); // Title -------------------------------------------------------------- $label = Widget::Label(__('Title')); $label->appendChild(Widget::Input('fields[title]', isset($fields['title']) ? $fields['title'] : null)); if (isset($this->errors->title)) { $label = Widget::wrapFormElementWithError($label, $this->errors->title); } $fieldset->appendChild($label); // Type --------------------------------------------------------------- $container = $this->createElement('div'); $label = Widget::Label(__('View Type')); $label->appendChild(Widget::Input('fields[types]', isset($fields['types']) ? $fields['types'] : null)); if (isset($this->errors->types)) { $label = Widget::wrapFormElementWithError($label, $this->errors->types); } $tags = $this->createElement('ul'); $tags->setAttribute('class', 'tags'); foreach (self::__fetchAvailableViewTypes() as $t) { $tags->appendChild($this->createElement('li', $t)); } $container->appendChild($label); $container->appendChild($tags); $fieldset->appendChild($container); $left->appendChild($fieldset); // Fieldset ----------------------------------------------------------- $fieldset = Widget::Fieldset(__('URL Settings')); // Parent ------------------------------------------------------------- $label = Widget::Label(__('Parent')); $options = array(array(NULL, false, '/')); foreach (new ViewIterator() as $v) { // Make sure the current view cannot be set as either a child of itself, or a child of // another view that is already at child of the current view. if (isset($existing) && $existing instanceof View && ($v->isChildOf($existing) || $v->guid == $existing->guid)) { continue; } $options[] = array($v->path, isset($fields['parent']) and $fields['parent'] == $v->path, "/{$v->path}"); } $label->appendChild(Widget::Select('fields[parent]', $options)); $fieldset->appendChild($label); // Handle ------------------------------------------------------------- $label = Widget::Label(__('Handle')); $label->appendChild(Widget::Input('fields[handle]', isset($fields['handle']) ? $fields['handle'] : null)); if (isset($this->errors->handle)) { $label = Widget::wrapFormElementWithError($label, $this->errors->handle); } $fieldset->appendChild($label); // Parameters --------------------------------------------------------- $label = Widget::Label(__('Parameters')); $label->appendChild(Widget::Input('fields[url-parameters]', isset($fields['url-parameters']) ? $fields['url-parameters'] : null)); $fieldset->appendChild($label); $center->appendChild($fieldset); // Fieldset ----------------------------------------------------------- $fieldset = Widget::Fieldset(__('Resources')); $label = Widget::Label(__('Events')); $options = array(); foreach (new EventIterator() as $pathname) { $event = Event::load($pathname); $handle = Event::getHandleFromFilename($pathname); $options[] = array($handle, in_array($handle, (array) $fields['events']), $event->about()->name); } $label->appendChild(Widget::Select('fields[events][]', $options, array('multiple' => 'multiple'))); $fieldset->appendChild($label); // Data Sources ------------------------------------------------------- $label = Widget::Label(__('Data Sources')); $options = array(); foreach (new DataSourceIterator() as $pathname) { $ds = DataSource::load($pathname); $handle = DataSource::getHandleFromFilename($pathname); $options[] = array($handle, in_array($handle, (array) $fields['data-sources']), $ds->about()->name); } $label->appendChild(Widget::Select('fields[data-sources][]', $options, array('multiple' => 'multiple'))); $fieldset->appendChild($label); $right->appendChild($fieldset); $layout->appendTo($this->Form); // Controls ----------------------------------------------------------- $div = $this->createElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Submit('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create View'), array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $div->appendChild(Widget::Submit('action[delete]', __('Delete'), array('class' => 'confirm delete', 'title' => __('Delete this view')))); } $this->Form->appendChild($div); }