Course description: Remove app_view.php/layout.php code

pull/3733/head
Julio Montoya 4 years ago
parent fea5742fb2
commit 954af2f158
  1. 116
      public/main/course_description/course_description_controller.php
  2. 122
      public/main/course_description/edit.php
  3. 26
      public/main/course_description/layout.php
  4. 106
      public/main/inc/lib/app_view.php

@ -22,7 +22,6 @@ class CourseDescriptionController
public function __construct()
{
$this->toolname = 'course_description';
$this->view = new View($this->toolname);
}
public function getToolbar()
@ -190,12 +189,12 @@ class CourseDescriptionController
api_location($url);
}
} else {
$data['default_description_titles'] = $course_description->get_default_description_title();
$data['default_description_title_editable'] = $course_description->get_default_description_title_editable();
$data['default_description_icon'] = $course_description->get_default_description_icon();
$data['question'] = $course_description->get_default_question();
$data['information'] = $course_description->get_default_information();
$data['description_type'] = $description_type;
$default_description_titles = $course_description->get_default_description_title();
$default_description_title_editable = $course_description->get_default_description_title_editable();
$default_description_icon = $course_description->get_default_description_icon();
$question = $course_description->get_default_question();
$information = $course_description->get_default_information();
$description_type = $description_type;
if (empty($id)) {
// If the ID was not provided, find the first matching description item given the item type
$description = $course_description->get_data_by_description_type($description_type);
@ -213,11 +212,11 @@ class CourseDescriptionController
null,
$session_id
);
$data['description_type'] = $course_description_data['description_type'];
$data['description_title'] = $course_description_data['description_title'];
$data['description_content'] = $course_description_data['description_content'];
$data['progress'] = $course_description_data['progress'];
$data['descriptions'] = $course_description->get_data_by_description_type(
$description_type = $course_description_data['description_type'];
$description_title = $course_description_data['description_title'];
$description_content = $course_description_data['description_content'];
$progress = $course_description_data['progress'];
$descriptions = $course_description->get_data_by_description_type(
$description_type,
null,
$session_id
@ -225,10 +224,99 @@ class CourseDescriptionController
}
// render to the view
$this->view->set_data($data);
/*$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('edit');
$this->view->render();
$this->view->render();*/
if (empty($id)) {
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : '';
if (empty($id)) {
// If the ID was not provided, find the first matching description item given the item type
$course_description = new CourseDescription();
$description = $course_description->get_data_by_description_type($description_type);
if (count($description) > 0) {
$id = $description['id'];
}
// If no corresponding description is found, edit a new one
unset($course_description);
}
}
$original_id = $id;
// display categories
$categories = [];
foreach ($default_description_titles as $id => $title) {
$categories[$id] = $title;
}
$categories[ADD_BLOCK] = get_lang('Other');
// default header title form
$description_type = intval($description_type);
$header = $default_description_titles[$description_type];
if ($description_type >= ADD_BLOCK) {
$header = $default_description_titles[ADD_BLOCK];
}
// display form
$form = new FormValidator(
'course_description',
'POST',
'index.php?action=edit&id='.$original_id.'&description_type='.$description_type.'&'.api_get_cidreq()
);
$form->addElement('header', $header);
$form->addElement('hidden', 'id', $original_id);
$form->addElement('hidden', 'description_type', $description_type);
//$form->addElement('hidden', 'sec_token', $token);
if (api_get_configuration_value('save_titles_as_html')) {
$form->addHtmlEditor(
'title',
get_lang('Title'),
true,
false,
['ToolbarSet' => 'TitleAsHtml']
);
} else {
$form->addText('title', get_lang('Title'));
$form->applyFilter('title', 'html_filter');
}
$form->addHtmlEditor(
'contentDescription',
get_lang('Content'),
true,
false,
[
'ToolbarSet' => 'Basic',
'Width' => '100%',
'Height' => '200',
]
);
$form->addButtonCreate(get_lang('Save'));
$actions = self::getToolbar();
// Set some default values
if (!empty($description_title)) {
$default['title'] = Security::remove_XSS($description_title);
}
if (!empty($description_content)) {
$default['contentDescription'] = Security::remove_XSS($description_content, COURSEMANAGERLOWSECURITY);
}
$default['description_type'] = $description_type;
$form->setDefaults($default);
if (isset($question[$description_type])) {
$message = '<strong>'.get_lang('Help').'</strong><br />';
$message .= $question[$description_type];
Display::addFlash(Display::return_message($message, 'normal', false));
}
$tpl = new Template(get_lang('Description'));
//$tpl->assign('is_allowed_to_edit', $is_allowed_to_edit);
$tpl->assign('actions', $actions);
$tpl->assign('session_id', $session_id);
$tpl->assign('content', $form->returnForm());
$tpl->display_one_col_template();
}
}

@ -1,122 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* View (MVC patter) for editing a course description.
*
* @author Christian Fasanando <christian1827@gmail.com>
*/
// protect a course script
api_protect_course_script(true);
if (empty($id)) {
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : '';
if (empty($id)) {
// If the ID was not provided, find the first matching description item given the item type
$course_description = new CourseDescription();
$description = $course_description->get_data_by_description_type($description_type);
if (count($description) > 0) {
$id = $description['id'];
}
// If no corresponding description is found, edit a new one
unset($course_description);
}
}
$original_id = $id;
if (empty($error)) {
$token = Security::get_token();
}
// display categories
$categories = [];
foreach ($default_description_titles as $id => $title) {
$categories[$id] = $title;
}
$categories[ADD_BLOCK] = get_lang('Other');
$i = 1;
echo '<div class="actions" style="margin-bottom:30px">';
echo '<a href="index.php?'.api_get_cidreq().'">'.
Display::return_icon('back.png', get_lang('Back to').' '.get_lang('Course description'), '', ICON_SIZE_MEDIUM).
'</a>';
ksort($categories);
foreach ($categories as $id => $title) {
if (ADD_BLOCK == $i) {
echo '<a href="index.php?'.api_get_cidreq().'&action=add">'.
Display::return_icon($default_description_icon[$id], $title, '', ICON_SIZE_MEDIUM).'</a>';
break;
} else {
echo '<a href="index.php?action=edit&'.api_get_cidreq().'&description_type='.$id.'">'.
Display::return_icon($default_description_icon[$id], $title, '', ICON_SIZE_MEDIUM).'</a>';
$i++;
}
}
echo '</div>';
// error messages
if (isset($error) && 1 == intval($error)) {
echo Display::return_message(get_lang('The form contains incorrect or incomplete data. Please check your input.'), 'error', false);
}
// default header title form
$description_type = intval($description_type);
$header = $default_description_titles[$description_type];
if ($description_type >= ADD_BLOCK) {
$header = $default_description_titles[ADD_BLOCK];
}
// display form
$form = new FormValidator(
'course_description',
'POST',
'index.php?action=edit&id='.$original_id.'&description_type='.$description_type.'&'.api_get_cidreq()
);
$form->addElement('header', $header);
$form->addElement('hidden', 'id', $original_id);
$form->addElement('hidden', 'description_type', $description_type);
$form->addElement('hidden', 'sec_token', $token);
if (api_get_configuration_value('save_titles_as_html')) {
$form->addHtmlEditor(
'title',
get_lang('Title'),
true,
false,
['ToolbarSet' => 'TitleAsHtml']
);
} else {
$form->addText('title', get_lang('Title'));
$form->applyFilter('title', 'html_filter');
}
$form->addHtmlEditor(
'contentDescription',
get_lang('Content'),
true,
false,
[
'ToolbarSet' => 'Basic',
'Width' => '100%',
'Height' => '200',
]
);
$form->addButtonCreate(get_lang('Save'));
// Set some default values
if (!empty($description_title)) {
$default['title'] = Security::remove_XSS($description_title);
}
if (!empty($description_content)) {
$default['contentDescription'] = Security::remove_XSS($description_content, COURSEMANAGERLOWSECURITY);
}
$default['description_type'] = $description_type;
$form->setDefaults($default);
if (isset($question[$description_type])) {
$message = '<strong>'.get_lang('Help').'</strong><br />';
$message .= $question[$description_type];
Display::addFlash(Display::return_message($message, 'normal', false));
}
$form->display();

@ -1,26 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Layout (principal view) used for structuring other views.
*
* @author Christian Fasanando <christian1827@gmail.com>
*/
// protect a course script
api_protect_course_script(true);
// Header
Display::display_header('');
// Introduction section
Display::display_introduction_section(TOOL_COURSE_DESCRIPTION);
// Tracking
Event::event_access_tool(TOOL_COURSE_DESCRIPTION);
// Display
echo $content;
// Footer
Display::display_footer();

@ -1,106 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class View.
*
* @deprecated use Template class
*/
class View
{
private $data;
private $template;
private $layout;
private $tool_path;
/**
* Constructor, init tool path for rendering.
*
* @deprecated
*
* @param string $toolname tool name (optional)
* @param string $template_path
*/
public function __construct($toolname = '', $template_path = null)
{
if (!empty($toolname)) {
if (isset($template_path)) {
$path = $template_path.$toolname.'/';
} else {
$path = api_get_path(SYS_CODE_PATH).$toolname.'/';
}
if (is_dir($path)) {
$this->tool_path = $path;
} else {
throw new Exception('View::__construct() $path directory does not exist '.$path);
}
}
}
/**
* Set data sent from a controller.
*
* @param array data
*/
public function set_data($data)
{
if (!is_array($data)) {
throw new Exception('View::set_data() $data must to be an array, you have sent a'.gettype($data));
}
$this->data = $data;
}
/**
* Set layout view sent from a controller.
*
* @param string $layout view
*/
public function set_layout($layout)
{
$this->layout = $layout;
}
/**
* Set template view sent from a controller.
*
* @param string $template view
*/
public function set_template($template)
{
$this->template = $template;
}
/**
* Render data to the template and layout views.
*/
public function render()
{
$content = $this->render_template();
$target = $this->tool_path.$this->layout.'.php';
if (file_exists($target)) {
require_once $target;
} else {
throw new Exception('View::render() invalid file path '.$target);
}
}
/**
* It's used into render method for rendering data in the template and layout views.
*
* @return string Rendered template (as HTML, most of the time)
*/
private function render_template()
{
$target = $this->tool_path.$this->template.'.php';
if (file_exists($target)) {
ob_start();
@extract($this->data, EXTR_OVERWRITE); //pass the $this->data array into local scope
require_once $target;
$content = ob_get_clean();
return $content;
} else {
throw new Exception('View::render_template() invalid file path '.$target);
}
}
}
Loading…
Cancel
Save