Commit be10ffe7 authored by Stacey Walker's avatar Stacey Walker Committed by Richard Mansfield
Browse files

collection: added viewlist displayorder functionality

parent d15a42a1
...@@ -67,7 +67,7 @@ class PluginBlocktypeNavigation extends SystemBlocktype { ...@@ -67,7 +67,7 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
$data = get_record_select('collection', 'id = ?', array($configdata['collection'])); $data = get_record_select('collection', 'id = ?', array($configdata['collection']));
$collection = new Collection($configdata['collection'], (array)$data); $collection = new Collection($configdata['collection'], (array)$data);
if ($views = $collection->views()) { if ($views = $collection->views()) {
$smarty->assign('views',$views); $smarty->assign('views',$views['views']);
} }
} }
$smarty->assign('currentview',$instance->get('view')); $smarty->assign('currentview',$instance->get('view'));
......
...@@ -59,7 +59,7 @@ if ($collection->has_views()) { ...@@ -59,7 +59,7 @@ if ($collection->has_views()) {
$views = $collection->views(); $views = $collection->views();
$options[0] = get_string('nooverride','collection'); $options[0] = get_string('nooverride','collection');
foreach ($views as $v) { foreach ($views['views'] as $v) {
$options[$v->view] = $v->title; $options[$v->view] = $v->title;
} }
......
...@@ -43,9 +43,8 @@ if (!get_config('allowcollections')) { ...@@ -43,9 +43,8 @@ if (!get_config('allowcollections')) {
die(); die();
} }
$viewid = param_integer('v'); $viewid = param_integer('view');
$collectionid = param_integer('c'); $collectionid = param_integer('id');
define('VIEW', $viewid);
define('COLLECTION', $collectionid); define('COLLECTION', $collectionid);
$collection = Collection::current_collection(); $collection = Collection::current_collection();
......
...@@ -43,6 +43,8 @@ if (!get_config('allowcollections')) { ...@@ -43,6 +43,8 @@ if (!get_config('allowcollections')) {
die(); die();
} }
$view = param_integer('view',0);
$direction = param_variable('direction','');
$collectionid = param_integer('id'); $collectionid = param_integer('id');
define('COLLECTION', $collectionid); define('COLLECTION', $collectionid);
...@@ -53,7 +55,12 @@ if (!$USER->can_edit_collection($collection)) { ...@@ -53,7 +55,12 @@ if (!$USER->can_edit_collection($collection)) {
redirect('/collection/'); redirect('/collection/');
} }
$incollection = $collection->views(); if ($view AND !empty($direction)) {
$collection->set_viewdisplayorder($view,$direction);
redirect('/collection/views.php?id='.COLLECTION);
}
$views = $collection->views();
$elements = array(); $elements = array();
if ($available = Collection::available_views()) { if ($available = Collection::available_views()) {
...@@ -83,7 +90,7 @@ else { ...@@ -83,7 +90,7 @@ else {
} }
$smarty = smarty(); $smarty = smarty();
$smarty->assign_by_ref('incollection', $incollection); $smarty->assign_by_ref('views', $views);
$smarty->assign('form', $form); $smarty->assign('form', $form);
$smarty->assign('addviews', get_string('addviews', 'collection')); $smarty->assign('addviews', get_string('addviews', 'collection'));
$smarty->display('collection/views.tpl'); $smarty->display('collection/views.tpl');
......
...@@ -322,12 +322,23 @@ class Collection { ...@@ -322,12 +322,23 @@ class Collection {
LEFT JOIN {collection} c ON cv.collection = c.id LEFT JOIN {collection} c ON cv.collection = c.id
LEFT JOIN {view} v ON cv.view = v.id LEFT JOIN {view} v ON cv.view = v.id
WHERE c.id = ? AND c.owner = ? " . $mastersql . " WHERE c.id = ? AND c.owner = ? " . $mastersql . "
ORDER BY v.title, v.ctime ASC"; ORDER BY cv.displayorder, v.title, v.ctime ASC";
($views = get_records_sql_array($sql, array($this->get('id'), $USER->get('id')))) $result = get_records_sql_array($sql, array($this->get('id'), $USER->get('id')));
|| ($views = array());
if (!empty($result)) {
$max = get_field('collection_view', 'MAX(displayorder)', 'collection', $this->get('id'));
$min = get_field('collection_view', 'MIN(displayorder)', 'collection', $this->get('id'));
$views = array(
'views' => $result,
'max' => $max,
'min' => $min,
);
return $views; return $views;
}
return array();
} }
/** /**
...@@ -372,6 +383,11 @@ class Collection { ...@@ -372,6 +383,11 @@ class Collection {
$cv = array(); $cv = array();
$cv['view'] = substr($key,5); $cv['view'] = substr($key,5);
$cv['collection'] = $this->get('id'); $cv['collection'] = $this->get('id');
// set displayorder value
$max = get_field('collection_view', 'MAX(displayorder)', 'collection', $this->get('id'));
$cv['displayorder'] = is_numeric($max) ? $max + 1 : 0;
insert_record('collection_view', (object)$cv); insert_record('collection_view', (object)$cv);
$count++; $count++;
} }
...@@ -456,7 +472,7 @@ class Collection { ...@@ -456,7 +472,7 @@ class Collection {
// update all other views access // update all other views access
$views = $this->views(false); $views = $this->views(false);
foreach ($views as $view) { foreach ($views['views'] as $view) {
if ($v = new View($view->view)) { if ($v = new View($view->view)) {
delete_records('view_access','view',$view->view); // clear all current access delete_records('view_access','view',$view->view); // clear all current access
$v->set_access($validaccess['valid']); $v->set_access($validaccess['valid']);
...@@ -494,4 +510,46 @@ class Collection { ...@@ -494,4 +510,46 @@ class Collection {
'secreturl' => $secretURL, 'secreturl' => $secretURL,
); );
} }
/**
* Sets the displayorder for a view
*
* @param integer view
* @param string direction
*
*/
public function set_viewdisplayorder($id, $direction) {
$ids = get_column_sql('
SELECT view FROM {collection_view}
WHERE collection = ?
ORDER BY displayorder', array($this->get('id')));
foreach ($ids as $k => $v) {
if ($v == $id) {
$oldorder = $k;
break;
}
}
if ($direction == 'up' && $oldorder > 0) {
$neworder = array_merge(array_slice($ids, 0, $oldorder - 1),
array($id, $ids[$oldorder-1]),
array_slice($ids, $oldorder+1));
}
else if ($direction == 'down' && ($oldorder + 1 < count($ids))) {
$neworder = array_merge(array_slice($ids, 0, $oldorder),
array($ids[$oldorder+1], $id),
array_slice($ids, $oldorder+2));
}
if (isset($neworder)) {
foreach ($neworder as $k => $v) {
set_field('collection_view', 'displayorder', $k, 'view', $v, 'collection',$this->get('id'));
}
$this->set('mtime', time());
$this->commit();
}
}
} }
...@@ -809,6 +809,7 @@ ...@@ -809,6 +809,7 @@
<FIELD NAME="collection" TYPE="int" LENGTH="10" NOTNULL="true" /> <FIELD NAME="collection" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" /> <FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="master" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0"/> <FIELD NAME="master" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0"/>
<FIELD NAME="displayorder" TYPE="int" LENGTH="10" NOTNULL="true" />
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="collection,view" /> <KEY NAME="primary" TYPE="primary" FIELDS="collection,view" />
......
...@@ -2121,5 +2121,15 @@ function xmldb_core_upgrade($oldversion=0) { ...@@ -2121,5 +2121,15 @@ function xmldb_core_upgrade($oldversion=0) {
} }
if ($oldversion < 2010080401) {
// new field displayorder on collection_view
$table = new XMLDBTable('collection_view');
$field = new XMLDBField('displayorder');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, XMLDB_NOTNULL);
add_field($table, $field);
}
return $status; return $status;
} }
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
defined('INTERNAL') || die(); defined('INTERNAL') || die();
$config = new StdClass; $config = new StdClass;
$config->version = 2010080400; $config->version = 2010080401;
$config->release = '1.3.0beta4dev'; $config->release = '1.3.0beta4dev';
$config->minupgradefrom = 2008040200; $config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)'; $config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
...@@ -875,8 +875,33 @@ ul.groupuserstatus li, ...@@ -875,8 +875,33 @@ ul.groupuserstatus li,
.home-info-table { .home-info-table {
margin: 2em 0 2.5em; margin: 2em 0 2.5em;
} }
#hideinfo { #hideinfo {
} }
/* Collections */
#collectionviews {
background: #f6f6f6;
}
#collectionviews table {
width: 100%;
}
* html #collectionviews table,
* html #collectionviews {
width: 96%;
}
#collectionviews td {
padding: .25em 0;
}
#collectionviews td label {
font-size: 1em;
font-weight: bold;
}
#collectionviews td div {
text-align: center;
}
.inbox-message { .inbox-message {
background: #FAFBF7; background: #FAFBF7;
} }
\ No newline at end of file
{auto_escape off} {auto_escape off}
{include file="header.tpl"} {include file="header.tpl"}
{if !$incollection} {if !$views}
<div class="message">{str tag=noviews section=collection}</div> <div class="message">{str tag=noviews section=collection}</div>
{else} {else}
<table width='50%'> <table id="collectionviews" width="100%">
<tbody> <tbody>
{foreach from=$incollection item=view} {foreach from=$views.views item=view}
<tr> <tr class="{cycle values='r0,r1'}">
<td>{$view->title|safe}</td> <td><label><a href="{$WWWROOT}view/view.php?id={$view->view}">{$view->title|safe}</a></label></td>
<td><a class="btn-del" href="{$WWWROOT}collection/deleteview.php?v={$view->view|safe}&amp;c={$view->collection|safe}">{str tag=remove}</a></td> {if $view->master == 1}
<td>
{str tag="currentmaster" section="collection"}: <a href="{$WWWROOT}view/access.php?id={$view->view|safe}">{str tag=editaccess section="view"}</a>
</td>
{else}
<td>&nbsp;</td>
{/if}
<td>&nbsp;</td>
<td><a href="{$WWWROOT}collection/deleteview.php?id={$view->collection|safe}&amp;view={$view->view|safe}">{str tag=remove}</a></td>
<td class="displayordercontrols">
{if $view->displayorder == $views.min}
<div id="viewdisplayorder_{$view->view}">
<a href="{$WWWROOT}collection/views.php?id={$view->collection|safe}&amp;v={$view->view|safe}&amp;d=down"><img src="{theme_url filename='images/move-block-down.png'}" alt="" ></a>
</div>
{elseif $view->displayorder == $views.max}
<div id="viewdisplayorder_{$view->view}">
<a href="{$WWWROOT}collection/views.php?id={$view->collection|safe}&amp;view={$view->view|safe}&amp;direction=up"><img src="{theme_url filename='images/move-block-up.png'}" alt="" ></a>
</div>
{else}
<div id="viewdisplayorder_{$view->view}">
<a href="{$WWWROOT}collection/views.php?id={$view->collection|safe}&amp;view={$view->view|safe}&amp;direction=up"><img src="{theme_url filename='images/move-block-up.png'}" alt="" ></a>
<a href="{$WWWROOT}collection/views.php?id={$view->collection|safe}&amp;view={$view->view|safe}&amp;direction=down"><img src="{theme_url filename='images/move-block-down.png'}" alt="" ></a>
</div>
{/if}
</td>
</tr> </tr>
{/foreach} {/foreach}
</tbody> </tbody>
......
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