From ba95269ead92db0de99b5c263817cba4d09649f3 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 27 Feb 2015 11:45:49 +0100 Subject: [PATCH] Add entities. --- src/Chamilo/CoreBundle/Entity/AccessUrl.php | 2 +- .../CoreBundle/Entity/AccessUrlRelCourse.php | 92 +++ src/Chamilo/CoreBundle/Entity/Course.php | 4 +- .../Entity/Listener/CourseListener.php | 45 ++ .../Entity/Repository/CourseRepository.php | 104 +++ src/Chamilo/CoreBundle/Entity/Usergroup.php | 160 +++++ .../CourseBundle/Entity/CGroupInfo.php | 585 +++++++++++++++++ src/Chamilo/CourseBundle/Entity/CTool.php | 612 ++++++++++++++++++ .../UserRepository.php | 5 +- src/Chamilo/UserBundle/Entity/User.php | 11 +- 10 files changed, 1607 insertions(+), 13 deletions(-) create mode 100644 src/Chamilo/CoreBundle/Entity/AccessUrlRelCourse.php create mode 100644 src/Chamilo/CoreBundle/Entity/Listener/CourseListener.php create mode 100644 src/Chamilo/CoreBundle/Entity/Repository/CourseRepository.php create mode 100644 src/Chamilo/CoreBundle/Entity/Usergroup.php create mode 100644 src/Chamilo/CourseBundle/Entity/CGroupInfo.php create mode 100644 src/Chamilo/CourseBundle/Entity/CTool.php rename src/Chamilo/UserBundle/Entity/{Respository => Repository}/UserRepository.php (96%) diff --git a/src/Chamilo/CoreBundle/Entity/AccessUrl.php b/src/Chamilo/CoreBundle/Entity/AccessUrl.php index 26dfbbf867..3a575dc2af 100644 --- a/src/Chamilo/CoreBundle/Entity/AccessUrl.php +++ b/src/Chamilo/CoreBundle/Entity/AccessUrl.php @@ -72,7 +72,7 @@ class AccessUrl /** * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SettingsCurrent", mappedBy="url", cascade={"persist"}, orphanRemoval=true) **/ - protected $settings; + //protected $settings; /** * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SessionCategory", mappedBy="url", cascade={"persist"}, orphanRemoval=true) diff --git a/src/Chamilo/CoreBundle/Entity/AccessUrlRelCourse.php b/src/Chamilo/CoreBundle/Entity/AccessUrlRelCourse.php new file mode 100644 index 0000000000..fc4c65d831 --- /dev/null +++ b/src/Chamilo/CoreBundle/Entity/AccessUrlRelCourse.php @@ -0,0 +1,92 @@ +id; + } + + /** + * Set url + * + * @param $url + * @return AccessUrlRelCourse + */ + public function setUrl($url) + { + $this->url = $url; + + return $this; + } + + /** + * @return mixed + */ + public function getUrl() + { + return $this->url; + } + + + /** + * @param $course + */ + public function setCourse($course) + { + $this->course = $course; + } + + /** + * @return mixed + */ + public function getCourse() + { + return $this->course; + } +} diff --git a/src/Chamilo/CoreBundle/Entity/Course.php b/src/Chamilo/CoreBundle/Entity/Course.php index f7ea24ea9f..86a5f9c3c2 100644 --- a/src/Chamilo/CoreBundle/Entity/Course.php +++ b/src/Chamilo/CoreBundle/Entity/Course.php @@ -3,7 +3,7 @@ namespace Chamilo\CoreBundle\Entity; -use Chamilo\CourseBundle\Entity\CTool; +//use Chamilo\CourseBundle\Entity\CTool; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; @@ -11,7 +11,7 @@ use Gedmo\Mapping\Annotation as Gedmo; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Chamilo\UserBundle\Entity\User; -// @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\CourseListener"}) + /** * Class Course * diff --git a/src/Chamilo/CoreBundle/Entity/Listener/CourseListener.php b/src/Chamilo/CoreBundle/Entity/Listener/CourseListener.php new file mode 100644 index 0000000000..bd4dc4664a --- /dev/null +++ b/src/Chamilo/CoreBundle/Entity/Listener/CourseListener.php @@ -0,0 +1,45 @@ +toolChain = $toolChain; + } + + /** + * new object : prePersist + * edited object: preUpdate + * @param Course $course + * @param LifecycleEventArgs $args + */ + public function prePersist(Course $course, LifecycleEventArgs $args) + { + //$this->toolChain->addToolsInCourse($course); + /* + error_log('ddd'); + $course->setDescription( ' dq sdqs dqs dqs '); + + $args->getEntityManager()->persist($course); + $args->getEntityManager()->flush();*/ + } +} diff --git a/src/Chamilo/CoreBundle/Entity/Repository/CourseRepository.php b/src/Chamilo/CoreBundle/Entity/Repository/CourseRepository.php new file mode 100644 index 0000000000..0d7c9b34c6 --- /dev/null +++ b/src/Chamilo/CoreBundle/Entity/Repository/CourseRepository.php @@ -0,0 +1,104 @@ +createQueryBuilder('a'); + + // Selecting user info. + $queryBuilder->select('DISTINCT u'); + + // Loading EntityUser. + $queryBuilder->from('Chamilo\UserBundle\Entity\User', 'u'); + + // Selecting courses for users. + $queryBuilder->innerJoin('u.courses', 'c'); + + //@todo check app settings + $queryBuilder->add('orderBy', 'u.lastname ASC'); + + $wherePart = $queryBuilder->expr()->andx(); + + // Get only users subscribed to this course + $wherePart->add($queryBuilder->expr()->eq('c.cId', $course->getId())); + + // $wherePart->add($queryBuilder->expr()->eq('c.status', $status)); + + $queryBuilder->where($wherePart); + //$q = $queryBuilder->getQuery(); + //return $q->execute(); + return $queryBuilder; + } + + /** + * Gets students subscribed in the course + * + * @param Course $course + * + * @return QueryBuilder + */ + public function getSubscribedStudents(Course $course) + { + return self::getSubscribedUsersByStatus($course, STUDENT); + } + + /** + * Gets the students subscribed in the course + * @param Course $course + * + * @return QueryBuilder + */ + public function getSubscribedCoaches(Course $course) + { + $queryBuilder = $this->getSubscribedUsers($course); + //@todo add criterias + return $queryBuilder; + } + + /** + * + * Gets the teachers subscribed in the course + * @param Course $course + * + * @return QueryBuilder + */ + public function getSubscribedTeachers(Course $course) + { + return self::getSubscribedUsersByStatus($course, COURSEMANAGER); + } + + /** + * @param Course $course + * @param int $status use legacy chamilo constants COURSEMANAGER|STUDENT + * @return QueryBuilder + */ + public function getSubscribedUsersByStatus(Course $course, $status) + { + $queryBuilder = $this->getSubscribedUsers($course); + $wherePart = $queryBuilder->expr()->andx(); + $wherePart->add($queryBuilder->expr()->eq('c.status', $status)); + + return $queryBuilder; + } +} diff --git a/src/Chamilo/CoreBundle/Entity/Usergroup.php b/src/Chamilo/CoreBundle/Entity/Usergroup.php new file mode 100644 index 0000000000..b36abf9afe --- /dev/null +++ b/src/Chamilo/CoreBundle/Entity/Usergroup.php @@ -0,0 +1,160 @@ +users = new ArrayCollection(); + } + + /** + * @return string + */ + public function __toString() + { + return (string) $this->getName(); + } + + /** + * @return ArrayCollection + */ + public function getUsers() + { + return $this->users; + } + + /** + * @param $users + */ + public function setUsers($users) + { + $this->users = new ArrayCollection(); + + foreach ($users as $user) { + $this->addUsers($user); + } + } + + /** + * @param UsergroupRelUser $user + */ + public function addUsers(UsergroupRelUser $user) + { + $user->setUsergroup($this); + $this->users[] = $user; + } + + /** + * Remove $user + * + * @param UsergroupRelUser $user + */ + public function removeUsers(UsergroupRelUser $user) + { + foreach ($this->users as $key => $value) { + if ($value->getId() == $user->getId()) { + unset($this->users[$key]); + } + } + } + + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * Set name + * + * @param string $name + * @return Usergroup + */ + 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 Usergroup + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * Get description + * + * @return string + */ + public function getDescription() + { + return $this->description; + } +} diff --git a/src/Chamilo/CourseBundle/Entity/CGroupInfo.php b/src/Chamilo/CourseBundle/Entity/CGroupInfo.php new file mode 100644 index 0000000000..7654113e9f --- /dev/null +++ b/src/Chamilo/CourseBundle/Entity/CGroupInfo.php @@ -0,0 +1,585 @@ +items = new ArrayCollection(); + } + + /** + * + * @return ArrayCollection + */ + public function getItems() + { + return $this->items; + } + + /** + * Set cId + * + * @param integer $cId + * + * @return CGroupInfo + */ + public function setCId($cId) + { + $this->cId = $cId; + + return $this; + } + + /** + * Get cId + * + * @return integer + */ + public function getCId() + { + return $this->cId; + } + + /** + * Set iid + * + * @param integer $id + * @return CGroupInfo + */ + public function setIid($iid) + { + $this->iid = $iid; + + return $this; + } + + /** + * Get id + * + * @return integer + */ + public function getIid() + { + return $this->iid; + } + + /** + * Set id + * + * @param integer $id + * @return CGroupInfo + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * Set name + * + * @param string $name + * @return CGroupInfo + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set categoryId + * + * @param integer $categoryId + * @return CGroupInfo + */ + public function setCategoryId($categoryId) + { + $this->categoryId = $categoryId; + + return $this; + } + + /** + * Get categoryId + * + * @return integer + */ + public function getCategoryId() + { + return $this->categoryId; + } + + /** + * Set description + * + * @param string $description + * @return CGroupInfo + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * Get description + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Set maxStudent + * + * @param integer $maxStudent + * @return CGroupInfo + */ + public function setMaxStudent($maxStudent) + { + $this->maxStudent = $maxStudent; + + return $this; + } + + /** + * Get maxStudent + * + * @return integer + */ + public function getMaxStudent() + { + return $this->maxStudent; + } + + /** + * Set docState + * + * @param boolean $docState + * @return CGroupInfo + */ + public function setDocState($docState) + { + $this->docState = $docState; + + return $this; + } + + /** + * Get docState + * + * @return boolean + */ + public function getDocState() + { + return $this->docState; + } + + /** + * Set calendarState + * + * @param boolean $calendarState + * @return CGroupInfo + */ + public function setCalendarState($calendarState) + { + $this->calendarState = $calendarState; + + return $this; + } + + /** + * Get calendarState + * + * @return boolean + */ + public function getCalendarState() + { + return $this->calendarState; + } + + /** + * Set workState + * + * @param boolean $workState + * @return CGroupInfo + */ + public function setWorkState($workState) + { + $this->workState = $workState; + + return $this; + } + + /** + * Get workState + * + * @return boolean + */ + public function getWorkState() + { + return $this->workState; + } + + /** + * Set announcementsState + * + * @param boolean $announcementsState + * @return CGroupInfo + */ + public function setAnnouncementsState($announcementsState) + { + $this->announcementsState = $announcementsState; + + return $this; + } + + /** + * Get announcementsState + * + * @return boolean + */ + public function getAnnouncementsState() + { + return $this->announcementsState; + } + + /** + * Set forumState + * + * @param boolean $forumState + * @return CGroupInfo + */ + public function setForumState($forumState) + { + $this->forumState = $forumState; + + return $this; + } + + /** + * Get forumState + * + * @return boolean + */ + public function getForumState() + { + return $this->forumState; + } + + /** + * Set wikiState + * + * @param boolean $wikiState + * @return CGroupInfo + */ + public function setWikiState($wikiState) + { + $this->wikiState = $wikiState; + + return $this; + } + + /** + * Get wikiState + * + * @return boolean + */ + public function getWikiState() + { + return $this->wikiState; + } + + /** + * Set chatState + * + * @param boolean $chatState + * @return CGroupInfo + */ + public function setChatState($chatState) + { + $this->chatState = $chatState; + + return $this; + } + + /** + * Get chatState + * + * @return boolean + */ + public function getChatState() + { + return $this->chatState; + } + + /** + * Set secretDirectory + * + * @param string $secretDirectory + * @return CGroupInfo + */ + public function setSecretDirectory($secretDirectory) + { + $this->secretDirectory = $secretDirectory; + + return $this; + } + + /** + * Get secretDirectory + * + * @return string + */ + public function getSecretDirectory() + { + return $this->secretDirectory; + } + + /** + * Set selfRegistrationAllowed + * + * @param boolean $selfRegistrationAllowed + * @return CGroupInfo + */ + public function setSelfRegistrationAllowed($selfRegistrationAllowed) + { + $this->selfRegistrationAllowed = $selfRegistrationAllowed; + + return $this; + } + + /** + * Get selfRegistrationAllowed + * + * @return boolean + */ + public function getSelfRegistrationAllowed() + { + return $this->selfRegistrationAllowed; + } + + /** + * Set selfUnregistrationAllowed + * + * @param boolean $selfUnregistrationAllowed + * @return CGroupInfo + */ + public function setSelfUnregistrationAllowed($selfUnregistrationAllowed) + { + $this->selfUnregistrationAllowed = $selfUnregistrationAllowed; + + return $this; + } + + /** + * Get selfUnregistrationAllowed + * + * @return boolean + */ + public function getSelfUnregistrationAllowed() + { + return $this->selfUnregistrationAllowed; + } + + /** + * Set sessionId + * + * @param integer $sessionId + * @return CGroupInfo + */ + public function setSessionId($sessionId) + { + $this->sessionId = $sessionId; + + return $this; + } + + /** + * Get sessionId + * + * @return integer + */ + public function getSessionId() + { + return $this->sessionId; + } +} diff --git a/src/Chamilo/CourseBundle/Entity/CTool.php b/src/Chamilo/CourseBundle/Entity/CTool.php new file mode 100644 index 0000000000..3c1c2b49f6 --- /dev/null +++ b/src/Chamilo/CourseBundle/Entity/CTool.php @@ -0,0 +1,612 @@ +id = 0; + $this->sessionId = 0; + $this->address = 'squaregrey.gif'; + } + + /** + * @param Course $course + */ + public function setCourse($course) + { + $this->course = $course; + } + + /** + * @param ClassMetadata $metadata + */ + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint( + 'customIcon', + new Assert\File(array('mimeTypes' => array("image/png"))) + ); + $metadata->addPropertyConstraint( + 'customIcon', + new Assert\Image(array('maxWidth' => 64, 'minHeight' => 64)) + ); + $metadata->addPropertyConstraint('cId', new Assert\NotBlank()); + } + + /** + * @return Course + */ + public function getCourse() + { + return $this->course; + } + + /** + * @return null|string + */ + public function getAbsolutePath() + { + return null === $this->getCustomIcon() + ? null + : $this->getUploadRootDir().'/'.$this->getCustomIcon(); + } + + /** + * @return string + */ + protected function getUploadRootDir() + { + // the absolute directory path where uploaded + // documents should be saved + $dir = $this->getCourse()->getAbsoluteSysCoursePath().$this->getUploadDir(); + + if (is_dir($dir)) { + return $dir; + } else { + mkdir($dir); + return $dir; + } + } + + /** + * @return string + */ + protected function getUploadDir() + { + // get rid of the __DIR__ so it doesn't screw up + // when displaying uploaded doc/image in the view. + return 'upload/course_home_icons'; + } + + /** + * Called before saving the entity + * + * @ORM\PrePersist() + * @ORM\PreUpdate() + */ + public function preUpload() + { + if (null !== $this->getCustomIcon()) { + + // do whatever you want to generate a unique name + //$filename = sha1(uniqid(mt_rand(), true)); + $this->originalImage = $this->getCustomIcon(); + $this->customIcon = $this->getName().'_'.$this->getSessionId().'.'.$this->getCustomIcon()->guessExtension(); + } + } + + /** + * Called before entity removal + * + * @ORM\PostRemove() + */ + public function removeUpload() + { + if ($file = $this->getAbsolutePath()) { + unlink($file); + } + } + + /** + * Called after entity persistence + * + * @ORM\PostPersist() + * @ORM\PostUpdate() + */ + public function upload() + { + // the file property can be empty if the field is not required + if (null === $this->getCustomIcon()) { + return; + } + + // use the original file name here but you should + // sanitize it at least to avoid any security issues + + // move takes the target directory and then the + // target filename to move to + $this->originalImage->move( + $this->getUploadRootDir(), + $this->customIcon + ); + + // clean up the file property as you won't need it anymore + $this->originalImage = null; + } + + /** + * Set cId + * + * @param integer $cId + * @return CTool + */ + public function setCId($cId) + { + $this->cId = $cId; + + return $this; + } + + /** + * Get cId + * + * @return integer + */ + public function getCId() + { + return $this->cId; + } + + /** + * Set id + * + * @param integer $id + * @return CTool + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * Set name + * + * @param string $name + * @return CTool + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set link + * + * @param string $link + * @return CTool + */ + public function setLink($link) + { + $this->link = $link; + + return $this; + } + + /** + * Get link + * + * @return string + */ + public function getLink() + { + return $this->link; + } + + /** + * Set image + * + * @param string $image + * @return CTool + */ + public function setImage($image) + { + $this->image = $image; + + return $this; + } + + /** + * Get image + * + * @return string + */ + public function getImage() + { + return $this->image; + } + + /** + * Set visibility + * + * @param boolean $visibility + * @return CTool + */ + public function setVisibility($visibility) + { + $this->visibility = $visibility; + + return $this; + } + + /** + * Get visibility + * + * @return boolean + */ + public function getVisibility() + { + return $this->visibility; + } + + /** + * Set admin + * + * @param string $admin + * @return CTool + */ + public function setAdmin($admin) + { + $this->admin = $admin; + + return $this; + } + + /** + * Get admin + * + * @return string + */ + public function getAdmin() + { + return $this->admin; + } + + /** + * Set address + * + * @param string $address + * @return CTool + */ + public function setAddress($address) + { + $this->address = $address; + + return $this; + } + + /** + * Get address + * + * @return string + */ + public function getAddress() + { + return $this->address; + } + + /** + * Set addedTool + * + * @param boolean $addedTool + * @return CTool + */ + public function setAddedTool($addedTool) + { + $this->addedTool = $addedTool; + + return $this; + } + + /** + * Get addedTool + * + * @return boolean + */ + public function getAddedTool() + { + return $this->addedTool; + } + + /** + * Set target + * + * @param string $target + * @return CTool + */ + public function setTarget($target) + { + $this->target = $target; + + return $this; + } + + /** + * Get target + * + * @return string + */ + public function getTarget() + { + return $this->target; + } + + /** + * Set category + * + * @param string $category + * @return CTool + */ + public function setCategory($category) + { + $this->category = $category; + + return $this; + } + + /** + * Get category + * + * @return string + */ + public function getCategory() + { + return $this->category; + } + + /** + * Set sessionId + * + * @param integer $sessionId + * @return CTool + */ + public function setSessionId($sessionId) + { + $this->sessionId = $sessionId; + + return $this; + } + + /** + * Get sessionId + * + * @return integer + */ + public function getSessionId() + { + return $this->sessionId; + } + + /** + * @return string + */ + public function getCustomIcon() + { + return $this->customIcon; + } + + /** + * @param string $customIcon + * @return $this + */ + public function setCustomIcon($customIcon) + { + $this->customIcon = $customIcon; + return $this; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string $description + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * Creates a gray icon. + * @param \Imagine\Image\ImagineInterface $imagine + * @return bool + */ + public function createGrayIcon($imagine) + { + $customIcon = $this->getCustomIcon(); + if (empty($customIcon)) { + return false; + } + if (file_exists($this->getAbsolutePath())) { + $image = $imagine->open($this->getAbsolutePath()); + $fileInfo = pathinfo($this->getAbsolutePath()); + $originalFilename = $fileInfo['basename']; + $filename = $fileInfo['filename'].'_na.'.$fileInfo['extension']; + $newPath = str_replace($originalFilename, $filename, $this->getAbsolutePath()); + $transformation = new \Imagine\Filter\Advanced\Grayscale(); + $transformation->apply($image)->save($newPath); + } + } + + /** + * Replace the $this->image png extension to gif + * @return string + */ + public function imageGifToPng() + { + return str_replace('.gif', '.png', $this->getImage()); + } +} diff --git a/src/Chamilo/UserBundle/Entity/Respository/UserRepository.php b/src/Chamilo/UserBundle/Entity/Repository/UserRepository.php similarity index 96% rename from src/Chamilo/UserBundle/Entity/Respository/UserRepository.php rename to src/Chamilo/UserBundle/Entity/Repository/UserRepository.php index 55777097c7..55675881bf 100644 --- a/src/Chamilo/UserBundle/Entity/Respository/UserRepository.php +++ b/src/Chamilo/UserBundle/Entity/Repository/UserRepository.php @@ -1,7 +1,7 @@ find($userId); - } /** diff --git a/src/Chamilo/UserBundle/Entity/User.php b/src/Chamilo/UserBundle/Entity/User.php index c0d192f524..764ffe985c 100644 --- a/src/Chamilo/UserBundle/Entity/User.php +++ b/src/Chamilo/UserBundle/Entity/User.php @@ -31,14 +31,11 @@ use Chamilo\CoreBundle\Entity\ExtraFieldValues; * @ORM\HasLifecycleCallbacks * @ORM\Table(name="user") * //Vich\Uploadable - * UniqueEntity("username") - * @ORM\Entity() - * ORM\Entity(repositoryClass="Chamilo\UserBundle\Repository\UserRepository") - + * @UniqueEntity("username") + * @ORM\Entity(repositoryClass="Chamilo\UserBundle\Entity\Repository\UserRepository") * */ -//class User extends BaseUser implements ParticipantInterface, ThemeUser -class User +class User //class User extends BaseUser implements ParticipantInterface, ThemeUser { const COURSE_MANAGER = 1; const TEACHER = 1; @@ -289,7 +286,7 @@ class User */ //protected $salt; - private $isActive; + //private $isActive; /** * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CurriculumItemRelUser", mappedBy="user")