Internal - Fix entities, fix agenda event attachment using resources.

pull/3570/head
Julio Montoya 5 years ago
parent 50453a2773
commit 1cb6b828c0
  1. 4
      public/main/calendar/agenda_list.php
  2. 85
      public/main/inc/lib/agenda.lib.php
  3. 3
      public/main/inc/lib/document.lib.php
  4. 1
      src/CoreBundle/Repository/ResourceRepository.php
  5. 2
      src/CoreBundle/Traits/ControllerTrait.php
  6. 60
      src/CourseBundle/Entity/CCalendarEventAttachment.php
  7. 33
      src/CourseBundle/Repository/CDocumentRepository.php

@ -89,11 +89,11 @@ $tpl->assign('agenda_actions', $actions);
$tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit());
if (api_is_allowed_to_edit()) {
if ('change_visibility' == $action) {
if ('change_visibility' === $action) {
$courseInfo = api_get_course_info();
$courseCondition = '';
// This happens when list agenda is not inside a course
if (('course' == $type || 'session' == $type && !empty($courseInfo))) {
if (('course' === $type || 'session' === $type) && !empty($courseInfo)) {
// For course and session event types
// Just needs course ID
$agenda->changeVisibility($_GET['id'], $_GET['visibility'], $courseInfo);

@ -247,10 +247,10 @@ class Agenda
$content,
$usersToSend = [],
$addAsAnnouncement = false,
$parentEventId = null,
$parentEventId = 0,
$attachmentArray = [],
$attachmentCommentList = [],
$eventComment = null,
$eventComment = '',
$color = ''
) {
$start = api_get_utc_datetime($start, false, true);
@ -1032,30 +1032,28 @@ class Agenda
);
}
if (api_is_drh()) {
if (api_drh_can_access_all_session_content()) {
$session_list = [];
$sessionList = SessionManager::get_sessions_followed_by_drh(
api_get_user_id(),
null,
null,
null,
true,
false
);
if (api_is_drh() && api_drh_can_access_all_session_content()) {
$session_list = [];
$sessionList = SessionManager::get_sessions_followed_by_drh(
api_get_user_id(),
null,
null,
null,
true,
false
);
if (!empty($sessionList)) {
foreach ($sessionList as $sessionItem) {
$sessionId = $sessionItem['id'];
$courses = SessionManager::get_course_list_by_session_id(
$sessionId
);
$sessionInfo = [
'session_id' => $sessionId,
'courses' => $courses,
];
$session_list[] = $sessionInfo;
}
if (!empty($sessionList)) {
foreach ($sessionList as $sessionItem) {
$sessionId = $sessionItem['id'];
$courses = SessionManager::get_course_list_by_session_id(
$sessionId
);
$sessionInfo = [
'session_id' => $sessionId,
'courses' => $courses,
];
$session_list[] = $sessionInfo;
}
}
}
@ -2494,36 +2492,14 @@ class Agenda
}
if ($valid) {
/*$courseDir = $courseInfo['directory'].'/upload/calendar';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$uploadDir = $sys_course_path.$courseDir;*/
// Try to add an extension to the file if it hasn't one
/*$new_file_name = add_ext_on_mime(
stripslashes($fileUserUpload['name']),
$fileUserUpload['type']
);*/
// user's file name
$fileName = $file->getClientOriginalName();
$courseId = api_get_course_int_id();
/*$new_file_name = uniqid('');
$new_path = $uploadDir.'/'.$new_file_name;
$result = @move_uploaded_file(
$fileUserUpload['tmp_name'],
$new_path
);
$courseId = api_get_course_int_id();
$size = intval($fileUserUpload['size']);*/
// Storing the attachments if any
//if ($result) {
$attachment = new CCalendarEventAttachment();
$attachment
->setFilename($fileName)
->setComment($comment)
->setPath($fileName)
->setEvent($event)
->setSize($file->getSize())
->setParent($event)
->addCourseLink(
api_get_course_entity(),
@ -2535,16 +2511,9 @@ class Agenda
$repo->getEntityManager()->persist($attachment);
$repo->getEntityManager()->flush();
$id = $attachment->getIid();
if ($id) {
/*api_item_property_update(
$courseInfo,
'calendar_event_attachment',
$id,
'AgendaAttachmentAdded',
api_get_user_id()
);*/
}
$repo->addFile($attachment, $file);
$repo->getEntityManager()->persist($attachment);
$repo->getEntityManager()->flush();
}
}

@ -2793,8 +2793,9 @@ class DocumentManager
public static function enough_space($file_size, $max_dir_space)
{
if ($max_dir_space) {
$courseEntity = api_get_course_entity();
$repo = Container::getDocumentRepository();
$total = $repo->getTotalSpace(api_get_course_int_id());
$total = $repo->getFolderSize($courseEntity->getResourceNode(), $courseEntity);
if (($file_size + $total) > $max_dir_space) {
return false;

@ -229,7 +229,6 @@ class ResourceRepository extends EntityRepository
}
}
$em->persist($resourceNode);
$em->persist($resource);
$em->flush();

@ -10,6 +10,7 @@ use Chamilo\CoreBundle\Repository\IllustrationRepository;
use Chamilo\CoreBundle\Repository\ResourceFactory;
use Chamilo\CourseBundle\Repository\CAnnouncementAttachmentRepository;
use Chamilo\CourseBundle\Repository\CAnnouncementRepository;
use Chamilo\CourseBundle\Repository\CCalendarEventAttachmentRepository;
use Chamilo\CourseBundle\Repository\CDocumentRepository;
use Knp\Menu\FactoryInterface as MenuFactoryInterface;
use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory;
@ -33,6 +34,7 @@ trait ControllerTrait
$services[] = CDocumentRepository::class;
$services[] = CAnnouncementRepository::class;
$services[] = CAnnouncementAttachmentRepository::class;
$services[] = CCalendarEventAttachmentRepository::class;
/*$services[] = CAttendanceRepository::class;
$services[] = CDocumentRepository::class;

@ -29,13 +29,6 @@ class CCalendarEventAttachment extends AbstractResource implements ResourceInter
*/
protected $iid;
/**
* @var string
*
* @ORM\Column(name="path", type="string", length=255, nullable=false)
*/
protected $path;
/**
* @var string
*
@ -43,13 +36,6 @@ class CCalendarEventAttachment extends AbstractResource implements ResourceInter
*/
protected $comment;
/**
* @var int
*
* @ORM\Column(name="size", type="integer", nullable=false)
*/
protected $size;
/**
* @var string
*
@ -70,28 +56,6 @@ class CCalendarEventAttachment extends AbstractResource implements ResourceInter
return $this->getFilename();
}
/**
* Set path.
*
* @param string $path
*/
public function setPath($path): self
{
$this->path = $path;
return $this;
}
/**
* Get path.
*
* @return string
*/
public function getPath()
{
return $this->path;
}
/**
* Set comment.
*
@ -114,30 +78,6 @@ class CCalendarEventAttachment extends AbstractResource implements ResourceInter
return $this->comment;
}
/**
* Set size.
*
* @param int $size
*
* @return CCalendarEventAttachment
*/
public function setSize($size)
{
$this->size = $size;
return $this;
}
/**
* Get size.
*
* @return int
*/
public function getSize()
{
return $this->size;
}
/**
* Set filename.
*

@ -119,38 +119,9 @@ final class CDocumentRepository extends ResourceRepository implements GridInterf
return null;
}
/**
* @param int $courseId
* @param string $path
*
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function getFolderSize($courseId, $path)
public function getFolderSize(ResourceNode $resourceNode, Course $course, Session $session = null): int
{
$path = str_replace('_', '\_', $path);
$addedSlash = '/' === $path ? '' : '/';
$repo = $this->getRepository();
$qb = $repo->createQueryBuilder('d');
$query = $qb
->select('SUM(d.size)')
->innerJoin('d.resourceNode', 'r')
->innerJoin('r.resourceLinks', 'l')
->where('d.path LIKE :path')
->andWhere('d.path NOT LIKE :deleted')
->andWhere('d.path NOT LIKE :extra_path ')
->andWhere('l.visibility <> :visibility')
->andWhere('d.course = :course')
->setParameters([
'path' => $path.$addedSlash.'%',
'extra_path' => $path.$addedSlash.'%/%',
'course' => $courseId,
'deleted' => '%_DELETED_%',
'visibility' => ResourceLink::VISIBILITY_DELETED,
])
->getQuery();
return $query->getSingleScalarResult();
return $this->getResourceNodeRepository()->getSize($resourceNode, $this->getResourceType(), $course, $session);
}
/**

Loading…
Cancel
Save