Applied fixed from FlintCI + Codacy

pull/2463/head
root 8 years ago
parent 954b23a95d
commit eff07a3b91
  1. 2
      plugin/notebookteacher/database.php
  2. 2
      plugin/notebookteacher/install.php
  3. 3
      plugin/notebookteacher/lang/english.php
  4. 3
      plugin/notebookteacher/lang/spanish.php
  5. 2
      plugin/notebookteacher/plugin.php
  6. 38
      plugin/notebookteacher/src/index.php
  7. 124
      plugin/notebookteacher/src/notebookteacher.lib.php
  8. 9
      plugin/notebookteacher/src/notebookteacher_plugin.class.php
  9. 2
      plugin/notebookteacher/uninstall.php
  10. 2
      plugin/notebookteacher/update.php

@ -7,7 +7,7 @@
* @package chamilo.plugin.notebookteacher
*/
/**
* Check if script can be called
* Check if script can be called.
*/
if (!function_exists('api_get_path')) {
die('This script must be loaded through the Chamilo plugin installer sequence');

@ -7,7 +7,7 @@
* @package chamilo.plugin.notebookteacher
*/
/**
* Initialization
* Initialization.
*/
require_once __DIR__.'/config.php';
if (!api_is_platform_admin()) {

@ -1,6 +1,7 @@
<?php
$strings['plugin_title'] = "Teacher notes";
$strings['plugin_comment'] = "This plugin allows the teachers of a course to have a shared notebook. Students do not have access.";
$strings['plugin_comment'] = "This plugin allows the teachers of a course to have a shared notebook.
Students do not have access.";
$strings['NotebookTeacher'] = "Teacher notes";
$strings['enable_plugin_notebookteacher'] = "Enable plugin";
$strings['ToolDisabled'] = "The tool is disabled from the administration";

@ -1,6 +1,7 @@
<?php
$strings['plugin_title'] = "Notas profesores";
$strings['plugin_comment'] = "Este plugin permite a los profesores de un curso tener un bloc de notas compartido. Alumnos no tienen acceso.";
$strings['plugin_comment'] = "Este plugin permite a los profesores de un curso tener un bloc de notas compartido.
Alumnos no tienen acceso.";
$strings['NotebookTeacher'] = "Notas profesores";
$strings['enable_plugin_notebookteacher'] = "Activar plugin";
$strings['ToolDisabled'] = "La herramienta está deshabilitada desde la administración";

@ -8,7 +8,7 @@
* @package chamilo.plugin.notebookteacher
*/
/**
* Plugin details (must be present)
* Plugin details (must be present).
*/
require_once __DIR__.'/config.php';
$plugin_info = NotebookTeacherPlugin::create()->get_info();

@ -21,7 +21,7 @@ if ($enable) {
$location = 'index.php?'.api_get_cidreq();
// Additional javascript
$htmlHeadXtra[] = NotebookTeacher::javascript_notebook();
$htmlHeadXtra[] = NotebookTeacher::javascriptNotebook();
$htmlHeadXtra[] = '<script>
function setFocus(){
$("#note_title").focus();
@ -47,11 +47,17 @@ if ($enable) {
// Tool name
if ($action === 'addnote') {
$tool = 'NoteAddNew';
$interbreadcrumb[] = ['url' => 'index.php?'.api_get_cidreq(), 'name' => $plugin->get_lang('NotebookTeacher')];
$interbreadcrumb[] = [
'url' => 'index.php?'.api_get_cidreq(),
'name' => $plugin->get_lang('NotebookTeacher'),
];
}
if ($action === 'editnote') {
$tool = 'ModifyNote';
$interbreadcrumb[] = ['url' => 'index.php?'.api_get_cidreq(), 'name' => $plugin->get_lang('NotebookTeacher')];
$interbreadcrumb[] = [
'url' => 'index.php?'.api_get_cidreq(),
'name' => $plugin->get_lang('NotebookTeacher')
];
}
// Displaying the header
@ -112,9 +118,9 @@ if ($enable) {
} else {
$sql .= " AND session_course_user.status = 0 ";
}
$sql .= $sort_by_first_name ?
' ORDER BY user.firstname, user.lastname' :
' ORDER BY user.lastname, user.firstname';
$sql .= $sort_by_first_name
? ' ORDER BY user.firstname, user.lastname'
: ' ORDER BY user.lastname, user.firstname';
$rs = Database::query($sql);
@ -174,13 +180,13 @@ if ($enable) {
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
$res = NotebookTeacher::save_note($values);
$res = NotebookTeacher::saveNote($values);
if ($res) {
echo Display::return_message(get_lang('NoteAdded'), 'confirmation');
}
}
Security::clear_token();
NotebookTeacher::display_notes();
NotebookTeacher::displayNotes();
} else {
echo '<div class="actions">';
echo '<a href="index.php">'.
@ -195,7 +201,7 @@ if ($enable) {
} elseif ($action === 'editnote' && is_numeric($_GET['notebook_id'])) {
// Action handling: Editing a note
if (!empty($_GET['isStudentView']) || api_is_drh()) {
NotebookTeacher::display_notes();
NotebookTeacher::displayNotes();
exit;
}
@ -301,7 +307,7 @@ if ($enable) {
$form->addButtonUpdate(get_lang('ModifyNote'), 'SubmitNote');
// Setting the defaults
$defaults = NotebookTeacher::get_note_information(Security::remove_XSS($_GET['notebook_id']));
$defaults = NotebookTeacher::getNoteInformation(Security::remove_XSS($_GET['notebook_id']));
$form->setDefaults($defaults);
// Setting the rules
@ -312,13 +318,13 @@ if ($enable) {
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
$res = NotebookTeacher::update_note($values);
$res = NotebookTeacher::updateNote($values);
if ($res) {
echo Display::return_message(get_lang('NoteUpdated'), 'confirmation');
}
}
Security::clear_token();
NotebookTeacher::display_notes();
NotebookTeacher::displayNotes();
} else {
echo '<div class="actions">';
echo '<a href="index.php">'.
@ -331,12 +337,12 @@ if ($enable) {
}
} elseif ($action === 'deletenote' && is_numeric($_GET['notebook_id'])) {
// Action handling: deleting a note
$res = NotebookTeacher::delete_note($_GET['notebook_id']);
$res = NotebookTeacher::deleteNote($_GET['notebook_id']);
if ($res) {
echo Display::return_message(get_lang('NoteDeleted'), 'confirmation');
}
NotebookTeacher::display_notes();
NotebookTeacher::displayNotes();
} elseif (
$action === 'changeview' && in_array($_GET['view'], ['creation_date', 'update_date', 'title'])) {
@ -365,9 +371,9 @@ if ($enable) {
break;
}
$_SESSION['notebook_view'] = $_GET['view'];
NotebookTeacher::display_notes();
NotebookTeacher::displayNotes();
} else {
NotebookTeacher::display_notes();
NotebookTeacher::displayNotes();
}
Display::display_footer();

@ -1,5 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
require_once __DIR__.'/../config.php';
/**
* This class provides methods for the notebook management.
@ -13,14 +15,14 @@ require_once __DIR__.'/../config.php';
class NotebookTeacher
{
/**
* Constructor
* Constructor.
*/
public function __construct()
{
}
/**
* a little bit of javascript to display a prettier warning when deleting a note
* a little bit of javascript to display a prettier warning when deleting a note.
*
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
*
@ -28,7 +30,7 @@ class NotebookTeacher
*
* @return string
*/
public static function javascript_notebook()
public static function javascriptNotebook()
{
return "<script>
function confirmation (name)
@ -42,16 +44,16 @@ class NotebookTeacher
}
/**
* This functions stores the note in the database
* This functions stores the note in the database.
*
* @param array $values
* @param int $userId Optional. The user ID
* @param int $courseId Optional. The course ID
* @param int $sessionId Optional. The session ID
+ * @param int $courseId Optional. The course ID
+ * @param int $sessionId Optional. The session ID
*
* @return bool
*/
public static function save_note($values, $userId = 0, $courseId = 0, $sessionId = 0)
public static function saveNote($values, $userId = 0, $courseId = 0, $sessionId = 0)
{
if (!is_array($values) || empty($values['note_title'])) {
return false;
@ -85,13 +87,13 @@ class NotebookTeacher
}
/**
* @param int $notebook_id
* @param int $notebookId
*
* @return array|mixed
*/
public static function get_note_information($notebook_id)
public static function getNoteInformation($notebookId)
{
if (empty($notebook_id)) {
if (empty($notebookId)) {
return [];
}
@ -106,7 +108,7 @@ class NotebookTeacher
session_id AS session_id,
student_id AS student_id
FROM $tableNotebook
WHERE c_id = $courseId AND id = '".intval($notebook_id)."' ";
WHERE c_id = $courseId AND id = '".intval($notebookId)."' ";
$result = Database::query($sql);
if (Database::num_rows($result) != 1) {
return [];
@ -121,7 +123,7 @@ class NotebookTeacher
*
* @return bool
*/
public static function update_note($values)
public static function updateNote($values)
{
if (!is_array($values) or empty($values['note_title'])) {
return false;
@ -139,7 +141,7 @@ class NotebookTeacher
'session_id' => $sessionId,
'title' => $values['note_title'],
'description' => $values['note_comment'],
'update_date' => api_get_utc_datetime()
'update_date' => api_get_utc_datetime(),
];
Database::update(
@ -148,7 +150,7 @@ class NotebookTeacher
[
'c_id = ? AND id = ?' => [
$courseId,
$values['notebook_id']
$values['notebook_id'],
],
]
);
@ -156,13 +158,13 @@ class NotebookTeacher
}
/**
* @param int $notebook_id
* @param int $notebookId
*
* @return bool
*/
public static function delete_note($notebook_id)
public static function deleteNote($notebookId)
{
if (empty($notebook_id) || $notebook_id != strval(intval($notebook_id))) {
if (empty($notebookId) || $notebookId != strval(intval($notebookId))) {
return false;
}
@ -174,7 +176,7 @@ class NotebookTeacher
$sql = "DELETE FROM $tableNotebook
WHERE
c_id = $courseId AND
id = '".intval($notebook_id)."' AND
id = '".intval($notebookId)."' AND
user_id = '".api_get_user_id()."'";
$result = Database::query($sql);
@ -187,10 +189,10 @@ class NotebookTeacher
/**
* Display notes.
*/
public static function display_notes()
public static function displayNotes()
{
$plugin = NotebookTeacherPlugin::create();
$_user = api_get_user_info();
$userInfo = api_get_user_info();
if (!isset($_GET['direction'])) {
$sortDirection = 'ASC';
$linkSortDirection = 'DESC';
@ -212,12 +214,16 @@ class NotebookTeacher
$courseId = $courseInfo['real_id'];
$currentAccessUrlId = api_get_current_access_url_id();
$sortByfirstName = api_sort_by_first_name();
$type = isset($_REQUEST['type']) ? intval($_REQUEST['type']) : STUDENT;
if (!empty($sessionId)) {
$tableSessionCourseUser = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tableUsers = Database::get_main_table(TABLE_MAIN_USER);
$isWesternNameOrder = api_is_western_name_order();
$sql = "SELECT DISTINCT
user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname")."
user.user_id, ".($isWesternNameOrder
? "user.firstname, user.lastname"
: "user.lastname, user.firstname")."
FROM $tableSessionCourseUser as session_course_user,
$tableUsers as user ";
if (api_is_multiple_url_enabled()) {
@ -236,7 +242,9 @@ class NotebookTeacher
} else {
$sql .= " AND session_course_user.status = 0 ";
}
$sql .= $sortByfirstName ? ' ORDER BY user.firstname, user.lastname' : ' ORDER BY user.lastname, user.firstname';
$sql .= $sortByfirstName
? ' ORDER BY user.firstname, user.lastname'
: ' ORDER BY user.lastname, user.firstname';
$rs = Database::query($sql);
@ -307,11 +315,17 @@ class NotebookTeacher
}
}
echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=creation_date&direction='.$linkSortDirection.'&student_id='.$studentId.'">'.
echo '<a href="index.php?'.
api_get_cidreq().
'&action=changeview&view=creation_date&direction='.$linkSortDirection.'&student_id='.$studentId.'">'.
Display::return_icon('notes_order_by_date_new.png', get_lang('OrderByCreationDate'), '', '32').'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=update_date&direction='.$linkSortDirection.'&student_id='.$studentId.'">'.
echo '<a href="index.php?'.
api_get_cidreq().
'&action=changeview&view=update_date&direction='.$linkSortDirection.'&student_id='.$studentId.'">'.
Display::return_icon('notes_order_by_date_mod.png', get_lang('OrderByModificationDate'), '', '32').'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=title&direction='.$linkSortDirection.'&student_id='.$studentId.'">'.
echo '<a href="index.php?'.
api_get_cidreq().
'&action=changeview&view=title&direction='.$linkSortDirection.'&student_id='.$studentId.'">'.
Display::return_icon('notes_order_by_title.png', get_lang('OrderByTitle'), '', '32').'</a>';
echo '</div>';
@ -364,18 +378,24 @@ class NotebookTeacher
$first = false;
}
// Validation when belongs to a session
$sessionImg = api_get_session_image($row['session_id'], $_user['status']);
$sessionImg = api_get_session_image($row['session_id'], $userInfo['status']);
$updateValue = '';
if ($row['update_date'] <> $row['creation_date']) {
$updateValue = ', '.get_lang('UpdateDate').': '.Display::dateToStringAgoAndLongDate($row['update_date']);
if ($row['update_date'] != $row['creation_date']) {
$updateValue = ', '.get_lang('UpdateDate').': '.
Display::dateToStringAgoAndLongDate($row['update_date']);
}
$userInfo = api_get_user_info($row['user_id']);
$author = ', '.get_lang('Teacher').': '.$userInfo['complete_name'];
if (intval($row['user_id']) == api_get_user_id()) {
$actions = '<a href="'.api_get_self().'?'.api_get_cidreq().'action=editnote&notebook_id='.$row['id'].'">'.
$actions = '<a href="'.
api_get_self().'?'.
api_get_cidreq().'action=editnote&notebook_id='.$row['id'].'">'.
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>';
$actions .= '<a href="'.api_get_self().'?action=deletenote&notebook_id='.$row['id'].'" onclick="return confirmation(\''.$row['title'].'\');">'.
$actions .= '<a href="'.
api_get_self().
'?action=deletenote&notebook_id='.$row['id'].
'" onclick="return confirmation(\''.$row['title'].'\');">'.
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
} else {
$actions = '';
@ -384,7 +404,8 @@ class NotebookTeacher
echo Display::panel(
$row['description'],
$row['title'].$sessionImg.' <div class="pull-right">'.$actions.'</div>',
get_lang('CreationDate').': '.Display::dateToStringAgoAndLongDate($row['creation_date']).$updateValue.$author
get_lang('CreationDate').': '.
Display::dateToStringAgoAndLongDate($row['creation_date']).$updateValue.$author
);
}
} else {
@ -412,21 +433,30 @@ class NotebookTeacher
while ($row = Database::fetch_array($result)) {
// Validation when belongs to a session
$sessionImg = api_get_session_image($row['session_id'], $_user['status']);
$sessionImg = api_get_session_image($row['session_id'], $userInfo['status']);
$updateValue = '';
if ($row['update_date'] <> $row['creation_date']) {
$updateValue = ', '.get_lang('UpdateDate').': '.Display::dateToStringAgoAndLongDate($row['update_date']);
if ($row['update_date'] != $row['creation_date']) {
$updateValue = ', '.get_lang('UpdateDate').': '.
Display::dateToStringAgoAndLongDate($row['update_date']);
}
$userInfo = api_get_user_info($row['user_id']);
$author = ', '.get_lang('Teacher').': '.$userInfo['complete_name'];
if (intval($row['user_id']) == api_get_user_id()) {
$actions = '<a href="'.api_get_self().'?action=editnote&notebook_id='.$row['id'].'&'.api_get_cidreq().'">'.
$actions = '<a href="'.api_get_self().
'?action=editnote&notebook_id='.$row['id'].'&'.api_get_cidreq().'">'.
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>';
$actions .= '<a href="'.api_get_self().'?action=deletenote&notebook_id='.$row['id'].'" onclick="return confirmation(\''.$row['title'].'\');">'.
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
$actions .= '<a href="'.api_get_self().
'?action=deletenote&notebook_id='.$row['id'].
'" onclick="return confirmation(\''.$row['title'].'\');">'.
Display::return_icon(
'delete.png',
get_lang('Delete'),
'',
ICON_SIZE_SMALL
).'</a>';
} else {
$actions = '';
}
@ -434,7 +464,8 @@ class NotebookTeacher
echo Display::panel(
$row['description'],
$row['title'].$sessionImg.' <div class="pull-right">'.$actions.'</div>',
get_lang('CreationDate').': '.Display::dateToStringAgoAndLongDate($row['creation_date']).$updateValue.$author
get_lang('CreationDate').': '.
Display::dateToStringAgoAndLongDate($row['creation_date']).$updateValue.$author
);
}
}
@ -456,20 +487,24 @@ class NotebookTeacher
while ($row = Database::fetch_array($result)) {
// Validation when belongs to a session
$sessionImg = api_get_session_image($row['session_id'], $_user['status']);
$sessionImg = api_get_session_image($row['session_id'], $userInfo['status']);
$updateValue = '';
if ($row['update_date'] <> $row['creation_date']) {
$updateValue = ', '.get_lang('UpdateDate').': '.Display::dateToStringAgoAndLongDate($row['update_date']);
if ($row['update_date'] != $row['creation_date']) {
$updateValue = ', '.get_lang('UpdateDate').': '.
Display::dateToStringAgoAndLongDate($row['update_date']);
}
$userInfo = api_get_user_info($row['user_id']);
$author = ', '.get_lang('Teacher').': '.$userInfo['complete_name'];
if (intval($row['user_id']) == api_get_user_id()) {
$actions = '<a href="'.api_get_self().'?action=editnote&notebook_id='.$row['id'].'&'.api_get_cidreq().'">'.
$actions = '<a href="'.api_get_self().
'?action=editnote&notebook_id='.$row['id'].'&'.api_get_cidreq().'">'.
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>';
$actions .= '<a href="'.api_get_self().'?action=deletenote&notebook_id='.$row['id'].'" onclick="return confirmation(\''.$row['title'].'\');">'.
$actions .= '<a href="'.api_get_self().
'?action=deletenote&notebook_id='.$row['id'].
'" onclick="return confirmation(\''.$row['title'].'\');">'.
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
} else {
$actions = '';
@ -478,7 +513,8 @@ class NotebookTeacher
echo Display::panel(
$row['description'],
$row['title'].$sessionImg.' <div class="pull-right">'.$actions.'</div>',
get_lang('CreationDate').': '.Display::dateToStringAgoAndLongDate($row['creation_date']).$updateValue.$author
get_lang('CreationDate').': '.
Display::dateToStringAgoAndLongDate($row['creation_date']).$updateValue.$author
);
}
}

@ -29,7 +29,6 @@ class NotebookTeacherPlugin extends Plugin
}
/**
*
* @return StaticPlugin
*/
public static function create()
@ -48,7 +47,7 @@ class NotebookTeacherPlugin extends Plugin
$this->install_course_fields_in_all_courses();
$tablesToBeCompared = [
self::TABLE_NOTEBOOKTEACHER
self::TABLE_NOTEBOOKTEACHER,
];
$em = Database::getManager();
$cn = $em->getConnection();
@ -84,11 +83,11 @@ class NotebookTeacherPlugin extends Plugin
$this->uninstall_course_fields_in_all_courses($this->course_settings);
$tablesToBeDeleted = [
TABLE_NOTEBOOKTEACHER
TABLE_NOTEBOOKTEACHER,
];
foreach ($tablesToBeDeleted as $tableToBeDeleted) {
$table = Database::get_main_table($tableToBeDeleted);
$sql = "DROP TABLE IF EXISTS $tableToBeDeleted";
$sql = "DROP TABLE IF EXISTS $table";
Database::query($sql);
}
$this->manageTab(false);
@ -118,7 +117,7 @@ class NotebookTeacherPlugin extends Plugin
copy($srcfile3, $dstfile3);
copy($srcfile4, $dstfile4);
Display::display_header(get_lang(ucfirst($tool)));
Display::display_header(get_lang(ucfirst(self::TABLE_NOTEBOOKTEACHER)));
echo 'Plugin actualizado';
Display::display_footer();
}

@ -8,7 +8,7 @@
* @package chamilo.plugin.notebookteacher
*/
/**
* Queries
* Queries.
*/
require_once __DIR__.'/config.php';
NotebookTeacherPlugin::create()->uninstall();

@ -7,7 +7,7 @@
* @package chamilo.plugin.notebookteacher
*/
/**
* Initialization
* Initialization.
*/
require_once __DIR__ . '/config.php';
if (!api_is_platform_admin()) {

Loading…
Cancel
Save