Commit 5a781272 authored by merlinofchaos's avatar merlinofchaos

Step 1 of so-many-I-can't-count of Views UI, plus some fixes to last checkin

parent 021885c3
......@@ -107,15 +107,25 @@ function _views_fetch_plugin_data($type = NULL, $plugin = NULL) {
* @return An associative array of all known default views.
*/
function _views_discover_default_views() {
global $language;
views_include_default_views();
$defaults = module_invoke_all('views_default_views');
static $cache = NULL;
foreach ($defaults as $name => $view) {
if ($should_cache) {
views_cache_set('views_default_views:'. $name, $view, TRUE);
if (!isset($cache)) {
global $language;
$data = cache_get('views_default_views:' . $language, 'cache_views');
if (isset($data->data)) {
$cache = $data->data;
}
else {
views_include_default_views();
$defaults = module_invoke_all('views_default_views');
$cache = array();
dsm('..');
foreach ($defaults as $name => $view) {
$cache[$name] = $view;
}
cache_set('views_default_views:' . $language, $cache, 'cache_views');
}
$cache[$name] = $view;
}
return $cache;
......
......@@ -444,7 +444,7 @@ class view extends views_db_object {
*
* @todo: Implement this.
*/
function get_title($context) { }
function get_title($context = 'menu') { }
/**
* Get the URL for the current view.
......@@ -514,9 +514,9 @@ class view extends views_db_object {
* @todo FROM LG: We should document why this is passing in literal query fragments
* since it's bound to confuse someone else as much as it did/does me. :-)
*/
function load_views($where, $join = '') {
function load_views() {
// @todo: Integrate this in with caching.
$result = db_query("SELECT DISTINCT v.* FROM {views_view} v $join WHERE $where");
$result = db_query("SELECT DISTINCT v.* FROM {views_view} v");
$views = array();
// Load all the views.
......@@ -524,6 +524,7 @@ class view extends views_db_object {
$view = new view;
$view->load_row($data);
$view->loaded = TRUE;
$view->type = t('Normal');
$views[$view->vid] = $view;
}
......@@ -773,9 +774,8 @@ class views_db_object {
}
/**
* Export a loaded row to PHP code.
* Export a loaded row, such as an argument, field or the view itself to PHP code.
*
* @todo LG: I don't understand what a "row" is in this context.
* @param $identifier
* The variable to assign the PHP code for this object to.
* @param $indent
......
......@@ -459,9 +459,25 @@ function views_get_all_views() {
views_include('view');
$views = view::load_views();
// Merge in default views; this construct will not overwrite any keys that
// are already set.
$views += views_discover_default_views();
// Get all default views.
$status = variable_get('panel_page_defaults', array());
foreach (views_discover_default_views() as $view) {
// Determine if default view is enabled or disabled.
if (isset($status[$view->name])) {
$view->disabled = $status[$view->name];
}
// If overridden, also say so.
if (!empty($views[$view->name])) {
$views[$view->name]->type = t('Overridden');
}
else {
$view->type = t('Default');
$views[$view->name] = $view;
}
}
}
return $views;
}
......
; $Id$
name = Views UI
description = Administrative interface to views. Without this module, you cannot create or edit your views.
package = Views
core = 6.x
dependencies[] = views
<?php
// $Id$
/**
* @file views_ui.module
*
* Provide administrative interface to create and manipulate Views.
*/
function views_ui_menu() {
$items = array();
$items['admin/build/views'] = array(
'title' => t('Views'),
'page callback' => 'views_ui_list_views',
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'description' => t('Views are customized lists of content on your system; they are highly configurable and give you control over how lists of content are presented.'),
'type' => MENU_NORMAL_ITEM
);
$items['admin/build/views/list'] = array(
'title' => t('List'),
'page callback' => 'views_ui_list_views',
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => '-1'
);
$items['admin/build/views/add'] = array(
'title' => t('Add'),
'page callback' => 'views_ui_add_page',
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_LOCAL_TASK
);
$items['admin/build/views/import'] = array(
'title' => t('Import'),
'page callback' => 'views_ui_admin_import_page',
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_LOCAL_TASK
);
$items['admin/build/views/tools'] = array(
'title' => t('Tools'),
'page callback' => 'drupal_get_form',
'callback arguments' => array('views_ui_admin_tools'),
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_LOCAL_TASK
);
$items['admin/build/views/delete'] = array(
'title' => t('Edit view'),
'page callback' => 'drupal_get_form',
'callback arguments' => array('views_ui_admin_delete_confirm'),
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_CALLBACK
);
$items['admin/build/views/enable'] = array(
'page callback' => 'views_ui_admin_enable_page',
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_CALLBACK
);
$items['admin/build/views/disable'] = array(
'page callback' => 'views_ui_admin_disable_page',
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_CALLBACK
);
return $items;
}
/*
* Implementation of hook_perm()
*/
function views_ui_perm() {
return array('administer views');
}
/**
* Page callback to list views in the system.
*/
function views_ui_list_views() {
$items = array();
$sorts = array();
$header = array(
array('data' => t('View name'), 'field' => 'name', 'sort' => 'asc'),
array('data' => t('Description')),
array('data' => t('Title'), 'field' => 'title'),
array('data' => t('Type'), 'field' => 'type'),
array('data' => t('URL'), 'field' => 'url'),
array('data' => t('Operations')),
);
foreach (views_get_all_views() as $view) {
$ops = array();
if (empty($view->disabled)) {
$ops[] = l(t('Edit'), "admin/build/views/edit/$view->name");
$ops[] = l(t('Export'), "admin/build/views/$view->name/export");
}
if ($view->type != t('Default')) {
$text = $view->type == t('Overridden') ? t('Revert') : t('Delete');
$ops[] = l($text, "admin/build/views/$view->name/delete");
}
else {
if (empty($view->disabled)) {
$ops[] = l(t('Disable'), "admin/build/views/disable/$view->name", NULL, drupal_get_destination());
}
else {
$ops[] = l(t('Enable'), "admin/build/views/enable/$view->name", NULL, drupal_get_destination());
}
}
$path = 'Todo: path';
// $path = empty($view->disabled) && strpos($view->path, '%') === FALSE ? l($view->path, $view->path) : check_plain($view->path);
$item = array();
$item[] = check_plain($view->name);
$item[] = check_plain($view->description);
$item[] = check_plain($view->get_title());
$item[] = $view->type; // this is safe as it's always programmatic
$item[] = $path;
$item[] = implode(' | ', $ops);
$items[] = $item;
$ts = tablesort_init($header);
switch ($ts['sql']) {
case 'name':
default:
$sorts[] = $item[0];
break;
case 'title':
$sorts[] = $item[1];
break;
case 'url':
$sorts[] = 'todo: path'; // $path;
break;
case 'type':
$sorts[] = $view->type . $item[0];
break;
}
}
if (strtolower($ts['sort']) == 'desc') {
arsort($sorts);
}
else {
asort($sorts);
}
$i = array();
foreach ($sorts as $id => $title) {
$i[] = $items[$id];
}
$output = theme('table', $header, $i);
return $output;
}
/**
* Page callback to add a new view.
*/
function views_ui_add_page() {
$output = 'foo';
return $output;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment