From 7fff2eb3df18fcbbeeb0e8100d9e842a7f16d0ba Mon Sep 17 00:00:00 2001 From: christianbeeznst Date: Fri, 9 Aug 2024 16:57:04 -0500 Subject: [PATCH] Gradebook: Remove user_id from gradebook tables, ensure event tracking - refs BT#21911 --- .../gradebook_display_certificate.php | 2 +- .../gradebook/gradebook_display_summary.php | 6 +- public/main/gradebook/lib/GradebookUtils.php | 4 +- .../gradebook/lib/be/abstractlink.class.php | 13 ++- .../gradebook/lib/be/evaluation.class.php | 28 ++--- .../gradebook/lib/be/learnpathlink.class.php | 2 +- public/main/inc/lib/add_course.lib.inc.php | 1 - public/main/inc/lib/pdf.lib.php | 18 +-- src/CoreBundle/Entity/GradebookEvaluation.php | 5 - src/CoreBundle/Entity/GradebookLink.php | 5 - src/CoreBundle/Entity/User.php | 104 ------------------ 11 files changed, 40 insertions(+), 148 deletions(-) diff --git a/public/main/gradebook/gradebook_display_certificate.php b/public/main/gradebook/gradebook_display_certificate.php index 8b410bb4b6..3d54631dd4 100644 --- a/public/main/gradebook/gradebook_display_certificate.php +++ b/public/main/gradebook/gradebook_display_certificate.php @@ -242,7 +242,7 @@ if (!empty($cats)) { $total_weight = $cats[0]->get_weight(); $allcat = $cats[0]->get_subcategories( $stud_id, - api_get_course_id(), + api_get_course_int_id(), api_get_session_id() ); $alleval = $cats[0]->get_evaluations($stud_id); diff --git a/public/main/gradebook/gradebook_display_summary.php b/public/main/gradebook/gradebook_display_summary.php index 6c13101621..15e81445b8 100644 --- a/public/main/gradebook/gradebook_display_summary.php +++ b/public/main/gradebook/gradebook_display_summary.php @@ -57,13 +57,13 @@ switch ($action) { $cat = $cats[0]; $allcat = $cat->get_subcategories( null, - api_get_course_id(), + api_get_course_int_id(), api_get_session_id() ); $alleval = $cat->get_evaluations( null, true, - api_get_course_id(), + api_get_course_int_id(), api_get_session_id() ); $alllink = $cat->get_links( @@ -78,7 +78,7 @@ switch ($action) { $allcat, $alleval, $alllink, - null, // params + [], // params true, // $exportToPdf false, // showteacher null, diff --git a/public/main/gradebook/lib/GradebookUtils.php b/public/main/gradebook/lib/GradebookUtils.php index cb2458e4a5..b0cacc18a5 100644 --- a/public/main/gradebook/lib/GradebookUtils.php +++ b/public/main/gradebook/lib/GradebookUtils.php @@ -1501,7 +1501,7 @@ class GradebookUtils $cat = $cats[0]; $allcat = $cats[0]->get_subcategories( $userId, - api_get_course_id(), + api_get_course_int_id(), api_get_session_id() ); $alleval = $cats[0]->get_evaluations($userId); @@ -1517,7 +1517,7 @@ class GradebookUtils $allcat, $alleval, $alllink, - null, + [], true, false, $userId, diff --git a/public/main/gradebook/lib/be/abstractlink.class.php b/public/main/gradebook/lib/be/abstractlink.class.php index 73a497b475..badf61bbf1 100644 --- a/public/main/gradebook/lib/be/abstractlink.class.php +++ b/public/main/gradebook/lib/be/abstractlink.class.php @@ -379,7 +379,6 @@ abstract class AbstractLink implements GradebookItem $this->add_linked_data(); if (!empty($this->type) && !empty($this->ref_id) && - !empty($this->user_id) && !empty($this->course_id) && !empty($this->category) ) { @@ -406,7 +405,6 @@ abstract class AbstractLink implements GradebookItem ->setType($this->get_type()) ->setVisible($this->is_visible()) ->setWeight(api_float_val($this->get_weight())) - ->setUser(api_get_user_entity($this->get_user_id())) ->setRefId($this->get_ref_id()) ->setCategory($category) ->setCourse(api_get_course_entity($this->course_id)) @@ -416,6 +414,15 @@ abstract class AbstractLink implements GradebookItem $this->set_id($link->getId()); + Event::addEvent( + 'gradebook_link_created', + 'link', + $link->getId(), + null, + api_get_user_id(), + $this->course_id + ); + return $link->getId(); } } @@ -447,7 +454,6 @@ abstract class AbstractLink implements GradebookItem $link ->setType($this->get_type()) ->setRefId($this->get_ref_id()) - ->setUser(api_get_user_entity($this->get_user_id())) ->setCourse($course) ->setCategory($category) ->setWeight($this->get_weight()) @@ -768,7 +774,6 @@ abstract class AbstractLink implements GradebookItem $link->set_id($data['id']); $link->set_type($data['type']); $link->set_ref_id($data['ref_id']); - $link->set_user_id($data['user_id']); $link->setCourseId($data['c_id']); $link->set_category_id($data['category_id']); $link->set_date($data['created_at']); diff --git a/public/main/gradebook/lib/be/evaluation.class.php b/public/main/gradebook/lib/be/evaluation.class.php index 9716b2a8ef..b235659ea2 100644 --- a/public/main/gradebook/lib/be/evaluation.class.php +++ b/public/main/gradebook/lib/be/evaluation.class.php @@ -32,6 +32,8 @@ class Evaluation implements GradebookItem */ public function __construct() { + $this->type = ''; + $this->locked = 0; } /** @@ -141,7 +143,7 @@ class Evaluation implements GradebookItem public function get_type() { - return $this->type; + return $this->type ?? ''; } public function is_visible() @@ -151,7 +153,7 @@ class Evaluation implements GradebookItem public function get_locked() { - return $this->locked; + return $this->locked ?? 0; } public function is_locked() @@ -304,18 +306,11 @@ class Evaluation implements GradebookItem public function add(): bool { if (isset($this->name) && - isset($this->user_id) && isset($this->weight) && isset($this->eval_max) && isset($this->visible) ) { - $user = api_get_user_entity($this->get_user_id()); - - if (null === $user) { - return false; - } - if (empty($this->type)) { $this->type = 'evaluation'; } @@ -334,7 +329,6 @@ class Evaluation implements GradebookItem ->setCourse(api_get_course_entity($courseId)) ->setTitle($this->get_name()) ->setCategory($category) - ->setUser($user) ->setWeight(api_float_val($this->get_weight())) ->setMax(api_float_val($this->get_max())) ->setVisible($this->is_visible()) @@ -344,6 +338,15 @@ class Evaluation implements GradebookItem $em->flush(); $this->set_id($evaluation->getId()); + Event::addEvent( + 'gradebook_evaluation_created', + 'evaluation', + $evaluation->getId(), + api_get_utc_datetime(), + api_get_user_id(), + $courseId + ); + return true; } @@ -964,15 +967,14 @@ class Evaluation implements GradebookItem $eval->set_id($data['id']); $eval->set_name($data['title']); $eval->set_description($data['description']); - $eval->set_user_id($data['user_id']); $eval->setCourseId($data['c_id']); $eval->set_category_id($data['category_id']); $eval->set_date(api_get_local_time($data['created_at'])); $eval->set_weight($data['weight']); $eval->set_max($data['max']); $eval->set_visible($data['visible']); - $eval->set_type($data['type']); - $eval->set_locked($data['locked']); + $eval->set_type($data['type'] ?? ''); + $eval->set_locked($data['locked'] ?? 0); $eval->setSessionId(api_get_session_id()); if ($allow) { diff --git a/public/main/gradebook/lib/be/learnpathlink.class.php b/public/main/gradebook/lib/be/learnpathlink.class.php index 1dae05ab83..d23e0cd163 100644 --- a/public/main/gradebook/lib/be/learnpathlink.class.php +++ b/public/main/gradebook/lib/be/learnpathlink.class.php @@ -173,7 +173,7 @@ class LearnpathLink extends AbstractLink { $data = $this->get_learnpath_data(); - return $data['name']; + return $data['title']; } /** diff --git a/public/main/inc/lib/add_course.lib.inc.php b/public/main/inc/lib/add_course.lib.inc.php index 57df90656a..7110cd570a 100644 --- a/public/main/inc/lib/add_course.lib.inc.php +++ b/public/main/inc/lib/add_course.lib.inc.php @@ -604,7 +604,6 @@ class AddCourse $gradebookLink->setType(1); $gradebookLink->setRefId($refId); - $gradebookLink->setUser(api_get_user_entity()); $gradebookLink->setCourse($course); $gradebookLink->setCategory($childGradebookCategory); $gradebookLink->setCreatedAt(new \DateTime()); diff --git a/public/main/inc/lib/pdf.lib.php b/public/main/inc/lib/pdf.lib.php index 475a6897bc..8f9242bc96 100644 --- a/public/main/inc/lib/pdf.lib.php +++ b/public/main/inc/lib/pdf.lib.php @@ -303,7 +303,7 @@ class PDF $documentHtml = preg_replace($clean_search, '', $documentHtml); //absolute path for frames.css //TODO: necessary? - $absolute_css_path = api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/frames.css'; + $absolute_css_path = api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets.stylesheets').'/frames.css'; $documentHtml = str_replace('href="./css/frames.css"', $absolute_css_path, $documentHtml); if (!empty($courseInfo['path'])) { $documentHtml = str_replace('../', '', $documentHtml); @@ -316,7 +316,7 @@ class PDF ); } - $documentHtml = self::fixImagesPaths($documentHtml, $courseInfo, $dirName); + //$documentHtml = self::fixImagesPaths($documentHtml, $courseInfo, $dirName); // The library mPDF expects UTF-8 encoded input data. api_set_encoding_html($documentHtml, 'UTF-8'); // TODO: Maybe it is better idea the title to be passed through @@ -547,7 +547,7 @@ class PDF { $web_path = false; $urlId = api_get_current_access_url_id(); - if (!empty($courseCode) && 'true' == api_get_setting('pdf_export_watermark_by_course')) { + if (!empty($courseCode) && 'true' == api_get_setting('document.pdf_export_watermark_by_course')) { $course_info = api_get_course_info($courseCode); // course path $store_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/'.$urlId.'_pdf_watermark.png'; @@ -576,7 +576,7 @@ class PDF public static function delete_watermark($courseCode = null) { $urlId = api_get_current_access_url_id(); - if (!empty($courseCode) && 'true' === api_get_setting('pdf_export_watermark_by_course')) { + if (!empty($courseCode) && 'true' === api_get_setting('document.pdf_export_watermark_by_course')) { $course_info = api_get_course_info($courseCode); // course path $store_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/'.$urlId.'_pdf_watermark.png'; @@ -605,7 +605,7 @@ class PDF public static function upload_watermark($filename, $source_file, $courseCode = null) { $urlId = api_get_current_access_url_id(); - if (!empty($courseCode) && 'true' === api_get_setting('pdf_export_watermark_by_course')) { + if (!empty($courseCode) && 'true' === api_get_setting('document.pdf_export_watermark_by_course')) { $course_info = api_get_course_info($courseCode); $store_path = api_get_path(SYS_COURSE_PATH).$course_info['path']; // course path $web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/pdf_watermark.png'; @@ -754,7 +754,7 @@ class PDF // Add decoration only if not stated otherwise if ($complete) { // Adding watermark - if ('true' == api_get_setting('pdf_export_watermark_enable')) { + if ('true' == api_get_setting('document.pdf_export_watermark_enable')) { $watermark_file = self::get_watermark($courseCode); if ($watermark_file) { $this->pdf->SetWatermarkImage($watermark_file); @@ -766,9 +766,9 @@ class PDF $this->pdf->showWatermarkImage = true; } } - $watermark_text = api_get_setting('pdf_export_watermark_text'); - if ($courseCode && 'true' === api_get_setting('pdf_export_watermark_by_course')) { - $courseWaterMark = api_get_course_setting('pdf_export_watermark_text'); + $watermark_text = api_get_setting('document.pdf_export_watermark_text'); + if ($courseCode && 'true' === api_get_setting('document.pdf_export_watermark_by_course')) { + $courseWaterMark = api_get_course_setting('document.pdf_export_watermark_text'); if (!empty($courseWaterMark) && -1 != $courseWaterMark) { $watermark_text = $courseWaterMark; } diff --git a/src/CoreBundle/Entity/GradebookEvaluation.php b/src/CoreBundle/Entity/GradebookEvaluation.php index c2231d9321..9305b7a783 100644 --- a/src/CoreBundle/Entity/GradebookEvaluation.php +++ b/src/CoreBundle/Entity/GradebookEvaluation.php @@ -19,7 +19,6 @@ use Symfony\Component\Validator\Constraints as Assert; class GradebookEvaluation { use CourseTrait; - use UserTrait; #[ORM\Column(name: 'id', type: 'integer')] #[ORM\Id] @@ -33,10 +32,6 @@ class GradebookEvaluation #[ORM\Column(name: 'description', type: 'text', nullable: true)] protected ?string $description = null; - #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'gradeBookEvaluations')] - #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')] - protected User $user; - #[ORM\ManyToOne(targetEntity: Course::class, inversedBy: 'gradebookEvaluations')] #[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', onDelete: 'CASCADE')] protected Course $course; diff --git a/src/CoreBundle/Entity/GradebookLink.php b/src/CoreBundle/Entity/GradebookLink.php index 30c0171d98..5aba525c49 100644 --- a/src/CoreBundle/Entity/GradebookLink.php +++ b/src/CoreBundle/Entity/GradebookLink.php @@ -19,7 +19,6 @@ use Symfony\Component\Validator\Constraints as Assert; class GradebookLink { use CourseTrait; - use UserTrait; #[ORM\Column(name: 'id', type: 'integer')] #[ORM\Id] @@ -34,10 +33,6 @@ class GradebookLink #[ORM\Column(name: 'ref_id', type: 'integer', nullable: false)] protected int $refId; - #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'gradeBookLinks')] - #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')] - protected User $user; - #[ORM\ManyToOne(targetEntity: Course::class, inversedBy: 'gradebookLinks')] #[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', onDelete: 'CASCADE')] protected Course $course; diff --git a/src/CoreBundle/Entity/User.php b/src/CoreBundle/Entity/User.php index e4d69ad864..2fa171dd0a 100644 --- a/src/CoreBundle/Entity/User.php +++ b/src/CoreBundle/Entity/User.php @@ -397,28 +397,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso #[ORM\OneToMany(mappedBy: 'user', targetEntity: GradebookComment::class)] protected Collection $gradeBookComments; - /** - * @var Collection - */ - #[ORM\OneToMany( - mappedBy: 'user', - targetEntity: GradebookEvaluation::class, - cascade: ['persist', 'remove'], - orphanRemoval: true - )] - protected Collection $gradeBookEvaluations; - - /** - * @var Collection - */ - #[ORM\OneToMany( - mappedBy: 'user', - targetEntity: GradebookLink::class, - cascade: ['persist', 'remove'], - orphanRemoval: true - )] - protected Collection $gradeBookLinks; - /** * @var Collection */ @@ -758,8 +736,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso $this->commentedUserSkills = new ArrayCollection(); $this->gradeBookCategories = new ArrayCollection(); $this->gradeBookComments = new ArrayCollection(); - $this->gradeBookEvaluations = new ArrayCollection(); - $this->gradeBookLinks = new ArrayCollection(); $this->gradeBookResults = new ArrayCollection(); $this->gradeBookResultLogs = new ArrayCollection(); $this->gradeBookScoreLogs = new ArrayCollection(); @@ -781,7 +757,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso $this->receivedMessages = new ArrayCollection(); $this->surveyInvitations = new ArrayCollection(); $this->logins = new ArrayCollection(); - // $this->extraFields = new ArrayCollection(); $this->createdAt = new DateTime(); $this->updatedAt = new DateTime(); $this->registrationDate = new DateTime(); @@ -805,40 +780,13 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso { return [ new Assert\Length(['min' => 5]), - // Alpha numeric + "_" or "-" new Assert\Regex(['pattern' => '/^[a-z\-_0-9]+$/i', 'htmlPattern' => '/^[a-z\-_0-9]+$/i']), - // Min 3 letters - not needed - /*new Assert\Regex(array( - 'pattern' => '/[a-z]{3}/i', - 'htmlPattern' => '/[a-z]{3}/i') - ),*/ - // Min 2 numbers new Assert\Regex(['pattern' => '/[0-9]{2}/', 'htmlPattern' => '/[0-9]{2}/']), ]; } public static function loadValidatorMetadata(ClassMetadata $metadata): void { - // $metadata->addPropertyConstraint('firstname', new Assert\NotBlank()); - // $metadata->addPropertyConstraint('lastname', new Assert\NotBlank()); - // $metadata->addPropertyConstraint('email', new Assert\Email()); - /* - $metadata->addPropertyConstraint('password', - new Assert\Collection(self::getPasswordConstraints()) - );*/ - /*$metadata->addConstraint(new UniqueEntity(array( - 'fields' => 'username', - 'message' => 'This value is already used.', - )));*/ - /*$metadata->addPropertyConstraint( - 'username', - new Assert\Length(array( - 'min' => 2, - 'max' => 50, - 'minMessage' => 'This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.', - 'maxMessage' => 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.', - )) - );*/ } public function getUuid(): Uuid @@ -897,15 +845,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso return $this; } - /*public function getDropBoxReceivedFiles() - { - return $this->dropBoxReceivedFiles; - } - - public function setDropBoxReceivedFiles($value): void - { - $this->dropBoxReceivedFiles = $value; - }*/ public function getCourses(): Collection { return $this->courses; @@ -928,18 +867,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso return $this; } - /*public function getCurriculumItems(): Collection - { - return $this->curriculumItems; - } - - public function setCurriculumItems(array $items): self - { - $this->curriculumItems = $items; - - return $this; - }*/ - /** * Get a bool on whether the user is active or not. Active can be "-1" which means pre-deleted, and is returned as false (not active). * @@ -1430,31 +1357,16 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso public function isAccountNonExpired(): bool { - /*if (true === $this->expired) { - return false; - } - - if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) { - return false; - }*/ return true; } public function isAccountNonLocked(): bool { return true; - // return !$this->locked; } public function isCredentialsNonExpired(): bool { - /*if (true === $this->credentialsExpired) { - return false; - } - - if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) { - return false; - }*/ return true; } @@ -1985,22 +1897,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso return $this->gradeBookComments; } - /** - * @return Collection - */ - public function getGradeBookEvaluations(): Collection - { - return $this->gradeBookEvaluations; - } - - /** - * @return Collection - */ - public function getGradeBookLinks(): Collection - { - return $this->gradeBookLinks; - } - /** * @return Collection */