Internal - Fix legacy code, add psalm checks

pull/3543/head
Julio Montoya 5 years ago
parent 41516e4e1a
commit c87549682f
  1. 47
      psalm.xml
  2. 9
      public/main/auth/courses.php
  3. 151
      public/main/auth/inscription.php
  4. 8
      public/main/auth/profile.php
  5. 35
      public/main/calendar/ical_export.php
  6. 4
      public/main/inc/lib/CoursesAndSessionsCatalog.class.php
  7. 27
      public/main/inc/lib/MailTemplateManager.php
  8. 3
      public/main/inc/lib/api.lib.php
  9. 15
      public/main/inc/lib/exercise.lib.php
  10. 45
      public/main/inc/lib/extra_field.lib.php
  11. 10
      public/main/inc/lib/extra_field_option.lib.php
  12. 14
      public/main/inc/lib/extra_field_value.lib.php
  13. 8
      public/main/inc/lib/import.lib.php
  14. 11
      public/main/inc/lib/message.lib.php
  15. 4
      public/main/session/index.php
  16. 2
      public/main/session/session_category_edit.php
  17. 11
      src/CoreBundle/Entity/User.php

@ -11,9 +11,10 @@
<directory name="public/main/admin" />
<directory name="public/main/announcements"/>
<directory name="public/main/attendance"/>
<directory name="public/main/auth"/>
<!-- <directory name="public/main/badge"/>-->
<directory name="public/main/blog"/>
<!-- <directory name="public/main/calendar"/>-->
<directory name="public/main/calendar"/>
<!-- <directory name="public/main/chat"/>-->
<!-- <directory name="public/main/course_description"/>-->
<!-- <directory name="public/main/course_info"/>-->
@ -29,8 +30,10 @@
<directory name="public/main/link" />
<!-- <directory name="public/main/lp"/>-->
<!-- <directory name="public/main/session" /> -->
<!-- <directory name="public/main/inc/ajax" />-->
<!-- <directory name="public/main/session" />-->
<!-- <directory name="public/main/inc/ajax" />-->
<directory name="public/main/work" />
@ -39,24 +42,51 @@
<file name="public/main/inc/lib/access_url_edit_users_to_url_functions.lib.php"/>
<file name="public/main/inc/lib/add_course.lib.inc.php"/>
<file name="public/main/inc/lib/add_courses_to_session_functions.lib.php"/>
<!-- <file name="public/main/inc/lib/agenda.lib.php"/>-->
<file name="public/main/inc/lib/AnnouncementEmail.php"/>
<file name="public/main/inc/lib/AnnouncementManager.php"/>
<file name="public/main/inc/lib/api.lib.php"/>
<file name="public/main/inc/lib/array.lib.php"/>
<file name="public/main/inc/lib/attendance.lib.php"/>
<file name="public/main/inc/lib/auth.lib.php"/>
<!-- <file name="public/main/inc/lib/blog.lib.php"/>-->
<file name="public/main/inc/lib/career.lib.php"/>
<!-- <file name="public/main/inc/lib/certificate.lib.php"/>-->
<file name="public/main/inc/lib/course.lib.php"/>
<file name="public/main/inc/lib/course_category.lib.php"/>
<!-- <file name="public/main/inc/lib/course_description.lib.php"/>-->
<!-- <file name="public/main/inc/lib/course_home.lib.php"/>-->
<file name="public/main/inc/lib/course_request.lib.php"/>
<file name="public/main/inc/lib/display.lib.php"/>
<!-- <file name="public/main/inc/lib/CoursesAndSessionsCatalog.class.php"/>-->
<file name="public/main/inc/lib/dashboard.lib.php"/>
<!-- <file name="public/main/inc/lib/database.lib.php"/>-->
<!-- <file name="public/main/inc/lib/diagnoser.lib.php"/>-->
<!-- <file name="public/main/inc/lib/events.lib.php"/>-->
<!-- <file name="public/main/inc/lib/exercise.lib.php"/>-->
<file name="public/main/inc/lib/exercise_show_functions.lib.php"/>
<!-- <file name="public/main/inc/lib/ExerciseCategoryManager.php"/>-->
<!-- <file name="public/main/inc/lib/export.lib.inc.php"/>-->
<file name="public/main/inc/lib/extra_field.lib.php"/>
<file name="public/main/inc/lib/extra_field_option.lib.php"/>
<!-- <file name="public/main/inc/lib/extra_field_value.lib.php"/>-->
<!-- <file name="public/main/inc/lib/glossary.lib.php"/>-->
<file name="public/main/inc/lib/grade_model.lib.php"/>
<file name="public/main/inc/lib/gradebook.lib.php"/>
<file name="public/main/inc/lib/groupmanager.lib.php"/>
<!-- <file name="public/main/inc/lib/image.lib.php"/>-->
<file name="public/main/inc/lib/import.lib.php"/>
<file name="public/main/inc/lib/legal.lib.php"/>
<file name="public/main/inc/lib/link.lib.php"/>
<!-- <file name="public/main/inc/lib/message.lib.php"/>-->
<file name="public/main/inc/lib/model.lib.php"/>
<!-- <file name="public/main/inc/lib/myspace.lib.php"/>-->
<file name="public/main/inc/lib/sessionmanager.lib.php"/>
<!-- <file name="public/main/inc/lib/skill.lib.php"/>-->
<file name="public/main/inc/lib/link.lib.php"/>
@ -82,7 +112,6 @@
<file name="public/main/inc/lib/timeline.lib.php"/>
<file name="public/main/inc/lib/UnserializeApi.php"/>
<!-- <file name="public/main/inc/lib/tracking.lib.php"/>-->
<file name="public/main/inc/lib/urlmanager.lib.php"/>
<file name="public/main/inc/lib/usergroup.lib.php"/>
<!-- <file name="public/main/inc/lib/usermanager.lib.php"/>-->
@ -100,11 +129,8 @@
<file name="public/main/admin/index.php"/>
<file name="public/main/admin/db.php"/>
<file name="public/main/admin/settings.php"/>
<file name="public/main/admin/periodic_export.php"/>
<file name="public/main/admin/user_move_stats.php"/>
<file name="public/main/admin/settings.lib.php"/>
<file name="public/main/admin/user_update_import.php"/>
<file name="public/main/admin/teachers_time_by_session_report.php"/>
@ -112,7 +138,6 @@
<file name="public/main/admin/ldap_*"/>
<file name="public/main/admin/special_exports.php"/>
<file name="src/CoreBundle/Controller/EditorController.php"/>
<file name="src/CoreBundle/Controller/ResourceController.php"/>
</ignoreFiles>

@ -107,7 +107,8 @@ switch ($action) {
break;
case 'subscribe_course':
if (api_is_anonymous()) {
header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php?c='.$courseCodeToSubscribe);
//header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php?c='.$courseCodeToSubscribe);
header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php');
exit;
}
$courseCodeToSubscribe = isset($_GET['course_code']) ? Security::remove_XSS($_GET['course_code']) : '';
@ -408,8 +409,8 @@ switch ($action) {
if ($allowExtraFields) {
$extraFieldValues = new ExtraFieldValue('course');
$em = Database::getManager();
$fieldsRepo = $em->getRepository('ChamiloCoreBundle:ExtraField');
$fieldTagsRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag');
$fieldsRepo = $em->getRepository(\Chamilo\CoreBundle\Entity\ExtraField::class);
$fieldTagsRepo = $em->getRepository(\Chamilo\CoreBundle\Entity\ExtraFieldRelTag::class);
}
$courseUrl = api_get_path(WEB_COURSE_PATH);
@ -613,7 +614,7 @@ switch ($action) {
$registrationAllowed = api_get_setting('catalog_allow_session_auto_subscription');
if ('true' === $registrationAllowed) {
$entityManager = Database::getManager();
$repository = $entityManager->getRepository('ChamiloCoreBundle:SequenceResource');
$repository = $entityManager->getRepository(SequenceResource::class);
$sequences = $repository->getRequirements(
$sessionId,
SequenceResource::SESSION_TYPE

@ -431,47 +431,50 @@ $content = null;
$tool_name = get_lang('Registration');
if (!CustomPages::enabled()) {
// Load terms & conditions from the current lang
if ('true' === api_get_setting('allow_terms_conditions')) {
$get = array_keys($_GET);
if (isset($get)) {
if (isset($get[0]) && 'legal' == $get[0]) {
$language = api_get_interface_language();
// Load terms & conditions from the current lang
if ('true' === api_get_setting('allow_terms_conditions')) {
$get = array_keys($_GET);
if (isset($get)) {
if (isset($get[0]) && 'legal' == $get[0]) {
$language = api_get_interface_language();
$language = api_get_language_id($language);
$term_preview = LegalManager::get_last_condition($language);
if (!$term_preview) {
//look for the default language
$language = api_get_setting('platformLanguage');
$language = api_get_language_id($language);
$term_preview = LegalManager::get_last_condition($language);
if (!$term_preview) {
//look for the default language
$language = api_get_setting('platformLanguage');
$language = api_get_language_id($language);
$term_preview = LegalManager::get_last_condition($language);
}
Display::display_header(get_lang('Terms and Conditions'));
if (!empty($term_preview['content'])) {
echo $term_preview['content'];
$termExtraFields = new ExtraFieldValue('terms_and_condition');
$values = $termExtraFields->getAllValuesByItem($term_preview['id']);
foreach ($values as $value) {
echo '<h3>'.$value['display_text'].'</h3><br />'.$value['value'].'<br />';
}
} else {
echo get_lang('Coming soon...');
}
Display::display_header(get_lang('Terms and Conditions'));
if (!empty($term_preview['content'])) {
echo $term_preview['content'];
$termExtraFields = new ExtraFieldValue('terms_and_condition');
$values = $termExtraFields->getAllValuesByItem($term_preview['id']);
foreach ($values as $value) {
echo '<h3>'.$value['display_text'].'</h3><br />'.$value['value'].'<br />';
}
Display::display_footer();
exit;
} else {
echo get_lang('Coming soon...');
}
Display::display_footer();
exit;
}
}
}
if ('true' === api_get_setting('allow_terms_conditions') && $user_already_registered_show_terms) {
$tool_name = get_lang('Terms and Conditions');
}
if ('true' === api_get_setting('allow_terms_conditions') && $user_already_registered_show_terms) {
$tool_name = get_lang('Terms and Conditions');
}
// Forbidden to self-register
if ($isNotAllowedHere) {
api_not_allowed(true, get_lang('Sorry, you are trying to access the registration page for this portal, but registration is currently disabled. Please contact the administrator (see contact information in the footer). If you already have an account on this site.'));
api_not_allowed(
true,
get_lang(
'Sorry, you are trying to access the registration page for this portal, but registration is currently disabled. Please contact the administrator (see contact information in the footer). If you already have an account on this site.'
)
);
}
if ('approval' === api_get_setting('allow_registration')) {
@ -655,13 +658,13 @@ if ($form->validate()) {
//an extra field
$extras[substr($key, 6)] = $value;
} elseif (false !== strpos($key, 'remove_extra_')) {
$extra_value = Security::filter_filename(urldecode(key($value)));
/*$extra_value = Security::filter_filename(urldecode(key($value)));
// To remove from user_field_value and folder
UserManager::update_extra_field_value(
$user_id,
substr($key, 13),
$extra_value
);
);*/
}
}
@ -1061,60 +1064,46 @@ if ($form->validate()) {
Session::erase('session_redirect');
Session::erase('only_one_course_session_redirect');
if (CustomPages::enabled() && CustomPages::exists(CustomPages::REGISTRATION_FEEDBACK)) {
CustomPages::display(
CustomPages::REGISTRATION_FEEDBACK,
['info' => $text_after_registration]
);
} else {
$tpl = new Template($tool_name);
$tpl->assign('inscription_content', $content);
$tpl->assign('text_after_registration', $text_after_registration);
$tpl->assign('hide_header', $hideHeaders);
$inscription = $tpl->get_template('auth/inscription.tpl');
$tpl->display($inscription);
}
$tpl = new Template($tool_name);
$tpl->assign('inscription_content', $content);
$tpl->assign('text_after_registration', $text_after_registration);
$tpl->assign('hide_header', $hideHeaders);
$inscription = $tpl->get_template('auth/inscription.tpl');
$tpl->display($inscription);
} else {
// Custom pages
if (CustomPages::enabled() && CustomPages::exists(CustomPages::REGISTRATION)) {
CustomPages::display(
CustomPages::REGISTRATION,
['form' => $form, 'content' => $content]
);
} else {
if (!api_is_anonymous()) {
// Saving user to course if it was set.
if (!empty($course_code_redirect)) {
$course_info = api_get_course_info($course_code_redirect);
if (!empty($course_info)) {
if (in_array(
$course_info['visibility'],
[
COURSE_VISIBILITY_OPEN_PLATFORM,
COURSE_VISIBILITY_OPEN_WORLD,
]
)
) {
CourseManager::subscribeUser(
$user_id,
$course_info['code']
);
}
if (!api_is_anonymous()) {
// Saving user to course if it was set.
if (!empty($course_code_redirect)) {
$course_info = api_get_course_info($course_code_redirect);
if (!empty($course_info)) {
if (in_array(
$course_info['visibility'],
[
COURSE_VISIBILITY_OPEN_PLATFORM,
COURSE_VISIBILITY_OPEN_WORLD,
]
)
) {
CourseManager::subscribeUser(
api_get_user_id(),
$course_info['code']
);
}
}
CourseManager::redirectToCourse([]);
}
CourseManager::redirectToCourse([]);
}
$tpl = new Template($tool_name);
$tpl = new Template($tool_name);
$tpl->assign('inscription_header', Display::page_header($tool_name));
$tpl->assign('inscription_content', $content);
$tpl->assign('form', $form->returnForm());
$tpl->assign('hide_header', $hideHeaders);
$page = Container::getPage('inscription');
$tpl->assign('page', $page);
$tpl->assign('inscription_header', Display::page_header($tool_name));
$tpl->assign('inscription_content', $content);
$tpl->assign('form', $form->returnForm());
$tpl->assign('hide_header', $hideHeaders);
//$page = Container::getPage('inscription');
//$tpl->assign('page', $page);
$inscription = $tpl->get_template('auth/inscription.tpl');
$tpl->display($inscription);
$inscription = $tpl->get_template('auth/inscription.tpl');
$tpl->display($inscription);
}
}

@ -481,7 +481,7 @@ if ($form->validate()) {
}
// upload production if a new one is provided
if (isset($_FILES['production']) && $_FILES['production']['size']) {
/*if (isset($_FILES['production']) && $_FILES['production']['size']) {
$res = upload_user_production(api_get_user_id());
if (!$res) {
//it's a bit excessive to assume the extension is the reason why
@ -496,7 +496,7 @@ if ($form->validate()) {
)
);
}
}
}*/
// remove values that shouldn't go in the database
unset(
@ -640,12 +640,12 @@ if ($form->validate()) {
);
Session::write('_user', $userInfo);
if ($hook) {
/*if ($hook) {
Database::getManager()->clear(User::class); // Avoid cache issue (user entity is used before)
$user = api_get_user_entity(api_get_user_id()); // Get updated user info for hook event
$hook->setEventData(['user' => $user]);
$hook->notifyUpdateUser(HOOK_EVENT_TYPE_POST);
}
}*/
Session::erase('system_timezone');

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use Kigkonsult\Icalcreator\Vcalendar;
@ -44,13 +45,14 @@ if (isset($_GET['course_id'])) {
}
$event = $agenda->get_event($id);
$charset = api_get_system_encoding();
if (!empty($event)) {
define('ICAL_LANG', api_get_language_isocode());
$ical = new Vcalendar();
$ical->setConfig('unique_id', api_get_path(WEB_PATH));
$ical->setProperty('method', 'PUBLISH');
$ical->setMethod(Vcalendar::PUBLISH);
$ical->setConfig('url', api_get_path(WEB_PATH));
$vevent = new Vevent();
@ -75,15 +77,13 @@ if (!empty($event)) {
switch ($type) {
case 'personal':
case 'platform':
$vevent->setProperty('summary', api_convert_encoding($event['title'], 'UTF-8', $charset));
$vevent->setSummary(api_convert_encoding($event['title'], 'UTF-8', $charset));
if (empty($event['start_date'])) {
header('location:'.Security::remove_XSS($_SERVER['HTTP_REFERER']));
exit;
}
list($y, $m, $d, $h, $M, $s) = preg_split('/[\s:-]/', $event['start_date']);
$vevent->setProperty(
'dtstart',
['year' => $y, 'month' => $m, 'day' => $d, 'hour' => $h, 'min' => $M, 'sec' => $s]
);
$vevent->setDtstart(new DateTime($event['start_date']));
if (empty($event['end_date'])) {
$y2 = $y;
$m2 = $m;
@ -98,12 +98,10 @@ if (!empty($event)) {
} else {
list($y2, $m2, $d2, $h2, $M2, $s2) = preg_split('/[\s:-]/', $event['end_date']);
}
$vevent->setProperty(
'dtend',
['year' => $y2, 'month' => $m2, 'day' => $d2, 'hour' => $h2, 'min' => $M2, 'sec' => $s2]
);
$vevent->setDtend(new DateTime("$y2-$m2-$d2 $h2:$M2:$s2"));
//$vevent->setProperty( 'LOCATION', get_lang('Unknown') ); // property name - case independent
$vevent->setProperty('description', api_convert_encoding($event['description'], 'UTF-8', $charset));
$vevent->setDescription(api_convert_encoding($event['description'], 'UTF-8', $charset));
//$vevent->setProperty( 'comment', 'This is a comment' );
//$user = api_get_user_info($event['user']);
//$vevent->setProperty('organizer',$user['mail']);
@ -114,13 +112,12 @@ if (!empty($event)) {
$ical->returnCalendar();
break;
case 'course':
$vevent->setProperty('summary', api_convert_encoding($event['title'], 'UTF-8', $charset));
$vevent->setSummary(api_convert_encoding($event['title'], 'UTF-8', $charset));
if (empty($event['start_date'])) {
header('location:'.Security::remove_XSS($_SERVER['HTTP_REFERER']));
}
list($y, $m, $d, $h, $M, $s) = preg_split('/[\s:-]/', $event['start_date']);
$vevent->setProperty(
'dtstart',
$vevent->setDtstart(
['year' => $y, 'month' => $m, 'day' => $d, 'hour' => $h, 'min' => $M, 'sec' => $s]
);
if (empty($event['end_date'])) {
@ -137,17 +134,15 @@ if (!empty($event)) {
} else {
list($y2, $m2, $d2, $h2, $M2, $s2) = preg_split('/[\s:-]/', $event['end_date']);
}
$vevent->setProperty(
'dtend',
['year' => $y2, 'month' => $m2, 'day' => $d2, 'hour' => $h2, 'min' => $M2, 'sec' => $s2]
);
$vevent->setProperty('description', api_convert_encoding($event['description'], 'UTF-8', $charset));
$vevent->setDtend(new DateTime("$y2-$m2-$d2 $h2:$M2:$s2"));
$vevent->setDescription(api_convert_encoding($event['description'], 'UTF-8', $charset));
//$vevent->setProperty( 'comment', 'This is a comment' );
//$user = api_get_user_info($event['user']);
//$vevent->setProperty('organizer',$user['mail']);
//$vevent->setProperty('attendee',$user['mail']);
//$course = api_get_course_info();
$vevent->setProperty('location', $course_info['name']); // property name - case independent
$vevent->setLocation($course_info['name']); // property name - case independent
/*if($ai['repeat']) {
$trans = array('daily'=>'DAILY','weekly'=>'WEEKLY','monthlyByDate'=>'MONTHLY','yearly'=>'YEARLY');
$freq = $trans[$ai['repeat_type']];

@ -1017,7 +1017,7 @@ class CoursesAndSessionsCatalog
*/
public static function returnThumbnail($course)
{
$course_path = api_get_path(SYS_COURSE_PATH).$course['directory'];
/*$course_path = api_get_path(SYS_COURSE_PATH).$course['directory'];
if (file_exists($course_path.'/course-pic.png')) {
// redimensioned image 85x85
@ -1034,7 +1034,7 @@ class CoursesAndSessionsCatalog
);
}
return $courseMediumImage;
return $courseMediumImage;*/
}
/**

@ -173,7 +173,7 @@ class MailTemplateManager extends Model
}
$type = $template['type'];
$urlId = api_get_current_access_url_id();
$sql = "UPDATE {$this->table} SET default_template = 0
$sql = "UPDATE {$this->table} SET default_template = 0
WHERE type = '$type' AND url_id = $urlId";
Database::query($sql);
@ -209,4 +209,29 @@ class MailTemplateManager extends Model
return false;
}
/**
* Gets a custom mail template by the name of the template it replaces.
*
* @param string $templateType Name of the template file it replaces
*
* @return string
*/
public function getTemplateByType($templateType)
{
if (empty($templateType)) {
return '';
}
$result = Database::select(
'template',
$this->table,
['where' => ['type = ? ' => $templateType, ' AND url_id = ? ' => api_get_current_access_url_id()]],
'first'
);
if (empty($result)) {
return '';
}
return $result['template'];
}
}

@ -8393,12 +8393,13 @@ function api_is_student_view_active()
* @param int $itemId
* @param string $cropParameters
*
* @deprecated use Resources
*
* @return array|bool
*/
function api_upload_file($type, $file, $itemId, $cropParameters = '')
{
throw new Exception('api_upload_file not implemented');
$upload = process_uploaded_file($file);
if ($upload) {
$name = api_replace_dangerous_char($file['name']);

@ -472,6 +472,7 @@ class ExerciseLib
$hidingClass = '';
if (READING_COMPREHENSION == $answerType) {
/** @var ReadingComprehension */
$objQuestionTmp->setExerciseType($exercise->selectType());
$objQuestionTmp->processText($objQuestionTmp->selectDescription());
$hidingClass = 'hide-reading-answers';
@ -4542,7 +4543,7 @@ EOT;
} else {
$pluginEvaluation = QuestionOptionsEvaluationPlugin::create();
if ('true' === $pluginEvaluation->get(QuestionOptionsEvaluationPlugin::SETTING_ENABLE)) {
$formula = $pluginEvaluation->getFormulaForExercise($objExercise->selectId());
$formula = $pluginEvaluation->getFormulaForExercise($objExercise->getId());
if (!empty($formula)) {
$total_score = $pluginEvaluation->getResultWithFormula($exeId, $formula);
@ -4625,7 +4626,7 @@ EOT;
if (api_is_allowed_to_session_edit()) {
Event::updateEventExercise(
$exercise_stat_info['exe_id'],
$objExercise->selectId(),
$objExercise->getId(),
$total_score,
$total_weight,
$sessionId,
@ -4639,7 +4640,7 @@ EOT;
$allowStats = api_get_configuration_value('allow_gradebook_stats');
if ($allowStats) {
$objExercise->generateStats(
$objExercise->selectId(),
$objExercise->getId(),
api_get_course_info(),
$sessionId
);
@ -5235,7 +5236,7 @@ EOT;
$link = LinkFactory::load(
null,
null,
$objExercise->selectId(),
$objExercise->getId(),
null,
$courseCode,
$categoryId
@ -5280,7 +5281,7 @@ EOT;
$em = Database::getManager();
/** @var TrackEExercises $trackedExercise */
$trackedExercise = $em->getRepository('ChamiloCoreBundle:TrackEExercises')->find($exeId);
$trackedExercise = $em->getRepository(TrackEExercises::class)->find($exeId);
if (empty($trackedExercise)) {
return null;
@ -5351,8 +5352,8 @@ EOT;
}
$trackedExercise
->setExeResult($totalScore)
->setExeWeighting($totalWeight);
->setScore($totalScore)
->setMaxScore($totalWeight);
$em->persist($trackedExercise);
$em->flush();

@ -552,7 +552,7 @@ class ExtraField extends Model
public function get_count()
{
$em = Database::getManager();
$query = $em->getRepository('ChamiloCoreBundle:ExtraField')->createQueryBuilder('e');
$query = $em->getRepository(EntityExtraField::class)->createQueryBuilder('e');
$query->select('count(e.id)');
$query->where('e.extraFieldType = :type');
$query->setParameter('type', $this->getExtraFieldType());
@ -602,7 +602,7 @@ class ExtraField extends Model
break;
}
$em = Database::getManager();
$query = $em->getRepository('ChamiloCoreBundle:ExtraField')->createQueryBuilder('e');
$query = $em->getRepository(EntityExtraField::class)->createQueryBuilder('e');
$query->select('e')
->where('e.extraFieldType = :type')
->setParameter('type', $this->getExtraFieldType())
@ -895,23 +895,23 @@ class ExtraField extends Model
* Get an array of all the values from the extra_field and extra_field_options tables
* based on the current object's type.
*
* @param array $conditions
* @param array $options
* @param null $order_field_options_by
*
* @return array
*/
public function get_all($conditions = [], $order_field_options_by = null)
public function get_all($options = [], $order_field_options_by = null)
{
$conditions = Database::parse_conditions(['where' => $conditions]);
$options = Database::parse_conditions(['where' => $options]);
if (empty($conditions)) {
$conditions .= ' WHERE extra_field_type = '.$this->extraFieldType;
if (empty($options)) {
$options .= ' WHERE extra_field_type = '.$this->extraFieldType;
} else {
$conditions .= ' AND extra_field_type = '.$this->extraFieldType;
$options .= ' AND extra_field_type = '.$this->extraFieldType;
}
$sql = "SELECT * FROM $this->table
$conditions
$options
ORDER BY field_order ASC
";
@ -1246,7 +1246,7 @@ class ExtraField extends Model
if ($separateValue > 0) {
$em = Database::getManager();
$fieldTags = $em
->getRepository('ChamiloCoreBundle:ExtraFieldRelTag')
->getRepository(ExtraFieldRelTag::class)
->findBy(
[
'fieldId' => $field_id,
@ -1256,8 +1256,7 @@ class ExtraField extends Model
// ofaj
for ($i = 0; $i < $separateValue; $i++) {
$tagsSelect = $form->addElement(
'select',
$tagsSelect = $form->addSelect(
'extra_'.$field_details['variable'].'['.$i.']',
$customLabelsExtraMultipleSelect[$field_details['variable']][$i], //$field_details['display_text'],
null,
@ -1272,7 +1271,7 @@ class ExtraField extends Model
}
foreach ($fieldTags as $fieldTag) {
$tag = $em->find('ChamiloCoreBundle:Tag', $fieldTag->getTagId());
$tag = $em->find(Tag::class, $fieldTag->getTagId());
if (empty($tag)) {
continue;
@ -1330,7 +1329,7 @@ class ExtraField extends Model
} else {
$em = Database::getManager();
$fieldTags = $em->getRepository(
'ChamiloCoreBundle:ExtraFieldRelTag'
ExtraFieldRelTag::class
)
->findBy(
[
@ -1342,7 +1341,7 @@ class ExtraField extends Model
/** @var ExtraFieldRelTag $fieldTag */
foreach ($fieldTags as $fieldTag) {
/** @var Tag $tag */
$tag = $em->find('ChamiloCoreBundle:Tag', $fieldTag->getTagId());
$tag = $em->find(Tag::class, $fieldTag->getTagId());
if (empty($tag)) {
continue;
@ -1367,7 +1366,7 @@ class ExtraField extends Model
}
if ($useTagAsSelect) {
$fieldTags = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag')
$fieldTags = $em->getRepository(ExtraFieldRelTag::class)
->findBy(
[
'fieldId' => $field_id,
@ -1375,7 +1374,7 @@ class ExtraField extends Model
);
$tagsAdded = [];
foreach ($fieldTags as $fieldTag) {
$tag = $em->find('ChamiloCoreBundle:Tag', $fieldTag->getTagId());
$tag = $em->find(Tag::class, $fieldTag->getTagId());
if (empty($tag)) {
continue;
@ -1464,7 +1463,7 @@ class ExtraField extends Model
'extra_'.$field_details['variable'],
$field_details['display_text'],
[
'size' => 60,
//'size' => 60,
'size' => implode(
'; ',
[
@ -2007,7 +2006,7 @@ class ExtraField extends Model
public function delete($id)
{
$em = Database::getManager();
$items = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findBy(['field' => $id]);
$items = $em->getRepository(\Chamilo\CoreBundle\Entity\ExtraFieldSavedSearch::class)->findBy(['field' => $id]);
if ($items) {
foreach ($items as $item) {
$em->remove($item);
@ -2894,7 +2893,7 @@ JAVASCRIPT;
$fields = $this->get_all();
$em = Database::getManager();
$repoTag = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag');
$repoTag = $em->getRepository(ExtraFieldRelTag::class);
foreach ($fields as $field) {
if ('1' != $field['visible_to_self']) {
@ -2923,7 +2922,7 @@ JAVASCRIPT;
$data = [];
foreach ($tags as $extraFieldTag) {
/** @var \Chamilo\CoreBundle\Entity\Tag $tag */
$tag = $em->find('ChamiloCoreBundle:Tag', $extraFieldTag->getTagId());
$tag = $em->find(Tag::class, $extraFieldTag->getTagId());
$data[] = $tag->getTag();
}
$valueData = implode(',', $data);
@ -3481,7 +3480,7 @@ JAVASCRIPT;
$level3 = $this->getOptionsFromTripleSelect($options['level3'], $secondId);
/** @var \HTML_QuickForm_select $slctFirst */
$slctFirst = $form->createElement('select', "extra_$variable", null, $values1, ['id' => $slctFirstId]);
/** @var \HTML_QuickForm_select $slctFirst */
/** @var \HTML_QuickForm_select $slctSecond */
$slctSecond = $form->createElement(
'select',
"extra_{$variable}_second",
@ -3489,7 +3488,7 @@ JAVASCRIPT;
$values2,
['id' => $slctSecondId]
);
/** @var \HTML_QuickForm_select $slctFirst */
/** @var \HTML_QuickForm_select $slctThird */
$slctThird = $form->createElement('select', "extra_{$variable}_third", null, $values3, ['id' => $slctThirdId]);
foreach ($level1 as $item1) {

@ -66,7 +66,7 @@ class ExtraFieldOption extends Model
$fieldId = (int) $fieldId;
$sql = "SELECT count(*) as count
FROM $this->table o
FROM $this->table o
INNER JOIN $this->tableExtraField e
ON o.field_id = e.id
WHERE
@ -535,7 +535,7 @@ class ExtraFieldOption extends Model
}
$result = Database::getManager()
->getRepository('ChamiloCoreBundle:ExtraFieldOptions')
->getRepository(ExtraFieldOptions::class)
->findBy(['field' => $field_id], $orderBy);
if (!$result) {
@ -576,15 +576,13 @@ class ExtraFieldOption extends Model
public function get_second_select_field_options_by_field($option_value_id, $to_json = false)
{
$em = Database::getManager();
$option = $em->find('ChamiloCoreBundle:ExtraFieldOptions', $option_value_id);
$option = $em->find(ExtraFieldOptions::class, $option_value_id);
if (!$option) {
return !$to_json ? [] : '{}';
}
$subOptions = $em
->getRepository('ChamiloCoreBundle:ExtraFieldOptions')
->findSecondaryOptions($option);
$subOptions = $em->getRepository(ExtraFieldOptions::class)->findSecondaryOptions($option);
$optionsInfo = [];
/** @var ExtraFieldOptions $subOption */

@ -64,7 +64,7 @@ class ExtraFieldValue extends Model
public function get_count()
{
$em = Database::getManager();
$query = $em->getRepository('ChamiloCoreBundle:ExtraFieldValues')->createQueryBuilder('e');
$query = $em->getRepository(ExtraFieldValues::class)->createQueryBuilder('e');
$query->select('count(e.id)');
$query->where('e.extraFieldType = :type');
$query->setParameter('type', $this->getExtraField()->getExtraFieldType());
@ -198,7 +198,7 @@ class ExtraFieldValue extends Model
$em = Database::getManager();
$currentTags = $em
->getRepository('ChamiloCoreBundle:ExtraFieldRelTag')
->getRepository(ExtraFieldRelTag::class)
->findBy([
'fieldId' => $extraFieldInfo['id'],
'itemId' => $params['item_id'],
@ -216,7 +216,7 @@ class ExtraFieldValue extends Model
continue;
}
$tagsResult = $em->getRepository('ChamiloCoreBundle:Tag')
$tagsResult = $em->getRepository(Tag::class)
->findBy([
'tag' => $tagValue,
'fieldId' => $extraFieldInfo['id'],
@ -235,7 +235,7 @@ class ExtraFieldValue extends Model
foreach ($tags as $tag) {
$tagUses = $em
->getRepository('ChamiloCoreBundle:ExtraFieldRelTag')
->getRepository(ExtraFieldRelTag::class)
->findBy([
'tagId' => $tag->getId(),
]);
@ -908,7 +908,7 @@ class ExtraFieldValue extends Model
} else {
if (ExtraField::FIELD_TYPE_TAG == $field['field_type']) {
$tagResult = [];
$tags = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag')
$tags = $em->getRepository(ExtraFieldRelTag::class)
->findBy(
[
'fieldId' => $field['id'],
@ -919,7 +919,7 @@ class ExtraFieldValue extends Model
/** @var ExtraFieldRelTag $extraFieldTag */
foreach ($tags as $extraFieldTag) {
/** @var \Chamilo\CoreBundle\Entity\Tag $tag */
$tag = $em->find('ChamiloCoreBundle:Tag', $extraFieldTag->getTagId());
$tag = $em->find(Tag::class, $extraFieldTag->getTagId());
$tagResult[] = [
'id' => $extraFieldTag->getTagId(),
'value' => $tag->getTag(),
@ -1085,7 +1085,7 @@ class ExtraFieldValue extends Model
->getQuery()
->getResult();
$fieldOptionsRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldOptions');
$fieldOptionsRepo = $em->getRepository(\Chamilo\CoreBundle\Entity\ExtraFieldOptions::class);
$valueList = [];
/** @var ExtraFieldValues $fieldValue */

@ -1,7 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
use Ddeboer\DataImport\Reader\ExcelReader;
use League\Csv\Reader;
/**
@ -78,9 +77,10 @@ class Import
return [];
}
$file = new \SplFileObject($filename);
$reader = new ExcelReader($file, 0);
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
return $reader;
return $sheet->toArray();
}
}

@ -3,6 +3,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Message;
use Chamilo\CoreBundle\Entity\MessageFeedback;
use Chamilo\CoreBundle\Entity\User;
use ChamiloSession as Session;
@ -350,7 +351,7 @@ class MessageManager
';
$result = Database::query($sql);
$messages = [];
$repo = Database::getManager()->getRepository('ChamiloCoreBundle:Message');
$repo = Database::getManager()->getRepository(Message::class);
while ($row = Database::fetch_array($result)) {
$message = $repo->find($row['id']);
$messages[] = $message;
@ -387,7 +388,7 @@ class MessageManager
false,
false
);
$senderId = $message->getUserSenderId();
$senderId = $message->getUserSender()->getId();
$senderInfo = api_get_user_info($senderId);
$html .= Display::panelCollapse(
$localTime.' '.$senderInfo['complete_name'].' '.$message->getTitle(),
@ -1343,10 +1344,6 @@ class MessageManager
$table = Database::get_main_table(TABLE_MESSAGE);
if (empty($type)) {
return '';
}
switch ($type) {
case self::MESSAGE_TYPE_OUTBOX:
$status = MESSAGE_STATUS_OUTBOX;
@ -3047,7 +3044,7 @@ class MessageManager
}
$userLike = $em
->getRepository('ChamiloCoreBundle:MessageFeedback')
->getRepository(MessageFeedback::class)
->findOneBy(['message' => $messageId, 'user' => $userId]);
return [

@ -264,8 +264,10 @@ if (!empty($courseList)) {
$start_date = $exerciseInfo['start_time'];
}
$exerciseId = $exerciseInfo['id'];
$best_score_data = ExerciseLib::get_best_attempt_in_course(
$exerciseInfo['id'],
$exerciseId,
$courseInfo['real_id'],
$session_id
);

@ -8,6 +8,8 @@ require_once __DIR__.'/../inc/global.inc.php';
// setting the section (for the tabs)
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(true);
$_user = api_get_user_info();
$id = (int) $_GET['id'];
$formSent = 0;
$errorMsg = '';

@ -1536,11 +1536,11 @@ class User implements UserInterface, EquatableInterface
return $this->passwordRequestedAt;
}
/*public function isPasswordRequestNonExpired($ttl)
public function isPasswordRequestNonExpired($ttl)
{
return $this->getPasswordRequestedAt() instanceof \DateTime &&
$this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
}*/
}
public function getUsername(): string
{
@ -1791,6 +1791,13 @@ class User implements UserInterface, EquatableInterface
return $this;
}
public function setPasswordRequestedAt(\DateTime $date = null)
{
$this->passwordRequestedAt = $date;
return $this;
}
public function setRoles(array $roles): self
{
$this->roles = [];

Loading…
Cancel
Save