WIP Lp calendar - Fix php warning, errors, format code, fix query.

BT#14608
pull/2591/head
Julio Montoya 7 years ago
parent 590410f435
commit d425200768
  1. 3
      main/admin/usergroup_users.php
  2. 2
      main/inc/ajax/model.ajax.php
  3. 37
      main/inc/lib/tracking.lib.php
  4. 17
      main/inc/lib/usergroup.lib.php
  5. 29
      plugin/lp_calendar/LpCalendarPlugin.php
  6. 10
      plugin/lp_calendar/ajax.php
  7. 4
      plugin/lp_calendar/calendar.php
  8. 2
      plugin/lp_calendar/start.php

@ -34,7 +34,7 @@ switch ($action) {
case 'add_calendar': case 'add_calendar':
$calendars = LpCalendarPlugin::getCalendars(0, 1000, ''); $calendars = LpCalendarPlugin::getCalendars(0, 1000, '');
if (empty($calendars)) { if (empty($calendars)) {
echo Display::return_message(get_lang('Nodata')); echo Display::return_message(get_lang('NoData'), 'warning');
exit; exit;
} }
$userInfo = api_get_user_info($userId); $userInfo = api_get_user_info($userId);
@ -132,7 +132,6 @@ $column_model = [
], ],
]; ];
if (api_get_plugin_setting('lp_calendar', 'enabled') === 'true') { if (api_get_plugin_setting('lp_calendar', 'enabled') === 'true') {
$columns = [ $columns = [
get_lang('Name'), get_lang('Name'),

@ -797,7 +797,7 @@ switch ($action) {
'name', 'name',
'calendar', 'calendar',
'examn', 'examn',
'time_sent', 'time_spent',
'lp_day_completed', 'lp_day_completed',
'days_diff', 'days_diff',
'actions', 'actions',

@ -1624,18 +1624,18 @@ class Tracking
$courseId, $courseId,
$session_id = 0 $session_id = 0
) { ) {
$courseId = intval($courseId); $courseId = (int) $courseId;
if (empty($courseId) || empty($user_id)) { if (empty($courseId) || empty($user_id)) {
return 0; return 0;
} }
$session_id = intval($session_id); $session_id = (int) $session_id;
if (is_array($user_id)) { if (is_array($user_id)) {
$user_id = array_map('intval', $user_id); $user_id = array_map('intval', $user_id);
$conditionUser = " AND user_id IN (".implode(',', $user_id).") "; $conditionUser = " AND user_id IN (".implode(',', $user_id).") ";
} else { } else {
$user_id = intval($user_id); $user_id = (int) $user_id;
$conditionUser = " AND user_id = $user_id "; $conditionUser = " AND user_id = $user_id ";
} }
@ -4627,6 +4627,7 @@ class Tracking
* @param string $extra_params * @param string $extra_params
* @param bool $show_courses * @param bool $show_courses
* @param bool $showAllSessions * @param bool $showAllSessions
* @param bool $returnArray
* *
* @return string * @return string
*/ */
@ -4666,8 +4667,8 @@ class Tracking
$trackingColumns = $trackingColumnsConfig; $trackingColumns = $trackingColumnsConfig;
} }
$user_id = intval($user_id); $user_id = (int) $user_id;
$session_id = intval($session_id); $session_id = (int) $session_id;
$urlId = api_get_current_access_url_id(); $urlId = api_get_current_access_url_id();
if (api_is_multiple_url_enabled()) { if (api_is_multiple_url_enabled()) {
@ -4680,7 +4681,7 @@ class Tracking
WHERE WHERE
cu.user_id = $user_id AND cu.user_id = $user_id AND
relation_type<> ".COURSE_RELATION_TYPE_RRHH." AND relation_type<> ".COURSE_RELATION_TYPE_RRHH." AND
access_url_id = ".$urlId." access_url_id = $urlId
ORDER BY title"; ORDER BY title";
} else { } else {
$sql = "SELECT c.id, c.code, title $sql = "SELECT c.id, c.code, title
@ -4688,7 +4689,7 @@ class Tracking
INNER JOIN $tbl_course c ON (c_id = c.id) INNER JOIN $tbl_course c ON (c_id = c.id)
WHERE WHERE
u.user_id= $user_id AND u.user_id= $user_id AND
relation_type<>".COURSE_RELATION_TYPE_RRHH." relation_type <> ".COURSE_RELATION_TYPE_RRHH."
ORDER BY title"; ORDER BY title";
} }
@ -4700,11 +4701,11 @@ class Tracking
$courseIdList[] = $row['id']; $courseIdList[] = $row['id'];
} }
$orderBy = " ORDER BY name "; $orderBy = ' ORDER BY name ';
$extraInnerJoin = null; $extraInnerJoin = null;
if (SessionManager::orderCourseIsEnabled() && !empty($session_id)) { if (SessionManager::orderCourseIsEnabled() && !empty($session_id)) {
$orderBy = " ORDER BY s.id, position "; $orderBy = ' ORDER BY s.id, position ';
$tableSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $tableSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$extraInnerJoin = " INNER JOIN $tableSessionRelCourse src $extraInnerJoin = " INNER JOIN $tableSessionRelCourse src
ON (cu.c_id = src.c_id AND src.session_id = $session_id) "; ON (cu.c_id = src.c_id AND src.session_id = $session_id) ";
@ -4981,14 +4982,14 @@ class Tracking
// Exercise is not necessary to be visible to show results check the result_disable configuration instead // Exercise is not necessary to be visible to show results check the result_disable configuration instead
//$visible_return = $exercise_obj->is_visible(); //$visible_return = $exercise_obj->is_visible();
if ($exercise_data['results_disabled'] == 0 || $exercise_data['results_disabled'] == 2) { if ($exercise_data['results_disabled'] == 0 || $exercise_data['results_disabled'] == 2) {
$best_average = intval( $best_average = (int)
ExerciseLib::get_best_average_score_by_exercise( ExerciseLib::get_best_average_score_by_exercise(
$exercise_data['id'], $exercise_data['id'],
$course_data['real_id'], $course_data['real_id'],
$my_session_id, $my_session_id,
$user_count $user_count
) )
); ;
$exercise_graph_list[] = $best_average; $exercise_graph_list[] = $best_average;
$all_exercise_graph_list[] = $best_average; $all_exercise_graph_list[] = $best_average;
@ -5175,7 +5176,7 @@ class Tracking
// Checking selected session. // Checking selected session.
if (isset($_GET['session_id'])) { if (isset($_GET['session_id'])) {
$session_id_from_get = intval($_GET['session_id']); $session_id_from_get = (int) $_GET['session_id'];
$session_data = $course_in_session[$session_id_from_get]; $session_data = $course_in_session[$session_id_from_get];
$course_list = $session_data['course_list']; $course_list = $session_data['course_list'];
@ -5411,13 +5412,12 @@ class Tracking
} }
$html .= '</tbody></table></div>'; $html .= '</tbody></table></div>';
} }
}
$pluginCalendar = api_get_plugin_setting('lp_calendar', 'enabled') === 'true'; $pluginCalendar = api_get_plugin_setting('lp_calendar', 'enabled') === 'true';
if ($pluginCalendar) { if ($pluginCalendar) {
$course_in_session[0] = $courseIdList; $course_in_session[0] = $courseIdList;
$plugin = LpCalendarPlugin::create(); $html .= LpCalendarPlugin::getUserStatsPanel($user_id, $course_in_session);
$html .= LpCalendarPlugin::getUserStatsPanel($user_id, $course_in_session);
}
} }
return $html; return $html;
@ -6862,7 +6862,6 @@ class Tracking
} }
} }
} }
} }
} }

@ -129,11 +129,20 @@ class UserGroup extends Model
true true
); );
$stats = LpCalendarPlugin::getUserStats($userId, $courseAndSessionList) $stats = LpCalendarPlugin::getUserStats($userId, $courseAndSessionList);
$data['examn'] = 'examn'; $data['examn'] = 'examn';
$data['time_spent'] = 'time_spent'; $totalTime = 0;
$data['lp_day_completed'] = 'lp_day_completed'; foreach ($courseAndSessionList as $sessionId => $course) {
$data['days_diff'] = 'days_diff'; foreach ($course as $courseId) {
$totalTime += Tracking::get_time_spent_on_the_course($userId, $courseId,$sessionId);
}
}
$data['time_spent'] = api_time_to_hms($totalTime);
$data['lp_day_completed'] = $stats['completed'];
$data['days_diff'] = $stats['diff'];
} }

@ -1,25 +1,20 @@
<?php <?php
/* For license terms, see /license.txt */ /* For license terms, see /license.txt */
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\DBALException;
use Symfony\Component\Filesystem\Filesystem;
/** /**
* Class LpCalendarPlugin * Class LpCalendarPlugin.
*/ */
class LpCalendarPlugin extends Plugin class LpCalendarPlugin extends Plugin
{ {
const EVENT_TYPE_TAKEN = 1; const EVENT_TYPE_TAKEN = 1;
const EVENT_TYPE_EXAM = 2; const EVENT_TYPE_EXAM = 2;
public $hasPersonalEvents = true;
/** /**
* Class constructor * Class constructor.
*/ */
protected function __construct() protected function __construct()
{ {
$this->hasPersonalEvents = true;
$version = '0.1'; $version = '0.1';
$author = 'Julio Montoya'; $author = 'Julio Montoya';
parent::__construct($version, $author, ['enabled' => 'boolean']); parent::__construct($version, $author, ['enabled' => 'boolean']);
@ -33,12 +28,12 @@ class LpCalendarPlugin extends Plugin
return [ return [
//self::EVENT_TYPE_FREE => 'green', //self::EVENT_TYPE_FREE => 'green',
self::EVENT_TYPE_TAKEN => 'red', self::EVENT_TYPE_TAKEN => 'red',
self::EVENT_TYPE_EXAM => 'yellow' self::EVENT_TYPE_EXAM => 'yellow',
]; ];
} }
/** /**
* Get the class instance * Get the class instance.
* *
* @return $this * @return $this
*/ */
@ -50,7 +45,7 @@ class LpCalendarPlugin extends Plugin
} }
/** /**
* Get the plugin directory name * Get the plugin directory name.
*/ */
public function get_name() public function get_name()
{ {
@ -58,7 +53,7 @@ class LpCalendarPlugin extends Plugin
} }
/** /**
* Install the plugin. Setup the database * Install the plugin. Setup the database.
*/ */
public function install() public function install()
{ {
@ -121,7 +116,7 @@ class LpCalendarPlugin extends Plugin
} }
/** /**
* uninstall plugin. Clear the database * Uninstall the plugin.
*/ */
public function uninstall() public function uninstall()
{ {
@ -389,7 +384,7 @@ class LpCalendarPlugin extends Plugin
* @param int $type * @param int $type
* @param bool $getCount * @param bool $getCount
* *
* @return array * @return array|int
*/ */
public static function getUserEvents($userId, $start, $end, $type = 0, $getCount = false) public static function getUserEvents($userId, $start, $end, $type = 0, $getCount = false)
{ {
@ -400,6 +395,10 @@ class LpCalendarPlugin extends Plugin
return self::getCalendarsEventsByDate($calendar, $start, $end, $type, $getCount); return self::getCalendarsEventsByDate($calendar, $start, $end, $type, $getCount);
} }
if ($getCount) {
return 0;
}
return []; return [];
} }
@ -667,7 +666,7 @@ class LpCalendarPlugin extends Plugin
$userId, $userId,
strtotime(date('Y-01-01')), strtotime(date('Y-01-01')),
time(), time(),
LpCalendarPlugin::EVENT_TYPE_TAKEN, self::EVENT_TYPE_TAKEN,
true true
); );

@ -1,4 +1,5 @@
<?php <?php
/* For license terms, see /license.txt */
require_once __DIR__.'/../../main/inc/global.inc.php'; require_once __DIR__.'/../../main/inc/global.inc.php';
@ -48,22 +49,23 @@ switch ($action) {
'calendar_id' => $calendarId, 'calendar_id' => $calendarId,
'start_date' => $startDate, 'start_date' => $startDate,
'end_date' => $startDate, 'end_date' => $startDate,
'type' => LpCalendarPlugin::EVENT_TYPE_TAKEN 'type' => LpCalendarPlugin::EVENT_TYPE_TAKEN,
]; ];
Database::insert('learning_calendar_events', $params); Database::insert('learning_calendar_events', $params);
} }
break; break;
case 'get_events': case 'get_events':
$sql = "SELECT * FROM learning_calendar_events"; $sql = "SELECT * FROM learning_calendar_events
WHERE calendar_id = $calendarId ";
$result = Database::query($sql); $result = Database::query($sql);
$list = []; $list = [];
while ($row = Database::fetch_array($result, 'ASSOC')) { while ($row = Database::fetch_array($result, 'ASSOC')) {
$list[] = [ $list[] = [
'start_date' => $row['start_date'], 'start_date' => $row['start_date'],
'end_date' => $row['start_date'], 'end_date' => $row['start_date'],
'color' => $eventTypeList[$row['type']] 'color' => $eventTypeList[$row['type']],
]; ];
} }
echo json_encode($list); echo json_encode($list);
break; break;
} }

@ -35,10 +35,6 @@ $plugin = LpCalendarPlugin::create();
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$formToString = ''; $formToString = '';
switch ($action) {
}
$template = new Template(); $template = new Template();
$actionLeft = Display::url( $actionLeft = Display::url(

@ -1,7 +1,6 @@
<?php <?php
/* For license terms, see /license.txt */ /* For license terms, see /license.txt */
require_once __DIR__.'/../../main/inc/global.inc.php'; require_once __DIR__.'/../../main/inc/global.inc.php';
$allow = api_is_allowed_to_edit(); $allow = api_is_allowed_to_edit();
@ -180,7 +179,6 @@ if (in_array($action, ['add', 'edit'])) {
), ),
api_get_self().'?'.api_get_cidreq() api_get_self().'?'.api_get_cidreq()
); );
} else { } else {
$actionLeft = Display::url( $actionLeft = Display::url(
Display::return_icon( Display::return_icon(

Loading…
Cancel
Save