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 {
$data = get_record_select('collection', 'id = ?', array($configdata['collection']));
$collection = new Collection($configdata['collection'], (array)$data);
if ($views = $collection->views()) {
$smarty->assign('views',$views);
$smarty->assign('views',$views['views']);
}
}
$smarty->assign('currentview',$instance->get('view'));
......
......@@ -59,7 +59,7 @@ if ($collection->has_views()) {
$views = $collection->views();
$options[0] = get_string('nooverride','collection');
foreach ($views as $v) {
foreach ($views['views'] as $v) {
$options[$v->view] = $v->title;
}
......
......@@ -43,9 +43,8 @@ if (!get_config('allowcollections')) {
die();
}
$viewid = param_integer('v');
$collectionid = param_integer('c');
define('VIEW', $viewid);
$viewid = param_integer('view');
$collectionid = param_integer('id');
define('COLLECTION', $collectionid);
$collection = Collection::current_collection();
......
......@@ -43,6 +43,8 @@ if (!get_config('allowcollections')) {
die();
}
$view = param_integer('view',0);
$direction = param_variable('direction','');
$collectionid = param_integer('id');
define('COLLECTION', $collectionid);
......@@ -53,7 +55,12 @@ if (!$USER->can_edit_collection($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();
if ($available = Collection::available_views()) {
......@@ -83,7 +90,7 @@ else {
}
$smarty = smarty();
$smarty->assign_by_ref('incollection', $incollection);
$smarty->assign_by_ref('views', $views);
$smarty->assign('form', $form);
$smarty->assign('addviews', get_string('addviews', 'collection'));
$smarty->display('collection/views.tpl');
......
......@@ -322,14 +322,25 @@ class Collection {
LEFT JOIN {collection} c ON cv.collection = c.id
LEFT JOIN {view} v ON cv.view = v.id
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'))))
|| ($views = array());
$result = get_records_sql_array($sql, array($this->get('id'), $USER->get('id')));
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 array();
}
/**
* Get the available views the current user can choose from
* - currently dashboard, group and profile views are ignored to solve access issues
......@@ -372,6 +383,11 @@ class Collection {
$cv = array();
$cv['view'] = substr($key,5);
$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);
$count++;
}
......@@ -456,7 +472,7 @@ class Collection {
// update all other views access
$views = $this->views(false);
foreach ($views as $view) {
foreach ($views['views'] as $view) {
if ($v = new View($view->view)) {
delete_records('view_access','view',$view->view); // clear all current access
$v->set_access($validaccess['valid']);
......@@ -494,4 +510,46 @@ class Collection {
'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 @@
<FIELD NAME="collection" 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="displayorder" TYPE="int" LENGTH="10" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="collection,view" />
......
......@@ -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;
}
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2010080400;
$config->version = 2010080401;
$config->release = '1.3.0beta4dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
......@@ -875,8 +875,33 @@ ul.groupuserstatus li,
.home-info-table {
margin: 2em 0 2.5em;
}
#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 {
background: #FAFBF7;
}
{auto_escape off}
{include file="header.tpl"}
{if !$incollection}
{if !$views}
<div class="message">{str tag=noviews section=collection}</div>
{else}
<table width='50%'>
<table id="collectionviews" width="100%">
<tbody>
{foreach from=$incollection item=view}
<tr>
<td>{$view->title|safe}</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>
{foreach from=$views.views item=view}
<tr class="{cycle values='r0,r1'}">
<td><label><a href="{$WWWROOT}view/view.php?id={$view->view}">{$view->title|safe}</a></label></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>
{/foreach}
</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