Add association mapping between Session and CStudentPublication - refs BT#11395

pull/2487/head
Angel Fernando Quiroz Campos 9 years ago
parent 70d4441d56
commit 4b5689eae0
  1. 40
      app/Migrations/Schema/V111/Version20160715122300.php
  2. 2
      main/admin/teachers_time_by_session_report.php
  3. 42
      src/Chamilo/CoreBundle/Entity/Session.php
  4. 27
      src/Chamilo/CourseBundle/Entity/CStudentPublication.php
  5. 7
      src/Chamilo/CourseBundle/Entity/Repository/CStudentPublicationRepository.php

@ -0,0 +1,40 @@
<?php
/* For licensing terms, see /license.txt */
namespace Application\Migrations\Schema\V111;
use Application\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Type;
/**
* Class Version20160715122300
* Add association mapping between Session and CStudentPublication
* @package Application\Migrations\Schema\V111
*/
class Version20160715122300 extends AbstractMigrationChamilo
{
/**
* @param Schema $schema
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
public function up(Schema $schema)
{
$this->addSql('ALTER TABLE c_student_publication CHANGE session_id session_id INT DEFAULT NULL');
$this->addSql('UPDATE c_student_publication SET session_id = NULL WHERE session_id = 0');
$this->addSql('ALTER TABLE c_student_publication ADD CONSTRAINT fk_session FOREIGN KEY (session_id) REFERENCES session (id)');
}
/**
* @param Schema $schema
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
public function down(Schema $schema)
{
$studentPublication = $schema->getTable('c_student_publication');
$studentPublication->removeForeignKey('fk_session');
$studentPublication->getColumn('session_id')->setNotnull(true);
}
}

@ -81,7 +81,7 @@ if ($session) {
$works = $em $works = $em
->getRepository('ChamiloCourseBundle:CStudentPublication') ->getRepository('ChamiloCourseBundle:CStudentPublication')
->findByTeacher($user, $course, $session->getId()); ->findWorksByTeacher($user, $course, $session);
$usersInfo[$user->getId()][$course->getId() . '_number_of_students'] = $sessionCourse->getNbrUsers(); $usersInfo[$user->getId()][$course->getId() . '_number_of_students'] = $sessionCourse->getNbrUsers();
$usersInfo[$user->getId()][$course->getId() . '_number_of_works'] = count($works); $usersInfo[$user->getId()][$course->getId() . '_number_of_works'] = count($works);

@ -3,6 +3,7 @@
namespace Chamilo\CoreBundle\Entity; namespace Chamilo\CoreBundle\Entity;
use Chamilo\CourseBundle\Entity\CStudentPublication;
use Chamilo\UserBundle\Entity\User; use Chamilo\UserBundle\Entity\User;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\Criteria;
@ -202,6 +203,12 @@ class Session
*/ */
private $sendSubscriptionNotification; private $sendSubscriptionNotification;
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CStudentPublication", mappedBy="session", cascade={"persist"}, orphanRemoval=true)
*/
private $studentPublications;
/** /**
* Constructor * Constructor
*/ */
@ -226,6 +233,7 @@ class Session
$this->userCourseSubscriptions = new ArrayCollection(); $this->userCourseSubscriptions = new ArrayCollection();
$this->showDescription = 0; $this->showDescription = 0;
$this->category = null; $this->category = null;
$this->studentPublications = new ArrayCollection();
} }
/** /**
@ -1026,4 +1034,38 @@ class Session
return $return; return $return;
} }
/**
* @param ArrayCollection $studentPublications
* @return Session
*/
public function setStudentPublications(ArrayCollection $studentPublications)
{
$this->studentPublications = new ArrayCollection();
foreach ($studentPublications as $studentPublication) {
$this->addStudentPublication($studentPublication);
}
return $this;
}
/**
* @param CStudentPublication $studentPublication
* @return Session
*/
public function addStudentPublication(CStudentPublication $studentPublication)
{
$this->studentPublications[] = $studentPublication;
return $this;
}
/**
* Get studentPublications
* @return ArrayCollection
*/
public function getStudentPublications()
{
return $this->studentPublications;
}
} }

@ -3,6 +3,7 @@
namespace Chamilo\CourseBundle\Entity; namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\Session;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
@ -170,11 +171,11 @@ class CStudentPublication
private $weight; private $weight;
/** /**
* @var integer * @var Session
* * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session", inversedBy="studentPublications")
* @ORM\Column(name="session_id", type="integer", nullable=false) * @ORM\JoinColumn(name="session_id", referencedColumnName="id")
*/ */
private $sessionId; private $session;
/** /**
* @var integer * @var integer
@ -574,26 +575,24 @@ class CStudentPublication
} }
/** /**
* Set sessionId * Set session
* * @param Session $session
* @param integer $sessionId
* @return CStudentPublication * @return CStudentPublication
*/ */
public function setSessionId($sessionId) public function setSession(Session $session)
{ {
$this->sessionId = $sessionId; $this->session = $session;
return $this; return $this;
} }
/** /**
* Get sessionId * Get session
* * @return Session
* @return integer
*/ */
public function getSessionId() public function getSession()
{ {
return $this->sessionId; return $this->session;
} }
/** /**

@ -4,6 +4,7 @@
namespace Chamilo\CourseBundle\Entity\Repository; namespace Chamilo\CourseBundle\Entity\Repository;
use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\UserBundle\Entity\User; use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
@ -16,11 +17,11 @@ class CStudentPublicationRepository extends EntityRepository
* Find all the works registered by a teacher * Find all the works registered by a teacher
* @param User $user * @param User $user
* @param Course $course * @param Course $course
* @param int $sessionId Optional * @param Session $session Optional
* @param int $groupId Optional * @param int $groupId Optional
* @return array * @return array
*/ */
public function findByTeacher(User $user, Course $course, $sessionId = 0, $groupId = 0) public function findWorksByTeacher(User $user, Course $course, Session $session = null, $groupId = 0)
{ {
$qb = $this->createQueryBuilder('w'); $qb = $this->createQueryBuilder('w');
return $qb return $qb
@ -43,7 +44,7 @@ class CStudentPublicationRepository extends EntityRepository
->orderBy('w.sentDate', 'ASC') ->orderBy('w.sentDate', 'ASC')
->setParameters([ ->setParameters([
'course' => intval($course->getId()), 'course' => intval($course->getId()),
'session' => intval($sessionId), 'session' => $session,
'group' => intval($groupId), 'group' => intval($groupId),
'user' => $user->getId() 'user' => $user->getId()
]) ])

Loading…
Cancel
Save