Minor - format code.

pull/2487/head
jmontoyaa 8 years ago
parent 1f34a8deb1
commit ff1d64a956
  1. 13
      main/gradebook/lib/scoredisplay.class.php
  2. 4
      main/inc/lib/course_description.lib.php
  3. 37
      main/inc/lib/pdf.lib.php
  4. 140
      main/inc/lib/sortable_table.class.php
  5. 46
      main/inc/lib/urlmanager.lib.php
  6. 80
      main/lp/openoffice_text_document.class.php
  7. 92
      plugin/search_course/lib/search_course_widget.class.php
  8. 66
      plugin/vchamilo/views/editinstance_form.php

@ -55,7 +55,10 @@ class ScoreDisplay
if (empty($data[1])) {
$data[1] = "";
}
$portal_displays[$data[0]] = array('score' => $data[0], 'display' => $data[1]);
$portal_displays[$data[0]] = array(
'score' => $data[0],
'display' => $data[1]
);
}
sort($portal_displays);
}
@ -170,7 +173,7 @@ class ScoreDisplay
*/
private function get_current_gradebook_category_id()
{
$tbl_gradebook_category = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$curr_course_code = api_get_course_id();
$curr_session_id = api_get_session_id();
@ -180,7 +183,7 @@ class ScoreDisplay
$session_condition = ' AND session_id = '.$curr_session_id;
}
$sql = 'SELECT id FROM '.$tbl_gradebook_category.'
$sql = 'SELECT id FROM '.$table.'
WHERE course_code = "'.$curr_course_code.'" '.$session_condition;
$rs = Database::query($sql);
$category_id = 0;
@ -252,7 +255,7 @@ class ScoreDisplay
100 => get_lang('GradebookExcellent')
);
$tbl_display = Database::get_main_table(TABLE_MAIN_GRADEBOOK_SCORE_DISPLAY);
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_SCORE_DISPLAY);
foreach ($display as $value => $text) {
$params = array(
'score' => $value,
@ -260,7 +263,7 @@ class ScoreDisplay
'category_id' => $category_id,
'score_color_percent' => 0,
);
Database::insert($tbl_display, $params);
Database::insert($table, $params);
}
}

@ -48,8 +48,8 @@ class CourseDescription
} else {
return array();
}
$t_course_desc = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$sql = "SELECT * FROM $t_course_desc
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$sql = "SELECT * FROM $table
WHERE c_id = $course_id AND session_id = '0'";
$sql_result = Database::query($sql);
$results = array();

@ -18,7 +18,8 @@ class PDF
/**
* Creates the mPDF object
* @param string $pageFormat format A4 A4-L see http://mpdf1.com/manual/index.php?tid=184&searchstring=format
* @param string $pageFormat format A4 A4-L see
* http://mpdf1.com/manual/index.php?tid=184&searchstring=format
* @param string $orientation orientation "P" = Portrait "L" = Landscape
* @param array $params
* @param Template $template
@ -90,8 +91,11 @@ class PDF
*
* @return string
*/
public function html_to_pdf_with_template($content, $saveToFile = false, $returnHtml = false)
{
public function html_to_pdf_with_template(
$content,
$saveToFile = false,
$returnHtml = false
) {
if (empty($this->template)) {
$tpl = new Template('', false, false, false);
} else {
@ -176,7 +180,8 @@ class PDF
* 1 => array('title'=>'Bye','path'=>'file2.html')
* );
* @param string $pdf_name pdf name
* @param string $course_code (if you are using html that are located in the document tool you must provide this)
* @param string $course_code (if you are using html that are located
* in the document tool you must provide this)
* @param bool $print_title add title
* @param bool $complete_style show header and footer if true
* @param bool $addStyle
@ -476,8 +481,10 @@ class PDF
//$document_html= str_replace('src="',$src_http_www, $document_html);
//$document_html= str_replace('temp_template_path', 'src="/main/default_course_document/', $document_html);// restore src templates
api_set_encoding_html($document_html, 'UTF-8'); // The library mPDF expects UTF-8 encoded input data.
$title = api_get_title_html($document_html, 'UTF-8', 'UTF-8'); // TODO: Maybe it is better idea the title to be passed through
// The library mPDF expects UTF-8 encoded input data.
api_set_encoding_html($document_html, 'UTF-8');
// TODO: Maybe it is better idea the title to be passed through
$title = api_get_title_html($document_html, 'UTF-8', 'UTF-8');
// $_GET[] too, as it is done with file name.
// At the moment the title is retrieved from the html document itself.
@ -528,6 +535,7 @@ class PDF
* Gets the watermark from the platform or a course
* @param string course code (optional)
* @param mixed web path of the watermark image, false if there is nothing to return
* @return string
*/
public static function get_watermark($course_code = null)
{
@ -812,11 +820,14 @@ class PDF
* @param integer $courseId The course ID
* @param int $sessionId Optional. The session ID
*/
public function exportFromHtmlToDocumentsArea($htmlContent, $fileName, $courseId, $sessionId = 0)
{
public function exportFromHtmlToDocumentsArea(
$htmlContent,
$fileName,
$courseId,
$sessionId = 0
) {
$userId = api_get_user_id();
$courseInfo = api_get_course_info_by_id($courseId);
$courseDirectory = api_get_path(SYS_COURSE_PATH).$courseInfo['directory'].'/document/';
$docPath = $this->exportFromHtmlToFile(
@ -839,7 +850,13 @@ class PDF
$userId
);
api_item_property_update($courseInfo, TOOL_DOCUMENT, $docId, 'DocumentAdded', $userId);
api_item_property_update(
$courseInfo,
TOOL_DOCUMENT,
$docId,
'DocumentAdded',
$userId
);
Display::addFlash(Display::return_message(get_lang('ItemAdded')));
}

@ -206,10 +206,26 @@ class SortableTable extends HTML_Table
$params['urlVar'] = $this->param_prefix.'page_nr';
$params['currentPage'] = $this->page_nr;
$icon_attributes = array('style' => 'vertical-align: middle;');
$params['prevImg'] = Display:: return_icon('action_prev.png', get_lang('PreviousPage'), $icon_attributes);
$params['nextImg'] = Display:: return_icon('action_next.png', get_lang('NextPage'), $icon_attributes);
$params['firstPageText'] = Display:: return_icon('action_first.png', get_lang('FirstPage'), $icon_attributes);
$params['lastPageText'] = Display:: return_icon('action_last.png', get_lang('LastPage'), $icon_attributes);
$params['prevImg'] = Display:: return_icon(
'action_prev.png',
get_lang('PreviousPage'),
$icon_attributes
);
$params['nextImg'] = Display:: return_icon(
'action_next.png',
get_lang('NextPage'),
$icon_attributes
);
$params['firstPageText'] = Display:: return_icon(
'action_first.png',
get_lang('FirstPage'),
$icon_attributes
);
$params['lastPageText'] = Display:: return_icon(
'action_last.png',
get_lang('LastPage'),
$icon_attributes
);
$params['firstPagePre'] = '';
$params['lastPagePre'] = '';
$params['firstPagePost'] = '';
@ -219,7 +235,10 @@ class SortableTable extends HTML_Table
$query_vars = array_keys($_GET);
$query_vars_needed = array($this->param_prefix.'column', $this->param_prefix.'direction', $this->param_prefix.'per_page');
if (count($this->additional_parameters) > 0) {
$query_vars_needed = array_merge($query_vars_needed, array_keys($this->additional_parameters));
$query_vars_needed = array_merge(
$query_vars_needed,
array_keys($this->additional_parameters)
);
}
$query_vars_exclude = array_diff($query_vars, $query_vars_needed);
$params['excludeVars'] = $query_vars_exclude;
@ -393,23 +412,6 @@ class SortableTable extends HTML_Table
$html .= '<div class="clear"></div>';
if (count($this->form_actions) > 0) {
$script = '<script>
/*<![CDATA[*/
function setCheckbox(value) {
d = document.form_'.$this->table_name.';
for (i = 0; i < d.elements.length; i++) {
if (d.elements[i].type == "checkbox") {
d.elements[i].checked = value;
}
if (value) {
$(d.elements[i]).parentsUntil("tr").parent().addClass("row_selected");
} else {
$(d.elements[i]).parentsUntil("tr").parent().removeClass("row_selected");
}
}
}
/*]]>*/
</script>';
$params = $this->get_sortable_table_param_string().'&amp;'.$this->get_additional_url_paramstring();
$html .= '<form method="post" action="'.api_get_self().'?'.$params.'" name="form_'.$this->table_name.'">';
}
@ -489,23 +491,6 @@ class SortableTable extends HTML_Table
$html .= '<div class="clear"></div>';
if (count($this->form_actions) > 0) {
$script = '<script>
/*<![CDATA[*/
function setCheckbox(value) {
d = document.form_'.$this->table_name.';
for (i = 0; i < d.elements.length; i++) {
if (d.elements[i].type == "checkbox") {
d.elements[i].checked = value;
}
if (value) {
$(d.elements[i]).parentsUntil("tr").parent().addClass("row_selected");
} else {
$(d.elements[i]).parentsUntil("tr").parent().removeClass("row_selected");
}
}
}
/*]]>*/
</script>';
$params = $this->get_sortable_table_param_string().'&amp;'.$this->get_additional_url_paramstring();
$html .= '<form method="post" action="'.api_get_self().'?'.$params.'" name="form_'.$this->table_name.'">';
}
@ -550,11 +535,23 @@ class SortableTable extends HTML_Table
}
$i++;
}
$div .= Display::div($rows, array('class'=>$item_css_class.' '.$this->table_name.'_grid_item', 'style' => $item_css_style));
$div .= Display::div(
$rows,
array(
'class' => $item_css_class.' '.$this->table_name.'_grid_item',
'style' => $item_css_style
)
);
}
}
$html .= Display::div($div, array('class'=>$grid_css_class.' '.$this->table_name.'_grid_container', 'style' => $grid_css_style));
$html .= Display::div(
$div,
array(
'class' => $grid_css_class.' '.$this->table_name.'_grid_container',
'style' => $grid_css_style
)
);
$html .= '<div class="clear"></div>';
return $html;
}
@ -582,9 +579,7 @@ class SortableTable extends HTML_Table
$pager = $this->get_pager();
$offset = $pager->getOffsetByPageId();
$from = $offset[0] - 1;
$table_data = $this->get_table_data($from);
$this->processHeaders();
if (is_array($table_data)) {
@ -605,14 +600,23 @@ class SortableTable extends HTML_Table
}
$this->addRow($row);
if (isset($row['child_of'])) {
$this->setRowAttributes($count, array('class' => 'hidden hidden_'.$row['child_of']), true);
$this->setRowAttributes(
$count,
array('class' => 'hidden hidden_'.$row['child_of']),
true
);
}
$count++;
}
}
if ($this->odd_even_rows_enabled == true) {
$this->altRowAttributes(0, array('class' => 'row_odd'), array('class' => 'row_even'), true);
$this->altRowAttributes(
0,
array('class' => 'row_odd'),
array('class' => 'row_even'),
true
);
}
foreach ($this->th_attributes as $column => $attributes) {
@ -728,7 +732,6 @@ class SortableTable extends HTML_Table
}
$column = $counter;
$param['direction'] = 'ASC';
if ($this->column == $column && $this->direction == 'ASC') {
$param['direction'] = 'DESC';
@ -891,7 +894,8 @@ class SortableTable extends HTML_Table
/**
* Define a list of additional parameters to use in the generated URLs
* <code>$parameters['action'] = 'test'; will be convert in <input type="hidden" name="action" value="test"></code>
* <code>$parameters['action'] = 'test'; will be convert in
* <input type="hidden" name="action" value="test"></code>
* @param array $parameters
*/
public function set_additional_parameters($parameters)
@ -917,6 +921,7 @@ class SortableTable extends HTML_Table
* If you've defined actions, the first element of the given row will be
* converted into a checkbox
* @param array $row A row from the table.
* @return array
*/
public function filter_data($row)
{
@ -970,9 +975,15 @@ class SortableTable extends HTML_Table
* sorted
* @param string $direction In which order should the data be sorted (ASC
* or DESC)
* @return array
*/
public function get_table_data($from = null, $per_page = null, $column = null, $direction = null, $sort = null)
{
public function get_table_data(
$from = null,
$per_page = null,
$column = null,
$direction = null,
$sort = null
) {
$data = [];
if (!is_null($this->get_data_function)) {
$data = call_user_func(
@ -1026,10 +1037,19 @@ class SortableTableFromArray extends SortableTable
* Get table data to show on current page
* @see SortableTable#get_table_data
*/
public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = true)
{
public function get_table_data(
$from = 1,
$per_page = null,
$column = null,
$direction = null,
$sort = true
) {
if ($sort) {
$content = TableSort::sort_table($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC);
$content = TableSort::sort_table(
$this->table_data,
$this->column,
$this->direction == 'ASC' ? SORT_ASC : SORT_DESC
);
} else {
$content = $this->table_data;
}
@ -1064,12 +1084,15 @@ class SortableTableFromArray extends SortableTable
class SortableTableFromArrayConfig extends SortableTable
{
/**
* The array containing the columns that will be show i.e $column_show=array('1','0','0'); we will show only the 1st column
* The array containing the columns that will be show
* i.e $column_show=array('1','0','0'); we will show only the 1st column
*/
private $column_show;
/**
*The array containing the real sort column $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column
* The array containing the real sort column
* $column_order=array('1''4','3','4');
* The 2nd column will be order like the 4th column
*/
private $column_order;
/**
@ -1102,7 +1125,14 @@ class SortableTableFromArrayConfig extends SortableTable
$this->column_show = $column_show;
$this->column_order = $column_order;
$this->doc_filter = $doc_filter;
parent::__construct($tablename, null, null, $default_column, $default_items_per_page, $direction);
parent::__construct(
$tablename,
null,
null,
$default_column,
$default_items_per_page,
$direction
);
$this->table_data = $table_data;
}

@ -76,12 +76,12 @@ class UrlManager
$tableUser = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$tableCourse = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$tableSession = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$tableCourseCategory = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
$tableGroup = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USERGROUP);
$sql = "DELETE FROM $tableCourse WHERE access_url_id = ".$id;
Database::query($sql);
/*
* $tableCourseCategory = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
$sql = "DELETE FROM $tableCourseCategory WHERE access_url_id = ".$id;
Database::query($sql);
*/
@ -138,8 +138,8 @@ class UrlManager
* */
public static function url_count()
{
$table_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
$sql = "SELECT count(id) as count_result FROM $table_access_url";
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
$sql = "SELECT count(id) as count_result FROM $table";
$res = Database::query($sql);
$url = Database::fetch_array($res, 'ASSOC');
$result = $url['count_result'];
@ -407,8 +407,8 @@ class UrlManager
* */
public static function relation_url_course_exist($courseId, $urlId)
{
$table_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$sql = "SELECT c_id FROM $table_url_rel_course
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$sql = "SELECT c_id FROM $table
WHERE
access_url_id = ".intval($urlId)." AND
c_id = '".intval($courseId)."'";
@ -448,10 +448,10 @@ class UrlManager
* */
public static function relation_url_session_exist($session_id, $url_id)
{
$table_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$session_id = intval($session_id);
$url_id = intval($url_id);
$sql = "SELECT session_id FROM $table_url_rel_session
$sql = "SELECT session_id FROM $table
WHERE
access_url_id = ".intval($url_id)." AND
session_id = ".Database::escape_string($session_id);
@ -546,7 +546,10 @@ class UrlManager
if (is_array($userGroupList) && is_array($urlList)) {
foreach ($urlList as $urlId) {
foreach ($userGroupList as $userGroupId) {
$count = self::relationUrlUsergroupExist($userGroupId, $urlId);
$count = self::relationUrlUsergroupExist(
$userGroupId,
$urlId
);
if ($count == 0) {
$result = self::addUserGroupToUrl($userGroupId, $urlId);
if ($result) {
@ -775,7 +778,9 @@ class UrlManager
$result = true;
if (!empty($user_id) && !empty($url_id)) {
$sql = "DELETE FROM $table
WHERE user_id = ".intval($user_id)." AND access_url_id = ".intval($url_id);
WHERE
user_id = ".intval($user_id)." AND
access_url_id = ".intval($url_id);
$result = Database::query($sql);
}
@ -832,7 +837,7 @@ class UrlManager
{
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USERGROUP);
$sql = "DELETE FROM $table
WHERE usergroup_id = '".intval($userGroupId)."' AND
WHERE usergroup_id = '".intval($userGroupId)."' AND
access_url_id = ".intval($urlId);
$result = Database::query($sql);
@ -888,14 +893,14 @@ class UrlManager
**/
public static function update_urls_rel_user($user_list, $access_url_id)
{
$table_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$sql = "SELECT user_id
FROM $table_url_rel_user
FROM $table
WHERE access_url_id = ".intval($access_url_id);
$result = Database::query($sql);
$existing_users = array();
//Getting all users
// Getting all users
while ($row = Database::fetch_array($result)) {
$existing_users[] = $row['user_id'];
}
@ -961,7 +966,11 @@ class UrlManager
foreach ($existing_courses as $courseId) {
if (!in_array($courseId, $course_list)) {
self::delete_url_rel_course($courseId, $access_url_id);
CourseManager::update_course_ranking($courseId, 0, $access_url_id);
CourseManager::update_course_ranking(
$courseId,
0,
$access_url_id
);
}
}
}
@ -1078,7 +1087,10 @@ class UrlManager
foreach ($existing_sessions as $existing_session) {
if (!in_array($existing_session, $session_list)) {
if (!empty($existing_session) && !empty($access_url_id)) {
self::delete_url_rel_session($existing_session, $access_url_id);
self::delete_url_rel_session(
$existing_session,
$access_url_id
);
}
}
}
@ -1148,8 +1160,8 @@ class UrlManager
*/
public static function get_url_id($url)
{
$table_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
$sql = "SELECT id FROM $table_access_url
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
$sql = "SELECT id FROM $table
WHERE url = '".Database::escape_string($url)."'";
$result = Database::query($sql);
$access_url_id = Database::result($result, 0, 0);

@ -26,11 +26,11 @@ class OpenOfficeTextDocument extends OpenofficeDocument
/**
* Class constructor. Calls the parent class and initialises the local attribute split_steps
* @param boolean Whether to split steps (true) or make one large page (false)
* @param string Course code
* @param integer Resource ID
* @param integer Creator user id
* @return void
* @param boolean Whether to split steps (true) or make one large page (false)
* @param string Course code
* @param integer Resource ID
* @param integer Creator user id
* @return void
*/
public function __construct(
$split_steps = false,
@ -44,8 +44,8 @@ class OpenOfficeTextDocument extends OpenofficeDocument
/**
* Gets html pages and compose them into a learning path
* @param array The files that will compose the generated learning path. Unused so far.
* @return boolean False if file does not exit. Nothing otherwise.
* @param array The files that will compose the generated learning path. Unused so far.
* @return boolean False if file does not exit. Nothing otherwise.
*/
public function make_lp($files = array())
{
@ -105,9 +105,9 @@ class OpenOfficeTextDocument extends OpenofficeDocument
/**
* Manages dir/chapter splitting
* @param string Chapter header
* @param string Content
* @return void
* @param string Chapter header
* @param string Content
* @return void
*/
public function dealPerChapter($header, $content)
{
@ -183,7 +183,14 @@ class OpenOfficeTextDocument extends OpenofficeDocument
$slide_name = strip_tags(nl2br($item_title));
$slide_name = str_replace(array("\r\n", "\r", "\n"), '', $slide_name);
$slide_name = api_html_entity_decode($slide_name, ENT_COMPAT, api_get_system_encoding());
$previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, '');
$previous = learnpath::add_item(
0,
$previous,
'document',
$document_id,
$slide_name,
''
);
if ($this->first_item == 0) {
$this->first_item = (int) $previous;
}
@ -193,9 +200,9 @@ class OpenOfficeTextDocument extends OpenofficeDocument
/**
* Manages page splitting
* @param string Page header
* @param string Page body
* @return void
* @param string Page header
* @param string Page body
* @return void
*/
public function dealPerPage($header, $body)
{
@ -243,7 +250,14 @@ class OpenOfficeTextDocument extends OpenofficeDocument
$infos = pathinfo($this->filepath);
$slide_name = 'Page '.str_repeat('0', 2 - strlen($key)).$key;
$previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, '');
$previous = learnpath::add_item(
0,
$previous,
'document',
$document_id,
$slide_name,
''
);
if ($this->first_item == 0) {
$this->first_item = (int) $previous;
}
@ -279,7 +293,11 @@ class OpenOfficeTextDocument extends OpenofficeDocument
$xapian_data = array(
SE_COURSE_ID => $courseid,
SE_TOOL_ID => TOOL_LEARNPATH,
SE_DATA => array('lp_id' => $lp_id, 'lp_item' => $previous, 'document_id' => $document_id),
SE_DATA => array(
'lp_id' => $lp_id,
'lp_item' => $previous,
'document_id' => $document_id
),
SE_USER => (int) api_get_user_id(),
);
$ic_slide->xapian_data = serialize($xapian_data);
@ -291,7 +309,15 @@ class OpenOfficeTextDocument extends OpenofficeDocument
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
$sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, ref_id_second_level, search_did)
VALUES (NULL , \'%s\', \'%s\', %s, %s, %s)';
$sql = sprintf($sql, $tbl_se_ref, api_get_course_id(), TOOL_LEARNPATH, $lp_id, $previous, $did);
$sql = sprintf(
$sql,
$tbl_se_ref,
api_get_course_id(),
TOOL_LEARNPATH,
$lp_id,
$previous,
$did
);
Database::query($sql);
}
}
@ -301,7 +327,7 @@ class OpenOfficeTextDocument extends OpenofficeDocument
/**
* Returns additional Java command parameters
* @return string The additional parameters to be used in the Java call
* @return string The additional parameters to be used in the Java call
*/
public function add_command_parameters()
{
@ -310,9 +336,9 @@ class OpenOfficeTextDocument extends OpenofficeDocument
/**
* Formats a page content by reorganising the HTML code a little
* @param string Page header
* @param string Page content
* @return string Formatted page content
* @param string Page header
* @param string Page content
* @return string Formatted page content
*/
public function format_page_content($header, $content)
{
@ -350,8 +376,16 @@ class OpenOfficeTextDocument extends OpenofficeDocument
$content = str_replace($images[0][$key], $picture_resized, $content);
}
} elseif ($img_width > $max_width - 10) {
$picture_resized = str_ireplace('width='.$img_width, 'width="'.($max_width - 10).'"', $images[0][$key]);
$content = str_replace($images[0][$key], $picture_resized, $content);
$picture_resized = str_ireplace(
'width='.$img_width,
'width="'.($max_width - 10).'"',
$images[0][$key]
);
$content = str_replace(
$images[0][$key],
$picture_resized,
$content
);
}
}

@ -1,5 +1,6 @@
<?php
/* For license terms, see /license.txt */
require_once __DIR__.'/register_course_widget.class.php';
/**
@ -54,9 +55,8 @@ class SearchCourseWidget
*
* @return bool
*/
function is_homepage()
public function is_homepage()
{
$url = self::server('REQUEST_URI');
$url = explode('?', $url);
$url = reset($url);
@ -74,9 +74,8 @@ class SearchCourseWidget
*
* @return bool
*/
function is_user_portal()
public function is_user_portal()
{
$url = self::server('REQUEST_URI');
$url = explode('?', $url);
$url = reset($url);
@ -93,7 +92,7 @@ class SearchCourseWidget
/**
*
*/
function accept()
public function accept()
{
return $this->is_homepage() || $this->is_user_portal();
}
@ -106,10 +105,9 @@ class SearchCourseWidget
*
* Search results
*/
function run()
public function run()
{
if (!$this->accept())
{
if (!$this->accept()) {
return;
}
$this->display_header();
@ -120,21 +118,15 @@ class SearchCourseWidget
$action = self::get('action');
$has_content = !empty($search_term) || !empty($action);
if ($has_content)
{
if ($has_content) {
echo '<div class="list">';
}
else
{
} else {
echo '<div>';
}
if (RegisterCourseWidget::factory()->run())
{
if (RegisterCourseWidget::factory()->run()) {
$result = true;
}
else
{
} else {
$result = $this->action_display();
}
@ -144,12 +136,11 @@ class SearchCourseWidget
return $result;
}
function get_url($action = '')
public function get_url($action = '')
{
$self = $_SERVER['PHP_SELF'];
$parameters = array();
if ($action)
{
if ($action) {
$parameters[self::PARAM_ACTION] = $action;
}
$parameters = implode('&', $parameters);
@ -160,13 +151,12 @@ class SearchCourseWidget
/**
* Handle the display action
*/
function action_display()
public function action_display()
{
global $charset;
$search_term = self::post('search_term');
if ($search_term)
{
if ($search_term) {
$search_result_for_label = self::get_lang('SearchResultsFor');
$search_term_html = htmlentities($search_term, ENT_QUOTES, $charset);
echo "<h5>$search_result_for_label $search_term_html</h5>";
@ -177,7 +167,7 @@ class SearchCourseWidget
return true;
}
function display_header()
public function display_header()
{
$search_course_label = self::get_lang('SearchCourse');
echo <<<EOT
@ -187,7 +177,7 @@ class SearchCourseWidget
EOT;
}
function display_footer()
public function display_footer()
{
echo '</div></div>';
}
@ -195,10 +185,9 @@ EOT;
/**
* Display the search course form.
*/
function display_form()
public function display_form()
{
global $stok;
$search_label = self::get_lang('_search');
$self = api_get_self();
$search_term = self::post('search_term');
@ -218,16 +207,15 @@ EOT;
* @param array $courses
* @return bool
*/
function display_list($courses)
public function display_list($courses)
{
if (empty($courses)) {
return false;
}
$user_courses = $this->retrieve_user_courses();
$display_coursecode = (api_get_setting('display_coursecode_in_courselist') == 'true');
$display_teacher = (api_get_setting('display_teacher_in_courselist') == 'true');
$display_coursecode = api_get_setting('display_coursecode_in_courselist') == 'true';
$display_teacher = api_get_setting('display_teacher_in_courselist') == 'true';
echo '<table cellpadding="4">';
foreach ($courses as $key => $course) {
@ -269,14 +257,13 @@ EOT;
* @param array $user_courses
* @return bool
*/
function display_subscribe_icon($current_course, $user_courses)
public function display_subscribe_icon($current_course, $user_courses)
{
global $stok;
//Already subscribed
$code = $current_course['code'];
if (isset($user_courses[$code]))
{
if (isset($user_courses[$code])) {
echo self::get_lang('AlreadySubscribed');
return false;
}
@ -322,21 +309,17 @@ EOT;
* @param string $search_term
* @return array
*/
function retrieve_courses($search_term)
public function retrieve_courses($search_term)
{
if (empty($search_term))
{
if (empty($search_term)) {
return array();
}
$search_term = Database::escape_string($search_term);
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
if (api_is_anonymous())
{
if (api_is_anonymous()) {
$course_fiter = 'visibility = '.COURSE_VISIBILITY_OPEN_WORLD;
}
else
{
} else {
$course_fiter = 'visibility = '.COURSE_VISIBILITY_OPEN_WORLD.' OR ';
$course_fiter .= 'visibility = '.COURSE_VISIBILITY_OPEN_PLATFORM.' OR ';
$course_fiter .= '(visibility = '.COURSE_VISIBILITY_REGISTERED.' AND subscribe = 1)';
@ -372,10 +355,9 @@ EOT;
* @param int $user_id
* @return array
*/
function retrieve_user_courses($user_id = null)
public function retrieve_user_courses($user_id = null)
{
if (is_null($user_id))
{
if (is_null($user_id)) {
global $_user;
$user_id = $_user['user_id'];
}
@ -385,11 +367,11 @@ EOT;
$user_id = intval($user_id);
$sql_select_courses = "SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr,
course.title i, course.tutor_name t, course.directory dir, course_rel_user.status status,
course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
FROM $course_table course, $user_course_table course_rel_user
WHERE course.id = course_rel_user.c_id
AND course_rel_user.user_id = $user_id
ORDER BY course_rel_user.sort ASC";
course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
FROM $course_table course, $user_course_table course_rel_user
WHERE course.id = course_rel_user.c_id
AND course_rel_user.user_id = $user_id
ORDER BY course_rel_user.sort ASC";
$result = array();
$resultset = Database::query($sql_select_courses);
while ($row = Database::fetch_array($resultset)) {
@ -421,10 +403,9 @@ EOT;
* @param array $courses
* @return array
*/
function filter_out_user_courses($courses)
public function filter_out_user_courses($courses)
{
if (empty($courses))
{
if (empty($courses)) {
return $courses;
}
@ -432,8 +413,7 @@ EOT;
$user_id = $_user['user_id'];
$user_courses = $this->retrieve_user_courses($user_id);
foreach ($user_courses as $key => $value)
{
foreach ($user_courses as $key => $value) {
unset($courses[$key]);
}
return $courses;

@ -27,7 +27,13 @@ abstract class ChamiloForm
$attributes = array('style' => 'width: 60%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;'));
// $this->_form = new FormValidator($mode.'_instance', 'post', $returnurl, '', $attributes, true);
$this->_form = new FormValidator($mode.'_instance', 'post', $returnurl, '', $attributes);
$this->_form = new FormValidator(
$mode.'_instance',
'post',
$returnurl,
'',
$attributes
);
}
public abstract function definition();
@ -348,9 +354,21 @@ class InstanceForm extends ChamiloForm
$form->addElement('hidden', 'registeronly');
$form->addHeader($plugin->get_lang('hostdefinition'));
$form->addText('sitename', [$plugin->get_lang('sitename'), $plugin->get_lang('SiteNameExample')]);
$form->addText(
'sitename',
[
$plugin->get_lang('sitename'),
$plugin->get_lang('SiteNameExample')
]
);
$form->applyFilter('sitename', 'trim');
$form->addText('institution', [$plugin->get_lang('institution'), $plugin->get_lang('InstitutionExample')]);
$form->addText(
'institution',
[
$plugin->get_lang('institution'),
$plugin->get_lang('InstitutionExample')
]
);
$form->applyFilter('institution', 'trim');
// Host's name.
@ -385,11 +403,21 @@ class InstanceForm extends ChamiloForm
$form->addElement('header', $plugin->get_lang('dbgroup'));
// Database host.
$form->addElement('text', 'db_host', $this->_plugin->get_lang('dbhost'), array('id' => 'id_vdbhost'));
$form->addElement(
'text',
'db_host',
$this->_plugin->get_lang('dbhost'),
array('id' => 'id_vdbhost')
);
$form->applyFilter('db_host', 'trim');
// Database login.
$form->addElement('text', 'db_user', $this->_plugin->get_lang('dbuser'), array('id' => 'id_vdbuser'));
$form->addElement(
'text',
'db_user',
$this->_plugin->get_lang('dbuser'),
array('id' => 'id_vdbuser')
);
$form->applyFilter('db_user', 'trim');
// Database password.
@ -401,7 +429,12 @@ class InstanceForm extends ChamiloForm
);
// Database name.
$form->addText('main_database', [$plugin->get_lang('maindatabase'), $plugin->get_lang('DatabaseDescription')]);
$form->addText('main_database',
[
$plugin->get_lang('maindatabase'),
$plugin->get_lang('DatabaseDescription')
]
);
// Button for testing database connection.
$form->addElement(
@ -478,10 +511,19 @@ class InstanceForm extends ChamiloForm
}
}
$form->addButtonSave($this->_plugin->get_lang('savechanges'), 'submitbutton');
$form->addButtonSave(
$this->_plugin->get_lang('savechanges'),
'submitbutton'
);
// Rules
$form->addRule('sitename', $this->_plugin->get_lang('sitenameinputerror'), 'required', null, 'client');
$form->addRule(
'sitename',
$this->_plugin->get_lang('sitenameinputerror'),
'required',
null,
'client'
);
$form->addRule(
'institution',
$this->_plugin->get_lang('institutioninputerror'),
@ -490,7 +532,13 @@ class InstanceForm extends ChamiloForm
'client'
);
$form->addRule('root_web', $this->_plugin->get_lang('rootwebinputerror'), 'required', null, 'client');
$form->addRule(
'root_web',
$this->_plugin->get_lang('rootwebinputerror'),
'required',
null,
'client'
);
$form->addRule(
'main_database',
$this->_plugin->get_lang('databaseinputerror'),

Loading…
Cancel
Save