Internal: Fix: add document, add work + add work assignment

pull/3451/head
Julio Montoya 4 years ago
parent ba250d0fd9
commit 4fc9f851c7
  1. 2
      public/main/exercise/question.class.php
  2. 6
      public/main/inc/ajax/model.ajax.php
  3. 2
      public/main/inc/lib/AnnouncementManager.php
  4. 2
      public/main/inc/lib/agenda.lib.php
  5. 21
      public/main/inc/lib/document.lib.php
  6. 49
      public/main/work/work.lib.php
  7. 2
      src/CoreBundle/Entity/AbstractResource.php
  8. 2
      src/CoreBundle/Entity/Course.php
  9. 18
      src/CourseBundle/Entity/CStudentPublication.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(),

@ -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,

@ -669,7 +669,7 @@ class AnnouncementManager
$session,
$group
)
->addParent($course)
->setParent($course)
;
$repo = Container::getAnnouncementRepository();

@ -302,7 +302,7 @@ class Agenda
$event
// ->addCourseLink($courseEntity, $groupEntity, $sessionEntity)
->addParent($courseEntity)
->setParent($courseEntity)
;
if (!empty($usersToSend)) {

@ -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) {

@ -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());

@ -133,7 +133,7 @@ abstract class AbstractResource
return $this;
}
public function addParent(AbstractResource $parent)
public function setParent(AbstractResource $parent)
{
$this->parentResource = $parent;

@ -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)

@ -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;
}
/**

Loading…
Cancel
Save