Fix entities, adding objects instead of ids + add DB FK changes.

pull/2650/head
Julio Montoya 7 years ago
parent ca2c6421b2
commit e59ca4d718
  1. 19
      app/Migrations/Schema/V200/Version20.php
  2. 5
      main/admin/gradebook_list.php
  3. 2
      main/gradebook/lib/be/category.class.php
  4. 5
      src/CoreBundle/Entity/AccessUrl.php
  5. 50
      src/CoreBundle/Entity/AccessUrlRelCourseCategory.php
  6. 16
      src/CoreBundle/Entity/AccessUrlRelUser.php
  7. 19
      src/CoreBundle/Entity/Course.php
  8. 5
      src/CoreBundle/Entity/CourseCategory.php
  9. 52
      src/CoreBundle/Entity/GradebookCategory.php
  10. 20
      src/CoreBundle/Entity/Session.php
  11. 25
      src/CoreBundle/Entity/SessionCategory.php
  12. 2
      src/CoreBundle/Entity/SessionRelCourse.php
  13. 11
      src/CoreBundle/Entity/SessionRelCourseRelUser.php
  14. 1
      src/CoreBundle/Entity/SessionRelUser.php
  15. 2
      src/CoreBundle/Entity/SettingsCurrent.php
  16. 8
      src/CoreBundle/Entity/Skill.php
  17. 1
      src/UserBundle/Entity/Group.php
  18. 26
      src/UserBundle/Entity/User.php

@ -441,7 +441,13 @@ class Version20 extends AbstractMigrationChamilo
'ldap_description',
'openid_authentication',
//'platform_charset',
'shibboleth_description'
'shibboleth_description',
/*'sso_authentication',
'sso_authentication_domain',
'sso_authentication_auth_uri',
'sso_authentication_unauth_uri',
'sso_authentication_protocol',
'sso_force_redirect',*/
];
foreach ($settings as $setting) {
@ -638,6 +644,17 @@ class Version20 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE c_document ADD CONSTRAINT FK_C9FA0CBD613FECDF FOREIGN KEY (session_id) REFERENCES session (id)');
$this->addSql('CREATE INDEX IDX_C9FA0CBD613FECDF ON c_document (session_id)');
$this->addSql('ALTER TABLE access_url_rel_course_category CHANGE access_url_id access_url_id INT DEFAULT NULL, CHANGE course_category_id course_category_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE access_url_rel_course_category ADD CONSTRAINT FK_3545C2A673444FD5 FOREIGN KEY (access_url_id) REFERENCES access_url (id)');
$this->addSql('ALTER TABLE access_url_rel_course_category ADD CONSTRAINT FK_3545C2A66628AD36 FOREIGN KEY (course_category_id) REFERENCES course_category (id)');
$this->addSql('CREATE INDEX IDX_3545C2A673444FD5 ON access_url_rel_course_category (access_url_id)');
$this->addSql('CREATE INDEX IDX_3545C2A66628AD36 ON access_url_rel_course_category (course_category_id)');
$this->addSql('ALTER TABLE gradebook_category CHANGE user_id user_id INT DEFAULT NULL');
$this->addSql('DELETE FROM gradebook_category WHERE user_id IS NOT NULL AND user_id NOT IN (SELECT id FROM user)');
$this->addSql('ALTER TABLE gradebook_category ADD CONSTRAINT FK_96A4C705A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('CREATE INDEX IDX_96A4C705A76ED395 ON gradebook_category (user_id)');
// Drop unused tables
$dropTables = ['event_email_template', 'event_sent', 'user_rel_event_type', 'openid_association'];
foreach ($dropTables as $table) {

@ -109,6 +109,7 @@ switch ($action) {
$values = $form->getSubmitValues();
$courseId = isset($values['course_id']) ? $values['course_id'] : 0;
$courseInfo = api_get_course_info_by_id($courseId);
$courseEntity = api_get_course_entity($courseId);
$courseCode = $courseInfo['code'];
$criteria = ['courseCode' => $courseCode];
$exists = $repo->findBy($criteria);
@ -124,8 +125,8 @@ switch ($action) {
->setLocked(0)
->setGenerateCertificates(0)
->setIsRequirement(false)
->setCourseCode($courseCode)
->setUserId(api_get_user_id());
->setCourse($courseEntity)
->setUser(api_get_user_entity(api_get_user_id()));
$em->persist($category);
$em->flush();
if ($category->getId()) {

@ -582,7 +582,7 @@ class Category implements GradebookItem
$category = new GradebookCategory();
$category->setName($this->name);
$category->setDescription($this->description);
$category->setUserId($this->user_id);
$category->setUser(api_get_user_entity($this->user_id));
$category->setCourse($course);
$category->setParentId($this->parent);
$category->setWeight($this->weight);

@ -42,6 +42,11 @@ class AccessUrl
*/
protected $sessionCategory;
/**
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseCategory", mappedBy="url", cascade={"persist"}, orphanRemoval=true)
*/
protected $courseCategory;
/**
* @var string
*

@ -23,59 +23,57 @@ class AccessUrlRelCourseCategory
protected $id;
/**
* @var int
* @var AccessUrl
*
* @ORM\Column(name="access_url_id", type="integer")
* @ORM\ManyToOne(targetEntity="AccessUrl", inversedBy="courseCategory", cascade={"persist"})
* @ORM\JoinColumn(name="access_url_id", referencedColumnName="id")
*/
protected $accessUrlId;
protected $url;
/**
* @var int
* @var CourseCategory
*
* @ORM\Column(name="course_category_id", type="integer")
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\CourseCategory", inversedBy="urls", cascade={"persist"})
* @ORM\JoinColumn(name="course_category_id", referencedColumnName="id")
*/
protected $courseCategoryId;
protected $courseCategory;
/**
* Set accessUrlId.
*
* @param int $accessUrlId
*
* @return $this
* @return AccessUrl
*/
public function setAccessUrlId($accessUrlId)
public function getUrl(): AccessUrl
{
$this->accessUrlId = $accessUrlId;
return $this;
return $this->url;
}
/**
* Get accessUrlId.
* @param AccessUrl $url
*
* @return int
* @return AccessUrlRelCourseCategory
*/
public function getAccessUrlId()
public function setUrl(AccessUrl $url): AccessUrlRelCourseCategory
{
return $this->accessUrlId;
$this->url = $url;
return $this;
}
/**
* @return int
* @return CourseCategory
*/
public function getCourseCategoryId()
public function getCourseCategory(): CourseCategory
{
return $this->courseCategoryId;
return $this->courseCategory;
}
/**
* @param int $courseCategoryId
* @param CourseCategory $courseCategory
*
* @return $this
* @return AccessUrlRelCourseCategory
*/
public function setCourseCategoryId($courseCategoryId)
public function setCourseCategory(CourseCategory $courseCategory): AccessUrlRelCourseCategory
{
$this->courseCategoryId = $courseCategoryId;
$this->courseCategory = $courseCategory;
return $this;
}

@ -20,6 +20,15 @@ use Doctrine\ORM\Mapping as ORM;
*/
class AccessUrlRelUser
{
/**
* @var int
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(name="id", type="integer")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
@ -31,13 +40,6 @@ class AccessUrlRelUser
* @ORM\JoinColumn(name="access_url_id", referencedColumnName="id")
*/
protected $portal;
/**
* @var int
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(name="id", type="integer")
*/
protected $id;
/**
* @return string

@ -47,6 +47,15 @@ class Course
*/
protected $id;
/**
* @var string
*
* @Assert\NotBlank()
*
* @ORM\Column(name="title", type="string", length=250, nullable=true, unique=false)
*/
protected $title;
/**
* "orphanRemoval" is needed to delete the CourseRelUser relation
* in the CourseAdmin class. The setUsers, getUsers, removeUsers and
@ -149,14 +158,6 @@ class Course
/**
* @var string
*
* @Assert\NotBlank()
*
* @ORM\Column(name="title", type="string", length=250, nullable=true, unique=false)
*/
protected $title;
/**
* @var string
* @Gedmo\Slug(
* fields={"title"},
* updatable = false,
@ -196,7 +197,9 @@ class Course
/**
* @var bool
*
* @Assert\NotBlank()
*
* @ORM\Column(name="visibility", type="integer", nullable=true, unique=false)
*/
protected $visibility;

@ -99,6 +99,11 @@ class CourseCategory
*/
protected $description;
/**
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelCourseCategory", mappedBy="courseCategory", cascade={"persist"}, orphanRemoval=true)
*/
protected $urls;
/**
* Constructor.
*/

@ -3,6 +3,7 @@
namespace Chamilo\CoreBundle\Entity;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
/**
@ -37,11 +38,12 @@ class GradebookCategory
protected $description;
/**
* @var int
* @var User
*
* @ORM\Column(name="user_id", type="integer", nullable=false)
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", inversedBy="gradeBookCategories")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $userId;
protected $user;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="gradebookCategories")
@ -220,30 +222,6 @@ class GradebookCategory
return $this->description;
}
/**
* Set userId.
*
* @param int $userId
*
* @return GradebookCategory
*/
public function setUserId($userId)
{
$this->userId = $userId;
return $this;
}
/**
* Get userId.
*
* @return int
*/
public function getUserId()
{
return $this->userId;
}
/**
* Set course.
*
@ -551,4 +529,24 @@ class GradebookCategory
return $this;
}
/**
* @return User
*/
public function getUser(): User
{
return $this->user;
}
/**
* @param User $user
*
* @return GradebookCategory
*/
public function setUser(User $user): GradebookCategory
{
$this->user = $user;
return $this;
}
}

@ -29,14 +29,14 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Session
{
const VISIBLE = 1;
const READ_ONLY = 2;
const INVISIBLE = 3;
const AVAILABLE = 4;
public const VISIBLE = 1;
public const READ_ONLY = 2;
public const INVISIBLE = 3;
public const AVAILABLE = 4;
const STUDENT = 0;
const DRH = 1;
const COACH = 2;
public const STUDENT = 0;
public const DRH = 1;
public const COACH = 2;
/**
* @var int
@ -49,18 +49,22 @@ class Session
/**
* @var ArrayCollection
*
* @ORM\OrderBy({"position" = "ASC"})
* @ORM\OneToMany(targetEntity="SessionRelCourse", mappedBy="session", cascade={"persist"}, orphanRemoval=true)
*/
protected $courses;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="SessionRelUser", mappedBy="session", cascade={"persist"}, orphanRemoval=true)
*/
protected $users;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="SessionRelCourseRelUser", mappedBy="session", cascade={"persist"}, orphanRemoval=true)
*/
protected $userCourseSubscriptions;
@ -223,12 +227,14 @@ class Session
/**
* @var bool
*
* @ORM\Column(name="send_subscription_notification", type="boolean", nullable=false, options={"default":false})
*/
protected $sendSubscriptionNotification;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CStudentPublication", mappedBy="session", cascade={"persist"}, orphanRemoval=true)
*/
protected $studentPublications;

@ -13,6 +13,15 @@ use Doctrine\ORM\Mapping as ORM;
*/
class SessionCategory
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="AccessUrl", inversedBy="sessionCategory", cascade={"persist"})
* @ORM\JoinColumn(name="access_url_id", referencedColumnName="id")
@ -23,14 +32,6 @@ class SessionCategory
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="category")
*/
protected $session;
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue
*/
protected $id;
/**
* @var string
@ -64,11 +65,11 @@ class SessionCategory
/**
* Set url.
*
* @param $url
* @param AccessUrl $url
*
* @return SessionCategory
*/
public function setUrl($url)
public function setUrl(AccessUrl $url)
{
$this->url = $url;
@ -76,9 +77,9 @@ class SessionCategory
}
/**
* @return mixed
* @return AccessUrl
*/
public function getUrl()
public function getUrl(): AccessUrl
{
return $this->url;
}

@ -67,7 +67,7 @@ class SessionRelCourse
}
/**
* @param $session
* @param Session $session
*
* @return $this
*/

@ -20,8 +20,8 @@ use Doctrine\ORM\Mapping as ORM;
*/
class SessionRelCourseRelUser
{
const STATUS_STUDENT = 0;
const STATUS_COURSE_COACH = 2;
public const STATUS_STUDENT = 0;
public const STATUS_COURSE_COACH = 2;
public $statusList = [
0 => 'student',
@ -39,6 +39,7 @@ class SessionRelCourseRelUser
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", inversedBy="sessionCourseSubscriptions", cascade={"persist"})
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
*/
@ -46,6 +47,7 @@ class SessionRelCourseRelUser
/**
* @var Session
*
* @ORM\ManyToOne(targetEntity="Session", inversedBy="userCourseSubscriptions", cascade={"persist"})
* @ORM\JoinColumn(name="session_id", referencedColumnName="id", nullable=false)
*/
@ -53,6 +55,7 @@ class SessionRelCourseRelUser
/**
* @var Course
*
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="sessionUserSubscriptions", cascade={"persist"})
* @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false)
*/
@ -88,9 +91,9 @@ class SessionRelCourseRelUser
}
/**
* @return \Chamilo\UserBundle\Entity\User
* @return User
*/
public function getUser()
public function getUser(): User
{
return $this->user;
}

@ -82,6 +82,7 @@ class SessionRelUser
/**
* @var \DateTime
*
* @ORM\Column(name="registered_at", type="datetime", nullable=false, unique=false)
*/
protected $registeredAt;

@ -123,7 +123,7 @@ class SettingsCurrent
/**
* Constructor.
*/
public function __constructor()
public function __construct()
{
$this->accessUrlLocked = 0;
}

@ -20,8 +20,8 @@ use Gedmo\Mapping\Annotation as Gedmo;
*/
class Skill
{
const STATUS_DISABLED = 0;
const STATUS_ENABLED = 1;
public const STATUS_DISABLED = 0;
public const STATUS_ENABLED = 1;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\SkillBundle\Entity\Profile", inversedBy="skills")
@ -104,7 +104,9 @@ class Skill
/**
* @var \DateTime
*
* @Gedmo\Timestampable(on="update")
*
* @ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
protected $updatedAt;
@ -112,7 +114,7 @@ class Skill
/**
* Constructor.
*/
public function __constructor()
public function __construct()
{
$this->status = self::STATUS_ENABLED;
}

@ -28,6 +28,7 @@ class Group extends BaseGroup
/**
* @var string
*
* @ORM\Column(name="code", type="string", length=40, nullable=false, unique=true)
*/
protected $code;

@ -81,12 +81,12 @@ use Symfony\Component\Validator\Mapping\ClassMetadata;
*/
class User extends BaseUser implements ThemeUser, EquatableInterface //implements ParticipantInterface, ThemeUser
{
const COURSE_MANAGER = 1;
const TEACHER = 1;
const SESSION_ADMIN = 3;
const DRH = 4;
const STUDENT = 5;
const ANONYMOUS = 6;
public const COURSE_MANAGER = 1;
public const TEACHER = 1;
public const SESSION_ADMIN = 3;
public const DRH = 4;
public const STUDENT = 5;
public const ANONYMOUS = 6;
/**
* @var int
@ -292,23 +292,23 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement
*/
protected $curriculumItems;
/*
/**
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelUser", mappedBy="user")
*
*/
protected $portals;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="generalCoach")
*/
protected $sessionAsGeneralCoach;
/**
* @var ArrayCollection
* ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UserFieldValues", mappedBy="user", orphanRemoval=true, cascade={"persist"})
* ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UserFieldValues", mappedBy="user", orphanRemoval=true, cascade={"persist"})
*/
protected $extraFields;
//protected $extraFields;
/**
* ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", mappedBy="creator").
@ -330,6 +330,11 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement
*/
protected $commentedUserSkills;
/**
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookCategory", mappedBy="user")
*/
protected $gradeBookCategories;
/**
* @var string
*
@ -353,6 +358,7 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement
/**
* @var string
*
* @ORM\Column(name="picture_uri", type="string", length=250, nullable=true, unique=false)
*/
private $pictureUri;

Loading…
Cancel
Save