123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071 |
- <?php
- /* For licensing terms, see /license.txt */
- namespace Chamilo\CoreBundle\Entity;
- use Chamilo\CourseBundle\Entity\CStudentPublication;
- use Chamilo\UserBundle\Entity\User;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\Common\Collections\Criteria;
- use Doctrine\ORM\Mapping as ORM;
- use Chamilo\CoreBundle\Entity\SessionCategory;
- //use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
- //use Gedmo\Mapping\Annotation as Gedmo;
- /**
- * Session
- * UniqueEntity("name")
- * @ORM\Table(
- * name="session",
- * uniqueConstraints={@ORM\UniqueConstraint(name="name", columns={"name"})},
- * indexes={
- * @ORM\Index(name="idx_id_coach", columns={"id_coach"}),
- * @ORM\Index(name="idx_id_session_admin_id", columns={"session_admin_id"})
- * }
- * )
- * @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Entity\Repository\SessionRepository")
- */
- class Session
- {
- const VISIBLE = 1;
- const READ_ONLY = 2;
- const INVISIBLE = 3;
- const AVAILABLE = 4;
- const STUDENT = 0;
- const DRH = 1;
- const COACH = 2;
- /**
- * @var integer
- *
- * @ORM\Column(name="id", type="integer", nullable=false, unique=false)
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string
- *
- * @ORM\Column(name="name", type="string", length=150, nullable=false, unique=false)
- */
- private $name;
- /**
- * @var string
- *
- * @ORM\Column(name="description", type="text", nullable=true, unique=false)
- */
- private $description;
- /**
- * @var string
- *
- * @ORM\Column(name="show_description", type="boolean", nullable=true)
- */
- private $showDescription;
- /**
- * @var integer
- *
- * @ORM\Column(name="duration", type="integer", nullable=true)
- */
- private $duration;
- /**
- * @var integer
- *
- * @ORM\Column(name="nbr_courses", type="smallint", nullable=true, unique=false)
- */
- private $nbrCourses;
- /**
- * @var integer
- *
- * @ORM\Column(name="nbr_users", type="integer", nullable=true, unique=false)
- */
- private $nbrUsers;
- /**
- * @var integer
- *
- * @ORM\Column(name="nbr_classes", type="integer", nullable=true, unique=false)
- */
- private $nbrClasses;
- /**
- * @var integer
- *
- * @ORM\Column(name="session_admin_id", type="integer", nullable=true, unique=false)
- */
- private $sessionAdminId;
- /**
- * @var integer
- *
- * @ORM\Column(name="visibility", type="integer", nullable=false, unique=false)
- */
- private $visibility;
- /**
- * @var integer
- *
- * @ORM\Column(name="promotion_id", type="integer", nullable=true, unique=false)
- */
- private $promotionId;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="display_start_date", type="datetime", nullable=true, unique=false)
- */
- private $displayStartDate;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="display_end_date", type="datetime", nullable=true, unique=false)
- */
- private $displayEndDate;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="access_start_date", type="datetime", nullable=true, unique=false)
- */
- private $accessStartDate;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="access_end_date", type="datetime", nullable=true, unique=false)
- */
- private $accessEndDate;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="coach_access_start_date", type="datetime", nullable=true, unique=false)
- */
- private $coachAccessStartDate;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="coach_access_end_date", type="datetime", nullable=true, unique=false)
- */
- private $coachAccessEndDate;
- /**
- * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CItemProperty", mappedBy="session")
- **/
- //private $items;
- /**
- * @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", inversedBy="sessionAsGeneralCoach")
- * @ORM\JoinColumn(name="id_coach", referencedColumnName="id")
- **/
- private $generalCoach;
- /**
- * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\SessionCategory", inversedBy="session")
- * @ORM\JoinColumn(name="session_category_id", referencedColumnName="id")
- **/
- private $category;
- /**
- * @var ArrayCollection
- * @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;
- /**
- * @var Course
- **/
- protected $currentCourse;
- /**
- * @var boolean
- * @ORM\Column(name="send_subscription_notification", type="boolean", nullable=false, options={"default":false})
- */
- private $sendSubscriptionNotification;
- /**
- * @var ArrayCollection
- * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CStudentPublication", mappedBy="session", cascade={"persist"}, orphanRemoval=true)
- */
- private $studentPublications;
- /**
- * Constructor
- */
- public function __construct()
- {
- $this->items = new ArrayCollection();
- $this->nbrClasses = 0;
- $this->nbrUsers = 0;
- $this->nbrUsers = 0;
- $this->displayStartDate = new \DateTime();
- $this->displayEndDate = new \DateTime();
- $this->accessStartDate = new \DateTime();
- $this->accessEndDate = new \DateTime();
- $this->coachAccessStartDate = new \DateTime();
- $this->coachAccessEndDate = new \DateTime();
- $this->visibility = 1;
- $this->courses = new ArrayCollection();
- $this->users = new ArrayCollection();
- $this->userCourseSubscriptions = new ArrayCollection();
- $this->showDescription = 0;
- $this->category = null;
- $this->studentPublications = new ArrayCollection();
- }
- /**
- * @return int
- */
- public function getDuration()
- {
- return $this->duration;
- }
- /**
- * @param int $duration
- */
- public function setDuration($duration)
- {
- $this->duration = $duration;
- }
- /**
- * @return string
- */
- public function getShowDescription()
- {
- return $this->showDescription;
- }
- /**
- * @param string $showDescription
- */
- public function setShowDescription($showDescription)
- {
- $this->showDescription = $showDescription;
- }
- /**
- * @return string
- */
- public function __toString()
- {
- return (string) $this->getName();
- }
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * @param int $id
- */
- public function setId($id)
- {
- $this->id = $id;
- }
- /**
- * @return ArrayCollection
- */
- public function getUsers()
- {
- return $this->users;
- }
- /**
- * @param $users
- */
- public function setUsers($users)
- {
- $this->users = new ArrayCollection();
- foreach ($users as $user) {
- $this->addUser($user);
- }
- }
- /**
- * @param SessionRelUser $user
- */
- public function addUser(SessionRelUser $user)
- {
- $user->setSession($this);
- if (!$this->hasUser($user)) {
- $this->users[] = $user;
- }
- }
- /**
- * @param int $status
- * @param User $user
- */
- public function addUserInSession($status, User $user)
- {
- $sessionRelUser = new SessionRelUser();
- $sessionRelUser->setSession($this);
- $sessionRelUser->setUser($user);
- $sessionRelUser->setRelationType($status);
- $this->addUser($sessionRelUser);
- }
- /**
- * @param SessionRelUser $subscription
- * @return bool
- */
- public function hasUser(SessionRelUser $subscription)
- {
- if ($this->getUsers()->count()) {
- $criteria = Criteria::create()->where(
- Criteria::expr()->eq("user", $subscription->getUser())
- )->andWhere(
- Criteria::expr()->eq("session", $subscription->getSession())
- )->andWhere(
- Criteria::expr()->eq("relationType", $subscription->getRelationType())
- );
- $relation = $this->getUsers()->matching($criteria);
- return $relation->count() > 0;
- }
- return false;
- }
- /**
- * @return ArrayCollection
- */
- public function getCourses()
- {
- return $this->courses;
- }
- /**
- * @param $courses
- */
- public function setCourses($courses)
- {
- $this->courses = new ArrayCollection();
- foreach ($courses as $course) {
- $this->addCourses($course);
- }
- }
- /**
- * @param SessionRelCourse $course
- */
- public function addCourses(SessionRelCourse $course)
- {
- $course->setSession($this);
- $this->courses[] = $course;
- }
- /**
- * @param Course $course
- *
- * @return bool
- */
- public function hasCourse(Course $course)
- {
- if ($this->getCourses()->count()) {
- $criteria = Criteria::create()->where(
- Criteria::expr()->eq("course", $course)
- );
- $relation = $this->getCourses()->matching($criteria);
- return $relation->count() > 0;
- }
- return false;
- }
- /**
- * Remove $course
- *
- * @param SessionRelCourse $course
- */
- public function removeCourses($course)
- {
- foreach ($this->courses as $key => $value) {
- if ($value->getId() == $course->getId()) {
- unset($this->courses[$key]);
- }
- }
- }
- /**
- * @param User $user
- * @param Course $course
- * @param int $status if not set it will check if the user is registered
- * with any status
- *
- * @return bool
- */
- public function hasUserInCourse(User $user, Course $course, $status = null)
- {
- $relation = $this->getUserInCourse($user, $course, $status);
- return $relation->count() > 0;
- }
- /**
- * @param User $user
- * @param Course $course
- *
- * @return bool
- */
- public function hasStudentInCourse(User $user, Course $course)
- {
- return $this->hasUserInCourse($user, $course, self::STUDENT);
- }
- /**
- * @param User $user
- * @param Course $course
- *
- * @return bool
- */
- public function hasCoachInCourseWithStatus(User $user, Course $course)
- {
- return $this->hasUserInCourse($user, $course, self::COACH);
- }
- /**
- * @param User $user
- * @param Course $course
- * @param string $status
- *
- * @return \Doctrine\Common\Collections\Collection|static
- */
- public function getUserInCourse(User $user, Course $course, $status = null)
- {
- $criteria = Criteria::create()->where(
- Criteria::expr()->eq("course", $course)
- )->andWhere(
- Criteria::expr()->eq("user", $user)
- );
- if (!is_null($status)) {
- $criteria->andWhere(
- Criteria::expr()->eq("status", $status)
- );
- }
- return $this->getUserCourseSubscriptions()->matching($criteria);
- }
- /**
- * Set name
- *
- * @param string $name
- * @return Session
- */
- public function setName($name)
- {
- $this->name = $name;
- return $this;
- }
- /**
- * Get name
- *
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * Set description
- *
- * @param string $description
- * @return Groups
- */
- public function setDescription($description)
- {
- $this->description = $description;
- return $this;
- }
- /**
- * Get description
- *
- * @return string
- */
- public function getDescription()
- {
- return $this->description;
- }
- /**
- * Set nbrCourses
- *
- * @param integer $nbrCourses
- * @return Session
- */
- public function setNbrCourses($nbrCourses)
- {
- $this->nbrCourses = $nbrCourses;
- return $this;
- }
- /**
- * Get nbrCourses
- *
- * @return integer
- */
- public function getNbrCourses()
- {
- return $this->nbrCourses;
- }
- /**
- * Set nbrUsers
- *
- * @param integer $nbrUsers
- * @return Session
- */
- public function setNbrUsers($nbrUsers)
- {
- $this->nbrUsers = $nbrUsers;
- return $this;
- }
- /**
- * Get nbrUsers
- *
- * @return integer
- */
- public function getNbrUsers()
- {
- return $this->nbrUsers;
- }
- /**
- * Set nbrClasses
- *
- * @param integer $nbrClasses
- * @return Session
- */
- public function setNbrClasses($nbrClasses)
- {
- $this->nbrClasses = $nbrClasses;
- return $this;
- }
- /**
- * Get nbrClasses
- *
- * @return integer
- */
- public function getNbrClasses()
- {
- return $this->nbrClasses;
- }
- /**
- * Set sessionAdminId
- *
- * @param integer $sessionAdminId
- * @return Session
- */
- public function setSessionAdminId($sessionAdminId)
- {
- $this->sessionAdminId = $sessionAdminId;
- return $this;
- }
- /**
- * Get sessionAdminId
- *
- * @return integer
- */
- public function getSessionAdminId()
- {
- return $this->sessionAdminId;
- }
- /**
- * Set visibility
- *
- * @param integer $visibility
- * @return Session
- */
- public function setVisibility($visibility)
- {
- $this->visibility = $visibility;
- return $this;
- }
- /**
- * Get visibility
- *
- * @return integer
- */
- public function getVisibility()
- {
- return $this->visibility;
- }
- /**
- * Set promotionId
- *
- * @param integer $promotionId
- * @return Session
- */
- public function setPromotionId($promotionId)
- {
- $this->promotionId = $promotionId;
- return $this;
- }
- /**
- * Get promotionId
- *
- * @return integer
- */
- public function getPromotionId()
- {
- return $this->promotionId;
- }
- /**
- * Set displayStartDate
- *
- * @param \DateTime $displayStartDate
- * @return Session
- */
- public function setDisplayStartDate($displayStartDate)
- {
- $this->displayStartDate = $displayStartDate;
- return $this;
- }
- /**
- * Get displayStartDate
- *
- * @return \DateTime
- */
- public function getDisplayStartDate()
- {
- return $this->displayStartDate;
- }
- /**
- * Set displayEndDate
- *
- * @param \DateTime $displayEndDate
- * @return Session
- */
- public function setDisplayEndDate($displayEndDate)
- {
- $this->displayEndDate = $displayEndDate;
- return $this;
- }
- /**
- * Get displayEndDate
- *
- * @return \DateTime
- */
- public function getDisplayEndDate()
- {
- return $this->displayEndDate;
- }
- /**
- * Set accessStartDate
- *
- * @param \DateTime $accessStartDate
- * @return Session
- */
- public function setAccessStartDate($accessStartDate)
- {
- $this->accessStartDate = $accessStartDate;
- return $this;
- }
- /**
- * Get accessStartDate
- *
- * @return \DateTime
- */
- public function getAccessStartDate()
- {
- return $this->accessStartDate;
- }
- /**
- * Set accessEndDate
- *
- * @param \DateTime $accessEndDate
- * @return Session
- */
- public function setAccessEndDate($accessEndDate)
- {
- $this->accessEndDate = $accessEndDate;
- return $this;
- }
- /**
- * Get accessEndDate
- *
- * @return \DateTime
- */
- public function getAccessEndDate()
- {
- return $this->accessEndDate;
- }
- /**
- * Set coachAccessStartDate
- *
- * @param \DateTime $coachAccessStartDate
- * @return Session
- */
- public function setCoachAccessStartDate($coachAccessStartDate)
- {
- $this->coachAccessStartDate = $coachAccessStartDate;
- return $this;
- }
- /**
- * Get coachAccessStartDate
- *
- * @return \DateTime
- */
- public function getCoachAccessStartDate()
- {
- return $this->coachAccessStartDate;
- }
- /**
- * Set coachAccessEndDate
- *
- * @param \DateTime $coachAccessEndDate
- * @return Session
- */
- public function setCoachAccessEndDate($coachAccessEndDate)
- {
- $this->coachAccessEndDate = $coachAccessEndDate;
- return $this;
- }
- /**
- * Get coachAccessEndDate
- *
- * @return \DateTime
- */
- public function getCoachAccessEndDate()
- {
- return $this->coachAccessEndDate;
- }
- /**
- * Get id
- * @return User
- */
- public function getGeneralCoach()
- {
- return $this->generalCoach;
- }
- /**
- * @param $coach
- */
- public function setGeneralCoach($coach)
- {
- $this->generalCoach = $coach;
- }
- /**
- * @return mixed
- * @return SessionCategory
- */
- public function getCategory()
- {
- return $this->category;
- }
- /**
- * @param $category
- * @return $this
- */
- public function setCategory($category)
- {
- $this->category = $category;
- return $this;
- }
- /**
- * @return array
- */
- public static function getStatusList()
- {
- return array(
- self::VISIBLE => 'status_visible',
- self::READ_ONLY => 'status_read_only',
- self::INVISIBLE => 'status_invisible',
- self::AVAILABLE => 'status_available',
- );
- }
- /**
- * Check if session is visible
- * @return bool
- */
- public function isActive()
- {
- $now = new \Datetime('now');
- if ($now > $this->getAccessStartDate()) {
- return true;
- }
- return false;
- }
- /**
- * @param Course $course
- */
- public function addCourse(Course $course)
- {
- $entity = new SessionRelCourse();
- $entity->setCourse($course);
- $this->addCourses($entity);
- }
- /**
- * @return ArrayCollection
- */
- public function getUserCourseSubscriptions()
- {
- return $this->userCourseSubscriptions;
- }
- /**
- * @param ArrayCollection $userCourseSubscriptions
- */
- public function setUserCourseSubscriptions($userCourseSubscriptions)
- {
- $this->userCourseSubscriptions = new ArrayCollection();
- foreach ($userCourseSubscriptions as $item) {
- $this->addUserCourseSubscription($item);
- }
- }
- /**
- * @param SessionRelCourseRelUser $subscription
- */
- public function addUserCourseSubscription(SessionRelCourseRelUser $subscription)
- {
- $subscription->setSession($this);
- if (!$this->hasUserCourseSubscription($subscription)) {
- $this->userCourseSubscriptions[] = $subscription;
- }
- }
- /**
- * @param int $status
- * @param User $user
- * @param Course $course
- */
- public function addUserInCourse($status, User $user, Course $course)
- {
- $userRelCourseRelSession = new SessionRelCourseRelUser();
- $userRelCourseRelSession->setCourse($course);
- $userRelCourseRelSession->setUser($user);
- $userRelCourseRelSession->setSession($this);
- $userRelCourseRelSession->setStatus($status);
- $this->addUserCourseSubscription($userRelCourseRelSession);
- }
- /**
- * @param SessionRelCourseRelUser $subscription
- * @return bool
- */
- public function hasUserCourseSubscription(SessionRelCourseRelUser $subscription)
- {
- if ($this->getUserCourseSubscriptions()->count()) {
- $criteria = Criteria::create()->where(
- Criteria::expr()->eq("user", $subscription->getUser())
- )->andWhere(
- Criteria::expr()->eq("course", $subscription->getCourse())
- )->andWhere(
- Criteria::expr()->eq("session", $subscription->getSession())
- );
- $relation = $this->getUserCourseSubscriptions()->matching($criteria);
- return $relation->count() > 0;
- }
- return false;
- }
- /**
- * @return Course
- */
- public function getCurrentCourse()
- {
- return $this->currentCourse;
- }
- /**
- * @param Course $course
- * @return $this
- */
- public function setCurrentCourse(Course $course)
- {
- // If the session is registered in the course session list.
- if ($this->getCourses()->contains($course->getId())) {
- $this->currentCourse = $course;
- }
- return $this;
- }
- /**
- * Set $sendSubscriptionNotification
- * @param boolean $sendNotification
- * @return \Chamilo\CoreBundle\Entity\Session
- */
- public function setSendSubscriptionNotification($sendNotification)
- {
- $this->sendSubscriptionNotification = $sendNotification;
- return $this;
- }
- /**
- * Get $sendSubscriptionNotification
- * @return boolean
- */
- public function getSendSubscriptionNotification()
- {
- return $this->sendSubscriptionNotification;
- }
- /**
- * Get user from course by status
- * @param \Chamilo\CoreBundle\Entity\Course $course
- * @param string $status
- * @return \Doctrine\Common\Collections\Collection|static
- */
- public function getUserCourseSubscriptionsByStatus(Course $course, $status)
- {
- $criteria = Criteria::create()
- ->where(
- Criteria::expr()->eq("course", $course)
- )
- ->andWhere(
- Criteria::expr()->eq("status", $status)
- );
- return $this->userCourseSubscriptions->matching($criteria);
- }
- public function getBuyCoursePluginPrice()
- {
- // start buycourse validation
- // display the course price and buy button if the buycourses plugin is enabled and this course is configured
- $plugin = \BuyCoursesPlugin::create();
- $isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator($this->id, \BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
- $return = [];
- if ($isThisCourseInSale) {
- // set the Price label
- $return['html'] = $isThisCourseInSale['html'];
- // set the Buy button instead register.
- if ($isThisCourseInSale['verificator']) {
- $return['buy_button'] = $plugin->returnBuyCourseButton($this->id, \BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
- }
- }
- // end buycourse validation
- 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;
- }
- }
|