Glossary updates see BT#10895

Remove glossary_title and glossary_comment madness.
Add update option when import from csv.
Format code.
Update docs.
ofaj
jmontoyaa 9 years ago
parent 04cd41642c
commit 412e4b567e
  1. 6
      main/glossary/glossary_ajax_request.php
  2. 103
      main/glossary/index.php
  3. 177
      main/inc/lib/glossary.lib.php
  4. 18
      main/inc/lib/internationalization.lib.php
  5. 2
      tests/main/inc/lib/glossary.lib.test.php

@ -46,14 +46,14 @@ if (isset($_POST['glossary_id']) &&
$my_glossary_name = api_convert_encoding($my_glossary_name, $charset, 'UTF-8'); $my_glossary_name = api_convert_encoding($my_glossary_name, $charset, 'UTF-8');
$my_glossary_name = trim($my_glossary_name); $my_glossary_name = trim($my_glossary_name);
$glossary_description = GlossaryManager::get_glossary_term_by_glossary_name( $glossaryInfo = GlossaryManager::get_glossary_term_by_glossary_name(
$my_glossary_name $my_glossary_name
); );
$glossary_description = str_replace( $glossary_description = str_replace(
$path_image_search, $path_image_search,
$path_image, $path_image,
$glossary_description $glossaryInfo['description']
); );
if (is_null($glossary_description) || strlen(trim($glossary_description)) == 0) { if (is_null($glossary_description) || strlen(trim($glossary_description)) == 0) {

@ -63,21 +63,21 @@ switch ($action) {
$form->addElement('header', get_lang('TermAddNew')); $form->addElement('header', get_lang('TermAddNew'));
$form->addElement( $form->addElement(
'text', 'text',
'glossary_title', 'name',
get_lang('TermName'), get_lang('TermName'),
array('id' => 'glossary_title') array('id' => 'glossary_title')
); );
$form->addElement( $form->addElement(
'html_editor', 'html_editor',
'glossary_comment', 'description',
get_lang('TermDefinition'), get_lang('TermDefinition'),
null, null,
array('ToolbarSet' => 'Glossary', 'Height' => '300') array('ToolbarSet' => 'Glossary', 'Height' => '300')
); );
$form->addButtonCreate(get_lang('TermAddButton'), 'SubmitGlossary'); $form->addButtonCreate(get_lang('TermAddButton'), 'SubmitGlossary');
// setting the rules // setting the rules
$form->addRule('glossary_title', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
// The validation or display // The validation or display
if ($form->validate()) { if ($form->validate()) {
$check = Security::check_token('post'); $check = Security::check_token('post');
@ -110,41 +110,46 @@ switch ($action) {
// Setting the form elements // Setting the form elements
$form->addElement('header', get_lang('TermEdit')); $form->addElement('header', get_lang('TermEdit'));
$form->addElement('hidden', 'glossary_id'); $form->addElement('hidden', 'glossary_id');
$form->addElement('text', 'glossary_title', get_lang('TermName')); $form->addElement('text', 'name', get_lang('TermName'));
$form->addElement( $form->addElement(
'html_editor', 'html_editor',
'glossary_comment', 'description',
get_lang('TermDefinition'), get_lang('TermDefinition'),
null, null,
array('ToolbarSet' => 'Glossary', 'Height' => '300') array('ToolbarSet' => 'Glossary', 'Height' => '300')
); );
$element = $form->addElement('text', 'insert_date', get_lang('CreationDate'));
$element->freeze();
$element = $form->addElement('text', 'update_date', get_lang('UpdateDate'));
$element->freeze();
$form->addButtonUpdate(get_lang('TermUpdateButton'), 'SubmitGlossary');
// setting the defaults // setting the defaults
$glossary_data = GlossaryManager::get_glossary_information($_GET['glossary_id']); $glossary_data = GlossaryManager::get_glossary_information($_GET['glossary_id']);
// Date treatment for timezones // Date treatment for timezones
if (!empty($glossary_data['insert_date'])) { if (!empty($glossary_data['insert_date'])) {
$glossary_data['insert_date'] = api_get_local_time($glossary_data['insert_date']); $glossary_data['insert_date'] = Display::tip(
date_to_str_ago($glossary_data['insert_date']),
api_get_local_time($glossary_data['insert_date'])
);
} else { } else {
$glossary_data['insert_date'] = ''; $glossary_data['insert_date'] = '';
} }
if (!empty($glossary_data['update_date'])) { if (!empty($glossary_data['update_date'])) {
$glossary_data['update_date'] = api_get_local_time($glossary_data['update_date']); $glossary_data['update_date'] = Display::tip(
date_to_str_ago($glossary_data['update_date']),
api_get_local_time($glossary_data['update_date'])
);
} else { } else {
$glossary_data['update_date'] = ''; $glossary_data['update_date'] = '';
} }
$form->addLabel(get_lang('CreationDate'), $glossary_data['insert_date']);
$form->addLabel(get_lang('UpdateDate'), $glossary_data['update_date']);
$form->addButtonUpdate(get_lang('TermUpdateButton'), 'SubmitGlossary');
$form->setDefaults($glossary_data); $form->setDefaults($glossary_data);
// setting the rules // setting the rules
$form->addRule('glossary_title', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
// The validation or display // The validation or display
if ($form->validate()) { if ($form->validate()) {
@ -193,7 +198,10 @@ switch ($action) {
); );
$form->addElement('header', '', get_lang('ImportGlossary')); $form->addElement('header', '', get_lang('ImportGlossary'));
$form->addElement('file', 'file', get_lang('ImportCSVFileLocation')); $form->addElement('file', 'file', get_lang('ImportCSVFileLocation'));
$form->addElement('checkbox', 'replace', null, get_lang('DeleteAllGlossaryTerms')); $form->addElement('checkbox', 'replace', null, get_lang('DeleteAllGlossaryTerms'));
$form->addElement('checkbox', 'update', null, get_lang('UpdateExistingGlossaryTerms'));
$form->addButtonImport(get_lang('Import'), 'SubmitImport'); $form->addButtonImport(get_lang('Import'), 'SubmitImport');
$content = $form->returnForm(); $content = $form->returnForm();
@ -201,21 +209,31 @@ switch ($action) {
$content .= '<pre> $content .= '<pre>
<strong>term</strong>;<strong>definition</strong>; <strong>term</strong>;<strong>definition</strong>;
"Hello";"Hola"; "Hello";"Hola";
"Good";"Bueno";</pre>'; "Goodbye";"Adiós";
</pre>';
if ($form->validate()) { if ($form->validate()) {
$termsDeleted = [];
//this is a bad idea //jm //this is a bad idea //jm
if (isset($_POST['replace']) && $_POST['replace']) { if (isset($_POST['replace']) && $_POST['replace']) {
foreach (GlossaryManager::get_glossary_terms() as $term) { foreach (GlossaryManager::get_glossary_terms() as $term) {
if (!GlossaryManager::delete_glossary($term['id'])) { if (!GlossaryManager::delete_glossary($term['id'], false)) {
Display::addFlash( Display::addFlash(
Display::return_message(get_lang("CannotDeleteGlossary") . ':' . $term['id'], 'error') Display::return_message(get_lang("CannotDeleteGlossary") . ':' . $term['id'], 'error')
); );
} else {
$termsDeleted[] = $term['name'];
} }
} }
} }
$updateTerms = isset($_POST['update']) && $_POST['update'] ? true : false;
$data = Import::csv_reader($_FILES['file']['tmp_name']); $data = Import::csv_reader($_FILES['file']['tmp_name']);
$goodList = []; $goodList = [];
$updatedList = [];
$addedList = [];
$badList = []; $badList = [];
$doubles = []; $doubles = [];
$added = []; $added = [];
@ -225,20 +243,22 @@ switch ($action) {
$termsToAdd = []; $termsToAdd = [];
foreach ($data as $item) { foreach ($data as $item) {
$items = [ $items = [
'glossary_title' => $item['term'], 'name' => $item['term'],
'glossary_comment' => $item['definition'] 'description' => $item['definition']
]; ];
$termsToAdd[] = $items; $termsToAdd[] = $items;
$termsPerKey[$item['term']] = $items; $termsPerKey[$item['term']] = $items;
} }
if (empty($termsToAdd)) { if (empty($termsToAdd)) {
Display::return_message(get_lang("NothingToAdd"), 'warning'); Display::addFlash(
Display::return_message(get_lang('NothingToAdd'), 'warning')
);
header('Location: '.$currentUrl); header('Location: '.$currentUrl);
exit; exit;
} }
$repeatItems = array_count_values(array_column($termsToAdd, 'glossary_title')); $repeatItems = array_count_values(array_column($termsToAdd, 'name'));
foreach ($repeatItems as $item => $count) { foreach ($repeatItems as $item => $count) {
if ($count > 1) { if ($count > 1) {
$doubles[] = $item; $doubles[] = $item;
@ -249,19 +269,48 @@ switch ($action) {
foreach ($uniqueTerms as $itemTerm) { foreach ($uniqueTerms as $itemTerm) {
$item = $termsPerKey[$itemTerm]; $item = $termsPerKey[$itemTerm];
$result = GlossaryManager::save_glossary($item, false);
if ($result) { if ($updateTerms) {
$goodList[] = $item['glossary_title']; $glossaryInfo = GlossaryManager::get_glossary_term_by_glossary_name($item['name']);
if (!empty($glossaryInfo)) {
$glossaryInfo['description'] = $item['description'];
GlossaryManager::update_glossary($glossaryInfo, false);
$updatedList[] = $item['name'];
} else {
$result = GlossaryManager::save_glossary($item, false);
if ($result) {
$addedList[] = $item['name'];
} else {
$badList[] = $item['name'];
}
}
} else { } else {
$badList[] = $item['glossary_title']; $result = GlossaryManager::save_glossary($item, false);
if ($result) {
$addedList[] = $item['name'];
} else {
$badList[] = $item['name'];
}
} }
} }
} }
if (count($goodList) > 0) { if (count($termsDeleted) > 0) {
Display::addFlash(
Display::return_message(get_lang("TermDeleted").': '.implode(', ', $termsDeleted))
);
}
if (count($updatedList) > 0) {
Display::addFlash(
Display::return_message(get_lang("TermsUpdated").': '.implode(', ', $updatedList))
);
}
if (count($addedList) > 0) {
Display::addFlash( Display::addFlash(
Display::return_message(get_lang("TermsImported").': '.implode(', ', $goodList)) Display::return_message(get_lang("TermsAdded").': '.implode(', ', $addedList))
); );
} }

@ -7,6 +7,11 @@ use ChamiloSession as Session;
* Class GlossaryManager * Class GlossaryManager
* This library provides functions for the glossary tool. * This library provides functions for the glossary tool.
* Include/require it in your code to use its functionality. * Include/require it in your code to use its functionality.
*
* @author Julio Montoya
* @author Christian Fasanando
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium januari 2009, dokeos 1.8.6
*
* @package chamilo.library * @package chamilo.library
*/ */
class GlossaryManager class GlossaryManager
@ -63,7 +68,7 @@ class GlossaryManager
* @author Isaac Flores <florespaz_isaac@hotmail.com> * @author Isaac Flores <florespaz_isaac@hotmail.com>
* @param string $glossary_name The glossary term name * @param string $glossary_name The glossary term name
* *
* @return string The glossary description * @return array The glossary info
*/ */
public static function get_glossary_term_by_glossary_name($glossary_name) public static function get_glossary_term_by_glossary_name($glossary_name)
{ {
@ -71,33 +76,31 @@ class GlossaryManager
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$sql_filter = api_get_session_condition($session_id); $sql_filter = api_get_session_condition($session_id);
$sql = 'SELECT description FROM '.$glossary_table.' $sql = 'SELECT * FROM '.$glossary_table.'
WHERE WHERE
c_id = '.$course_id.' AND c_id = '.$course_id.' AND
name LIKE trim("'.Database::escape_string($glossary_name).'")'.$sql_filter; name LIKE trim("'.Database::escape_string($glossary_name).'")'.$sql_filter;
$rs = Database::query($sql); $rs = Database::query($sql);
if (Database::num_rows($rs) > 0) { if (Database::num_rows($rs) > 0) {
$row = Database::fetch_array($rs); $row = Database::fetch_array($rs, 'ASSOC');
return $row['description'];
} else {
return ''; return $row;
} }
return [];
} }
/** /**
* This functions stores the glossary in the database * This functions stores the glossary in the database
* *
* @param array Array of title + description (glossary_title => $title, glossary_comment => $comment) * @param array $values Array of title + description (name => $title, description => $comment)
*
* @return mixed Term id on success, false on failure * @return mixed Term id on success, false on failure
* @author Christian Fasanando <christian.fasanando@dokeos.com> *
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
* @version januari 2009, dokeos 1.8.6
*/ */
public static function save_glossary($values, $showMessage = true) public static function save_glossary($values, $showMessage = true)
{ {
if (!is_array($values) || !isset($values['glossary_title'])) { if (!is_array($values) || !isset($values['name'])) {
return false; return false;
} }
@ -111,7 +114,7 @@ class GlossaryManager
$session_id = api_get_session_id(); $session_id = api_get_session_id();
// check if the glossary term already exists // check if the glossary term already exists
if (GlossaryManager::glossary_exists($values['glossary_title'])) { if (GlossaryManager::glossary_exists($values['name'])) {
// display the feedback message // display the feedback message
if ($showMessage) { if ($showMessage) {
Display::addFlash( Display::addFlash(
@ -124,8 +127,8 @@ class GlossaryManager
$params = [ $params = [
'glossary_id' => 0, 'glossary_id' => 0,
'c_id' => api_get_course_int_id(), 'c_id' => api_get_course_int_id(),
'name' => $values['glossary_title'], 'name' => $values['name'],
'description' => $values['glossary_comment'], 'description' => $values['description'],
'display_order' => $max_glossary_item + 1, 'display_order' => $max_glossary_item + 1,
'session_id' => $session_id, 'session_id' => $session_id,
]; ];
@ -160,33 +163,33 @@ class GlossaryManager
* *
* @param array $values an array containing all the form elements * @param array $values an array containing all the form elements
* @return boolean True on success, false on failure * @return boolean True on success, false on failure
* @author Christian Fasanando <christian.fasanando@dokeos.com>
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
* @version januari 2009, dokeos 1.8.6
*/ */
public static function update_glossary($values) public static function update_glossary($values, $showMessage = true)
{ {
// Database table definition // Database table definition
$t_glossary = Database :: get_course_table(TABLE_GLOSSARY); $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
// check if the glossary term already exists // check if the glossary term already exists
if (GlossaryManager::glossary_exists($values['glossary_title'], $values['glossary_id'])) { if (GlossaryManager::glossary_exists($values['name'], $values['glossary_id'])) {
// display the feedback message // display the feedback message
Display::addFlash( if ($showMessage) {
Display::return_message(get_lang('GlossaryTermAlreadyExistsYouShouldEditIt'), 'error') Display::addFlash(
); Display::return_message(get_lang('GlossaryTermAlreadyExistsYouShouldEditIt'), 'error')
);
}
return false; return false;
} else { } else {
$sql = "UPDATE $t_glossary SET $sql = "UPDATE $t_glossary SET
name = '".Database::escape_string($values['glossary_title'])."', name = '".Database::escape_string($values['name'])."',
description = '".Database::escape_string($values['glossary_comment'])."' description = '".Database::escape_string($values['description'])."'
WHERE WHERE
c_id = $course_id AND c_id = $course_id AND
glossary_id = ".intval($values['glossary_id']); glossary_id = ".intval($values['glossary_id']);
$result = Database::query($sql); $result = Database::query($sql);
if ($result === false) { if ($result === false) {
return false; return false;
} }
@ -199,11 +202,12 @@ class GlossaryManager
api_get_user_id() api_get_user_id()
); );
// display the feedback message if ($showMessage) {
Display::addFlash( // display the feedback message
Display::return_message(get_lang('TermUpdated')) Display::addFlash(
); Display::return_message(get_lang('TermUpdated'))
);
}
} }
return true; return true;
@ -212,9 +216,6 @@ class GlossaryManager
/** /**
* Get the maximum display order of the glossary item * Get the maximum display order of the glossary item
* @return integer Maximum glossary display order * @return integer Maximum glossary display order
* @author Christian Fasanando <christian.fasanando@dokeos.com>
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
* @version januari 2009, dokeos 1.8.6
*/ */
public static function get_max_glossary_item() public static function get_max_glossary_item()
{ {
@ -242,8 +243,6 @@ class GlossaryManager
* @param integer $not_id ID to counter-check if the term exists with this ID as well (optional) * @param integer $not_id ID to counter-check if the term exists with this ID as well (optional)
* @return bool True if term exists * @return bool True if term exists
* *
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
* @version januari 2009, dokeos 1.8.6
*/ */
public static function glossary_exists($term, $not_id = '') public static function glossary_exists($term, $not_id = '')
{ {
@ -271,9 +270,8 @@ class GlossaryManager
* Get one specific glossary term data * Get one specific glossary term data
* *
* @param integer $glossary_id ID of the flossary term * @param integer $glossary_id ID of the flossary term
* @return mixed Array(glossary_id,glossary_title,glossary_comment,glossary_display_order) or false on error * @return mixed Array(glossary_id,name,description,glossary_display_order) or false on error
* *
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
*/ */
public static function get_glossary_information($glossary_id) public static function get_glossary_information($glossary_id)
{ {
@ -285,8 +283,8 @@ class GlossaryManager
} }
$sql = "SELECT $sql = "SELECT
g.glossary_id as glossary_id, g.glossary_id as glossary_id,
g.name as glossary_title, g.name as name,
g.description as glossary_comment, g.description as description,
g.display_order as glossary_display_order, g.display_order as glossary_display_order,
ip.insert_date as insert_date, ip.insert_date as insert_date,
ip.lastedit_date as update_date, ip.lastedit_date as update_date,
@ -303,31 +301,37 @@ class GlossaryManager
if ($result === false || Database::num_rows($result) != 1) { if ($result === false || Database::num_rows($result) != 1) {
return false; return false;
} }
return Database::fetch_array($result); return Database::fetch_array($result);
} }
/** /**
* Delete a glossary term (and re-order all the others) * Delete a glossary term (and re-order all the others)
* *
* @param integer The id of the glossary term to delete * @param integer $glossary_id
* @param bool $showMessage
*
* @return bool True on success, false on failure * @return bool True on success, false on failure
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
* @version januari 2009, dokeos 1.8.6
*/ */
public static function delete_glossary($glossary_id) public static function delete_glossary($glossary_id, $showMessage = true)
{ {
// Database table definition // Database table definition
$t_glossary = Database :: get_course_table(TABLE_GLOSSARY); $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
if (empty($glossary_id)) { $glossaryInfo = self::get_glossary_information($glossary_id);
if (empty($glossaryInfo)) {
return false; return false;
} }
$glossary_id = (int) $glossary_id;
$sql = "DELETE FROM $t_glossary $sql = "DELETE FROM $t_glossary
WHERE WHERE
c_id = $course_id AND c_id = $course_id AND
glossary_id='".intval($glossary_id)."'"; glossary_id='".$glossary_id."'";
$result = Database::query($sql); $result = Database::query($sql);
if ($result === false || Database::affected_rows($result) < 1) { if ($result === false || Database::affected_rows($result) < 1) {
return false; return false;
@ -337,7 +341,7 @@ class GlossaryManager
api_item_property_update( api_item_property_update(
api_get_course_info(), api_get_course_info(),
TOOL_GLOSSARY, TOOL_GLOSSARY,
intval($glossary_id), $glossary_id,
'delete', 'delete',
api_get_user_id() api_get_user_id()
); );
@ -345,9 +349,11 @@ class GlossaryManager
// reorder the remaining terms // reorder the remaining terms
GlossaryManager::reorder_glossary(); GlossaryManager::reorder_glossary();
Display::addFlash( if ($showMessage) {
Display::return_message(get_lang('TermDeleted')) Display::addFlash(
); Display::return_message(get_lang('TermDeleted').': '.$glossaryInfo['name'])
);
}
return true; return true;
} }
@ -357,9 +363,8 @@ class GlossaryManager
* the glossary terms * the glossary terms
* @param string View ('table' or 'list'). Optional parameter. * @param string View ('table' or 'list'). Optional parameter.
* Defaults to 'table' and prefers glossary_view from the session by default. * Defaults to 'table' and prefers glossary_view from the session by default.
*
* @return string * @return string
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
* @version januari 2009, dokeos 1.8.6
*/ */
public static function display_glossary($view = 'table') public static function display_glossary($view = 'table')
{ {
@ -372,14 +377,14 @@ class GlossaryManager
// action links // action links
//echo '<div class="actions">'; //echo '<div class="actions">';
$actionsLeft = ''; $actionsLeft = '';
if (api_is_allowed_to_edit(null,true)) { if (api_is_allowed_to_edit(null, true)) {
$actionsLeft .= '<a href="index.php?'.api_get_cidreq().'&action=addglossary&msg=add?'.api_get_cidreq().'">'. $actionsLeft .= '<a href="index.php?'.api_get_cidreq().'&action=addglossary&msg=add?'.api_get_cidreq().'">'.
Display::return_icon('new_glossary_term.png',get_lang('TermAddNew'),'', ICON_SIZE_MEDIUM).'</a>'; Display::return_icon('new_glossary_term.png',get_lang('TermAddNew'),'', ICON_SIZE_MEDIUM).'</a>';
} }
$actionsLeft .= '<a href="index.php?'.api_get_cidreq().'&action=export">'. $actionsLeft .= '<a href="index.php?'.api_get_cidreq().'&action=export">'.
Display::return_icon('export_csv.png',get_lang('ExportGlossaryAsCSV'),'',ICON_SIZE_MEDIUM).'</a>'; Display::return_icon('export_csv.png',get_lang('ExportGlossaryAsCSV'),'',ICON_SIZE_MEDIUM).'</a>';
if (api_is_allowed_to_edit(null,true)) { if (api_is_allowed_to_edit(null, true)) {
$actionsLeft .= '<a href="index.php?'.api_get_cidreq().'&action=import">'. $actionsLeft .= '<a href="index.php?'.api_get_cidreq().'&action=import">'.
Display::return_icon('import_csv.png',get_lang('ImportGlossary'),'',ICON_SIZE_MEDIUM).'</a>'; Display::return_icon('import_csv.png',get_lang('ImportGlossary'),'',ICON_SIZE_MEDIUM).'</a>';
} }
@ -417,7 +422,7 @@ class GlossaryManager
$content = $toolbar; $content = $toolbar;
if (!$view || $view == 'table') { if (!$view || $view === 'table') {
$table = new SortableTable( $table = new SortableTable(
'glossary', 'glossary',
array('GlossaryManager', 'get_number_glossary_terms'), array('GlossaryManager', 'get_number_glossary_terms'),
@ -434,7 +439,7 @@ class GlossaryManager
$content .= $table->return_table(); $content .= $table->return_table();
} }
if ($view == 'list') { if ($view === 'list') {
$content .= GlossaryManager::displayGlossaryList(); $content .= GlossaryManager::displayGlossaryList();
} }
@ -443,9 +448,7 @@ class GlossaryManager
/** /**
* Display the glossary terms in a list * Display the glossary terms in a list
* @return bool True * @return bool true
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
* @version januari 2009, dokeos 1.8.6
*/ */
public static function displayGlossaryList() public static function displayGlossaryList()
{ {
@ -466,8 +469,6 @@ class GlossaryManager
* @param int Session ID filter (optional) * @param int Session ID filter (optional)
* @return integer Count of glossary terms * @return integer Count of glossary terms
* *
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
* @version januari 2009, dokeos 1.8.6
*/ */
public static function get_number_glossary_terms($session_id=0) public static function get_number_glossary_terms($session_id=0)
{ {
@ -499,17 +500,14 @@ class GlossaryManager
/** /**
* Get all the data of a glossary * Get all the data of a glossary
* *
* @param integer From which item * @param int $from From which item
* @param integer Number of items to collect * @param int $number_of_items Number of items to collect
* @param string Name of column on which to order * @param string $column Name of column on which to order
* @param string Whether to sort in ascending (ASC) or descending (DESC) * @param string $direction Whether to sort in ascending (ASC) or descending (DESC)
* @return unknown
* *
* @author Patrick Cool <patrick.cool@ugent.be> * @return array
* @author Julio Montoya fixing this function, adding intvals
* @version januari 2009, dokeos 1.8.6
*/ */
public static function get_glossary_data($from, $number_of_items, $column, $direction) public static function get_glossary_data($from, $number_of_items, $column, $direction)
{ {
$_user = api_get_user_info(); $_user = api_get_user_info();
$view = Session::read('glossary_view'); $view = Session::read('glossary_view');
@ -521,7 +519,7 @@ class GlossaryManager
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
$col2 = " glossary.glossary_id as col2, "; $col2 = " glossary.glossary_id as col2, ";
} else { } else {
$col2 = " "; $col2 = ' ';
} }
//condition for the session //condition for the session
@ -568,7 +566,7 @@ class GlossaryManager
$session_img = api_get_session_image($data['session_id'], $_user['status']); $session_img = api_get_session_image($data['session_id'], $_user['status']);
$array[0] = $data[0] . $session_img; $array[0] = $data[0] . $session_img;
if (!$view || $view == 'table') { if (!$view || $view === 'table') {
$array[1] = str_replace(array('<p>', '</p>'), array('', '<br />'), $data[1]); $array[1] = str_replace(array('<p>', '</p>'), array('', '<br />'), $data[1]);
} else { } else {
$array[1] = $data[1]; $array[1] = $data[1];
@ -587,12 +585,10 @@ class GlossaryManager
* Update action icons column * Update action icons column
* *
* @param integer $glossary_id * @param integer $glossary_id
* @param array Parameters to use to affect links * @param array $url_params Parameters to use to affect links
* @param array The line of results from a query on the glossary table * @param array $row The line of results from a query on the glossary table
* @return string HTML string for the action icons columns
* *
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium * @return string HTML string for the action icons columns
* @version januari 2009, dokeos 1.8.6
*/ */
public static function actions_filter($glossary_id, $url_params, $row) public static function actions_filter($glossary_id, $url_params, $row)
{ {
@ -600,9 +596,7 @@ class GlossaryManager
$return = '<a href="'.api_get_self().'?action=edit_glossary&amp;glossary_id='.$glossary_id.'&'.api_get_cidreq().'&msg=edit">'. $return = '<a href="'.api_get_self().'?action=edit_glossary&amp;glossary_id='.$glossary_id.'&'.api_get_cidreq().'&msg=edit">'.
Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>'; Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>';
$glossary_data = GlossaryManager::get_glossary_information($glossary_id); $glossary_data = GlossaryManager::get_glossary_information($glossary_id);
$glossary_term = $glossary_data['name'];
$glossary_term = $glossary_data['glossary_title'];
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
if ($glossary_data['session_id'] == api_get_session_id()) { if ($glossary_data['session_id'] == api_get_session_id()) {
$return .= '<a href="'.api_get_self().'?action=delete_glossary&amp;glossary_id='.$glossary_id.'&'.api_get_cidreq().'" onclick="return confirmation(\''.$glossary_term.'\');">'. $return .= '<a href="'.api_get_self().'?action=delete_glossary&amp;glossary_id='.$glossary_id.'&'.api_get_cidreq().'" onclick="return confirmation(\''.$glossary_term.'\');">'.
@ -620,26 +614,22 @@ class GlossaryManager
* *
* @return string HTML string including JavaScript * @return string HTML string including JavaScript
* *
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
* @version januari 2009, dokeos 1.8.6
*/ */
public static function javascript_glossary() public static function javascript_glossary()
{ {
return "<script> return "<script>
function confirmation (name) { function confirmation (name) {
if (confirm(\" ".get_lang("TermConfirmDelete")." \"+ name + \" ?\")) if (confirm(\" ".get_lang("TermConfirmDelete")." \"+ name + \" ?\")) {
{return true;} return true;
else } else {
{return false;} return false;
} }
}
</script>"; </script>";
} }
/** /**
* Re-order glossary * Re-order glossary
*
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
* @version januari 2009, dokeos 1.8.6
*/ */
public static function reorder_glossary() public static function reorder_glossary()
{ {
@ -665,9 +655,6 @@ class GlossaryManager
* *
* @param string $direction * @param string $direction
* @param string $glossary_id * @param string $glossary_id
*
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
* @version januari 2009, dokeos 1.8.6
*/ */
public static function move_glossary($direction, $glossary_id) public static function move_glossary($direction, $glossary_id)
{ {
@ -675,7 +662,7 @@ class GlossaryManager
$t_glossary = Database :: get_course_table(TABLE_GLOSSARY); $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
// sort direction // sort direction
if ($direction == 'up') { if ($direction === 'up') {
$sortorder = 'DESC'; $sortorder = 'DESC';
} else { } else {
$sortorder = 'ASC'; $sortorder = 'ASC';
@ -730,6 +717,6 @@ class GlossaryManager
$html .= '</body></html>'; $html .= '</body></html>';
$courseCode = api_get_course_id(); $courseCode = api_get_course_id();
$pdf = new PDF(); $pdf = new PDF();
$pdf->content_to_pdf($html, '', get_lang('Glossary').'_'.$courseCode, $course_code); $pdf->content_to_pdf($html, '', get_lang('Glossary').'_'.$courseCode, $courseCode);
} }
} }

@ -644,15 +644,19 @@ function api_format_date($time, $format = null, $language = null)
* Example: $date = '2008-03-07 15:44:08'; * Example: $date = '2008-03-07 15:44:08';
* date_to_str($date) it will return 3 days, 20 hours * date_to_str($date) it will return 3 days, 20 hours
* The given date should be in the timezone chosen by the user or administrator. Use api_get_local_time() to get it... * The given date should be in the timezone chosen by the user or administrator. Use api_get_local_time() to get it...
* You can use it like this:
* Display::tip(date_to_str_ago($dateInUtc), api_get_local_time($dateInUtc));
*
* @param string $date The string has to be the result of a date function in this format -> date('Y-m-d H:i:s', time());
* @return string $timeZone
* *
* @param string The string has to be the result of a date function in this format -> date('Y-m-d H:i:s', time());
* @return string The difference between the current date and the parameter in a literal way "3 days, 2 hour" *
* @author Julio Montoya * @author Julio Montoya
*/ */
function date_to_str_ago($date, $timeZone = 'UTC') function date_to_str_ago($date, $timeZone = 'UTC')
{ {
if ($date == '0000-00-00 00:00:00') { if ($date === '0000-00-00 00:00:00') {
return ''; return '';
} }
@ -1965,15 +1969,15 @@ function _api_convert_encoding_supports($encoding) {
function apiGetHumanDateTime($date, $showTime = true, $humanForm = false) { function apiGetHumanDateTime($date, $showTime = true, $humanForm = false) {
if ($showTime) { if ($showTime) {
if ($humanForm) { if ($humanForm) {
return $date->format('j M Y H:i:s'); return $date->format('j M Y H:i:s');
} else { } else {
return $date->format('Y-m-d H:i:s'); return $date->format('Y-m-d H:i:s');
} }
} else { } else {
if ($humanForm) { if ($humanForm) {
return $date->format('j M Y'); return $date->format('j M Y');
} else { } else {
return $date->format('Y-m-d'); return $date->format('Y-m-d');
} }
} }
} }

@ -52,7 +52,7 @@ class TestGlossary extends UnitTestCase {
function testGetGlossaryTermByGlossaryName() { function testGetGlossaryTermByGlossaryName() {
$glossary_name = ''; $glossary_name = '';
$res = GlossaryManager::get_glossary_term_by_glossary_name($glossary_name); $res = GlossaryManager::get_glossary_term_by_glossary_name($glossary_name);
$this->assertTrue(is_string($res)); $this->assertTrue(is_array($res));
} }
function testUpdateGlossary() { function testUpdateGlossary() {

Loading…
Cancel
Save