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() {
var queryString = parseQueryString(i.href.substr(i.href.indexOf('?')));
removeElementClass(getFirstElementByTagAndClassName('li', 'current', 'category-list'), '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;
self.makeBlockTypesDraggable();
});
......@@ -221,9 +221,9 @@ function ViewManager() {
connect(button, 'onclick', function(e) {
setNodeAttribute(button, 'disabled', 'disabled');
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;
sendjsonrequest('viewrework.json.php', pd, 'POST', function(data) {
sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {
removeElement(getFirstParentByTagAndClassName(button, 'div', 'blockinstance'));
removeNodeAttribute(button, 'disabled');
}, function() {
......@@ -257,9 +257,9 @@ function ViewManager() {
setNodeAttribute(i, 'disabled', 'disabled');
var name = e.src().getAttribute('name');
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;
sendjsonrequest('viewrework.json.php', pd, 'POST', function(data) {
sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {
self.addColumn(id, data);
self.checkColumnButtonDisabledState();
}, function() {
......@@ -290,9 +290,9 @@ function ViewManager() {
setNodeAttribute(i, 'disabled', 'disabled');
var name = e.src().getAttribute('name');
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;
sendjsonrequest('viewrework.json.php', pd, 'POST', function(data) {
sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {
self.removeColumn(id);
self.checkColumnButtonDisabledState();
}, function() {
......@@ -648,12 +648,12 @@ function ViewManager() {
log(whereTo);
var pd = {
'view': $('viewid').value,
'id': $('viewid').value,
'change': 1,
'blocktype': getFirstElementByTagAndClassName('input', 'blocktype-radio', self.currentlyMovingObject).value
};
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();
div.innerHTML = data.data;
var blockinstance = getFirstElementByTagAndClassName('div', 'blockinstance', div);
......@@ -710,9 +710,9 @@ function ViewManager() {
// Work out where to send the block to
var whereTo = self.getBlockinstanceCoordinates(draggable);
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;
sendjsonrequest('viewrework.json.php', pd, 'POST');
sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST');
}
}
}
......
......@@ -831,5 +831,7 @@ $string['country.zw'] = 'Zimbabwe';
// general stuff that doesn't really fit anywhere else
$string['system'] = 'System';
$string['preview'] = 'Preview';
$string['done'] = 'Done';
$string['next'] = 'Next';
?>
......@@ -26,13 +26,10 @@
defined('INTERNAL') || die();
$string['createviewstep1'] = 'Create View - Step 1 of 4';
$string['editmetadata'] = 'Edit View Information';
$string['createviewstep2'] = 'Create View - Step 2 of 4';
$string['createviewstep3'] = 'Create View - Step 3 of 4';
$string['createview'] = 'Create View';
$string['editview'] = 'Edit View';
$string['createviewstep4'] = 'Create View - Step 4 of 4';
$string['editaccess'] = 'Edit View Access';
$string['editblocks'] = 'Edit blocks';
$string['next'] = 'Next';
$string['back'] = 'Back';
$string['createview'] = 'Create View';
......@@ -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['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['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';
$string['addtutors'] = 'Add Tutors';
$string['viewcreatedsuccessfully'] = 'View created successfully';
$string['viewsavedsuccessfully'] = 'View saved successfully';
$string['invalidcolumn'] = 'Column %s out of range';
......
......@@ -36,6 +36,8 @@ class View {
private $ctime;
private $mtime;
private $atime;
private $startdate;
private $stopdate;
private $submittedto;
private $title;
private $description;
......@@ -44,23 +46,29 @@ class View {
private $artefact_instances;
private $artefact_metadata;
private $artefact_hierarchy;
private $contents;
private $ownerobj;
private $numcolumns;
private $columns;
private $dirtycolumns; // for when we change stuff
private $tags;
public function __construct($id=0, $data=null) {
if (!empty($id)) {
if (empty($data)) {
if (!$data = get_record('view','id',$id)) {
$tempdata = get_record('view','id',$id);
if (empty($tempdata)) {
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;
}
else {
$this->ctime = time();
$this->mtime = time();
$this->dirty = true;
}
......@@ -81,6 +89,9 @@ class View {
if (!property_exists($this, $field)) {
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};
}
......@@ -97,6 +108,13 @@ class View {
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.
*
......@@ -127,12 +145,23 @@ class View {
$fordb->{$k} = db_format_timestamp($v);
}
}
db_begin();
if (empty($this->id)) {
$this->id = insert_record('view', $fordb, 'id', true);
}
else {
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->deleted = false;
}
......@@ -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() {
if ($this->get_artefact_metadata()) {
return true;
......@@ -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) {
// Left hand side
var searchTable = new TableRenderer(
'results',
'create4.json.php',
'access.json.php',
[
undefined, undefined, undefined
]
......
<ul>
{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}
</ul>
......@@ -5,8 +5,10 @@
<h2>{str tag='myviews'}</h2>
<div id="views">
<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">
<input class="button" type="submit" value="{str tag="createnewview"}" id="createnew">
{contextualhelp plugintype='core' pluginname='views' section='createviewbutton'}
</form>
</div>
<table id="viewlist">
<tbody>
......
......@@ -18,7 +18,7 @@
*
* @package mahara
* @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
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
......@@ -26,176 +26,160 @@
define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/views');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'edit');
require(dirname(dirname(__FILE__)) . '/init.php');
define('TITLE', get_string('editview', 'view'));
require_once('template.php');
require_once(get_config('docroot') . 'lib/view.php');
$view_id = param_integer('viewid');
$artefacts = param_variable('template', array());
$viewid = param_integer('id', 0); // if 0, we're creating a new view
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) {
$SESSION->add_error_msg(get_string('canteditdontown', 'view'));
redirect('/view/');
}
require_once('pieforms/pieform.php');
$data = array(
'template' => $view_data->template,
'title' => $view_data->title,
'description' => $view_data->description,
'ownerformat' => $view_data->ownerformat,
'artefacts' => array(),
$formatstring = '%s (%s)';
$ownerformatoptions = array(
FORMAT_NAME_FIRSTNAME => sprintf($formatstring, get_string('firstname'), $USER->get('firstname')),
FORMAT_NAME_LASTNAME => sprintf($formatstring, get_string('lastname'), $USER->get('lastname')),
FORMAT_NAME_FIRSTNAMELASTNAME => sprintf($formatstring, get_string('fullname'), full_name())
);
$view_content = get_records_array('view_content', 'view', $view_id);
if ($view_content) {
foreach ($view_content as &$label) {
$data['artefacts'][$label->block] = array(
'value' => $label->content,
);
}
$preferredname = $USER->get('preferredname');
if ($preferredname !== '') {
$ownerformatoptions[FORMAT_NAME_PREFERREDNAME] = sprintf($formatstring, get_string('preferredname'), $preferredname);
}
$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);
if ($view_artefact) {
foreach ($view_artefact as &$artefact) {
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,
);
}
function editview_validate(Pieform $form, $values) {
if ($values['startdate'] && $values['stopdate'] && $values['startdate'] > $values['stopdate']) {
$form->set_error('startdate', get_string('startdatemustbebeforestopdate', 'view'));
}
}
// @todo load artefacts
$parsed_template = template_locate($data['template']);
function editview_cancel_submit() {
redirect('/view');
}
function validate_artefacts(&$artefacts) {
global $parsed_template;
function editview_submit(Pieform $form, $values) {
if (isset($parsed_template['parseddata'])) {
$template_data = $parsed_template['parseddata'];
}
else {
$template_data = $parsed_template['cacheddata'];
}
global $USER, $SESSION;
$template_fields = array();
$editing = !empty($values['viewid']);
$view = new View($values['viewid'], $values);
foreach ($template_data as $block) {
if ($block['type'] == 'block') {
$template_fields[$block['data']['id']] = $block['data'];
}
}
foreach ($artefacts as $block => &$data) {
if (!isset($template_fields[$block])) {
unset($artefacts[$block]);
next;
if (empty($editing)) {
$view->set('numcolumns', 3); // default
$view->set('owner', $USER->get('id'));
}
// @todo martyn more validation ;)
$data['type'] = $template_fields[$block]['type'];
else {
$view->set('dirty', true);
}
}
if (param_boolean('submit')) {
validate_artefacts($artefacts);
$data['artefacts'] = $artefacts;
$view->commit();
db_begin();
delete_records('view_content', 'view', $view_id);
delete_records('view_artefact', 'view', $view_id);
$time = db_format_timestamp(time());
foreach ($data['artefacts'] as $block => $blockdata) {
if ($blockdata['type'] == 'label') {
$viewcontent = new StdClass;
$viewcontent->view = $view_id;
$viewcontent->content = $blockdata['value'];
$viewcontent->block = $block;
$viewcontent->ctime = $time;
insert_record('view_content', $viewcontent);
}
else if ($blockdata['type'] == 'artefact') {
$blockdata['id'] = (array)$blockdata['id'];
foreach ($blockdata['id'] as $id) {
$viewartefact = new StdClass;
$viewartefact->view = $view_id;
$viewartefact->artefact = $id;
$viewartefact->block = $block;
$viewartefact->ctime = $time;
$viewartefact->format = $blockdata['format'];
insert_record('view_artefact', $viewartefact);
}
if (empty($editing)) {
$redirecturl = '/view/blocks.php?id=' . $view->get('id') . '&new=1';
}
else {
throw new MaharaException('Unknown block data type, this simply should _not_ happen. Perhaps someone changed step3 and forgot to change this?');
}
$redirecturl = '/view/index.php';
$SESSION->add_ok_msg(get_string('viewsavedsuccessfully', 'view'));
}
db_commit();
activity_occurred('watchlist', (object) array('view' => $view_id,
'subject' => get_string('viewmodified', 'activity')));
redirect($redirecturl);
handle_event('saveview', $view_id);
$SESSION->add_ok_msg(get_string('viewinformationsaved', 'view'));
redirect('/view/');
}
if (param_boolean('cancel')) {
redirect('/view/');
}
$template = template_render($parsed_template, TEMPLATE_RENDER_EDITMODE, array_merge($data, $data['artefacts']), $view_id);
$headers = array();
if (isset($parsed_template['css'])) {
$headers[] = '<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'view/template.css.php?template=' . $data['template'] . '">';
}
$smarty = smarty(
array('collapsabletree', 'move', 'tablerenderer'),
$headers,
array(
'view' => array(
'chooseformat',
'format.listself',
'format.listchildren',
'format.renderfull',
'format.rendermetadata',
'empty_block',
'empty_label',
),
)
);
$smarty->assign('plusicon', theme_get_url('images/plus.png'));
$smarty->assign('minusicon', theme_get_url('images/minus.png'));
$smarty->assign('template', $template);
$smarty->assign('EDITMODE', true);
$smarty->assign('viewid', $view_id);
$smarty->display('view/create3.tpl');
$smarty = smarty();
$smarty->assign('heading', $heading);
$smarty->assign('editview', $editview);
$smarty->display('view/edit.tpl');
?>