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. 27
      main/inc/lib/tracking.lib.php
  4. 17
      main/inc/lib/usergroup.lib.php
  5. 29
      plugin/lp_calendar/LpCalendarPlugin.php
  6. 8
      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':
$calendars = LpCalendarPlugin::getCalendars(0, 1000, '');
if (empty($calendars)) {
echo Display::return_message(get_lang('Nodata'));
echo Display::return_message(get_lang('NoData'), 'warning');
exit;
}
$userInfo = api_get_user_info($userId);
@ -132,7 +132,6 @@ $column_model = [
],
];
if (api_get_plugin_setting('lp_calendar', 'enabled') === 'true') {
$columns = [
get_lang('Name'),

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

@ -1624,18 +1624,18 @@ class Tracking
$courseId,
$session_id = 0
) {
$courseId = intval($courseId);
$courseId = (int) $courseId;
if (empty($courseId) || empty($user_id)) {
return 0;
}
$session_id = intval($session_id);
$session_id = (int) $session_id;
if (is_array($user_id)) {
$user_id = array_map('intval', $user_id);
$conditionUser = " AND user_id IN (".implode(',', $user_id).") ";
} else {
$user_id = intval($user_id);
$user_id = (int) $user_id;
$conditionUser = " AND user_id = $user_id ";
}
@ -4627,6 +4627,7 @@ class Tracking
* @param string $extra_params
* @param bool $show_courses
* @param bool $showAllSessions
* @param bool $returnArray
*
* @return string
*/
@ -4666,8 +4667,8 @@ class Tracking
$trackingColumns = $trackingColumnsConfig;
}
$user_id = intval($user_id);
$session_id = intval($session_id);
$user_id = (int) $user_id;
$session_id = (int) $session_id;
$urlId = api_get_current_access_url_id();
if (api_is_multiple_url_enabled()) {
@ -4680,7 +4681,7 @@ class Tracking
WHERE
cu.user_id = $user_id AND
relation_type<> ".COURSE_RELATION_TYPE_RRHH." AND
access_url_id = ".$urlId."
access_url_id = $urlId
ORDER BY title";
} else {
$sql = "SELECT c.id, c.code, title
@ -4700,11 +4701,11 @@ class Tracking
$courseIdList[] = $row['id'];
}
$orderBy = " ORDER BY name ";
$orderBy = ' ORDER BY name ';
$extraInnerJoin = null;
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);
$extraInnerJoin = " INNER JOIN $tableSessionRelCourse src
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
//$visible_return = $exercise_obj->is_visible();
if ($exercise_data['results_disabled'] == 0 || $exercise_data['results_disabled'] == 2) {
$best_average = intval(
$best_average = (int)
ExerciseLib::get_best_average_score_by_exercise(
$exercise_data['id'],
$course_data['real_id'],
$my_session_id,
$user_count
)
);
;
$exercise_graph_list[] = $best_average;
$all_exercise_graph_list[] = $best_average;
@ -5175,7 +5176,7 @@ class Tracking
// Checking selected session.
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];
$course_list = $session_data['course_list'];
@ -5411,14 +5412,13 @@ class Tracking
}
$html .= '</tbody></table></div>';
}
}
$pluginCalendar = api_get_plugin_setting('lp_calendar', 'enabled') === 'true';
if ($pluginCalendar) {
$course_in_session[0] = $courseIdList;
$plugin = LpCalendarPlugin::create();
$html .= LpCalendarPlugin::getUserStatsPanel($user_id, $course_in_session);
}
}
return $html;
}
@ -6862,7 +6862,6 @@ class Tracking
}
}
}
}
}

@ -129,11 +129,20 @@ class UserGroup extends Model
true
);
$stats = LpCalendarPlugin::getUserStats($userId, $courseAndSessionList)
$stats = LpCalendarPlugin::getUserStats($userId, $courseAndSessionList);
$data['examn'] = 'examn';
$data['time_spent'] = 'time_spent';
$data['lp_day_completed'] = 'lp_day_completed';
$data['days_diff'] = 'days_diff';
$totalTime = 0;
foreach ($courseAndSessionList as $sessionId => $course) {
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
/* 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
{
const EVENT_TYPE_TAKEN = 1;
const EVENT_TYPE_EXAM = 2;
public $hasPersonalEvents = true;
/**
* Class constructor
* Class constructor.
*/
protected function __construct()
{
$this->hasPersonalEvents = true;
$version = '0.1';
$author = 'Julio Montoya';
parent::__construct($version, $author, ['enabled' => 'boolean']);
@ -33,12 +28,12 @@ class LpCalendarPlugin extends Plugin
return [
//self::EVENT_TYPE_FREE => 'green',
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
*/
@ -50,7 +45,7 @@ class LpCalendarPlugin extends Plugin
}
/**
* Get the plugin directory name
* Get the plugin directory 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()
{
@ -121,7 +116,7 @@ class LpCalendarPlugin extends Plugin
}
/**
* uninstall plugin. Clear the database
* Uninstall the plugin.
*/
public function uninstall()
{
@ -389,7 +384,7 @@ class LpCalendarPlugin extends Plugin
* @param int $type
* @param bool $getCount
*
* @return array
* @return array|int
*/
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);
}
if ($getCount) {
return 0;
}
return [];
}
@ -667,7 +666,7 @@ class LpCalendarPlugin extends Plugin
$userId,
strtotime(date('Y-01-01')),
time(),
LpCalendarPlugin::EVENT_TYPE_TAKEN,
self::EVENT_TYPE_TAKEN,
true
);

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

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

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

Loading…
Cancel
Save