From 905f88afbc686eb514c428024ff2b56cce441cab Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 2 Aug 2018 15:30:35 +0200 Subject: [PATCH] Minor - clean entity remove plugin funcionality from entity - function getBuyCoursePluginPrice - use protected instead of private --- main/auth/courses_controller.php | 3 +- .../src/buy_course_plugin.class.php | 29 ++++++++++- src/Chamilo/CoreBundle/Entity/Portfolio.php | 20 ++++---- src/Chamilo/CoreBundle/Entity/Session.php | 20 -------- .../CourseBundle/Entity/CItemProperty.php | 49 ++++++++++--------- src/Chamilo/UserBundle/Entity/User.php | 2 - 6 files changed, 64 insertions(+), 59 deletions(-) diff --git a/main/auth/courses_controller.php b/main/auth/courses_controller.php index b307ebf7f2..1e4eea6b48 100755 --- a/main/auth/courses_controller.php +++ b/main/auth/courses_controller.php @@ -930,7 +930,8 @@ class CoursesController $actions = api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session->getId(); } - $isThisSessionOnSale = $session->getBuyCoursePluginPrice(); + $plugin = \BuyCoursesPlugin::create(); + $isThisSessionOnSale = $plugin->getBuyCoursePluginPrice($session); $sessionsBlock = [ 'id' => $session->getId(), diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index 3537e119fd..b7234c1659 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -2514,8 +2514,33 @@ class BuyCoursesPlugin extends Plugin return Database::update( $serviceSaleTable, - ['status' => intval($newStatus)], - ['id = ?' => intval($serviceSaleId)] + ['status' => (int) $newStatus], + ['id = ?' => (int) $serviceSaleId] ); } + + /** + * @param Session $session + * + * @return array + */ + public function getBuyCoursePluginPrice(Session $session) + { + // start buycourse validation + // display the course price and buy button if the buycourses plugin is enabled and this course is configured + $isThisCourseInSale = $this->buyCoursesForGridCatalogValidator($session->getId(), self::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'] = $this->returnBuyCourseButton($session->getId(), self::PRODUCT_TYPE_SESSION); + } + } + // end buycourse validation + return $return; + } + } diff --git a/src/Chamilo/CoreBundle/Entity/Portfolio.php b/src/Chamilo/CoreBundle/Entity/Portfolio.php index 598d5c6431..2593ea9bc2 100644 --- a/src/Chamilo/CoreBundle/Entity/Portfolio.php +++ b/src/Chamilo/CoreBundle/Entity/Portfolio.php @@ -32,20 +32,20 @@ class Portfolio * @ORM\Id * @ORM\GeneratedValue */ - private $id; + protected $id; /** * @var string * * @ORM\Column(name="title", type="string", length=255) */ - private $title; + protected $title; /** * @var string * @ORM\Column(name="content", type="text") */ - private $content; + protected $content; /** * @var User @@ -53,7 +53,7 @@ class Portfolio * @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User") * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false, onDelete="CASCADE") */ - private $user; + protected $user; /** * @var Course @@ -61,7 +61,7 @@ class Portfolio * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course") * @ORM\JoinColumn(name="c_id", referencedColumnName="id", onDelete="CASCADE") */ - private $course = null; + protected $course = null; /** * @var Session @@ -69,28 +69,28 @@ class Portfolio * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session") * @ORM\JoinColumn(name="session_id", referencedColumnName="id", onDelete="CASCADE") */ - private $session = null; + protected $session = null; /** * @var \DateTime * * @ORM\Column(name="creation_date", type="datetime") */ - private $creationDate; + protected $creationDate; /** * @var \DateTime * * @ORM\Column(name="update_date", type="datetime") */ - private $updateDate; + protected $updateDate; /** * @var bool * * @ORM\Column(name="is_visible", type="boolean", options={"default": true}) */ - private $isVisible = true; + protected $isVisible = true; /** * @var \Chamilo\CoreBundle\Entity\PortfolioCategory @@ -98,7 +98,7 @@ class Portfolio * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\PortfolioCategory", inversedBy="items") * @ORM\JoinColumn(name="category_id", referencedColumnName="id", onDelete="SET NULL") */ - private $category; + protected $category; /** * Portfolio constructor. diff --git a/src/Chamilo/CoreBundle/Entity/Session.php b/src/Chamilo/CoreBundle/Entity/Session.php index ca54547f57..1ffb378dc8 100644 --- a/src/Chamilo/CoreBundle/Entity/Session.php +++ b/src/Chamilo/CoreBundle/Entity/Session.php @@ -1103,26 +1103,6 @@ class Session 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 * diff --git a/src/Chamilo/CourseBundle/Entity/CItemProperty.php b/src/Chamilo/CourseBundle/Entity/CItemProperty.php index 6d9fe17481..c6afedd120 100644 --- a/src/Chamilo/CourseBundle/Entity/CItemProperty.php +++ b/src/Chamilo/CourseBundle/Entity/CItemProperty.php @@ -15,6 +15,22 @@ use Doctrine\ORM\Mapping as ORM; */ class CItemProperty { + /** + * @var int + * + * @ORM\Column(name="iid", type="integer") + * @ORM\Id + * @ORM\GeneratedValue + */ + protected $iid; + + /** + * @var int + * + * @ORM\Column(name="id", type="integer", nullable=true) + */ + protected $id; + /** //, inversedBy="users", * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", cascade={"persist"}) * @ORM\JoinColumn(name="c_id", referencedColumnName="id") @@ -44,84 +60,69 @@ class CItemProperty * @ORM\JoinColumn(name="session_id", referencedColumnName="id") */ protected $session; - /** - * @var int - * - * @ORM\Column(name="iid", type="integer") - * @ORM\Id - * @ORM\GeneratedValue - */ - private $iid; - - /** - * @var int - * - * @ORM\Column(name="id", type="integer", nullable=true) - */ - private $id; /** * @var string * * @ORM\Column(name="tool", type="string", length=100, nullable=false) */ - private $tool; + protected $tool; /** * @var \DateTime * * @ORM\Column(name="insert_date", type="datetime", nullable=false) */ - private $insertDate; + protected $insertDate; /** * @var \DateTime * * @ORM\Column(name="lastedit_date", type="datetime", nullable=false) */ - private $lasteditDate; + protected $lasteditDate; /** * @var int * * @ORM\Column(name="ref", type="integer", nullable=false) */ - private $ref; + protected $ref; /** * @var string * * @ORM\Column(name="lastedit_type", type="string", length=100, nullable=false) */ - private $lasteditType; + protected $lasteditType; /** * @var int * * @ORM\Column(name="lastedit_user_id", type="integer", nullable=false) */ - private $lasteditUserId; + protected $lasteditUserId; /** * @var int * * @ORM\Column(name="visibility", type="integer", nullable=false) */ - private $visibility; + protected $visibility; /** * @var \DateTime * * @ORM\Column(name="start_visible", type="datetime", nullable=true) */ - private $startVisible; + protected $startVisible; /** * @var \DateTime * * @ORM\Column(name="end_visible", type="datetime", nullable=true) */ - private $endVisible; + protected $endVisible; /** * CItemProperty constructor. diff --git a/src/Chamilo/UserBundle/Entity/User.php b/src/Chamilo/UserBundle/Entity/User.php index aa98ee00fb..c62b3e1a13 100644 --- a/src/Chamilo/UserBundle/Entity/User.php +++ b/src/Chamilo/UserBundle/Entity/User.php @@ -2582,6 +2582,4 @@ class User implements UserInterface //implements ParticipantInterface, ThemeUser return $this; } - - }