Use correct entity relations, add migration, fix order query

pull/3844/head
Julio Montoya 4 years ago
parent 5a0940e7f6
commit dee18e118a
  1. 18
      src/CoreBundle/Migrations/Schema/V200/Version20170625143000.php
  2. 2
      src/CoreBundle/Repository/BranchSyncRepository.php
  3. 4
      src/CoreBundle/Repository/Node/CourseRepository.php
  4. 4
      src/CoreBundle/Repository/Node/UserRepository.php
  5. 2
      src/CourseBundle/Entity/CForumForum.php
  6. 42
      src/CourseBundle/Entity/CForumThread.php
  7. 92
      src/CourseBundle/Entity/CStudentPublication.php
  8. 45
      src/CourseBundle/Entity/CStudentPublicationAssignment.php
  9. 8
      src/CourseBundle/Entity/CSurveyQuestion.php

@ -178,6 +178,10 @@ class Version20170625143000 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE c_student_publication ADD filesize INT DEFAULT NULL');
}
if ($table->hasForeignKey('FK_5246F746613FECDF')) {
$this->addSql('ALTER TABLE c_student_publication DROP FOREIGN KEY FK_5246F746613FECDF;');
}
if ($table->hasIndex('course')) {
$this->addSql('DROP INDEX course ON c_student_publication;');
}
@ -196,7 +200,8 @@ class Version20170625143000 extends AbstractMigrationChamilo
$this->addSql('CREATE UNIQUE INDEX UNIQ_5246F7461BAD783F ON c_student_publication (resource_node_id)');
}
/*$table = $schema->getTable('c_student_publication_assignment');
$table = $schema->getTable('c_student_publication_assignment');
/*
if (false === $table->hasColumn('resource_node_id')) {
$this->addSql('ALTER TABLE c_student_publication_assignment ADD resource_node_id INT DEFAULT NULL');
$this->addSql(
@ -208,6 +213,17 @@ class Version20170625143000 extends AbstractMigrationChamilo
}
*/
$this->addSql('UPDATE c_student_publication_assignment SET publication_id = NULL WHERE publication_id = 0');
$this->addSql('ALTER TABLE c_student_publication_assignment CHANGE publication_id publication_id INT DEFAULT NULL');
if (false === $table->hasForeignKey('FK_25687EB838B217A7')) {
$this->addSql('ALTER TABLE c_student_publication_assignment ADD CONSTRAINT FK_25687EB838B217A7 FOREIGN KEY (publication_id) REFERENCES c_student_publication (iid) ON DELETE CASCADE;');
}
if (false === $table->hasIndex('UNIQ_25687EB838B217A7')) {
$this->addSql('ALTER TABLE c_student_publication_assignment ADD UNIQUE INDEX UNIQ_25687EB838B217A7 (publication_id)');
}
if (false === $schema->hasTable('c_student_publication_correction')) {
$this->addSql(
'CREATE TABLE c_student_publication_correction (id INT AUTO_INCREMENT NOT NULL, resource_node_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_B7309BBA1BAD783F (resource_node_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC'

@ -46,7 +46,7 @@ class BranchSyncRepository extends NestedTreeRepository
$qb->from('Chamilo\CoreBundle\Entity\BranchSync', 'b');
$qb->where('b.parent IS NULL');
$qb->orderBy('b.id ASC');
$qb->orderBy('b.id', 'ASC');
$qb->setMaxResults(1);
$q = $qb->getQuery()->getResult();
if (empty($q)) {

@ -96,9 +96,9 @@ class CourseRepository extends ResourceRepository
);
if (api_is_western_name_order()) {
$queryBuilder->orderBy('user.firstname ASC');
$queryBuilder->orderBy('user.firstname', 'ASC');
} else {
$queryBuilder->orderBy('user.lastname ASC');
$queryBuilder->orderBy('user.lastname', 'ASC');
}
$wherePart = $queryBuilder->expr()->andx();

@ -253,7 +253,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
$qb->from('Chamilo\CoreBundle\Entity\User', 'b');
//@todo check app settings
$qb->orderBy('b.firstname ASC');
$qb->orderBy('b.firstname', 'ASC');
$qb->where('b.firstname LIKE :keyword OR b.lastname LIKE :keyword ');
$qb->setParameter('keyword', "%{$keyword}%");
$query = $qb->getQuery();
@ -299,7 +299,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
;
}
$qb->orderBy('course.title DESC');
$qb->orderBy('course.title', 'DESC');
$query = $qb->getQuery();

@ -679,7 +679,7 @@ class CForumForum extends AbstractResource implements ResourceInterface
return $this->lp;
}
public function setLp(CLp $lp): self
public function setLp(?CLp $lp): self
{
$this->lp = $lp;

@ -11,6 +11,7 @@ use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\User;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
@ -63,7 +64,7 @@ class CForumThread extends AbstractResource implements ResourceInterface
protected int $threadViews;
/**
* @var ArrayCollection|CForumPost[]
* @var Collection|CForumPost[]
*
* @ORM\OneToMany(
* targetEntity="Chamilo\CourseBundle\Entity\CForumPost",
@ -77,7 +78,7 @@ class CForumThread extends AbstractResource implements ResourceInterface
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CForumPost", cascade={"persist", "remove"})
* @ORM\JoinColumn(name="thread_last_post", referencedColumnName="iid", onDelete="SET NULL")
*/
protected CForumPost $threadLastPost;
protected ?CForumPost $threadLastPost;
/**
* @ORM\Column(name="thread_date", type="datetime", nullable=false)
@ -154,7 +155,7 @@ class CForumThread extends AbstractResource implements ResourceInterface
*
* @return $this
*/
public function setThreadPeerQualify($threadPeerQualify)
public function setThreadPeerQualify($threadPeerQualify): self
{
$this->threadPeerQualify = $threadPeerQualify;
@ -165,10 +166,8 @@ class CForumThread extends AbstractResource implements ResourceInterface
* Set threadTitle.
*
* @param string $threadTitle
*
* @return CForumThread
*/
public function setThreadTitle($threadTitle)
public function setThreadTitle($threadTitle): self
{
$this->threadTitle = $threadTitle;
@ -185,12 +184,7 @@ class CForumThread extends AbstractResource implements ResourceInterface
return $this->threadTitle;
}
/**
* Set forum.
*
* @return CForumThread
*/
public function setForum(CForumForum $forum = null)
public function setForum(CForumForum $forum = null): self
{
$this->forum = $forum;
@ -214,7 +208,7 @@ class CForumThread extends AbstractResource implements ResourceInterface
*
* @return CForumThread
*/
public function setThreadReplies($threadReplies)
public function setThreadReplies($threadReplies): self
{
$this->threadReplies = $threadReplies;
@ -235,10 +229,8 @@ class CForumThread extends AbstractResource implements ResourceInterface
* Set threadViews.
*
* @param int $threadViews
*
* @return CForumThread
*/
public function setThreadViews($threadViews)
public function setThreadViews($threadViews): self
{
$this->threadViews = $threadViews;
@ -281,10 +273,8 @@ class CForumThread extends AbstractResource implements ResourceInterface
* Set threadSticky.
*
* @param bool $threadSticky
*
* @return CForumThread
*/
public function setThreadSticky($threadSticky)
public function setThreadSticky($threadSticky): self
{
$this->threadSticky = $threadSticky;
@ -305,10 +295,8 @@ class CForumThread extends AbstractResource implements ResourceInterface
* Set locked.
*
* @param int $locked
*
* @return CForumThread
*/
public function setLocked($locked)
public function setLocked($locked): self
{
$this->locked = $locked;
@ -329,10 +317,8 @@ class CForumThread extends AbstractResource implements ResourceInterface
* Set threadTitleQualify.
*
* @param string $threadTitleQualify
*
* @return CForumThread
*/
public function setThreadTitleQualify($threadTitleQualify)
public function setThreadTitleQualify($threadTitleQualify): self
{
$this->threadTitleQualify = $threadTitleQualify;
@ -375,10 +361,8 @@ class CForumThread extends AbstractResource implements ResourceInterface
* Set threadCloseDate.
*
* @param DateTime $threadCloseDate
*
* @return CForumThread
*/
public function setThreadCloseDate($threadCloseDate)
public function setThreadCloseDate($threadCloseDate): self
{
$this->threadCloseDate = $threadCloseDate;
@ -466,7 +450,7 @@ class CForumThread extends AbstractResource implements ResourceInterface
}
/**
* @return ArrayCollection|CForumPost[]
* @return Collection|CForumPost[]
*/
public function getPosts()
{

@ -9,7 +9,6 @@ namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Entity\Session;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
@ -20,7 +19,6 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\Table(
* name="c_student_publication",
* indexes={
* @ORM\Index(name="session_id", columns={"session_id"}),
* @ORM\Index(name="idx_csp_u", columns={"user_id"})
* }
* )
@ -116,12 +114,6 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
*/
protected float $weight;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session", inversedBy="studentPublications")
* @ORM\JoinColumn(name="session_id", referencedColumnName="id")
*/
protected Session $session;
/**
* @ORM\Column(name="user_id", type="integer", nullable=false)
*/
@ -147,6 +139,11 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
*/
protected ?int $fileSize;
/**
* @ORM\OneToOne(targetEntity="Chamilo\CourseBundle\Entity\CStudentPublicationAssignment", mappedBy="publication")
*/
protected ?CStudentPublicationAssignment $assignment;
public function __construct()
{
$this->description = '';
@ -202,10 +199,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
* Set title.
*
* @param string $title
*
* @return CStudentPublication
*/
public function setTitle($title)
public function setTitle($title): self
{
$this->title = $title;
@ -238,10 +233,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
* Set author.
*
* @param string $author
*
* @return CStudentPublication
*/
public function setAuthor($author)
public function setAuthor($author): self
{
$this->author = $author;
@ -258,12 +251,7 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
return $this->author;
}
/**
* Set active.
*
* @return CStudentPublication
*/
public function setActive(int $active)
public function setActive(int $active): self
{
$this->active = $active;
@ -284,10 +272,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
* Set accepted.
*
* @param bool $accepted
*
* @return CStudentPublication
*/
public function setAccepted($accepted)
public function setAccepted($accepted): self
{
$this->accepted = $accepted;
@ -332,10 +318,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
* Set sentDate.
*
* @param DateTime $sentDate
*
* @return CStudentPublication
*/
public function setSentDate($sentDate)
public function setSentDate($sentDate): self
{
$this->sentDate = $sentDate;
@ -356,10 +340,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
* Set filetype.
*
* @param string $filetype
*
* @return CStudentPublication
*/
public function setFiletype($filetype)
public function setFiletype($filetype): self
{
$this->filetype = $filetype;
@ -380,10 +362,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
* Set hasProperties.
*
* @param int $hasProperties
*
* @return CStudentPublication
*/
public function setHasProperties($hasProperties)
public function setHasProperties($hasProperties): self
{
$this->hasProperties = $hasProperties;
@ -404,10 +384,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
* Set viewProperties.
*
* @param bool $viewProperties
*
* @return CStudentPublication
*/
public function setViewProperties($viewProperties)
public function setViewProperties($viewProperties): self
{
$this->viewProperties = $viewProperties;
@ -539,30 +517,6 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
return $this->weight;
}
/**
* Set session.
*
* @param Session $session
*
* @return CStudentPublication
*/
public function setSession(Session $session = null)
{
$this->session = $session;
return $this;
}
/**
* Get session.
*
* @return Session
*/
public function getSession()
{
return $this->session;
}
/**
* Set userId.
*
@ -591,10 +545,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
* Set allowTextAssignment.
*
* @param int $allowTextAssignment
*
* @return CStudentPublication
*/
public function setAllowTextAssignment($allowTextAssignment)
public function setAllowTextAssignment($allowTextAssignment): self
{
$this->allowTextAssignment = $allowTextAssignment;
@ -615,10 +567,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
* Set containsFile.
*
* @param int $containsFile
*
* @return CStudentPublication
*/
public function setContainsFile($containsFile)
public function setContainsFile($containsFile): self
{
$this->containsFile = $containsFile;
@ -680,6 +630,18 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
return null;
}
public function getAssignment(): ?CStudentPublicationAssignment
{
return $this->assignment;
}
public function setAssignment(?CStudentPublicationAssignment $assignment): self
{
$this->assignment = $assignment;
return $this;
}
public function getResourceIdentifier(): int
{
return $this->getIid();

@ -55,9 +55,10 @@ class CStudentPublicationAssignment
protected bool $enableQualification;
/**
* @ORM\Column(name="publication_id", type="integer", nullable=false)
* @ORM\OneToOne(targetEntity="CStudentPublication", inversedBy="assignment")
* @ORM\JoinColumn(name="publication_id", referencedColumnName="iid", onDelete="CASCADE")
*/
protected int $publicationId;
protected CStudentPublication $publication;
public function __toString(): string
{
@ -73,10 +74,8 @@ class CStudentPublicationAssignment
* Set expiresOn.
*
* @param DateTime $expiresOn
*
* @return CStudentPublicationAssignment
*/
public function setExpiresOn($expiresOn)
public function setExpiresOn($expiresOn): self
{
$this->expiresOn = $expiresOn;
@ -97,10 +96,8 @@ class CStudentPublicationAssignment
* Set endsOn.
*
* @param DateTime $endsOn
*
* @return CStudentPublicationAssignment
*/
public function setEndsOn($endsOn)
public function setEndsOn($endsOn): self
{
$this->endsOn = $endsOn;
@ -121,10 +118,8 @@ class CStudentPublicationAssignment
* Set addToCalendar.
*
* @param bool $addToCalendar
*
* @return CStudentPublicationAssignment
*/
public function setAddToCalendar($addToCalendar)
public function setAddToCalendar($addToCalendar): self
{
$this->addToCalendar = $addToCalendar;
@ -145,10 +140,8 @@ class CStudentPublicationAssignment
* Set enableQualification.
*
* @param bool $enableQualification
*
* @return CStudentPublicationAssignment
*/
public function setEnableQualification($enableQualification)
public function setEnableQualification($enableQualification): self
{
$this->enableQualification = $enableQualification;
@ -165,30 +158,6 @@ class CStudentPublicationAssignment
return $this->enableQualification;
}
/**
* Set publicationId.
*
* @param int $publicationId
*
* @return CStudentPublicationAssignment
*/
public function setPublicationId($publicationId)
{
$this->publicationId = $publicationId;
return $this;
}
/**
* Get publicationId.
*
* @return int
*/
public function getPublicationId()
{
return $this->publicationId;
}
/**
* Set cId.
*

@ -117,9 +117,17 @@ class CSurveyQuestion
*/
protected bool $isMandatory = false;
/**
* @var Collection|CSurveyAnswer[]
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CSurveyAnswer", mappedBy="question")
*/
protected $answers;
public function __construct()
{
$this->children = new ArrayCollection();
$this->answers = new ArrayCollection();
$this->surveyGroupPri = 0;
$this->surveyGroupSec1 = 0;
$this->surveyGroupSec2 = 0;

Loading…
Cancel
Save