@ -2,7 +2,9 @@
/* For licensing terms, see /license.txt */
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
use ChamiloSession as Session;
require_once __DIR__.'/../config.php';
require_once __DIR__.'/../config.php';
/**
/**
* This class provides methods for the notebook management.
* This class provides methods for the notebook management.
* Include/require it in your code to use its features.
* Include/require it in your code to use its features.
@ -48,8 +50,8 @@ class NotebookTeacher
*
*
* @param array $values
* @param array $values
* @param int $userId Optional. The user ID
* @param int $userId Optional. The user ID
+ * @param int $courseId Optional. The course ID
* @param int $courseId Optional. The course ID
+ * @param int $sessionId Optional. The session ID
* @param int $sessionId Optional. The session ID
*
*
* @return bool
* @return bool
*/
*/
@ -154,6 +156,7 @@ class NotebookTeacher
],
],
]
]
);
);
return true;
return true;
}
}
@ -196,7 +199,7 @@ class NotebookTeacher
if (!isset($_GET['direction'])) {
if (!isset($_GET['direction'])) {
$sortDirection = 'ASC';
$sortDirection = 'ASC';
$linkSortDirection = 'DESC';
$linkSortDirection = 'DESC';
} else if ($_GET['direction'] == 'ASC') {
} elseif ($_GET['direction'] == 'ASC') {
$sortDirection = 'ASC';
$sortDirection = 'ASC';
$linkSortDirection = 'DESC';
$linkSortDirection = 'DESC';
} else {
} else {
@ -205,7 +208,6 @@ class NotebookTeacher
}
}
$studentId = isset($_GET['student_id']) ? $_GET['student_id'] : null;
$studentId = isset($_GET['student_id']) ? $_GET['student_id'] : null;
$selectStudent = '';
$sessionId = api_get_session_id();
$sessionId = api_get_session_id();
$courseCode = api_get_course_id();
$courseCode = api_get_course_id();
$active = isset($_GET['active']) ? $_GET['active'] : null;
$active = isset($_GET['active']) ? $_GET['active'] : null;
@ -242,9 +244,9 @@ class NotebookTeacher
} else {
} else {
$sql .= " AND session_course_user.status = 0 ";
$sql .= " AND session_course_user.status = 0 ";
}
}
$sql .= $sortByfirstName
$sql .= $sortByfirstName
? ' ORDER BY user.firstname, user.lastname'
? ' ORDER BY user.firstname, user.lastname'
: ' ORDER BY user.lastname, user.firstname';
: ' ORDER BY user.lastname, user.firstname';
$rs = Database::query($sql);
$rs = Database::query($sql);
@ -331,25 +333,28 @@ class NotebookTeacher
echo '< / div > ';
echo '< / div > ';
echo '< div class = "row" > '.$selectStudent.'< / div > ';
echo '< div class = "row" > '.$selectStudent.'< / div > ';
if (!isset($_SESSION['notebook_view']) ||
$view = Session::read('notebook_view');
!in_array($_SESSION['notebook_view'], ['creation_date', 'update_date', 'title'])
if (!isset($view) ||
!in_array($view, ['creation_date', 'update_date', 'title'])
) {
) {
$_SESSION['notebook_view'] = 'creation_date' ;
Session::write('notebook_view', 'creation_date') ;
}
}
$view = Session::read('notebook_view');
// Database table definition
// Database table definition
$tableNotebook = Database::get_main_table(NotebookTeacherPlugin::TABLE_NOTEBOOKTEACHER);
$tableNotebook = Database::get_main_table(NotebookTeacherPlugin::TABLE_NOTEBOOKTEACHER);
if ($_SESSION['notebook_ view'] == 'creation_date' || $_SESSION['notebook_ view'] == 'update_date') {
if ($view == 'creation_date' || $view == 'update_date') {
$orderBy = " ORDER BY ". $_SESSION['notebook_ view']." $sortDirection ";
$orderBy = " ORDER BY $view $sortDirection ";
} else {
} else {
$orderBy = " ORDER BY ". $_SESSION['notebook_ view']." $sortDirection ";
$orderBy = " ORDER BY $view $sortDirection ";
}
}
//condition for the session
//condition for the session
$session_id = api_get_session_id();
$session_id = api_get_session_id();
$conditionSession = api_get_session_condition($session_id);
$conditionSession = api_get_session_condition($session_id);
$condExtra = ( $_SESSION['notebook_ view'] == 'update_date') ? " AND update_date < > ''" : " ";
$condExtra = $view == 'update_date' ? " AND update_date < > ''" : " ";
$courseId = api_get_course_int_id();
$courseId = api_get_course_int_id();
if ($studentId > 0) {
if ($studentId > 0) {
@ -368,11 +373,10 @@ class NotebookTeacher
if (Database::num_rows($result) > 0) {
if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result)) {
while ($row = Database::fetch_array($result)) {
if ($first) {
if ($first) {
$studentText = '';
if ($row['student_id'] > 0) {
if ($row['student_id'] > 0) {
$studentInfo = api_get_user_info($row['student_id']);
$studentInfo = api_get_user_info($row['student_id']);
$studentText = $studentInfo['complete_name'];
$studentText = $studentInfo['complete_name'];
} else {
$studentText = '';
}
}
echo Display::page_subheader($studentText);
echo Display::page_subheader($studentText);
$first = false;
$first = false;
@ -386,7 +390,7 @@ class NotebookTeacher
}
}
$userInfo = api_get_user_info($row['user_id']);
$userInfo = api_get_user_info($row['user_id']);
$author = ', '.get_lang('Teacher').': '.$userInfo['complete_name'];
$author = ', '.get_lang('Teacher').': '.$userInfo['complete_name'];
$actions = '';
if (intval($row['user_id']) == api_get_user_id()) {
if (intval($row['user_id']) == api_get_user_id()) {
$actions = '< a href = "'.
$actions = '< a href = "'.
api_get_self().'?'.
api_get_self().'?'.
@ -397,15 +401,12 @@ class NotebookTeacher
'?action=deletenote& notebook_id='.$row['id'].
'?action=deletenote& notebook_id='.$row['id'].
'" onclick="return confirmation(\''.$row['title'].'\');">'.
'" onclick="return confirmation(\''.$row['title'].'\');">'.
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'< / a > ';
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'< / a > ';
} else {
$actions = '';
}
}
echo Display::panel(
echo Display::panel(
$row['description'],
$row['description'],
$row['title'].$sessionImg.' < div class = "pull-right" > '.$actions.'< / div > ',
$row['title'].$sessionImg.' < div class = "pull-right" > '.$actions.'< / div > ',
get_lang('CreationDate').': '.
get_lang('CreationDate').': '.
Display::dateToStringAgoAndLongDate($row['creation_date']).$updateValue.$author
Display::dateToStringAgoAndLongDate($row['creation_date']).$updateValue.$author
);
);
}
}
} else {
} else {
@ -416,7 +417,6 @@ class NotebookTeacher
foreach ($courseUsersList as $key => $userItem) {
foreach ($courseUsersList as $key => $userItem) {
$studentId = $key;
$studentId = $key;
$studentText = $userItem['firstname'].' '.$userItem['lastname'];
$studentText = $userItem['firstname'].' '.$userItem['lastname'];
$conditionStudent = " AND student_id = $studentId";
$conditionStudent = " AND student_id = $studentId";
$sql = "SELECT * FROM $tableNotebook
$sql = "SELECT * FROM $tableNotebook
@ -431,7 +431,6 @@ class NotebookTeacher
if (Database::num_rows($result) > 0) {
if (Database::num_rows($result) > 0) {
echo Display::page_subheader($studentText);
echo Display::page_subheader($studentText);
while ($row = Database::fetch_array($result)) {
while ($row = Database::fetch_array($result)) {
// Validation when belongs to a session
// Validation when belongs to a session
$sessionImg = api_get_session_image($row['session_id'], $userInfo['status']);
$sessionImg = api_get_session_image($row['session_id'], $userInfo['status']);
$updateValue = '';
$updateValue = '';
@ -446,26 +445,26 @@ class NotebookTeacher
if (intval($row['user_id']) == api_get_user_id()) {
if (intval($row['user_id']) == api_get_user_id()) {
$actions = '< a href = "'.api_get_self().
$actions = '< a href = "'.api_get_self().
'?action=editnote& notebook_id='.$row['id'].'& '.api_get_cidreq().'">'.
'?action=editnote& notebook_id='.$row['id'].'& '.api_get_cidreq().'">'.
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'< / a > ';
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'< / a > ';
$actions .= '< a href = "'.api_get_self().
$actions .= '< a href = "'.api_get_self().
'?action=deletenote& notebook_id='.$row['id'].
'?action=deletenote& notebook_id='.$row['id'].
'" onclick="return confirmation(\''.$row['title'].'\');">'.
'" onclick="return confirmation(\''.$row['title'].'\');">'.
Display::return_icon(
Display::return_icon(
'delete.png',
'delete.png',
get_lang('Delete'),
get_lang('Delete'),
'',
'',
ICON_SIZE_SMALL
ICON_SIZE_SMALL
).'< / a > ';
).'< / a > ';
} else {
} else {
$actions = '';
$actions = '';
}
}
echo Display::panel(
echo Display::panel(
$row['description'],
$row['description'],
$row['title'].$sessionImg.' < div class = "pull-right" > '.$actions.'< / div > ',
$row['title'].$sessionImg.' < div class = "pull-right" > '.$actions.'< / div > ',
get_lang('CreationDate').': '.
get_lang('CreationDate').': '.
Display::dateToStringAgoAndLongDate($row['creation_date']).$updateValue.$author
Display::dateToStringAgoAndLongDate($row['creation_date']).$updateValue.$author
);
);
}
}
}
}
@ -485,7 +484,6 @@ class NotebookTeacher
if (Database::num_rows($result) > 0) {
if (Database::num_rows($result) > 0) {
echo Display::page_subheader($plugin->get_lang('NotebookNoStudentAssigned'));
echo Display::page_subheader($plugin->get_lang('NotebookNoStudentAssigned'));
while ($row = Database::fetch_array($result)) {
while ($row = Database::fetch_array($result)) {
// Validation when belongs to a session
// Validation when belongs to a session
$sessionImg = api_get_session_image($row['session_id'], $userInfo['status']);
$sessionImg = api_get_session_image($row['session_id'], $userInfo['status']);
$updateValue = '';
$updateValue = '';
@ -497,7 +495,7 @@ class NotebookTeacher
$userInfo = api_get_user_info($row['user_id']);
$userInfo = api_get_user_info($row['user_id']);
$author = ', '.get_lang('Teacher').': '.$userInfo['complete_name'];
$author = ', '.get_lang('Teacher').': '.$userInfo['complete_name'];
$actions = '';
if (intval($row['user_id']) == api_get_user_id()) {
if (intval($row['user_id']) == api_get_user_id()) {
$actions = '< a href = "'.api_get_self().
$actions = '< a href = "'.api_get_self().
'?action=editnote& notebook_id='.$row['id'].'& '.api_get_cidreq().'">'.
'?action=editnote& notebook_id='.$row['id'].'& '.api_get_cidreq().'">'.
@ -506,15 +504,12 @@ class NotebookTeacher
'?action=deletenote& notebook_id='.$row['id'].
'?action=deletenote& notebook_id='.$row['id'].
'" onclick="return confirmation(\''.$row['title'].'\');">'.
'" onclick="return confirmation(\''.$row['title'].'\');">'.
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'< / a > ';
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'< / a > ';
} else {
$actions = '';
}
}
echo Display::panel(
echo Display::panel(
$row['description'],
$row['description'],
$row['title'].$sessionImg.' < div class = "pull-right" > '.$actions.'< / div > ',
$row['title'].$sessionImg.' < div class = "pull-right" > '.$actions.'< / div > ',
get_lang('CreationDate').': '.
get_lang('CreationDate').': '.
Display::dateToStringAgoAndLongDate($row['creation_date']).$updateValue.$author
Display::dateToStringAgoAndLongDate($row['creation_date']).$updateValue.$author
);
);
}
}
}
}