Internal - Fix work creation, fix behat tests

pull/3464/head
Julio Montoya 5 years ago
parent da03040b70
commit 13486e0d86
  1. 3
      public/main/inc/ajax/work.ajax.php
  2. 2
      public/main/work/upload.php
  3. 4
      public/main/work/view.php
  4. 36
      public/main/work/work.lib.php
  5. 42
      src/CoreBundle/Repository/ResourceRepository.php
  6. 33
      src/CourseBundle/Repository/CDocumentRepository.php
  7. 4
      tests/behat/features/sessionAccess.feature
  8. 4
      tests/behat/features/toolAgenda.feature

@ -11,6 +11,7 @@ require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
$isAllowedToEdit = api_is_allowed_to_edit();
$courseInfo = api_get_course_info();
$courseEntity = api_get_course_entity();
switch ($action) {
case 'show_student_work':
@ -161,7 +162,7 @@ switch ($action) {
$courseInfo = api_get_course_info();
$workInfo = get_work_data_by_id($itemId);
$workInfoParent = get_work_data_by_id($workInfo['parent_id']);
$resultUpload = uploadWork($workInfoParent, $courseInfo, true, $workInfo);
$resultUpload = uploadWork($workInfoParent, $courseEntity, true, $workInfo);
if (!$resultUpload) {
echo 'false';
break;

@ -88,7 +88,7 @@ if ($allowRedirect) {
$succeed = false;
if ($form->validate()) {
if ($student_can_edit_in_session && $check) {
if ($student_can_edit_in_session) {
$values = $form->getSubmitValues();
// Process work
$result = processWorkForm(

@ -30,7 +30,7 @@ $interbreadcrumb[] = [
$folderData = get_work_data_by_id($work['parent_id']);
$courseInfo = api_get_course_info();
$courseEntity = api_get_course_entity();
$isCourseManager = api_is_platform_admin() || api_is_coach() || api_is_allowed_to_edit(false, false, true);
$allowEdition = false;
@ -116,7 +116,7 @@ if ((user_is_author($id) || $isDrhOfCourse || $allowEdition || $isDrhOfSession)
$resultUpload = uploadWork(
$folderData,
$courseInfo,
$courseEntity,
true,
$work
);

@ -7,6 +7,7 @@ use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CStudentPublication;
use Chamilo\CourseBundle\Entity\CStudentPublicationComment;
use ChamiloSession as Session;
use Chamilo\CoreBundle\Entity\Course;
/**
* @author Thomas, Hugues, Christophe - original version
@ -2222,10 +2223,8 @@ function get_work_user_list(
$repo = Container::getStudentPublicationRepository();
while ($work = Database::fetch_array($result, 'ASSOC')) {
/** @var CStudentPublication $studentPublication */
$studentPublication = $repo->find($work['iid']);
$item_id = $work['iid'];
$dbTitle = $work['title'];
$studentPublication = $repo->find($work['id']);
$item_id = $work['id'];
// Get the author ID for that document from the item_property table
$is_author = false;
$can_read = false;
@ -3983,14 +3982,14 @@ function setWorkUploadForm($form, $uploadFormType = 0)
/**
* @param array $my_folder_data
* @param array $_course
* @param Course $course
* @param bool $isCorrection
* @param array $workInfo
* @param array $file
*
* @return array
*/
function uploadWork($my_folder_data, $_course, $isCorrection = false, $workInfo = [], $file = [])
function uploadWork($my_folder_data, $course, $isCorrection = false, $workInfo = [], $file = [])
{
if (isset($_FILES['file']) && !empty($_FILES['file'])) {
$file = $_FILES['file'];
@ -3999,7 +3998,9 @@ function uploadWork($my_folder_data, $_course, $isCorrection = false, $workInfo
if (empty($file['size'])) {
return [
'error' => Display:: return_message(
get_lang('There was a problem uploading your document: the received file had a 0 bytes size on the server. Please, review your local file for any corruption or damage, then try again.'),
get_lang(
'There was a problem uploading your document: the received file had a 0 bytes size on the server. Please, review your local file for any corruption or damage, then try again.'
),
'error'
),
];
@ -4019,7 +4020,9 @@ function uploadWork($my_folder_data, $_course, $isCorrection = false, $workInfo
if (empty($filesize)) {
return [
'error' => Display::return_message(
get_lang('There was a problem uploading your document: the received file had a 0 bytes size on the server. Please, review your local file for any corruption or damage, then try again.'),
get_lang(
'There was a problem uploading your document: the received file had a 0 bytes size on the server. Please, review your local file for any corruption or damage, then try again.'
),
'error'
),
];
@ -4035,13 +4038,18 @@ function uploadWork($my_folder_data, $_course, $isCorrection = false, $workInfo
}*/
$repo = Container::getDocumentRepository();
$totalSpace = $repo->getTotalSpace($_course['real_id']);
$course_max_space = DocumentManager::get_course_quota($_course['code']);
$totalSpace = $repo->getTotalSpaceByCourse($course);
$course_max_space = DocumentManager::get_course_quota($course->getCode());
$total_size = $filesize + $totalSpace;
if ($total_size > $course_max_space) {
return [
'error' => Display::return_message(get_lang('The upload has failed. Either you have exceeded your maximum quota, or there is not enough disk space.'), 'error'),
'error' => Display::return_message(
get_lang(
'The upload has failed. Either you have exceeded your maximum quota, or there is not enough disk space.'
),
'error'
),
];
}
@ -4225,6 +4233,8 @@ function processWorkForm(
$checkDuplicated = false,
$showFlashMessage = true
) {
$courseEntity = $courseInfo['entity'];
$courseId = $courseInfo['real_id'];
$groupId = (int) $groupId;
$sessionId = (int) $sessionId;
@ -4260,10 +4270,10 @@ function processWorkForm(
$result['error'] = get_lang('You have already sent this file or another file with the same name. Please make sure you only upload each file once.');
$workData['error'] = get_lang(' already exists.');
} else {
$result = uploadWork($workInfo, $courseInfo, false, [], $file);
$result = uploadWork($workInfo, $courseEntity, false, [], $file);
}
} else {
$result = uploadWork($workInfo, $courseInfo, false, [], $file);
$result = uploadWork($workInfo, $courseEntity, false, [], $file);
}
if (isset($result['error'])) {

@ -16,6 +16,7 @@ use Chamilo\CoreBundle\Entity\ResourceRight;
use Chamilo\CoreBundle\Entity\ResourceType;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Form\Resource\PersonalFileType;
use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter;
use Chamilo\CoreBundle\ToolChain;
use Chamilo\CourseBundle\Entity\CGroup;
@ -796,4 +797,45 @@ class ResourceRepository extends EntityRepository
return true;
}
public function getTotalSpaceByCourse(Course $course, CGroup $group = null, Session $session = null): int
{
$repo = $this->getRepository();
$qb = $repo->createQueryBuilder('resource');
$qb
->select('SUM(file.size) as total')
->innerJoin('resource.resourceNode', 'node')
->innerJoin('node.resourceLinks', 'l')
->innerJoin('node.resourceFile', 'file')
->where('l.course = :course')
->andWhere('l.visibility <> :visibility')
->andWhere('file IS NOT NULL')
->setParameters(
[
'course' => $course,
'visibility' => ResourceLink::VISIBILITY_DELETED,
]
);
if (null === $group) {
$qb->andWhere('l.group IS NULL');
} else {
$qb
->andWhere('l.group = :group')
->setParameter('group', $group);
}
if (null === $session) {
$qb->andWhere('l.session IS NULL');
} else {
$qb
->andWhere('l.session = :session')
->setParameter('session', $session);
}
$query = $qb->getQuery();
return (int) $query->getSingleScalarResult();
}
}

@ -153,39 +153,6 @@ final class CDocumentRepository extends ResourceRepository implements GridInterf
return $query->getSingleScalarResult();
}
/**
* @param int $courseId
* @param int $groupId
* @param int $sessionId
*
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function getTotalSpace($courseId, $groupId = null, $sessionId = null)
{
$repo = $this->getRepository();
$groupId = empty($groupId) ? null : $groupId;
$sessionId = empty($sessionId) ? null : $sessionId;
$qb = $repo->createQueryBuilder('d');
$query = $qb
->select('SUM(d.size)')
->innerJoin('d.resourceNode', 'r')
->innerJoin('r.resourceLinks', 'l')
->where('l.course = :course')
->andWhere('l.group = :group')
->andWhere('l.session = :session')
->andWhere('l.visibility <> :visibility')
->setParameters([
'course' => $courseId,
'group' => $groupId,
'session' => $sessionId,
'visibility' => ResourceLink::VISIBILITY_DELETED,
])
->getQuery();
return $query->getSingleScalarResult();
}
/**
* @param int $userId
*

@ -14,7 +14,7 @@ Feature: Session access
Then I select "TEMP_PRIVATE (TEMPPRIVATE)" from "NoSessionCoursesList[]"
And I press "add_course"
And I press "next"
And wait the page to be loaded when ready
And wait very long for the page to be loaded
Then I should see "Update successful"
Then I should see "Subscribe users to this session"
Then I follow "Multiple registration"
@ -38,7 +38,7 @@ Feature: Session access
Then I select "TEMP_PRIVATE (TEMPPRIVATE)" from "NoSessionCoursesList[]"
And I press "add_course"
And I press "next"
And wait the page to be loaded when ready
And wait very long for the page to be loaded
Then I should see "Update successful"
Then I should see "Subscribe users to this session"
Then I follow "Multiple registration"

@ -14,7 +14,7 @@ Feature: Agenda tool
And I focus "date_range"
And I fill in "date_range" with "2017-03-07 12:15 / 2017-03-07 12:15"
And I press "Add event"
And wait the page to be loaded when ready
And wait very long for the page to be loaded
Then I should see "Event added"
Scenario: Create an event inside course TEMP
@ -27,7 +27,7 @@ Feature: Agenda tool
And I focus "date_range"
And I fill in "date_range" with "2017-03-07 12:15 / 2017-03-07 12:15"
And I press "Add event"
And wait the page to be loaded when ready
And wait very long for the page to be loaded
Then I should see "Event added"

Loading…
Cancel
Save