';
return $html;
@@ -86,14 +91,17 @@ function card_settings_close()
return $html;
}
-$form->addHtml(card_settings_open('course_settings', get_lang('Course settings'), true, 'settings.png', 'accordionSettings'));
+$form->addHtml(
+ card_settings_open('course_settings', get_lang('Course settings'), true, 'settings.png', 'accordionSettings')
+);
$image = '';
$illustrationUrl = $illustrationRepo->getIllustrationUrl($courseEntity, 'course_picture_medium');
if (!empty($illustrationUrl)) {
- $image = '
';
+ $image = '
+
+
';
}
$form->addText('title', get_lang('Title'), true);
diff --git a/public/main/gradebook/gradebook_edit_all.php b/public/main/gradebook/gradebook_edit_all.php
index f7f4455838..28c000abef 100644
--- a/public/main/gradebook/gradebook_edit_all.php
+++ b/public/main/gradebook/gradebook_edit_all.php
@@ -39,7 +39,7 @@ $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
$table_evaluated[LINK_EXERCISE] = [
TABLE_QUIZ_TEST,
'title',
- 'id',
+ 'iid',
get_lang('Test'),
];
$table_evaluated[LINK_DROPBOX] = [
@@ -51,31 +51,31 @@ $table_evaluated[LINK_DROPBOX] = [
$table_evaluated[LINK_STUDENTPUBLICATION] = [
TABLE_STUDENT_PUBLICATION,
'url',
- 'id',
+ 'iid',
get_lang('Assignments'),
];
$table_evaluated[LINK_LEARNPATH] = [
TABLE_LP_MAIN,
'name',
- 'id',
+ 'iid',
get_lang('Courses'),
];
$table_evaluated[LINK_FORUM_THREAD] = [
TABLE_FORUM_THREAD,
'thread_title_qualify',
- 'thread_id',
+ 'iid',
get_lang('Forum'),
];
$table_evaluated[LINK_ATTENDANCE] = [
TABLE_ATTENDANCE,
'attendance_title_qualify',
- 'id',
+ 'iid',
get_lang('Attendance'),
];
$table_evaluated[LINK_SURVEY] = [
TABLE_SURVEY,
'code',
- 'survey_id',
+ 'iid',
get_lang('Survey'),
];
diff --git a/public/main/gradebook/lib/fe/catform.class.php b/public/main/gradebook/lib/fe/catform.class.php
index 49624e79c3..c3dbd05470 100644
--- a/public/main/gradebook/lib/fe/catform.class.php
+++ b/public/main/gradebook/lib/fe/catform.class.php
@@ -342,7 +342,7 @@ class CatForm extends FormValidator
if (isset($this->category_object) &&
0 == $this->category_object->get_parent_id() &&
- (api_is_platform_admin() || 'true' == api_get_setting('teachers_can_change_grade_model_settings'))
+ (api_is_platform_admin() || 'true' === api_get_setting('teachers_can_change_grade_model_settings'))
) {
// Getting grade models
$obj = new GradeModel();
@@ -370,7 +370,7 @@ class CatForm extends FormValidator
}
if (count($test_cats) > 1 || !empty($links)) {
- if ('true' == api_get_setting('gradebook_enable_grade_model')) {
+ if ('true' === api_get_setting('gradebook_enable_grade_model')) {
$this->freeze('grade_model_id');
}
}
@@ -404,23 +404,25 @@ class CatForm extends FormValidator
$documentId = $this->category_object->getDocumentId();
if (!empty($documentId)) {
- $documentData = DocumentManager::get_document_data_by_id($documentId, api_get_course_id());
+ $repo = \Chamilo\CoreBundle\Framework\Container::getDocumentRepository();
+ /** @var \Chamilo\CourseBundle\Entity\CDocument $documentData */
+ $documentData = $repo->find($documentId);
if (!empty($documentData)) {
- $this->addLabel(get_lang('Certificate'), $documentData['title']);
+ $this->addLabel(get_lang('Certificate'), $documentData->getTitle());
}
}
if (self::TYPE_ADD == $this->form_type) {
$this->addButtonCreate(get_lang('Add category'));
} else {
- $this->addElement('hidden', 'editcat', intval($_GET['editcat']));
+ $this->addElement('hidden', 'editcat', (int) $_GET['editcat']);
$this->addButtonUpdate(get_lang('Edit this category'));
}
$setting = api_get_setting('tool_visible_by_default_at_creation');
$visibility_default = 1;
- if (isset($setting['gradebook']) && 'false' == $setting['gradebook']) {
+ if (isset($setting['gradebook']) && 'false' === $setting['gradebook']) {
$visibility_default = 0;
}
diff --git a/public/main/gradebook/lib/fe/dataform.class.php b/public/main/gradebook/lib/fe/dataform.class.php
index 650df41f8e..a012adf355 100644
--- a/public/main/gradebook/lib/fe/dataform.class.php
+++ b/public/main/gradebook/lib/fe/dataform.class.php
@@ -1,4 +1,5 @@
validate()) {
if ($id) {
$item = learnpath::getCategory($id);
$defaults = [
- 'id' => $item->getId(),
+ 'id' => $item->getIid(),
'name' => $item->getName(),
];
$form->setDefaults($defaults);
diff --git a/public/main/lp/lp_edit.php b/public/main/lp/lp_edit.php
index 9401c57cf4..eab95095ac 100644
--- a/public/main/lp/lp_edit.php
+++ b/public/main/lp/lp_edit.php
@@ -375,7 +375,9 @@ if ($form->validate()) {
$request = Container::getRequest();
if ($request->files->has('lp_preview_image')) {
$file = $request->files->get('lp_preview_image');
- $lpRepo->addFile($lp, $file);
+ if (!empty($file)) {
+ $lpRepo->addFile($lp, $file);
+ }
}
$em->persist($lp);
diff --git a/public/main/mySpace/myStudents.php b/public/main/mySpace/myStudents.php
index 5564c31822..2e582ef8c3 100644
--- a/public/main/mySpace/myStudents.php
+++ b/public/main/mySpace/myStudents.php
@@ -2133,7 +2133,7 @@ if (empty($details)) {
echo '
'.api_convert_and_format_date(
$results['sent_date_from_db']
).' '.$results['expiry_note'].' | ';
- $assignment = get_work_assignment_by_id($work->id, $courseInfo['real_id']);
+ $assignment = get_work_assignment_by_id($work->iid, $courseInfo['real_id']);
echo '
';
if (!empty($assignment['expires_on'])) {
diff --git a/public/main/survey/survey.lib.php b/public/main/survey/survey.lib.php
index afaee151a3..1e56d7f932 100644
--- a/public/main/survey/survey.lib.php
+++ b/public/main/survey/survey.lib.php
@@ -311,7 +311,7 @@ class SurveyManager
$sql = 'SELECT survey_version FROM '.$table_survey.'
WHERE
c_id = '.$course_id.' AND
- survey_id = '.intval($values['parent_id']);
+ iid = '.intval($values['parent_id']);
$rs = Database::query($sql);
$getversion = Database::fetch_array($rs, 'ASSOC');
if (empty($getversion['survey_version'])) {
@@ -590,9 +590,6 @@ class SurveyManager
'".$_course['id']."')";
Database::query($sql);
$return = Database::insert_id();
-
- $sql = "UPDATE $table_survey SET survey_id = $return WHERE iid = $return";
- Database::query($sql);
} else {
$sql = "UPDATE $table_survey SET
code = '".Database::escape_string($values['survey_code'])."',
@@ -2124,12 +2121,12 @@ class SurveyManager
Database::query($sql);
$sql = "DELETE FROM $surveyAnswerTable
- WHERE survey_id = $surveyId AND c_id = $courseId ";
+ WHERE survey_id = $surveyId AND c_id = $courseId ";
Database::query($sql);
$sql = "UPDATE $surveyTable
SET invited = 0, answered = 0
- WHERE survey_id = $surveyId AND c_id = $courseId AND session_id = $sessionId ";
+ WHERE iid = $surveyId AND c_id = $courseId AND session_id = $sessionId ";
Database::query($sql);
return true;
@@ -2176,10 +2173,6 @@ class SurveyManager
$newSurveyId = Database::insert($surveyTable, $surveyData);
if ($newSurveyId) {
- $sql = "UPDATE $surveyTable SET survey_id = $newSurveyId
- WHERE iid = $newSurveyId";
- Database::query($sql);
-
$sql = "SELECT * FROM $surveyQuestionGroupTable
WHERE c_id = $originalCourseId AND survey_id = $surveyId";
$res = Database::query($sql);
diff --git a/public/main/work/edit.php b/public/main/work/edit.php
index ad3bc3af78..5bc193e0d0 100644
--- a/public/main/work/edit.php
+++ b/public/main/work/edit.php
@@ -148,7 +148,7 @@ $form->addText('title', get_lang('Title'), true, ['id' => 'file_upload']);
if ($is_allowed_to_edit && !empty($item_id)) {
$sql = "SELECT contains_file, url
FROM $work_table
- WHERE c_id = $course_id AND id ='$item_id' ";
+ WHERE c_id = $course_id AND iid ='$item_id' ";
$result = Database::query($sql);
if (false !== $result && Database::num_rows($result) > 0) {
$row = Database::fetch_array($result);
diff --git a/public/main/work/view.php b/public/main/work/view.php
index fb8fb2aa27..47fa3fea11 100644
--- a/public/main/work/view.php
+++ b/public/main/work/view.php
@@ -2,25 +2,32 @@
/* For licensing terms, see /license.txt */
+use Chamilo\CoreBundle\Framework\Container;
+use Chamilo\CourseBundle\Entity\CStudentPublication;
+
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
require_once 'work.lib.php';
$id = isset($_GET['id']) ? (int) $_GET['id'] : null;
-$work = get_work_data_by_id($id);
+
+$repo = Container::getStudentPublicationRepository();
+/** @var CStudentPublication $work */
+$work = $repo->find($id);
if (empty($work)) {
api_not_allowed(true);
}
-protectWork(api_get_course_info(), $work['parent_id']);
+$parentId = $work->getParentId();
+protectWork(api_get_course_info(), $parentId);
-$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
-$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : null;
+$action = $_REQUEST['action'] ?? null;
+$page = $_REQUEST['page'] ?? null;
-$work['title'] = isset($work['title']) ? Security::remove_XSS($work['title']) : '';
-$work['description'] = isset($work['description']) ? Security::remove_XSS($work['description']) : '';
+/*$work['title'] = isset($work['title']) ? Security::remove_XSS($work['title']) : '';
+$work['description'] = isset($work['description']) ? Security::remove_XSS($work['description']) : '';*/
$htmlHeadXtra[] = '';
$interbreadcrumb[] = [
@@ -28,7 +35,7 @@ $interbreadcrumb[] = [
'name' => get_lang('Assignments'),
];
-$folderData = get_work_data_by_id($work['parent_id']);
+$folderData = get_work_data_by_id($parentId);
$courseInfo = api_get_course_info();
$courseEntity = api_get_course_entity();
$isCourseManager = api_is_platform_admin() || api_is_coach() || api_is_allowed_to_edit(false, false, true);
@@ -36,7 +43,9 @@ $isCourseManager = api_is_platform_admin() || api_is_coach() || api_is_allowed_t
$allowEdition = false;
if ($isCourseManager) {
$allowEdition = true;
- if (!empty($work['qualification']) && api_get_configuration_value('block_student_publication_score_edition')) {
+ if (!empty($work->getQualification()) &&
+ api_get_configuration_value('block_student_publication_score_edition')
+ ) {
$allowEdition = false;
}
}
@@ -50,26 +59,28 @@ $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
$courseInfo
);
-$isDrhOfSession = !empty(SessionManager::getSessionFollowedByDrh(api_get_user_id(), $work['session_id']));
+$isDrhOfSession = false;
+// @todo fix $isDrhOfSession check
+//$isDrhOfSession = !empty(SessionManager::getSessionFollowedByDrh(api_get_user_id(), $work['session_id']));
-if ((user_is_author($id) || $isDrhOfCourse || $allowEdition || $isDrhOfSession) ||
+if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id)) ||
(
0 == $courseInfo['show_score'] &&
- 1 == $work['active'] &&
- 1 == $work['accepted']
+ 1 == $work->getActive() &&
+ 1 == $work->getAccepted()
)
) {
if ((api_is_allowed_to_edit() || api_is_coach()) || api_is_drh()) {
- $url_dir = api_get_path(WEB_CODE_PATH).'work/work_list_all.php?id='.$folderData['id'].'&'.api_get_cidreq();
+ $url_dir = api_get_path(WEB_CODE_PATH).'work/work_list_all.php?id='.$folderData['iid'].'&'.api_get_cidreq();
} else {
- $url_dir = api_get_path(WEB_CODE_PATH).'work/work_list.php?id='.$folderData['id'].'&'.api_get_cidreq();
+ $url_dir = api_get_path(WEB_CODE_PATH).'work/work_list.php?id='.$folderData['iid'].'&'.api_get_cidreq();
}
- $userInfo = api_get_user_info($work['user_id']);
+ $userInfo = api_get_user_info($work->getUserId());
$interbreadcrumb[] = ['url' => $url_dir, 'name' => $folderData['title']];
$interbreadcrumb[] = ['url' => '#', 'name' => $userInfo['complete_name']];
- $interbreadcrumb[] = ['url' => '#', 'name' => $work['title']];
-
+ $interbreadcrumb[] = ['url' => '#', 'name' => $work->getTitle()];
+ $workId = $work->getIid();
if ((
0 == $courseInfo['show_score'] &&
1 == $work['active'] &&
@@ -78,9 +89,10 @@ if ((user_is_author($id) || $isDrhOfCourse || $allowEdition || $isDrhOfSession)
$isCourseManager || user_is_author($id) || $isDrhOfCourse || $isDrhOfSession
) {
if ('edit' === $page) {
- $url = api_get_path(WEB_CODE_PATH).'work/edit.php?id='.$folderData['id'].'&item_id='.$work['id'].'&'.api_get_cidreq();
+ $url = api_get_path(WEB_CODE_PATH).
+ 'work/edit.php?id='.$folderData['iid'].'&item_id='.$workId.'&'.api_get_cidreq();
} else {
- $url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['id'].'&'.api_get_cidreq();
+ $url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$workId.'&'.api_get_cidreq();
$allowRedirect = api_get_configuration_value('allow_redirect_to_main_page_after_work_upload');
$urlToRedirect = '';
@@ -172,7 +184,7 @@ if ((user_is_author($id) || $isDrhOfCourse || $allowEdition || $isDrhOfSession)
$tpl->assign('comments', $comments);
$actions = '';
- if (isset($work['contains_file']) && !empty($work['contains_file'])) {
+ if ($work->getContainsFile()) {
if (isset($work['download_url']) && !empty($work['download_url'])) {
$actions = Display::url(
Display::return_icon(
diff --git a/public/main/work/work.lib.php b/public/main/work/work.lib.php
index 2190a268e6..2d848eb782 100644
--- a/public/main/work/work.lib.php
+++ b/public/main/work/work.lib.php
@@ -142,15 +142,15 @@ function get_work_data_by_id($id, $courseId = 0, $sessionId = 0)
if (empty($studentPublication->getTitle())) {
$work['title'] = basename($studentPublication->getUrl());
}
- $work['download_url'] = $router->generate(
- 'chamilo_core_resource_download',
- [
- 'id' => $studentPublication->getResourceNode()->getId(),
- 'tool' => 'student_publication',
- 'type' => 'student_publications',
- ]
- ).'?'.api_get_cidreq();
-
+ $url = $router->generate(
+ 'chamilo_core_resource_download',
+ [
+ 'id' => $studentPublication->getResourceNode()->getId(),
+ 'tool' => 'student_publication',
+ 'type' => 'student_publications',
+ ]
+ );
+ $work['download_url'] = $url.'?'.api_get_cidreq();
$work['view_url'] = $webCodePath.'work/view.php?id='.$workId.'&'.api_get_cidreq();
$showUrl = $work['show_url'] = $webCodePath.'work/show_file.php?id='.$workId.'&'.api_get_cidreq();
$work['show_content'] = '';
@@ -697,7 +697,7 @@ function build_work_move_to_selector($folders, $curdirpath, $move_file, $group_d
$move_file = (int) $move_file;
$tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = "SELECT title, url FROM $tbl_work
- WHERE c_id = $course_id AND id ='".$move_file."'";
+ WHERE c_id = $course_id AND iid ='".$move_file."'";
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');
$title = empty($row['title']) ? basename($row['url']) : $row['title'];
@@ -3284,29 +3284,29 @@ function getWorkDescriptionToolbar()
}
/**
- * @param array $work
- *
* @return array
*/
-function getWorkComments($work)
+function getWorkComments(CStudentPublication $work)
{
$commentTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT_COMMENT);
$userTable = Database::get_main_table(TABLE_MAIN_USER);
- $courseId = (int) $work['c_id'];
+ /*$courseId = (int) $work['c_id'];
$workId = (int) $work['iid'];
if (empty($courseId) || empty($workId)) {
return [];
- }
+ }*/
+
+ $workId = $work->getIid();
$sql = "SELECT
- c.id,
+ c.iid,
c.user_id
FROM $commentTable c
INNER JOIN $userTable u
ON (u.id = c.user_id)
- WHERE c_id = $courseId AND work_id = $workId
+ WHERE work_id = $workId
ORDER BY sent_at
";
$result = Database::query($sql);
@@ -3793,14 +3793,15 @@ function addWorkComment($courseInfo, $userId, $parentWork, $work, $data)
}
/**
- * @param array $work
* @param array $workParent
*
* @return string
*/
-function getWorkCommentForm($work, $workParent)
+function getWorkCommentForm(CStudentPublication $work, $workParent)
{
- $url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['iid'].'&action=send_comment&'.api_get_cidreq();
+ $id = $work->getIid();
+
+ $url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$id.'&action=send_comment&'.api_get_cidreq();
$form = new FormValidator(
'work_comment',
'post',
@@ -3815,7 +3816,9 @@ function getWorkCommentForm($work, $workParent)
$allowEdition = false;
if ($isCourseManager) {
$allowEdition = true;
- if (!empty($work['qualification']) && api_get_configuration_value('block_student_publication_score_edition')) {
+ if (!empty($work->getQualification()) &&
+ api_get_configuration_value('block_student_publication_score_edition')
+ ) {
$allowEdition = false;
}
}
@@ -3842,18 +3845,24 @@ function getWorkCommentForm($work, $workParent)
$form,
'qualification',
$qualification,
- $work['qualification']
+ $work->getQualification()
);
}
$form->addFile('file', get_lang('Correction'));
- $form->setDefaults(['qualification' => $work['qualification']]);
+ $form->setDefaults(['qualification' => $work->getQualification()]);
}
}
- Skill::addSkillsToUserForm($form, ITEM_TYPE_STUDENT_PUBLICATION, $workParent['iid'], $work['user_id'], $work['iid']);
+ Skill::addSkillsToUserForm(
+ $form,
+ ITEM_TYPE_STUDENT_PUBLICATION,
+ $workParent['iid'],
+ $work->getUserId(),
+ $id
+ );
$form->addHtmlEditor('comment', get_lang('Comment'), false);
$form->addFile('attachment', get_lang('Attachment'));
- $form->addElement('hidden', 'iid', $work['iid']);
+ $form->addElement('hidden', 'iid', $id);
if (api_is_allowed_to_edit()) {
$form->addCheckBox(
diff --git a/src/CoreBundle/Tool/Settings.php b/src/CoreBundle/Tool/Settings.php
index d02722f79e..51730b5ff2 100644
--- a/src/CoreBundle/Tool/Settings.php
+++ b/src/CoreBundle/Tool/Settings.php
@@ -4,9 +4,6 @@
namespace Chamilo\CoreBundle\Tool;
-/**
- * Class Announcement.
- */
class Settings extends AbstractTool
{
}
diff --git a/src/CoreBundle/Traits/ControllerTrait.php b/src/CoreBundle/Traits/ControllerTrait.php
index 43fe0f401b..ce283245b8 100644
--- a/src/CoreBundle/Traits/ControllerTrait.php
+++ b/src/CoreBundle/Traits/ControllerTrait.php
@@ -21,6 +21,7 @@ use Chamilo\CourseBundle\Repository\CLpCategoryRepository;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\CourseBundle\Repository\CQuizQuestionCategoryRepository;
use Chamilo\CourseBundle\Repository\CQuizQuestionRepository;
+use Chamilo\CourseBundle\Repository\CStudentPublicationRepository;
use Knp\Menu\FactoryInterface as MenuFactoryInterface;
use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory;
use Symfony\Component\HttpFoundation\Request;
@@ -43,19 +44,21 @@ trait ControllerTrait
*/
$services[] = ResourceFactory::class;
$services[] = ResourceNodeRepository::class;
+
$services[] = CAnnouncementRepository::class;
$services[] = CAnnouncementAttachmentRepository::class;
$services[] = CAttendanceRepository::class;
$services[] = CBlogRepository::class;
$services[] = CCalendarEventAttachmentRepository::class;
$services[] = CDocumentRepository::class;
- $services[] = CQuizQuestionRepository::class;
- $services[] = CQuizQuestionCategoryRepository::class;
$services[] = CForumForumRepository::class;
$services[] = CForumAttachmentRepository::class;
-
$services[] = CLpRepository::class;
$services[] = CLpCategoryRepository::class;
+ $services[] = CQuizQuestionRepository::class;
+ $services[] = CQuizQuestionCategoryRepository::class;
+ $services[] = CStudentPublicationRepository::class;
+
$services[] = IllustrationRepository::class;
|