Added the new Entities to Doctrine files - Refs BT#10651

ofaj
José Loguercio 10 years ago
parent ad26596a76
commit adb886e09f
  1. 5
      src/Chamilo/CoreBundle/Entity/Course.php
  2. 77
      src/Chamilo/CoreBundle/Entity/Skill.php
  3. 307
      src/Chamilo/CoreBundle/Entity/SkillRelUser.php
  4. 183
      src/Chamilo/CoreBundle/Entity/SkillRelUserComment.php
  5. 53
      src/Chamilo/UserBundle/Entity/User.php

@ -276,6 +276,11 @@ class Course
**/
protected $currentSession;
/**
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser", mappedBy="course", cascade={"persist"})
*/
protected $issuedSkills;
/**
* Constructor
*/

@ -1,5 +1,13 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Skill Entity
*
* @package chamilo.skill
*/
namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
@ -12,6 +20,9 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Skill
{
const STATUS_DISABLED = 0;
const STATUS_ENABLED = 1;
/**
* @var string
*
@ -77,7 +88,24 @@ class Skill
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\SkillBundle\Entity\Profile", inversedBy="skills")
* @ORM\JoinColumn(name="profile_id", referencedColumnName="id")
**/
protected $profile;
/**
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser", mappedBy="skill", cascade={"persist"})
*/
protected $issuedSkills;
/**
* @return string
*/
public function __toString()
{
return (string) $this->getName();
}
/**
* Set name
@ -195,16 +223,25 @@ class Skill
}
/**
* Get the icon URL
* Get the icon (badge image) URL
* @param boolean $getSmall Optional. Allow get the small image
* @return string
*/
public function getWebIconPath()
public function getWebIconPath($getSmall = false)
{
if ($this->getIcon()) {
return api_get_path(WEB_UPLOAD_PATH) . "badges/{$this->getIcon()}";
if ($getSmall) {
if (empty($this->icon)) {
return \Display::return_icon('badges-default.png', null, null, ICON_SIZE_BIG, null, true);
}
return api_get_path(WEB_UPLOAD_PATH) . 'badges/' . sha1($this->name) . '-small.png';
}
if (empty($this->icon)) {
return \Display::return_icon('badges-default.png', null, null, ICON_SIZE_HUGE, null, true);
}
return \Display::return_icon('badges-default.png', null, null, ICON_SIZE_HUGE, null, true);
return api_get_path(WEB_UPLOAD_PATH) . "badges/{$this->icon}";
}
/**
@ -281,4 +318,34 @@ class Skill
{
return $this->id;
}
/**
* @return Profile
*/
public function getProfile()
{
return $this->profile;
}
/**
* @param Profile $profile
*
* @return Skill
*/
public function setProfile($profile)
{
$this->profile = $profile;
return $this;
}
/**
* Get issuedSkills
* @return ArrayCollection
*/
public function getIssuedSkills()
{
return $this->issuedSkills;
}
}

@ -1,5 +1,13 @@
<?php
/* For licensing terms, see /license.txt */
/**
* SkillRelUser Entity
*
* @package chamilo.skill
*/
namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
@ -7,7 +15,14 @@ use Doctrine\ORM\Mapping as ORM;
/**
* SkillRelUser
*
* @ORM\Table(name="skill_rel_user", indexes={@ORM\Index(name="idx_select_cs", columns={"course_id", "session_id"})})
* @ORM\Table(
* name="skill_rel_user",
* indexes={
* @ORM\Index(name="idx_select_cs", columns={"course_id", "session_id"}),
* @ORM\Index(name="idx_select_s_c_u", columns={"session_id", "course_id", "user_id"}),
* @ORM\Index(name="idx_select_sk_u", columns={"skill_id", "user_id"})
* }
* )
* @ORM\Entity
*/
class SkillRelUser
@ -26,6 +41,17 @@ class SkillRelUser
*/
private $skillId;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", inversedBy="achievedSkills", cascade={"persist"})
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Skill", inversedBy="issuedSkills", cascade={"persist"})
* @ORM\JoinColumn(name="skill_id", referencedColumnName="id", nullable=false)
*/
private $skill;
/**
* @var \DateTime
*
@ -54,6 +80,18 @@ class SkillRelUser
*/
private $sessionId;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="issuedSkills", cascade={"persist"})
* @ORM\JoinColumn(name="course_id", referencedColumnName="id")
*/
private $course;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session", inversedBy="issuedSkills", cascade={"persist"})
* @ORM\JoinColumn(name="session_id", referencedColumnName="id")
*/
private $session;
/**
* @var integer
*
@ -63,7 +101,37 @@ class SkillRelUser
*/
private $id;
/**
* @var Level
*
* @ORM\ManyToOne(targetEntity="Chamilo\SkillBundle\Entity\Level")
* @ORM\JoinColumn(name="acquired_level", referencedColumnName="id")
*/
private $acquiredLevel;
/**
* @var string
*
* @ORM\Column(name="argumentation", type="text")
*/
private $argumentation;
/**
* @var integer
*
* @ORM\Column(name="argumentation_author_id", type="integer")
*/
private $argumentationAuthorId;
/**
* @ORM\OneToMany(targetEntity="SkillRelUserComment", mappedBy="skillRelUser")
*/
protected $comments;
public function __construct()
{
$this->comments = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Set userId
@ -111,6 +179,91 @@ class SkillRelUser
return $this->skillId;
}
/**
* Set user
* @param \Chamilo\UserBundle\Entity\User $user
* @return \Chamilo\CoreBundle\Entity\SkillRelUser
*/
public function setUser(\Chamilo\UserBundle\Entity\User $user)
{
$this->user = $user;
return $this;
}
/**
* Get user
* @return \Chamilo\UserBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
/**
* Set skill
* @param \Chamilo\CoreBundle\Entity\Skill $skill
* @return \Chamilo\CoreBundle\Entity\SkillRelUser
*/
public function setSkill(Skill $skill)
{
$this->skill = $skill;
return $this;
}
/**
* Get skill
* @return \Chamilo\CoreBundle\Entity\Skill
*/
public function getSkill()
{
return $this->skill;
}
/**
* Set course
* @param \Chamilo\CoreBundle\Entity\Course $course
* @return \Chamilo\CoreBundle\Entity\SkillRelUser
*/
public function setCourse(Course $course)
{
$this->course = $course;
return $this;
}
/**
* Get course
* @return \Chamilo\CoreBundle\Entity\Course
*/
public function getCourse()
{
return $this->course;
}
/**
* Set session
* @param \Chamilo\CoreBundle\Entity\Session $session
* @return \Chamilo\CoreBundle\Entity\SkillRelUser
*/
public function setSession(Session $session)
{
$this->session = $session;
return $this;
}
/**
* Get session
* @return \Chamilo\CoreBundle\Entity\Session
*/
public function getSession()
{
return $this->session;
}
/**
* Set acquiredSkillAt
*
@ -212,4 +365,156 @@ class SkillRelUser
{
return $this->id;
}
/**
* Set acquiredLevel
* @param \Chamilo\SkillBundle\Entity\Level $acquiredLevel
* @return \Chamilo\CoreBundle\Entity\SkillRelUser
*/
public function setAcquiredLevel($acquiredLevel)
{
$this->acquiredLevel = $acquiredLevel;
return $this;
}
/**
* Get acquiredLevel
* @return \Chamilo\SkillBundle\Entity\Level
*/
public function getAcquiredLevel()
{
return $this->acquiredLevel;
}
/**
* Set argumentationAuthorId
* @param integer $argumentationAuthorId
* @return \Chamilo\CoreBundle\Entity\SkillRelUser
*/
public function setArgumentationAuthorId($argumentationAuthorId)
{
$this->argumentationAuthorId = $argumentationAuthorId;
return $this;
}
/**
* Get argumentationAuthorId
* @return integer
*/
public function getArgumentationAuthorId()
{
return $this->argumentationAuthorId;
}
/**
* Set argumentation
* @param string $argumentation
* @return \Chamilo\CoreBundle\Entity\SkillRelUser
*/
public function setArgumentation($argumentation)
{
$this->argumentation = $argumentation;
return $this;
}
/**
* Get argumentation
* @return string
*/
public function getArgumentation()
{
return $this->argumentation;
}
/**
* Get the source which the skill was obtained
* @return string
*/
public function getSourceName()
{
$source = '';
if ($this->session) {
$source .= "[{$this->session->getName()}] ";
}
if ($this->course) {
$source .= $this->course->getTitle();
}
return $source;
}
/**
* Get the URL for the issue
* @return string
*/
public function getIssueUrl()
{
return api_get_path(WEB_PATH) . "badge/issue/{$this->id}/user/{$this->user->getId()}/";
}
/**
* Get the URL for the assertion
* @return string
*/
public function getAssertionUrl()
{
$url = api_get_path(WEB_CODE_PATH) . "badge/assertion.php?";
$url .= http_build_query(array(
'user' => $this->user->getId(),
'skill' => $this->skill->getId(),
'course' => $this->course ? $this->course->getId() : 0,
'session' => $this->session ? $this->session->getId() : 0
));
return $url;
}
/**
* Get comments
* @param boolean $sortDescByDateTime
* @return ArrayCollection
*/
public function getComments($sortDescByDateTime = false)
{
if ($sortDescByDateTime) {
$criteria = \Doctrine\Common\Collections\Criteria::create();
$criteria->orderBy([
'feedbackDateTime' => \Doctrine\Common\Collections\Criteria::DESC
]);
return $this->comments->matching($criteria);
}
return $this->comments;
}
/**
* Calculate the average value from the feedback comments
* @return type
*/
public function getAverage()
{
$sum = 0;
$average = 0;
$countValues = 0;
foreach ($this->comments as $comment) {
if (!$comment->getFeedbackValue()) {
continue;
}
$sum += $comment->getFeedbackValue();
$countValues++;
}
$average = $countValues > 0 ? $sum / $countValues : 0;
return number_format($average, 2);
}
}

@ -0,0 +1,183 @@
<?php
/* For licensing terms, see /license.txt */
/**
* SkillRelUserComment Entity
*
* @package chamilo.skill
*/
namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* SkillRelUserComment class
*
* @ORM\Table(
* name="skill_rel_user_comment",
* indexes={
* @ORM\Index(name="idx_select_su_giver", columns={"skill_rel_user_id", "feedback_giver_id"})
* }
* )
* @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Entity\Repository\SkillRelUserCommentRepository")
*/
class SkillRelUserComment
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser", inversedBy="comments")
* @ORM\JoinColumn(name="skill_rel_user_id", referencedColumnName="id")
*/
private $skillRelUser;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", inversedBy="commentedUserSkills")
* @ORM\JoinColumn(name="feedback_giver_id", referencedColumnName="id")
*/
private $feedbackGiver;
/**
* @var string
*
* @ORM\Column(name="feedback_text", type="text")
*/
private $feedbackText;
/**
* @var int
*
* @ORM\Column(name="feedback_value", type="integer", nullable=true, options={"default":1})
*/
private $feedbackValue;
/**
* @var \DateTime
*
* @ORM\Column(name="feedback_datetime", type="datetime")
*/
private $feedbackDateTime;
/**
* Get id
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Get skillRelUser
* @return Chamilo\CoreBundle\Entity\SkillRelUser
*/
public function getSkillRelUser()
{
return $this->skillRelUser;
}
/**
* Get feedbackGiver
* @return Chamilo\UserBundle\Entity\User
*/
public function getFeedbackGiver()
{
return $this->feedbackGiver;
}
/**
* Get feedbackText
* @return string
*/
public function getFeedbackText()
{
return $this->feedbackText;
}
/**
* Get feedbackValue
* @return int
*/
public function getFeedbackValue()
{
return $this->feedbackValue;
}
/**
* Get feedbackDateTime
* @return type
*/
public function getFeedbackDateTime()
{
return $this->feedbackDateTime;
}
/**
* Set skillRelUser
* @param \Chamilo\CoreBundle\Entity\SkillRelUser $skillRelUser
* @return \Chamilo\CoreBundle\Entity\SkillRelUserComment
*/
public function setSkillRelUser(SkillRelUser $skillRelUser)
{
$this->skillRelUser = $skillRelUser;
return $this;
}
/**
* Set feedbackGiver
* @param \Chamilo\UserBundle\Entity\User $feedbackGiver
* @return \Chamilo\CoreBundle\Entity\SkillRelUserComment
*/
public function setFeedbackGiver(\Chamilo\UserBundle\Entity\User $feedbackGiver)
{
$this->feedbackGiver = $feedbackGiver;
return $this;
}
/**
* Set feedbackText
* @param string $feedbackText
* @return \Chamilo\CoreBundle\Entity\SkillRelUserComment
*/
public function setFeedbackText($feedbackText)
{
$this->feedbackText = $feedbackText;
return $this;
}
/**
* Set feebackValue
* @param int $feedbackValue
* @return \Chamilo\CoreBundle\Entity\SkillRelUserComment
*/
public function setFeedbackValue($feedbackValue)
{
$this->feedbackValue = $feedbackValue;
return $this;
}
/**
* Set feedbackDateTime
* @param \DateTime $feedbackDateTime
* @return \Chamilo\CoreBundle\Entity\SkillRelUserComment
*/
public function setFeedbackDateTime(\DateTime $feedbackDateTime)
{
$this->feedbackDateTime = $feedbackDateTime;
return $this;
}
}

@ -1,6 +1,13 @@
<?php
/* For licensing terms, see /license.txt */
/**
* User Entity
*
* @package chamilo.User
*/
namespace Chamilo\UserBundle\Entity;
use Chamilo\CoreBundle\Entity\ExtraFieldValues;
@ -433,6 +440,16 @@ class User implements UserInterface //implements ParticipantInterface, ThemeUser
**/
protected $sessionCourseSubscriptions;
/**
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser", mappedBy="user", cascade={"persist"})
*/
protected $achievedSkills;
/**
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUserComment", mappedBy="feedbackGiver")
*/
protected $commentedUserSkills;
/**
* Constructor
*/
@ -743,6 +760,16 @@ class User implements UserInterface //implements ParticipantInterface, ThemeUser
});*/
}
/**
* Return Complete Name with the Username
*
* @return string
*/
public function getCompleteNameWithUsername()
{
return api_get_person_name($this->firstname, $this->lastname).' ('.$this->username.')';
}
/**
* @todo don't use api_get_person_name
* @return string
@ -2423,4 +2450,30 @@ class User implements UserInterface //implements ParticipantInterface, ThemeUser
$this->id
) = $data;
}
/**
* Get achievedSkills
* @return ArrayCollection
*/
public function getAchievedSkills()
{
return $this->achievedSkills;
}
/**
* Check if the user has the skill
* @param \Chamilo\CoreBundle\Entity\Skill $skill The skill
* @return boolean
*/
public function hasSkill(\Chamilo\CoreBundle\Entity\Skill $skill)
{
$achievedSkills = $this->getAchievedSkills();
foreach ($achievedSkills as $userSkill) {
if ($userSkill->getSkill()->getId() !== $skill->getId()) {
continue;
}
return true;
}
}
}

Loading…
Cancel
Save