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
->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_works'] = count($works);

@ -3,6 +3,7 @@
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CourseBundle\Entity\CStudentPublication;
use Chamilo\UserBundle\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
@ -202,6 +203,12 @@ class Session
*/
private $sendSubscriptionNotification;
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CStudentPublication", mappedBy="session", cascade={"persist"}, orphanRemoval=true)
*/
private $studentPublications;
/**
* Constructor
*/
@ -226,6 +233,7 @@ class Session
$this->userCourseSubscriptions = new ArrayCollection();
$this->showDescription = 0;
$this->category = null;
$this->studentPublications = new ArrayCollection();
}
/**
@ -1026,4 +1034,38 @@ class Session
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;
use Chamilo\CoreBundle\Entity\Session;
use Doctrine\ORM\Mapping as ORM;
/**
@ -170,11 +171,11 @@ class CStudentPublication
private $weight;
/**
* @var integer
*
* @ORM\Column(name="session_id", type="integer", nullable=false)
* @var Session
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session", inversedBy="studentPublications")
* @ORM\JoinColumn(name="session_id", referencedColumnName="id")
*/
private $sessionId;
private $session;
/**
* @var integer
@ -574,26 +575,24 @@ class CStudentPublication
}
/**
* Set sessionId
*
* @param integer $sessionId
* Set session
* @param Session $session
* @return CStudentPublication
*/
public function setSessionId($sessionId)
public function setSession(Session $session)
{
$this->sessionId = $sessionId;
$this->session = $session;
return $this;
}
/**
* Get sessionId
*
* @return integer
* Get session
* @return Session
*/
public function getSessionId()
public function getSession()
{
return $this->sessionId;
return $this->session;
}
/**

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

Loading…
Cancel
Save