Commit 3bf2f318 authored by Penny Leach's avatar Penny Leach Committed by Nigel McNie
Browse files

very broken commit - need to merge with origin

parent 8b8d638f
...@@ -196,7 +196,7 @@ function ViewManager() { ...@@ -196,7 +196,7 @@ function ViewManager() {
var queryString = parseQueryString(i.href.substr(i.href.indexOf('?'))); var queryString = parseQueryString(i.href.substr(i.href.indexOf('?')));
removeElementClass(getFirstElementByTagAndClassName('li', 'current', 'category-list'), 'current'); removeElementClass(getFirstElementByTagAndClassName('li', 'current', 'category-list'), 'current');
addElementClass(i.parentNode, 'current'); addElementClass(i.parentNode, 'current');
sendjsonrequest('viewrework.json.php', {'view': $('viewid').value, 'action': 'blocktype_list', 'category': queryString['category']}, 'POST', function(data) { sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', {'id': $('viewid').value, 'action': 'blocktype_list', 'c': queryString['c']}, 'POST', function(data) {
$('blocktype-list').innerHTML = data.data; $('blocktype-list').innerHTML = data.data;
self.makeBlockTypesDraggable(); self.makeBlockTypesDraggable();
}); });
...@@ -221,9 +221,9 @@ function ViewManager() { ...@@ -221,9 +221,9 @@ function ViewManager() {
connect(button, 'onclick', function(e) { connect(button, 'onclick', function(e) {
setNodeAttribute(button, 'disabled', 'disabled'); setNodeAttribute(button, 'disabled', 'disabled');
if (confirm(get_string('confirmdeleteblockinstance'))) { if (confirm(get_string('confirmdeleteblockinstance'))) {
var pd = {'view': $('viewid').value, 'change': 1}; var pd = {'id': $('viewid').value, 'change': 1};
pd[e.src().getAttribute('name')] = 1; pd[e.src().getAttribute('name')] = 1;
sendjsonrequest('viewrework.json.php', pd, 'POST', function(data) { sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {
removeElement(getFirstParentByTagAndClassName(button, 'div', 'blockinstance')); removeElement(getFirstParentByTagAndClassName(button, 'div', 'blockinstance'));
removeNodeAttribute(button, 'disabled'); removeNodeAttribute(button, 'disabled');
}, function() { }, function() {
...@@ -257,9 +257,9 @@ function ViewManager() { ...@@ -257,9 +257,9 @@ function ViewManager() {
setNodeAttribute(i, 'disabled', 'disabled'); setNodeAttribute(i, 'disabled', 'disabled');
var name = e.src().getAttribute('name'); var name = e.src().getAttribute('name');
var id = parseInt(name.substr(-1)); var id = parseInt(name.substr(-1));
var pd = {'view': $('viewid').value, 'change': 1} var pd = {'id': $('viewid').value, 'change': 1}
pd['action_addcolumn_before_' + id] = 1; pd['action_addcolumn_before_' + id] = 1;
sendjsonrequest('viewrework.json.php', pd, 'POST', function(data) { sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {
self.addColumn(id, data); self.addColumn(id, data);
self.checkColumnButtonDisabledState(); self.checkColumnButtonDisabledState();
}, function() { }, function() {
...@@ -290,9 +290,9 @@ function ViewManager() { ...@@ -290,9 +290,9 @@ function ViewManager() {
setNodeAttribute(i, 'disabled', 'disabled'); setNodeAttribute(i, 'disabled', 'disabled');
var name = e.src().getAttribute('name'); var name = e.src().getAttribute('name');
var id = parseInt(name.substr(-1)); var id = parseInt(name.substr(-1));
var pd = {'view': $('viewid').value, 'change': 1} var pd = {'id': $('viewid').value, 'change': 1}
pd['action_removecolumn_column_' + id] = 1; pd['action_removecolumn_column_' + id] = 1;
sendjsonrequest('viewrework.json.php', pd, 'POST', function(data) { sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {
self.removeColumn(id); self.removeColumn(id);
self.checkColumnButtonDisabledState(); self.checkColumnButtonDisabledState();
}, function() { }, function() {
...@@ -648,12 +648,12 @@ function ViewManager() { ...@@ -648,12 +648,12 @@ function ViewManager() {
log(whereTo); log(whereTo);
var pd = { var pd = {
'view': $('viewid').value, 'id': $('viewid').value,
'change': 1, 'change': 1,
'blocktype': getFirstElementByTagAndClassName('input', 'blocktype-radio', self.currentlyMovingObject).value 'blocktype': getFirstElementByTagAndClassName('input', 'blocktype-radio', self.currentlyMovingObject).value
}; };
pd['action_addblocktype_column_' + whereTo['column'] + '_order_' + whereTo['order']] = true; pd['action_addblocktype_column_' + whereTo['column'] + '_order_' + whereTo['order']] = true;
sendjsonrequest('viewrework.json.php', pd, 'POST', function(data) { sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {
var div = DIV(); var div = DIV();
div.innerHTML = data.data; div.innerHTML = data.data;
var blockinstance = getFirstElementByTagAndClassName('div', 'blockinstance', div); var blockinstance = getFirstElementByTagAndClassName('div', 'blockinstance', div);
...@@ -710,9 +710,9 @@ function ViewManager() { ...@@ -710,9 +710,9 @@ function ViewManager() {
// Work out where to send the block to // Work out where to send the block to
var whereTo = self.getBlockinstanceCoordinates(draggable); var whereTo = self.getBlockinstanceCoordinates(draggable);
if (self.origCoordinates.column != whereTo.column || self.origCoordinates.order != whereTo.order) { if (self.origCoordinates.column != whereTo.column || self.origCoordinates.order != whereTo.order) {
var pd = {'view': $('viewid').value, 'change': 1}; var pd = {'id': $('viewid').value, 'change': 1};
pd['action_moveblockinstance_id_' + draggable.id.substr(draggable.id.lastIndexOf('_') + 1) + '_column_' + whereTo['column'] + '_order_' + whereTo['order']] = 1; pd['action_moveblockinstance_id_' + draggable.id.substr(draggable.id.lastIndexOf('_') + 1) + '_column_' + whereTo['column'] + '_order_' + whereTo['order']] = 1;
sendjsonrequest('viewrework.json.php', pd, 'POST'); sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST');
} }
} }
} }
......
...@@ -831,5 +831,7 @@ $string['country.zw'] = 'Zimbabwe'; ...@@ -831,5 +831,7 @@ $string['country.zw'] = 'Zimbabwe';
// general stuff that doesn't really fit anywhere else // general stuff that doesn't really fit anywhere else
$string['system'] = 'System'; $string['system'] = 'System';
$string['preview'] = 'Preview'; $string['preview'] = 'Preview';
$string['done'] = 'Done';
$string['next'] = 'Next';
?> ?>
...@@ -26,13 +26,10 @@ ...@@ -26,13 +26,10 @@
defined('INTERNAL') || die(); defined('INTERNAL') || die();
$string['createviewstep1'] = 'Create View - Step 1 of 4'; $string['createview'] = 'Create View';
$string['editmetadata'] = 'Edit View Information';
$string['createviewstep2'] = 'Create View - Step 2 of 4';
$string['createviewstep3'] = 'Create View - Step 3 of 4';
$string['editview'] = 'Edit View'; $string['editview'] = 'Edit View';
$string['createviewstep4'] = 'Create View - Step 4 of 4';
$string['editaccess'] = 'Edit View Access'; $string['editaccess'] = 'Edit View Access';
$string['editblocks'] = 'Edit blocks';
$string['next'] = 'Next'; $string['next'] = 'Next';
$string['back'] = 'Back'; $string['back'] = 'Back';
$string['createview'] = 'Create View'; $string['createview'] = 'Create View';
...@@ -45,16 +42,6 @@ $string['ownerformat'] = 'Name display format'; ...@@ -45,16 +42,6 @@ $string['ownerformat'] = 'Name display format';
$string['ownerformatdescription'] = 'This field controls what appears in the author field for the template you select in step 2'; $string['ownerformatdescription'] = 'This field controls what appears in the author field for the template you select in step 2';
$string['nochildren'] = 'no artefacts'; $string['nochildren'] = 'no artefacts';
$string['category.all'] = 'All Templates';
$string['category.resume'] = 'Resume Templates';
$string['category.blog'] = 'Blog Templates';
$string['category.gallery'] = 'Gallery Templates';
$string['category.academic'] = 'Academic Templates';
$string['category.professionaldevelopment'] = 'Professional Development Templates';
$string['category.personaldevelopment'] = 'Personal Development Templates';
$string['usethistemplate'] = 'Select this template';
$string['emptylabel'] = 'Click here to enter text for this label'; $string['emptylabel'] = 'Click here to enter text for this label';
$string['empty_block'] = 'Select an artefact from the tree on the left to place here'; $string['empty_block'] = 'Select an artefact from the tree on the left to place here';
...@@ -73,6 +60,7 @@ $string['format.rendermetadata'] = 'Display metadata for this Artefact'; ...@@ -73,6 +60,7 @@ $string['format.rendermetadata'] = 'Display metadata for this Artefact';
$string['addtutors'] = 'Add Tutors'; $string['addtutors'] = 'Add Tutors';
$string['viewcreatedsuccessfully'] = 'View created successfully'; $string['viewcreatedsuccessfully'] = 'View created successfully';
$string['viewsavedsuccessfully'] = 'View saved successfully';
$string['invalidcolumn'] = 'Column %s out of range'; $string['invalidcolumn'] = 'Column %s out of range';
......
...@@ -36,6 +36,8 @@ class View { ...@@ -36,6 +36,8 @@ class View {
private $ctime; private $ctime;
private $mtime; private $mtime;
private $atime; private $atime;
private $startdate;
private $stopdate;
private $submittedto; private $submittedto;
private $title; private $title;
private $description; private $description;
...@@ -44,23 +46,29 @@ class View { ...@@ -44,23 +46,29 @@ class View {
private $artefact_instances; private $artefact_instances;
private $artefact_metadata; private $artefact_metadata;
private $artefact_hierarchy; private $artefact_hierarchy;
private $contents;
private $ownerobj; private $ownerobj;
private $numcolumns; private $numcolumns;
private $columns; private $columns;
private $dirtycolumns; // for when we change stuff private $dirtycolumns; // for when we change stuff
private $tags;
public function __construct($id=0, $data=null) { public function __construct($id=0, $data=null) {
if (!empty($id)) { if (!empty($id)) {
if (empty($data)) { $tempdata = get_record('view','id',$id);
if (!$data = get_record('view','id',$id)) { if (empty($tempdata)) {
throw new ViewNotFoundException("View with id $id not found"); throw new ViewNotFoundException("View with id $id not found");
}
} }
if (!empty($data)) {
$data = array_merge((array)$tempdata, $data);
}
else {
$data = $tempdata; // use what the database has
}
$this->id = $id; $this->id = $id;
} }
else { else {
$this->ctime = time(); $this->ctime = time();
$this->mtime = time();
$this->dirty = true; $this->dirty = true;
} }
...@@ -81,6 +89,9 @@ class View { ...@@ -81,6 +89,9 @@ class View {
if (!property_exists($this, $field)) { if (!property_exists($this, $field)) {
throw new InvalidArgumentException("Field $field wasn't found in class " . get_class($this)); throw new InvalidArgumentException("Field $field wasn't found in class " . get_class($this));
} }
if ($field == 'tags') { // special case
return $this->get_tags();
}
return $this->{$field}; return $this->{$field};
} }
...@@ -97,6 +108,13 @@ class View { ...@@ -97,6 +108,13 @@ class View {
throw new InvalidArgumentException("Field $field wasn't found in class " . get_class($this)); throw new InvalidArgumentException("Field $field wasn't found in class " . get_class($this));
} }
public function get_tags() {
if (!isset($this->tags)) {
$this->tags = get_column('view_tag', 'tag', 'view', $this->get('id'));
}
return $this->tags;
}
/** /**
* View destructor. Calls commit if necessary. * View destructor. Calls commit if necessary.
* *
...@@ -127,12 +145,23 @@ class View { ...@@ -127,12 +145,23 @@ class View {
$fordb->{$k} = db_format_timestamp($v); $fordb->{$k} = db_format_timestamp($v);
} }
} }
db_begin();
if (empty($this->id)) { if (empty($this->id)) {
$this->id = insert_record('view', $fordb, 'id', true); $this->id = insert_record('view', $fordb, 'id', true);
} }
else { else {
update_record('view', $fordb, 'id'); update_record('view', $fordb, 'id');
} }
delete_records('view_tag', 'view', $this->get('id'));
foreach ($this->get_tags() as $tag) {
insert_record('view_tag', (object)array( 'view' => $this->get('id'), 'tag' => $tag));
}
db_commit();
$this->dirty = false; $this->dirty = false;
$this->deleted = false; $this->deleted = false;
} }
...@@ -224,13 +253,6 @@ class View { ...@@ -224,13 +253,6 @@ class View {
} }
public function get_contents() { // lazy setup.
if (!isset($this->contents)) {
$this->contents = get_records_array('view_content', 'view', $this->id);
}
return $this->contents;
}
public function has_artefacts() { public function has_artefacts() {
if ($this->get_artefact_metadata()) { if ($this->get_artefact_metadata()) {
return true; return true;
...@@ -886,4 +908,34 @@ class View { ...@@ -886,4 +908,34 @@ class View {
} }
} }
/**
* display format for author names in views - firstname
*/
define('FORMAT_NAME_FIRSTNAME', 1);
/**
* display format for author names in views - lastname
*/
define('FORMAT_NAME_LASTNAME', 2);
/**
* display format for author names in views - firstname lastname
*/
define('FORMAT_NAME_FIRSTNAMELASTNAME', 3);
/**
* display format for author names in views - preferred name
*/
define('FORMAT_NAME_PREFERREDNAME', 4);
/**
* display format for author names in views - student id
*/
define('FORMAT_NAME_STUDENTID', 5);
/**
* display format for author names in views - obeys display_name
*/
define('FORMAT_NAME_DISPLAYNAME', 6);
?> ?>
...@@ -165,7 +165,7 @@ forEach(potentialPresets, function(preset) { ...@@ -165,7 +165,7 @@ forEach(potentialPresets, function(preset) {
// Left hand side // Left hand side
var searchTable = new TableRenderer( var searchTable = new TableRenderer(
'results', 'results',
'create4.json.php', 'access.json.php',
[ [
undefined, undefined, undefined undefined, undefined, undefined
] ]
......
<ul> <ul>
{foreach from=$categories item=category} {foreach from=$categories item=category}
<li class="{$category.class}"><a href="{$WWWROOT}viewrework.php?view={$viewid}&amp;category={$category.name | escape}">{$category.title | escape}</a></li> <li class="{$category.class}"><a href="{$WWWROOT}view/blocks.php?id={$viewid}&amp;c={$category.name | escape}">{$category.title | escape}</a></li>
{/foreach} {/foreach}
</ul> </ul>
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
<h2>{str tag='myviews'}</h2> <h2>{str tag='myviews'}</h2>
<div id="views"> <div id="views">
<div style="text-align:right;"> <div style="text-align:right;">
<input type="button" class="button" value="{str tag="createnewview"}" onclick="window.location='create1.php';" id="createnew"> <form action="{$WWWROOT}view/edit.php" method="GET">
{contextualhelp plugintype='core' pluginname='views' section='createviewbutton'} <input class="button" type="submit" value="{str tag="createnewview"}" id="createnew">
{contextualhelp plugintype='core' pluginname='views' section='createviewbutton'}
</form>
</div> </div>
<table id="viewlist"> <table id="viewlist">
<tbody> <tbody>
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* @package mahara * @package mahara
* @subpackage core * @subpackage core
* @author Nigel McNie <nigel@catalyst.net.nz> * @author Martyn Smith <martyn@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
* *
...@@ -26,176 +26,160 @@ ...@@ -26,176 +26,160 @@
define('INTERNAL', 1); define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/views'); define('MENUITEM', 'myportfolio/views');
define('SECTION_PLUGINTYPE', 'core'); define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view'); define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'edit'); define('SECTION_PAGE', 'edit');
require(dirname(dirname(__FILE__)) . '/init.php'); require(dirname(dirname(__FILE__)) . '/init.php');
define('TITLE', get_string('editview', 'view')); require_once(get_config('docroot') . 'lib/view.php');
require_once('template.php');
$view_id = param_integer('viewid'); $viewid = param_integer('id', 0); // if 0, we're creating a new view
$artefacts = param_variable('template', array()); if (empty($viewid)) {
define('TITLE', get_string('createview', 'view'));
}
else {
define('TITLE', get_string('editview', 'view'));
$view = new View($viewid);
if ($view->get('owner') != $USER->get('id')) {
throw new AccessDeniedException(get_string('canteditdontown', 'view'));
}
}
$view_data = get_record( 'view', 'id', $view_id, 'owner', $USER->get('id')); $heading = TITLE; // for the smarty template
if(!$view_data) { require_once('pieforms/pieform.php');
$SESSION->add_error_msg(get_string('canteditdontown', 'view'));
redirect('/view/');
}
$data = array( $formatstring = '%s (%s)';
'template' => $view_data->template, $ownerformatoptions = array(
'title' => $view_data->title, FORMAT_NAME_FIRSTNAME => sprintf($formatstring, get_string('firstname'), $USER->get('firstname')),
'description' => $view_data->description, FORMAT_NAME_LASTNAME => sprintf($formatstring, get_string('lastname'), $USER->get('lastname')),
'ownerformat' => $view_data->ownerformat, FORMAT_NAME_FIRSTNAMELASTNAME => sprintf($formatstring, get_string('fullname'), full_name())
'artefacts' => array(),
); );
$view_content = get_records_array('view_content', 'view', $view_id); $preferredname = $USER->get('preferredname');
if ($view_content) { if ($preferredname !== '') {
foreach ($view_content as &$label) { $ownerformatoptions[FORMAT_NAME_PREFERREDNAME] = sprintf($formatstring, get_string('preferredname'), $preferredname);
$data['artefacts'][$label->block] = array( }
'value' => $label->content, $studentid = (string)get_field('artefact', 'title', 'owner', $USER->get('id'), 'artefacttype', 'studentid');
); if ($studentid !== '') {
} $ownerformatoptions[FORMAT_NAME_STUDENTID] = sprintf($formatstring, get_string('studentid'), $studentid);
} }
$ownerformatoptions[FORMAT_NAME_DISPLAYNAME] = sprintf($formatstring, get_string('displayname'), display_name($USER));
// @todo need a rule here that prevents stopdate being smaller than startdate
$editview = pieform(array(
'name' => 'editview',
'method' => 'post',
'autofocus' => 'title',
'plugintype' => 'core',
'pluginname' => 'view',
'elements' => array(
'viewid' => array(
'type' => 'hidden',
'value' => $viewid,
),
'title' => array(
'type' => 'text',
'title' => get_string('title','view'),
'defaultvalue' => isset($view) ? $view->get('title') : null,
'rules' => array( 'required' => true ),
'help' => true,
),
'startdate' => array(
'type' => 'calendar',
'title' => get_string('startdate','view'),
'defaultvalue' => isset($view) ? $view->get('startdate') : null,
'caloptions' => array(
'showsTime' => true,
'ifFormat' => '%Y/%m/%d %H:%M'
),
'help' => true,
),
'stopdate' => array(
'type' => 'calendar',
'title' => get_string('stopdate','view'),
'defaultvalue' => isset($view) ? $view->get('stopdate') : null,
'caloptions' => array(
'showsTime' => true,
'ifFormat' => '%Y/%m/%d %H:%M'
),
'help' => true,
),
'description' => array(
'type' => 'wysiwyg',
'title' => get_string('description','view'),
'rows' => 10,
'cols' => 70,
'defaultvalue' => isset($view) ? $view->get('description') : null,
'help' => true,
),
'tags' => array(
'type' => 'tags',
'title' => get_string('tags'),
'description' => get_string('tagsdesc'),
'defaultvalue' => isset($view) ? $view->get('tags') : null,
'help' => true,
),
'ownerformat' => array(
'type' => 'select',
'title' => get_string('ownerformat','view'),
'description' => get_string('ownerformatdescription','view'),
'options' => $ownerformatoptions,
'defaultvalue' => isset($view) ? $view->get('ownerformat') : FORMAT_NAME_DISPLAYNAME,
'rules' => array('required' => true),
'help' => true,
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(isset($view) ? get_string('save') : get_string('next'), get_string('cancel')),
),
),
));
$view_artefact = get_records_array('view_artefact', 'view', $view_id); function editview_validate(Pieform $form, $values) {
if ($view_artefact) { if ($values['startdate'] && $values['stopdate'] && $values['startdate'] > $values['stopdate']) {
foreach ($view_artefact as &$artefact) { $form->set_error('startdate', get_string('startdatemustbebeforestopdate', 'view'));
if (isset($data['artefacts'][$artefact->block])) {
if (!is_array($data['artefacts'][$artefact->block]['id'])) {
$data['artefacts'][$artefact->block]['id'] = array($data['artefacts'][$artefact->block]['id']);
}
$data['artefacts'][$artefact->block]['id'][] = $artefact->artefact;
}
else {
$data['artefacts'][$artefact->block] = array(
'id' => $artefact->artefact,
'format' => $artefact->format,
);
}
} }
} }
// @todo load artefacts function editview_cancel_submit() {
redirect('/view');
}
$parsed_template = template_locate($data['template']); function editview_submit(Pieform $form, $values) {
function validate_artefacts(&$artefacts) {