diff --git a/public/main/exercise/question.class.php b/public/main/exercise/question.class.php index 6c0fbc4733..78779a55d8 100644 --- a/public/main/exercise/question.class.php +++ b/public/main/exercise/question.class.php @@ -593,7 +593,7 @@ abstract class Question ; $exerciseEntity = $exerciseRepo->find($exerciseId); - $question->addParent($exerciseEntity); + $question->setParent($exerciseEntity); $question->addCourseLink( api_get_course_entity(), api_get_session_entity(), diff --git a/public/main/inc/ajax/model.ajax.php b/public/main/inc/ajax/model.ajax.php index f9e23010e8..3a25bd53d1 100644 --- a/public/main/inc/ajax/model.ajax.php +++ b/public/main/inc/ajax/model.ajax.php @@ -572,7 +572,7 @@ switch ($action) { } if (empty($documents)) { - $whereCondition .= " AND u.user_id = ".api_get_user_id(); + $whereCondition .= " AND u.id = ".api_get_user_id(); $count = get_work_user_list( 0, $limit, @@ -1372,7 +1372,7 @@ switch ($action) { $whereCondition = ''; } - $whereCondition .= " AND u.user_id <> ".api_get_user_id(); + $whereCondition .= " AND u.id <> ".api_get_user_id(); $result = get_work_user_list( $start, $limit, @@ -1405,7 +1405,7 @@ switch ($action) { } if (empty($documents)) { - $whereCondition .= ' AND u.user_id = '.api_get_user_id(); + $whereCondition .= ' AND u.id = '.api_get_user_id(); $result = get_work_user_list( $start, $limit, diff --git a/public/main/inc/lib/AnnouncementManager.php b/public/main/inc/lib/AnnouncementManager.php index 8a3e146c50..5eb47023f7 100644 --- a/public/main/inc/lib/AnnouncementManager.php +++ b/public/main/inc/lib/AnnouncementManager.php @@ -669,7 +669,7 @@ class AnnouncementManager $session, $group ) - ->addParent($course) + ->setParent($course) ; $repo = Container::getAnnouncementRepository(); diff --git a/public/main/inc/lib/agenda.lib.php b/public/main/inc/lib/agenda.lib.php index 4d3d87fbc6..67c052c75d 100644 --- a/public/main/inc/lib/agenda.lib.php +++ b/public/main/inc/lib/agenda.lib.php @@ -302,7 +302,7 @@ class Agenda $event // ->addCourseLink($courseEntity, $groupEntity, $sessionEntity) - ->addParent($courseEntity) + ->setParent($courseEntity) ; if (!empty($usersToSend)) { diff --git a/public/main/inc/lib/document.lib.php b/public/main/inc/lib/document.lib.php index 0e30ac2283..3c4d2a9abf 100644 --- a/public/main/inc/lib/document.lib.php +++ b/public/main/inc/lib/document.lib.php @@ -6052,7 +6052,6 @@ This folder contains all sessions that have been opened in the chat. Although th */ public static function addFileToDocument(CDocument $document, $realPath, $content, $visibility, $group) { - $repo = Container::getDocumentRepository(); $fileType = $document->getFiletype(); $resourceNode = $document->getResourceNode(); @@ -6095,22 +6094,7 @@ This folder contains all sessions that have been opened in the chat. Although th $resourceNode->setResourceFile($resourceFile); $em->persist($resourceNode); } - - // By default visibility is published - // @todo change default visibility - //$newVisibility = ResourceLink::VISIBILITY_PUBLISHED; - $visibility = (int) $visibility; - if (empty($visibility)) { - $visibility = ResourceLink::VISIBILITY_PUBLISHED; - } - - $repo->addResourceNodeToCourse( - $resourceNode, - $visibility, - $document->getCourse(), - $document->getSession(), - $group - ); + $em->persist($document); $em->flush(); $documentId = $document->getIid(); @@ -6213,12 +6197,13 @@ This folder contains all sessions that have been opened in the chat. Although th ->setComment($comment) ->setReadonly($readonly) ->setSession($session) + ->setParent($courseEntity) + ->addCourseLink($courseEntity, $session, $group) ; $em = $documentRepo->getEntityManager(); $em->persist($document); - $documentRepo->addResourceNode($document, $userEntity, $parentNode); $document = self::addFileToDocument($document, $realPath, $content, $visibility, $group); if ($document) { diff --git a/public/main/work/work.lib.php b/public/main/work/work.lib.php index 0aa518053a..7e4b564325 100644 --- a/public/main/work/work.lib.php +++ b/public/main/work/work.lib.php @@ -1891,7 +1891,7 @@ function get_work_user_list( $select = 'SELECT DISTINCT u.id as user_id, - work.id as id, + work.iid as id, title as title, description, url, @@ -4073,6 +4073,12 @@ function processWorkForm( } } + $session = api_get_session_entity($sessionId); + $courseEntity = api_get_course_entity($courseId); + + $repo = Container::getStudentPublicationRepository(); + $parentResource = $repo->find($workInfo['id']); + $studentPublication = new CStudentPublication(); $studentPublication ->setCId($courseId) @@ -4092,36 +4098,20 @@ function processWorkForm( ->setFilesize($filesize) ->setUserId($userId) ->setDocumentId($documentId) + ->setParent($parentResource) + ->addCourseLink($courseEntity, $session, api_get_group_entity()) ; - $repo = Container::getStudentPublicationRepository(); - $parentResource = $repo->find($workInfo['id']); - $em = $repo->getEntityManager(); - $courseEntity = api_get_course_entity($courseId); - $userEntity = api_get_user_entity(api_get_user_id()); - - $resourceNode = $repo->addResourceNode($studentPublication, $userEntity, $parentResource); - - $repo->addResourceNodeToCourse( - $resourceNode, - ResourceLink::VISIBILITY_PUBLISHED, - $courseEntity, - api_get_session_entity(), - api_get_group_entity() - ); - $em->flush(); - - $studentPublication->setId($studentPublication->getIid()); $em->persist($studentPublication); - $em->flush(); - $repo->addFile($studentPublication, $content); $em->flush(); $workId = $studentPublication->getIid(); if ($workId) { + $studentPublication->setId($studentPublication->getIid()); + /*if (array_key_exists('filename', $workInfo) && !empty($filename)) { $filename = Database::escape_string($filename); $sql = "UPDATE $work_table SET @@ -4253,6 +4243,7 @@ function addDir($formValues, $user_id, $courseInfo, $groupId, $sessionId = 0) $today = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC')); $title = isset($formValues['work_title']) ? $formValues['work_title'] : $formValues['new_dir']; + $courseEntity = api_get_course_entity($course_id); $studentPublication = new CStudentPublication(); $studentPublication @@ -4269,21 +4260,17 @@ function addDir($formValues, $user_id, $courseInfo, $groupId, $sessionId = 0) ->setSession($session) ->setAllowTextAssignment($formValues['allow_text_assignment']) ->setUserId($user_id) + ->setParent($courseEntity) + ->addCourseLink( + $courseEntity, + api_get_session_entity(), + api_get_group_entity() + ) ; $repo = Container::getStudentPublicationRepository(); $em = $repo->getEntityManager(); $em->persist($studentPublication); - $courseEntity = api_get_course_entity($course_id); - - $repo->addResourceToCourse( - $studentPublication, - ResourceLink::VISIBILITY_PUBLISHED, - api_get_user_entity(api_get_user_id()), - $courseEntity, - api_get_session_entity(), - api_get_group_entity() - ); $em->flush(); $studentPublication->setId($studentPublication->getIid()); diff --git a/src/CoreBundle/Entity/AbstractResource.php b/src/CoreBundle/Entity/AbstractResource.php index c54fc849d9..bf39ebc7cc 100644 --- a/src/CoreBundle/Entity/AbstractResource.php +++ b/src/CoreBundle/Entity/AbstractResource.php @@ -133,7 +133,7 @@ abstract class AbstractResource return $this; } - public function addParent(AbstractResource $parent) + public function setParent(AbstractResource $parent) { $this->parentResource = $parent; diff --git a/src/CoreBundle/Entity/Course.php b/src/CoreBundle/Entity/Course.php index 89ade5c57e..b6eaec39c4 100644 --- a/src/CoreBundle/Entity/Course.php +++ b/src/CoreBundle/Entity/Course.php @@ -112,7 +112,7 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith * Groups({"course:read"}) * ORM\OneToMany(targetEntity="ResourceLink", mappedBy="course", cascade={"persist"}, orphanRemoval=true) */ - //protected $resourceLinks; + protected $resourceLinks; /** * @ORM\OneToMany(targetEntity="AccessUrlRelCourse", mappedBy="course", cascade={"persist", "remove"}, orphanRemoval=true) diff --git a/src/CourseBundle/Entity/CStudentPublication.php b/src/CourseBundle/Entity/CStudentPublication.php index f3f909b5ec..3492bab90b 100644 --- a/src/CourseBundle/Entity/CStudentPublication.php +++ b/src/CourseBundle/Entity/CStudentPublication.php @@ -6,6 +6,7 @@ namespace Chamilo\CourseBundle\Entity; use Chamilo\CoreBundle\Entity\AbstractResource; use Chamilo\CoreBundle\Entity\ResourceInterface; +use Chamilo\CoreBundle\Entity\ResourceToCourseInterface; use Chamilo\CoreBundle\Entity\Session; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; @@ -23,7 +24,7 @@ use Symfony\Component\Validator\Constraints as Assert; * ) * @ORM\Entity() */ -class CStudentPublication extends AbstractResource implements ResourceInterface +class CStudentPublication extends AbstractResource implements ResourceInterface, ResourceToCourseInterface { /** * @var int @@ -734,14 +735,7 @@ class CStudentPublication extends AbstractResource implements ResourceInterface return $this->id; } - /** - * Set cId. - * - * @param int $cId - * - * @return CStudentPublication - */ - public function setCId($cId) + public function setCId(int $cId) { $this->cId = $cId; @@ -772,6 +766,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface public function setUrlCorrection($urlCorrection) { $this->urlCorrection = $urlCorrection; + + return $this; } /** @@ -788,6 +784,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface public function setTitleCorrection($titleCorrection) { $this->titleCorrection = $titleCorrection; + + return $this; } /** @@ -804,6 +802,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface public function setDocumentId($documentId) { $this->documentId = $documentId; + + return $this; } /**