Gradebook: Remove user_id from gradebook tables, ensure event tracking - refs BT#21911

pull/5718/head
christianbeeznst 1 year ago
parent 0cabb60554
commit 7fff2eb3df
  1. 2
      public/main/gradebook/gradebook_display_certificate.php
  2. 6
      public/main/gradebook/gradebook_display_summary.php
  3. 4
      public/main/gradebook/lib/GradebookUtils.php
  4. 13
      public/main/gradebook/lib/be/abstractlink.class.php
  5. 28
      public/main/gradebook/lib/be/evaluation.class.php
  6. 2
      public/main/gradebook/lib/be/learnpathlink.class.php
  7. 1
      public/main/inc/lib/add_course.lib.inc.php
  8. 18
      public/main/inc/lib/pdf.lib.php
  9. 5
      src/CoreBundle/Entity/GradebookEvaluation.php
  10. 5
      src/CoreBundle/Entity/GradebookLink.php
  11. 104
      src/CoreBundle/Entity/User.php

@ -242,7 +242,7 @@ if (!empty($cats)) {
$total_weight = $cats[0]->get_weight(); $total_weight = $cats[0]->get_weight();
$allcat = $cats[0]->get_subcategories( $allcat = $cats[0]->get_subcategories(
$stud_id, $stud_id,
api_get_course_id(), api_get_course_int_id(),
api_get_session_id() api_get_session_id()
); );
$alleval = $cats[0]->get_evaluations($stud_id); $alleval = $cats[0]->get_evaluations($stud_id);

@ -57,13 +57,13 @@ switch ($action) {
$cat = $cats[0]; $cat = $cats[0];
$allcat = $cat->get_subcategories( $allcat = $cat->get_subcategories(
null, null,
api_get_course_id(), api_get_course_int_id(),
api_get_session_id() api_get_session_id()
); );
$alleval = $cat->get_evaluations( $alleval = $cat->get_evaluations(
null, null,
true, true,
api_get_course_id(), api_get_course_int_id(),
api_get_session_id() api_get_session_id()
); );
$alllink = $cat->get_links( $alllink = $cat->get_links(
@ -78,7 +78,7 @@ switch ($action) {
$allcat, $allcat,
$alleval, $alleval,
$alllink, $alllink,
null, // params [], // params
true, // $exportToPdf true, // $exportToPdf
false, // showteacher false, // showteacher
null, null,

@ -1501,7 +1501,7 @@ class GradebookUtils
$cat = $cats[0]; $cat = $cats[0];
$allcat = $cats[0]->get_subcategories( $allcat = $cats[0]->get_subcategories(
$userId, $userId,
api_get_course_id(), api_get_course_int_id(),
api_get_session_id() api_get_session_id()
); );
$alleval = $cats[0]->get_evaluations($userId); $alleval = $cats[0]->get_evaluations($userId);
@ -1517,7 +1517,7 @@ class GradebookUtils
$allcat, $allcat,
$alleval, $alleval,
$alllink, $alllink,
null, [],
true, true,
false, false,
$userId, $userId,

@ -379,7 +379,6 @@ abstract class AbstractLink implements GradebookItem
$this->add_linked_data(); $this->add_linked_data();
if (!empty($this->type) && if (!empty($this->type) &&
!empty($this->ref_id) && !empty($this->ref_id) &&
!empty($this->user_id) &&
!empty($this->course_id) && !empty($this->course_id) &&
!empty($this->category) !empty($this->category)
) { ) {
@ -406,7 +405,6 @@ abstract class AbstractLink implements GradebookItem
->setType($this->get_type()) ->setType($this->get_type())
->setVisible($this->is_visible()) ->setVisible($this->is_visible())
->setWeight(api_float_val($this->get_weight())) ->setWeight(api_float_val($this->get_weight()))
->setUser(api_get_user_entity($this->get_user_id()))
->setRefId($this->get_ref_id()) ->setRefId($this->get_ref_id())
->setCategory($category) ->setCategory($category)
->setCourse(api_get_course_entity($this->course_id)) ->setCourse(api_get_course_entity($this->course_id))
@ -416,6 +414,15 @@ abstract class AbstractLink implements GradebookItem
$this->set_id($link->getId()); $this->set_id($link->getId());
Event::addEvent(
'gradebook_link_created',
'link',
$link->getId(),
null,
api_get_user_id(),
$this->course_id
);
return $link->getId(); return $link->getId();
} }
} }
@ -447,7 +454,6 @@ abstract class AbstractLink implements GradebookItem
$link $link
->setType($this->get_type()) ->setType($this->get_type())
->setRefId($this->get_ref_id()) ->setRefId($this->get_ref_id())
->setUser(api_get_user_entity($this->get_user_id()))
->setCourse($course) ->setCourse($course)
->setCategory($category) ->setCategory($category)
->setWeight($this->get_weight()) ->setWeight($this->get_weight())
@ -768,7 +774,6 @@ abstract class AbstractLink implements GradebookItem
$link->set_id($data['id']); $link->set_id($data['id']);
$link->set_type($data['type']); $link->set_type($data['type']);
$link->set_ref_id($data['ref_id']); $link->set_ref_id($data['ref_id']);
$link->set_user_id($data['user_id']);
$link->setCourseId($data['c_id']); $link->setCourseId($data['c_id']);
$link->set_category_id($data['category_id']); $link->set_category_id($data['category_id']);
$link->set_date($data['created_at']); $link->set_date($data['created_at']);

@ -32,6 +32,8 @@ class Evaluation implements GradebookItem
*/ */
public function __construct() public function __construct()
{ {
$this->type = '';
$this->locked = 0;
} }
/** /**
@ -141,7 +143,7 @@ class Evaluation implements GradebookItem
public function get_type() public function get_type()
{ {
return $this->type; return $this->type ?? '';
} }
public function is_visible() public function is_visible()
@ -151,7 +153,7 @@ class Evaluation implements GradebookItem
public function get_locked() public function get_locked()
{ {
return $this->locked; return $this->locked ?? 0;
} }
public function is_locked() public function is_locked()
@ -304,18 +306,11 @@ class Evaluation implements GradebookItem
public function add(): bool public function add(): bool
{ {
if (isset($this->name) && if (isset($this->name) &&
isset($this->user_id) &&
isset($this->weight) && isset($this->weight) &&
isset($this->eval_max) && isset($this->eval_max) &&
isset($this->visible) isset($this->visible)
) { ) {
$user = api_get_user_entity($this->get_user_id());
if (null === $user) {
return false;
}
if (empty($this->type)) { if (empty($this->type)) {
$this->type = 'evaluation'; $this->type = 'evaluation';
} }
@ -334,7 +329,6 @@ class Evaluation implements GradebookItem
->setCourse(api_get_course_entity($courseId)) ->setCourse(api_get_course_entity($courseId))
->setTitle($this->get_name()) ->setTitle($this->get_name())
->setCategory($category) ->setCategory($category)
->setUser($user)
->setWeight(api_float_val($this->get_weight())) ->setWeight(api_float_val($this->get_weight()))
->setMax(api_float_val($this->get_max())) ->setMax(api_float_val($this->get_max()))
->setVisible($this->is_visible()) ->setVisible($this->is_visible())
@ -344,6 +338,15 @@ class Evaluation implements GradebookItem
$em->flush(); $em->flush();
$this->set_id($evaluation->getId()); $this->set_id($evaluation->getId());
Event::addEvent(
'gradebook_evaluation_created',
'evaluation',
$evaluation->getId(),
api_get_utc_datetime(),
api_get_user_id(),
$courseId
);
return true; return true;
} }
@ -964,15 +967,14 @@ class Evaluation implements GradebookItem
$eval->set_id($data['id']); $eval->set_id($data['id']);
$eval->set_name($data['title']); $eval->set_name($data['title']);
$eval->set_description($data['description']); $eval->set_description($data['description']);
$eval->set_user_id($data['user_id']);
$eval->setCourseId($data['c_id']); $eval->setCourseId($data['c_id']);
$eval->set_category_id($data['category_id']); $eval->set_category_id($data['category_id']);
$eval->set_date(api_get_local_time($data['created_at'])); $eval->set_date(api_get_local_time($data['created_at']));
$eval->set_weight($data['weight']); $eval->set_weight($data['weight']);
$eval->set_max($data['max']); $eval->set_max($data['max']);
$eval->set_visible($data['visible']); $eval->set_visible($data['visible']);
$eval->set_type($data['type']); $eval->set_type($data['type'] ?? '');
$eval->set_locked($data['locked']); $eval->set_locked($data['locked'] ?? 0);
$eval->setSessionId(api_get_session_id()); $eval->setSessionId(api_get_session_id());
if ($allow) { if ($allow) {

@ -173,7 +173,7 @@ class LearnpathLink extends AbstractLink
{ {
$data = $this->get_learnpath_data(); $data = $this->get_learnpath_data();
return $data['name']; return $data['title'];
} }
/** /**

@ -604,7 +604,6 @@ class AddCourse
$gradebookLink->setType(1); $gradebookLink->setType(1);
$gradebookLink->setRefId($refId); $gradebookLink->setRefId($refId);
$gradebookLink->setUser(api_get_user_entity());
$gradebookLink->setCourse($course); $gradebookLink->setCourse($course);
$gradebookLink->setCategory($childGradebookCategory); $gradebookLink->setCategory($childGradebookCategory);
$gradebookLink->setCreatedAt(new \DateTime()); $gradebookLink->setCreatedAt(new \DateTime());

@ -303,7 +303,7 @@ class PDF
$documentHtml = preg_replace($clean_search, '', $documentHtml); $documentHtml = preg_replace($clean_search, '', $documentHtml);
//absolute path for frames.css //TODO: necessary? //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); $documentHtml = str_replace('href="./css/frames.css"', $absolute_css_path, $documentHtml);
if (!empty($courseInfo['path'])) { if (!empty($courseInfo['path'])) {
$documentHtml = str_replace('../', '', $documentHtml); $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. // The library mPDF expects UTF-8 encoded input data.
api_set_encoding_html($documentHtml, 'UTF-8'); api_set_encoding_html($documentHtml, 'UTF-8');
// TODO: Maybe it is better idea the title to be passed through // TODO: Maybe it is better idea the title to be passed through
@ -547,7 +547,7 @@ class PDF
{ {
$web_path = false; $web_path = false;
$urlId = api_get_current_access_url_id(); $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_info = api_get_course_info($courseCode);
// course path // course path
$store_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/'.$urlId.'_pdf_watermark.png'; $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) public static function delete_watermark($courseCode = null)
{ {
$urlId = api_get_current_access_url_id(); $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_info = api_get_course_info($courseCode);
// course path // course path
$store_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/'.$urlId.'_pdf_watermark.png'; $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) public static function upload_watermark($filename, $source_file, $courseCode = null)
{ {
$urlId = api_get_current_access_url_id(); $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_info = api_get_course_info($courseCode);
$store_path = api_get_path(SYS_COURSE_PATH).$course_info['path']; // course path $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'; $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 // Add decoration only if not stated otherwise
if ($complete) { if ($complete) {
// Adding watermark // 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); $watermark_file = self::get_watermark($courseCode);
if ($watermark_file) { if ($watermark_file) {
$this->pdf->SetWatermarkImage($watermark_file); $this->pdf->SetWatermarkImage($watermark_file);
@ -766,9 +766,9 @@ class PDF
$this->pdf->showWatermarkImage = true; $this->pdf->showWatermarkImage = true;
} }
} }
$watermark_text = api_get_setting('pdf_export_watermark_text'); $watermark_text = api_get_setting('document.pdf_export_watermark_text');
if ($courseCode && 'true' === api_get_setting('pdf_export_watermark_by_course')) { if ($courseCode && 'true' === api_get_setting('document.pdf_export_watermark_by_course')) {
$courseWaterMark = api_get_course_setting('pdf_export_watermark_text'); $courseWaterMark = api_get_course_setting('document.pdf_export_watermark_text');
if (!empty($courseWaterMark) && -1 != $courseWaterMark) { if (!empty($courseWaterMark) && -1 != $courseWaterMark) {
$watermark_text = $courseWaterMark; $watermark_text = $courseWaterMark;
} }

@ -19,7 +19,6 @@ use Symfony\Component\Validator\Constraints as Assert;
class GradebookEvaluation class GradebookEvaluation
{ {
use CourseTrait; use CourseTrait;
use UserTrait;
#[ORM\Column(name: 'id', type: 'integer')] #[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id] #[ORM\Id]
@ -33,10 +32,6 @@ class GradebookEvaluation
#[ORM\Column(name: 'description', type: 'text', nullable: true)] #[ORM\Column(name: 'description', type: 'text', nullable: true)]
protected ?string $description = null; 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\ManyToOne(targetEntity: Course::class, inversedBy: 'gradebookEvaluations')]
#[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected Course $course; protected Course $course;

@ -19,7 +19,6 @@ use Symfony\Component\Validator\Constraints as Assert;
class GradebookLink class GradebookLink
{ {
use CourseTrait; use CourseTrait;
use UserTrait;
#[ORM\Column(name: 'id', type: 'integer')] #[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id] #[ORM\Id]
@ -34,10 +33,6 @@ class GradebookLink
#[ORM\Column(name: 'ref_id', type: 'integer', nullable: false)] #[ORM\Column(name: 'ref_id', type: 'integer', nullable: false)]
protected int $refId; 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\ManyToOne(targetEntity: Course::class, inversedBy: 'gradebookLinks')]
#[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected Course $course; protected Course $course;

@ -397,28 +397,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
#[ORM\OneToMany(mappedBy: 'user', targetEntity: GradebookComment::class)] #[ORM\OneToMany(mappedBy: 'user', targetEntity: GradebookComment::class)]
protected Collection $gradeBookComments; protected Collection $gradeBookComments;
/**
* @var Collection<int, GradebookEvaluation>
*/
#[ORM\OneToMany(
mappedBy: 'user',
targetEntity: GradebookEvaluation::class,
cascade: ['persist', 'remove'],
orphanRemoval: true
)]
protected Collection $gradeBookEvaluations;
/**
* @var Collection<int, GradebookLink>
*/
#[ORM\OneToMany(
mappedBy: 'user',
targetEntity: GradebookLink::class,
cascade: ['persist', 'remove'],
orphanRemoval: true
)]
protected Collection $gradeBookLinks;
/** /**
* @var Collection<int, GradebookResult> * @var Collection<int, GradebookResult>
*/ */
@ -758,8 +736,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
$this->commentedUserSkills = new ArrayCollection(); $this->commentedUserSkills = new ArrayCollection();
$this->gradeBookCategories = new ArrayCollection(); $this->gradeBookCategories = new ArrayCollection();
$this->gradeBookComments = new ArrayCollection(); $this->gradeBookComments = new ArrayCollection();
$this->gradeBookEvaluations = new ArrayCollection();
$this->gradeBookLinks = new ArrayCollection();
$this->gradeBookResults = new ArrayCollection(); $this->gradeBookResults = new ArrayCollection();
$this->gradeBookResultLogs = new ArrayCollection(); $this->gradeBookResultLogs = new ArrayCollection();
$this->gradeBookScoreLogs = new ArrayCollection(); $this->gradeBookScoreLogs = new ArrayCollection();
@ -781,7 +757,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
$this->receivedMessages = new ArrayCollection(); $this->receivedMessages = new ArrayCollection();
$this->surveyInvitations = new ArrayCollection(); $this->surveyInvitations = new ArrayCollection();
$this->logins = new ArrayCollection(); $this->logins = new ArrayCollection();
// $this->extraFields = new ArrayCollection();
$this->createdAt = new DateTime(); $this->createdAt = new DateTime();
$this->updatedAt = new DateTime(); $this->updatedAt = new DateTime();
$this->registrationDate = new DateTime(); $this->registrationDate = new DateTime();
@ -805,40 +780,13 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
{ {
return [ return [
new Assert\Length(['min' => 5]), new Assert\Length(['min' => 5]),
// Alpha numeric + "_" or "-"
new Assert\Regex(['pattern' => '/^[a-z\-_0-9]+$/i', 'htmlPattern' => '/^[a-z\-_0-9]+$/i']), 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}/']), new Assert\Regex(['pattern' => '/[0-9]{2}/', 'htmlPattern' => '/[0-9]{2}/']),
]; ];
} }
public static function loadValidatorMetadata(ClassMetadata $metadata): void 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 public function getUuid(): Uuid
@ -897,15 +845,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
return $this; return $this;
} }
/*public function getDropBoxReceivedFiles()
{
return $this->dropBoxReceivedFiles;
}
public function setDropBoxReceivedFiles($value): void
{
$this->dropBoxReceivedFiles = $value;
}*/
public function getCourses(): Collection public function getCourses(): Collection
{ {
return $this->courses; return $this->courses;
@ -928,18 +867,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
return $this; 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). * 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 public function isAccountNonExpired(): bool
{ {
/*if (true === $this->expired) {
return false;
}
if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
return false;
}*/
return true; return true;
} }
public function isAccountNonLocked(): bool public function isAccountNonLocked(): bool
{ {
return true; return true;
// return !$this->locked;
} }
public function isCredentialsNonExpired(): bool public function isCredentialsNonExpired(): bool
{ {
/*if (true === $this->credentialsExpired) {
return false;
}
if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
return false;
}*/
return true; return true;
} }
@ -1985,22 +1897,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
return $this->gradeBookComments; return $this->gradeBookComments;
} }
/**
* @return Collection<int, GradebookEvaluation>
*/
public function getGradeBookEvaluations(): Collection
{
return $this->gradeBookEvaluations;
}
/**
* @return Collection<int, GradebookLink>
*/
public function getGradeBookLinks(): Collection
{
return $this->gradeBookLinks;
}
/** /**
* @return Collection<int, GradebookResult> * @return Collection<int, GradebookResult>
*/ */

Loading…
Cancel
Save