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

view/view.php reworked - all the blocktype and view class changes done in...

view/view.php reworked - all the blocktype and view class changes done in order to support non editable views
parent 1128455d
......@@ -301,6 +301,20 @@ class BlockInstance {
return $smarty->fetch('view/blocktypecontainer.tpl');
}
public function render_viewing() {
safe_require('blocktype', $this->get('blocktype'));
$content = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'render_instance', $this);
$smarty = smarty_core();
$smarty->assign('id', $this->get('id'));
$smarty->assign('title', $this->get('title'));
$smarty->assign('content', $content);
return $smarty->fetch('view/blocktypecontainerviewing.tpl');
}
public function commit() {
if (empty($this->dirty)) {
return;
......
......@@ -84,4 +84,6 @@ $string['addnewblockhere'] = 'Add new block here';
$string['addcolumn'] = 'Add column';
$string['removecolumn'] = 'Remove column';
$string['titleformatted'] = '%s by %s';
?>
......@@ -267,9 +267,6 @@ class View {
return $this->ownerobj;
}
public function render() {
//@ todo new view rendering system!
}
public function delete() {
delete_records('artefact_feedback','view',$this->id);
......@@ -714,12 +711,12 @@ class View {
/**
* Returns the HTML for the columns of this view
*/
public function build_columns() {
public function build_columns($editing=false) {
$numcols = $this->get('numcolumns');
$result = '';
for ($i = 1; $i <= $numcols; $i++) {
$result .= $this->build_column($i);
$result .= $this->build_column($i, $editing);
}
return $result;
......@@ -730,12 +727,17 @@ class View {
*
* @param int $column The column to build
*/
public function build_column($column) {
public function build_column($column, $editing=false) {
$data = $this->get_column_datastructure($column);
$renderfunction = 'render';
if (!$editing) {
$renderfunction = 'render_viewing';
}
$blockcontent = '';
foreach($data['blockinstances'] as $blockinstance) {
$blockcontent .= $blockinstance->render($blockinstance->get('id') == $this->blockinstance_currently_being_configured);
$blockcontent .= $blockinstance->$renderfunction($blockinstance->get('id') == $this->blockinstance_currently_being_configured);
}
$smarty = smarty_core();
......@@ -744,6 +746,9 @@ class View {
$smarty->assign('numcolumns', $this->get('numcolumns'));
$smarty->assign('blockcontent', $blockcontent);
if ($editing) {
return $smarty->fetch('view/columnediting.tpl');
}
return $smarty->fetch('view/column.tpl');
}
......@@ -1089,6 +1094,33 @@ EOF;
private function get_current_max_order($column) {
return get_field('block_instance', 'max("order")', 'column', $column, 'view', $this->get('id'));
}
/**
* This function formats a user's name
* according to their view preference
*
* @return string formatted name
*/
public function formatted_owner() {
$user = $this->get_owner_object();
switch ($this->ownerformat) {
case FORMAT_NAME_FIRSTNAME:
return $user->firstname;
case FORMAT_NAME_LASTNAME:
return $user->lastname;
case FORMAT_NAME_FIRSTNAMELASTNAME:
return $user->firstname . ' ' . $user->lastname;
case FORMAT_NAME_PREFERREDNAME:
return $user->preferredname;
case FORMAT_NAME_STUDENTID:
return $user->studentid;
case FORMAT_NAME_DISPLAYNAME:
default:
return display_name($user);
}
}
}
/**
......
<div id="column_{$column}" class="column columns{$numcolumns}">
<div class="column-header">
{if $column == 1}
<div class="add-column-left">
<input type="submit" class="submit addcolumn" name="action_addcolumn_before_1" value="{str tag='addcolumn' section='view'}">
</div>
{/if}
<div class="remove-column">
<input type="submit" class="submit removecolumn" name="action_removecolumn_column_{$column}" value="{str tag='removecolumn' section='view'}">
</div>
{if $column == $numcolumns}
<div class="add-column-right">
<input type="submit" class="submit addcolumn" name="action_addcolumn_before_{$column+1}" value="{str tag='addcolumn' section='view'}">
</div>
{else}
<div class="add-column-center">
<input type="submit" class="submit addcolumn" name="action_addcolumn_before_{$column+1}" value="{str tag='addcolumn' section='view'}">
</div>
{/if}
</div>
<div class="column-content">
{if !$javascript}
<div class="add-button">
<input type="submit" class="submit newblockhere" name="action_addblocktype_column_{$column}_order_1" value="{str tag='addnewblockhere' section='view'}">
</div>
{/if}
{$blockcontent}
</div>
</div>
......
......@@ -11,9 +11,15 @@
{/foreach}
</h3>
{if $VIEWCONTENT}
{$VIEWCONTENT}
{/if}
<div id="bottom-pane">
<div id="column-container">
{if $VIEWCONTENT}
{$VIEWCONTENT}
{/if}
<div id="clearer">
</div>
</div>
</div>
<div id="publicfeedback">
<table id="feedbacktable">
<thead>
......
......@@ -40,6 +40,9 @@ if (!can_view_view($viewid)) {
$viewbeingwatched = 0;
$title = get_string('titleformatted', 'view', $view->get('title'), $view->formatted_owner());
define('TITLE', $title);
if ($artefactid) {
if (!artefact_in_view($artefactid, $viewid)) {
......@@ -61,7 +64,7 @@ if ($artefactid) {
$content .= $rendered['html'];
$viewhref = 'view.php?view=' . $viewid;
$navlist = array('<a href="' . $viewhref . '">' . $view->get('title') . '</a>');
$navlist = array('<a href="' . $viewhref . '">' . $title . '</a>');
if (!empty($path)) {
$titles = get_records_sql_assoc('
SELECT id,title FROM {artefact}
......@@ -96,10 +99,11 @@ if ($artefactid) {
$jsartefact = $artefactid;
}
else {
$navlist = array($view->get('title'));
define('TITLE', $view->get('title'));
$navlist = array($title);
$jsartefact = 'undefined';
$content = $view->render();
$content = $view->build_columns();
global $USER;
$submittedgroup = $view->get('submittedto');
if ($submittedgroup
......@@ -324,6 +328,9 @@ $smarty = smarty(
'private',
'makeprivate',
),
),
array(
'stylesheets' => array('style/views.css'),
)
);
$smarty->assign('INLINEJAVASCRIPT', $javascript);
......
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