Refactor document and exercise actions.

Delete and change visibility using resources.
pull/3064/head
Julio Montoya 7 years ago
parent d832070fbb
commit 5b557dace6
  1. 2
      config/services.yaml
  2. 93
      main/document/document.php
  3. 151
      main/exercise/exercise.class.php
  4. 314
      main/exercise/exercise.php
  5. 2
      main/inc/lib/document.lib.php
  6. 10
      src/CoreBundle/Entity/Resource/ResourceLink.php
  7. 54
      src/CoreBundle/Repository/ResourceRepository.php
  8. 11
      src/CourseBundle/Repository/CDocumentRepository.php

@ -143,7 +143,7 @@ sonata_doctrine_orm_admin:
apy_data_grid:
theme: '@ChamiloTheme/Resource/grid_theme.html.twig'
limits: [20, 50, 100]
# persistence: false
persistence: false
# no_data_message: "No data"
# no_result_message: "No result"
# actions_columns_size: -1

@ -1,7 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Resource\ResourceLink;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CDocument;
use ChamiloSession as Session;
@ -9,25 +8,11 @@ use ChamiloSession as Session;
/**
* Homepage script for the documents tool.
*
* This script allows the user to manage files and directories on a remote http
* server.
* This script allows the user to manage files and directories.
* The user can : - navigate through files and directories.
* - upload a file
* - delete, copy a file or a directory
* - edit properties & content (name, comments, html content)
* The script is organised in four sections.
*
* 1) Execute the command called by the user
* Note: somme commands of this section are organised in two steps.
* The script always begins with the second step,
* so it allows to return more easily to the first step.
*
* Note (March 2004) some editing functions (renaming, commenting)
* are moved to a separate page, edit_document.php. This is also
* where xml and other stuff should be added.
* 2) Define the directory to display
* 3) Read files and directories from the directory defined in part 2
* 4) Display all of that on an HTML page
*/
require_once __DIR__.'/../inc/global.inc.php';
@ -221,10 +206,39 @@ if (!empty($groupId)) {
// Detail.
$document_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : null;
$documentIdToEdit = isset($_REQUEST['document_id']) ? (int) $_REQUEST['document_id'] : 0;
$currentUrl = api_get_self().'?'.api_get_cidreq().'&id='.$document_id;
$curdirpath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null;
switch ($action) {
case 'set_visible':
case 'set_invisible':
if (!$isAllowedToEdit) {
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($documentIdToEdit, $courseInfo, $sessionId, api_get_user_id())) {
api_not_allowed(true);
}
}
if (DocumentManager::check_readonly($courseInfo, api_get_user_id(), $documentIdToEdit)) {
api_not_allowed(true);
}
}
/** @var CDocument $document */
$document = $repo->find($documentIdToEdit);
// Make visible or invisible?
if ($action === 'set_visible') {
$repo->setVisibilityPublished($document);
} else {
$repo->setVisibilityDraft($document);
}
Display::addFlash(Display::return_message(get_lang('The visibility has been changed.'), 'confirmation'));
header('Location: '.$currentUrl);
exit;
break;
case 'delete_item':
if ($isAllowedToEdit ||
$groupMemberWithUploadRights ||
@ -1156,13 +1170,6 @@ if ($isAllowedToEdit ||
'/chat_files',
'/certificates',
];
$defaultVisibility = ResourceLink::VISIBILITY_DRAFT;
// Make visible or invisible?
if ($_POST['action'] === 'set_visible') {
$defaultVisibility = ResourceLink::VISIBILITY_PUBLISHED;
}
foreach ($files as $documentId) {
$data = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']);
/** @var CDocument $document */
@ -1174,10 +1181,10 @@ if ($isAllowedToEdit ||
} else {
switch ($_POST['action']) {
case 'set_invisible':
$repo->updateVisibility($document, $defaultVisibility);
$repo->setVisibilityPublished($document);
break;
case 'set_visible':
$repo->updateVisibility($document, $defaultVisibility);
$repo->setVisibilityDraft($document);
$messages .= Display::return_message(
get_lang('The visibility has been changed.').': '.$data['title'],
'confirmation'
@ -1328,42 +1335,6 @@ if ($isAllowedToEdit ||
}
}
/* VISIBILITY COMMANDS */
if ($isAllowedToEdit) {
if ((isset($_GET['set_invisible']) && !empty($_GET['set_invisible'])) ||
(isset($_GET['set_visible']) && !empty($_GET['set_visible']))
) {
$defaultVisibility = ResourceLink::VISIBILITY_DRAFT;
// Make visible or invisible?
if (isset($_GET['set_visible'])) {
$defaultVisibility = ResourceLink::VISIBILITY_PUBLISHED;
$update_id = intval($_GET['set_visible']);
$visibility_command = 'visible';
} else {
$update_id = intval($_GET['set_invisible']);
$visibility_command = 'invisible';
}
if (!$isAllowedToEdit) {
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($update_id, $courseInfo, $sessionId, api_get_user_id())) {
api_not_allowed(true);
}
}
if (DocumentManager::check_readonly($courseInfo, api_get_user_id(), $update_id)) {
api_not_allowed(true);
}
}
/** @var CDocument $document */
$document = $repo->find($update_id);
$repo->updateVisibility($document, $defaultVisibility);
Display::addFlash(Display::return_message(get_lang('The visibility has been changed.'), 'confirmation'));
header('Location: '.$currentUrl);
exit;
}
}
$templateForm = '';
/* TEMPLATE ACTION */

@ -11,6 +11,7 @@ use Chamilo\CoreBundle\Entity\TrackEHotspot;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter;
use Chamilo\CourseBundle\Entity\CExerciseCategory;
use Chamilo\CourseBundle\Entity\CQuiz;
use Chamilo\CourseBundle\Entity\CQuizCategory;
use ChamiloSession as Session;
use Doctrine\DBAL\Types\Type;
@ -1838,13 +1839,21 @@ class Exercise
public function delete()
{
$limitTeacherAccess = api_get_configuration_value('limit_exercise_teacher_access');
if ($limitTeacherAccess && !api_is_platform_admin()) {
return false;
}
$exerciseId = $this->iId;
$repo = Container::getExerciseRepository();
$exercise = $repo->find($exerciseId);
if ($exercise === null) {
return false;
}
$locked = api_resource_is_locked_by_gradebook(
$this->id,
$exerciseId,
LINK_EXERCISE
);
@ -1854,29 +1863,12 @@ class Exercise
$table = Database::get_course_table(TABLE_QUIZ_TEST);
$sql = "UPDATE $table SET active='-1'
WHERE c_id = ".$this->course_id." AND id = ".intval($this->id);
WHERE c_id = ".$this->course_id." AND iid = ".$exerciseId;
Database::query($sql);
$repo = Container::getExerciseRepository();
$exercise = $repo->find($this->iId);
$repo->softDelete($exercise);
/*api_item_property_update(
$this->course,
TOOL_QUIZ,
$this->id,
'QuizDeleted',
api_get_user_id()
);
api_item_property_update(
$this->course,
TOOL_QUIZ,
$this->id,
'delete',
api_get_user_id()
);*/
Skill::deleteSkillsFromItem($this->iId, ITEM_TYPE_EXERCISE);
Skill::deleteSkillsFromItem($exerciseId, ITEM_TYPE_EXERCISE);
if (api_get_setting('search_enabled') === 'true' &&
extension_loaded('xapian')
@ -1887,7 +1879,7 @@ class Exercise
$linkInfo = GradebookUtils::isResourceInCourseGradebook(
$this->course['code'],
LINK_EXERCISE,
$this->id,
$exerciseId,
$this->sessionId
);
if ($linkInfo !== false) {
@ -3766,10 +3758,6 @@ class Exercise
}
}
$totalScore += $answerWeighting;
if ($debug) {
error_log("studentChoice: $studentChoice");
}
break;
case GLOBAL_MULTIPLE_ANSWER:
if ($from_database) {
@ -8363,6 +8351,12 @@ class Exercise
}
}
/**
* @param int $categoryId
* @param string $keyword
*
* @return string
*/
public static function exerciseGridResource($categoryId, $keyword)
{
$courseId = api_get_course_int_id();
@ -8371,15 +8365,13 @@ class Exercise
$session = api_get_session_entity($sessionId);
// 1. Set entity
$source = new Entity('ChamiloCourseBundle:CQuizQuestionCategory');
$source = new Entity('ChamiloCourseBundle:CQuiz');
$repo = Container::getExerciseRepository();
// 2. Get query builder from repo.
$qb = $repo->getResourcesByCourse($course, $session);
if (!empty($categoryId)) {
//$repo = Container::getExerciseCategoryRepository();
//$category = $repo->find($categoryId);
$qb->andWhere($qb->expr()->eq('resource.exerciseCategory', $categoryId));
} else {
$qb->andWhere($qb->expr()->isNull('resource.exerciseCategory'));
@ -8422,6 +8414,7 @@ class Exercise
);
$grid = $grid->getGrid();
$grid->setId('grid_category_'.$categoryId);
// Url link.
$grid->getColumn('title')->manipulateRenderCell(
@ -8441,7 +8434,6 @@ class Exercise
// 7. Add actions
if ($editAccess) {
// Add row actions
$myRowAction = new RowAction(
get_lang('Edit'),
'legacy_main',
@ -8457,44 +8449,113 @@ class Exercise
'id_session' => $sessionId,
]
);
$myRowAction->addManipulateRender(
function (RowAction $action, Row $row) use ($session, $repo) {
return $repo->rowCanBeEdited($action, $row, $session);
}
);
$grid->addRowAction($myRowAction);
// Results
$myRowAction = new RowAction(
get_lang('Results'),
'legacy_main',
false,
'_self',
['class' => 'btn btn-primary']
);
$myRowAction->setRouteParameters(
[
'id',
'name' => 'exercise/exercise_report.php',
'cidReq' => $course->getCode(),
'id_session' => $sessionId,
]
);
$myRowAction->addManipulateRender(
function (RowAction $action, Row $row) use ($session, $repo) {
return $repo->rowCanBeEdited($action, $row, $session);
}
);
// To use icon instead of col
//$myRowAction->render()
$grid->addRowAction($myRowAction);
// Hide/show
$myRowAction = new RowAction(
get_lang('Active'),
'legacy_main',
false,
'_self'
);
$myRowAction->addManipulateRender(
function (RowAction $action, Row $row) use ($session, $repo, $course, $sessionId) {
$action = $repo->rowCanBeEdited($action, $row, $session);
/** @var CQuiz $exercise */
$exercise = $row->getEntity();
$link = $exercise->getFirstResourceLinkFromCourseSession($course, $session);
if ($link !== null) {
$visibleChoice = 'enable';
$attributes = ['class' => 'btn btn-secondary'];
$title = get_lang('Enable');
if ($link->getVisibility() === ResourceLink::VISIBILITY_PUBLISHED) {
$visibleChoice = 'disable';
$attributes = ['class' => 'btn btn-danger'];
$title = get_lang('Disable');
}
$params = [
'id' => $exercise->getIid(),
'name' => 'exercise/exercise.php',
'cidReq' => $course->getCode(),
'id_session' => $sessionId,
'action' => $visibleChoice,
];
if ($action) {
$action->setTitle($title);
$action->setAttributes($attributes);
$action->setRouteParameters($params);
}
return $action;
}
}
);
$grid->addRowAction($myRowAction);
// Delete
$myRowAction = new RowAction(
get_lang('Delete'),
'legacy_main',
true,
'_self',
['class' => 'btn btn-danger', 'form_delete' => true]
['class' => 'btn btn-danger']
);
$myRowAction->setRouteParameters(
[
'id',
'name' => 'exercise/exercise.php',
'cidReq' => $course->getCode(),
'choice' => 'delete',
'id_session' => $sessionId,
'action' => 'delete',
]
);
$myRowAction->addManipulateRender(
function (RowAction $action, Row $row) use ($session, $repo) {
return $repo->rowCanBeEdited($action, $row, $session);
}
);
$grid->addRowAction($myRowAction);
if (empty($session)) {
// Add mass actions
$deleteMassAction = new MassAction(
'Delete',
['TestCategory', 'deleteResource'],
['Exercise', 'deleteResource'],
true,
[],
ResourceNodeVoter::ROLE_CURRENT_COURSE_TEACHER
@ -8892,7 +8953,7 @@ class Exercise
'',
ICON_SIZE_SMALL
),
'exercise.php?'.api_get_cidreq().'&choice=enable_launch&sec_token='.$token.'&exerciseId='.$row['id']
'exercise.php?'.api_get_cidreq().'&action=enable_launch&sec_token='.$token.'&exerciseId='.$row['id']
);
} else {
$actions .= Display::url(
@ -8902,7 +8963,7 @@ class Exercise
'',
ICON_SIZE_SMALL
),
'exercise.php?'.api_get_cidreq().'&choice=disable_launch&sec_token='.$token.'&exerciseId='.$row['id']
'exercise.php?'.api_get_cidreq().'&action=disable_launch&sec_token='.$token.'&exerciseId='.$row['id']
);
}
}
@ -8913,7 +8974,7 @@ class Exercise
'',
[
'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('Are you sure to copy'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;",
'href' => 'exercise.php?'.api_get_cidreq().'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id'],
'href' => 'exercise.php?'.api_get_cidreq().'&action=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id'],
]
);
@ -8929,7 +8990,7 @@ class Exercise
'',
[
'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('Are you sure to delete results and feedback'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;",
'href' => 'exercise.php?'.api_get_cidreq().'&choice=clean_results&sec_token='.$token.'&exerciseId='.$row['id'],
'href' => 'exercise.php?'.api_get_cidreq().'&action=clean_results&sec_token='.$token.'&exerciseId='.$row['id'],
]
);
} else {
@ -8963,7 +9024,7 @@ class Exercise
'',
ICON_SIZE_SMALL
),
'exercise.php?'.api_get_cidreq().'&choice=enable&sec_token='.$token.'&exerciseId='.$row['id']
'exercise.php?'.api_get_cidreq().'&action=enable&sec_token='.$token.'&exerciseId='.$row['id']
);
} else {
// else if not active
@ -8974,7 +9035,7 @@ class Exercise
'',
ICON_SIZE_SMALL
),
'exercise.php?'.api_get_cidreq().'&choice=disable&sec_token='.$token.'&exerciseId='.$row['id']
'exercise.php?'.api_get_cidreq().'&action=disable&sec_token='.$token.'&exerciseId='.$row['id']
);
}
}
@ -9025,7 +9086,7 @@ class Exercise
'',
ICON_SIZE_SMALL
),
'exercise.php?'.api_get_cidreq().'&choice=enable&sec_token='.$token.'&exerciseId='.$row['id']
'exercise.php?'.api_get_cidreq().'&action=enable&sec_token='.$token.'&exerciseId='.$row['id']
);
} else {
// else if not active
@ -9036,7 +9097,7 @@ class Exercise
'',
ICON_SIZE_SMALL
),
'exercise.php?'.api_get_cidreq().'&choice=disable&sec_token='.$token.'&exerciseId='.$row['id']
'exercise.php?'.api_get_cidreq().'&action=disable&sec_token='.$token.'&exerciseId='.$row['id']
);
}
}
@ -9053,7 +9114,7 @@ class Exercise
'',
[
'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('Are you sure to copy'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;",
'href' => 'exercise.php?'.api_get_cidreq().'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id'],
'href' => 'exercise.php?'.api_get_cidreq().'&action=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id'],
]
);
}
@ -9072,7 +9133,7 @@ class Exercise
'',
[
'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('Are you sure to delete'), ENT_QUOTES, $charset))." ".addslashes($exercise->getUnformattedTitle())."?"."')) return false;",
'href' => 'exercise.php?'.api_get_cidreq().'&choice=delete&sec_token='.$token.'&exerciseId='.$row['id'],
'href' => 'exercise.php?'.api_get_cidreq().'&action=delete&sec_token='.$token.'&exerciseId='.$row['id'],
]
);
} else {

@ -1,6 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CExerciseCategory;
use Chamilo\CourseBundle\Entity\CQuiz;
/**
* Exercise list: This script shows the list of exercises for administrators and students.
*
@ -10,8 +14,6 @@
* Modified by hubert.borderiou (question category)
*/
use Chamilo\CourseBundle\Entity\CExerciseCategory;
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_QUIZ;
@ -26,7 +28,6 @@ $check = Security::get_existing_token('get');
$currentUrl = api_get_self().'?'.api_get_cidreq();
/* Constants and variables */
$is_allowedToEdit = api_is_allowed_to_edit(null, true);
$is_tutor = api_is_allowed_to_edit(true);
$is_tutor_course = api_is_course_tutor();
@ -51,7 +52,6 @@ Exercise::cleanSessionVariables();
//General POST/GET/SESSION/COOKIES parameters recovery
$origin = api_get_origin();
$choice = isset($_REQUEST['choice']) ? Security::remove_XSS($_REQUEST['choice']) : null;
$exerciseId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : null;
$file = isset($_REQUEST['file']) ? Database::escape_string($_REQUEST['file']) : null;
$learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : null;
@ -60,6 +60,13 @@ $categoryId = isset($_REQUEST['category_id']) ? (int) $_REQUEST['category_id'] :
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$keyword = isset($_REQUEST['keyword']) ? Security::remove_XSS($_REQUEST['keyword']) : '';
$exerciseRepo = Container::getExerciseRepository();
$exerciseEntity = null;
if (!empty($exerciseId)) {
/** @var CQuiz $exerciseEntity */
$exerciseEntity = $exerciseRepo->find($exerciseId);
}
if (api_is_in_gradebook()) {
$interbreadcrumb[] = [
'url' => Category::getUrl(),
@ -70,12 +77,91 @@ if (api_is_in_gradebook()) {
$nameTools = get_lang('Tests');
// Simple actions
if ($is_allowedToEdit) {
if ($is_allowedToEdit && !empty($action)) {
$objExerciseTmp = new Exercise();
$exercise_action_locked = api_resource_is_locked_by_gradebook(
$exerciseId,
LINK_EXERCISE
);
$result = $objExerciseTmp->read($exerciseId);
if (empty($result)) {
api_not_allowed();
}
switch ($action) {
case 'enable_launch':
$objExerciseTmp->cleanCourseLaunchSettings();
$objExerciseTmp->enableAutoLaunch();
Display::addFlash(Display::return_message(get_lang('Updated')));
break;
case 'disable_launch':
$objExerciseTmp->cleanCourseLaunchSettings();
break;
case 'delete':
$result = $objExerciseTmp->delete();
if ($result) {
Display::addFlash(Display::return_message(get_lang('ExerciseDeleted'), 'confirmation'));
}
break;
case 'enable':
if ($limitTeacherAccess && !api_is_platform_admin()) {
// Teacher change exercise
break;
}
$exerciseRepo->setVisibilityPublished($exerciseEntity);
Display::addFlash(Display::return_message(get_lang('The visibility has been changed.'), 'confirmation'));
break;
case 'disable':
if ($limitTeacherAccess && !api_is_platform_admin()) {
// Teacher change exercise
break;
}
header('Location: '.$currentUrl);
exit;
$exerciseRepo->setVisibilityDraft($exerciseEntity);
Display::addFlash(Display::return_message(get_lang('The visibility has been changed.'), 'confirmation'));
break;
case 'disable_results':
//disable the results for the learners
$objExerciseTmp->disable_results();
$objExerciseTmp->save();
Display::addFlash(Display::return_message(get_lang('Results disabled for learners'), 'confirmation'));
break;
case 'enable_results':
//disable the results for the learners
$objExerciseTmp->enable_results();
$objExerciseTmp->save();
Display::addFlash(Display::return_message(get_lang('Results enabled for learners'), 'confirmation'));
break;
case 'clean_results':
if ($limitTeacherAccess && !api_is_platform_admin()) {
// Teacher change exercise
break;
}
// Clean student results
if ($exercise_action_locked == false) {
$quantity_results_deleted = $objExerciseTmp->cleanResults(true);
$title = $objExerciseTmp->selectTitle();
Display::addFlash(
Display::return_message(
$title.': '.sprintf(
get_lang('%d results cleaned'),
$quantity_results_deleted
),
'confirmation'
)
);
}
break;
case 'copy_exercise': //copy an exercise
api_set_more_memory_and_time_limits();
$objExerciseTmp->copyExercise();
Display::addFlash(Display::return_message(
get_lang('Test copied'),
'confirmation'
));
break;
case 'clean_all_test':
if ($check) {
@ -163,80 +249,12 @@ if ($is_allowedToEdit) {
break;
}
}
// Mass actions
if (!empty($action) && $is_allowedToEdit) {
$exerciseListToEdit = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
if (!empty($exerciseListToEdit)) {
foreach ($exerciseListToEdit as $exerciseIdToEdit) {
$objExerciseTmp = new Exercise();
$result = $objExerciseTmp->read($exerciseIdToEdit);
if (empty($result)) {
continue;
}
switch ($action) {
case 'delete':
$objExerciseTmp->delete();
break;
case 'visible':
if ($limitTeacherAccess && !api_is_platform_admin()) {
// Teacher change exercise
break;
}
// enables an exercise
if (empty($sessionId)) {
$objExerciseTmp->enable();
$objExerciseTmp->save();
} else {
if (!empty($objExerciseTmp->sessionId)) {
$objExerciseTmp->enable();
$objExerciseTmp->save();
}
}
api_item_property_update(
$courseInfo,
TOOL_QUIZ,
$objExerciseTmp->id,
'visible',
$userId
);
break;
case 'invisible':
if ($limitTeacherAccess && !api_is_platform_admin()) {
// Teacher change exercise
break;
}
// enables an exercise
if (empty($sessionId)) {
$objExerciseTmp->disable();
$objExerciseTmp->save();
} else {
if (!empty($objExerciseTmp->sessionId)) {
$objExerciseTmp->disable();
$objExerciseTmp->save();
}
}
api_item_property_update(
$courseInfo,
TOOL_QUIZ,
$objExerciseTmp->id,
'visible',
$userId
);
break;
}
}
Display::addFlash(Display::return_message(get_lang('Update successful')));
header('Location: '.$currentUrl);
exit;
}
// destruction of Exercise
unset($objExerciseTmp);
Security::clear_token();
header('Location: '.$currentUrl);
exit;
}
Event::event_access_tool(TOOL_QUIZ);
@ -249,142 +267,6 @@ $logInfo = [
];
Event::registerLog($logInfo);
// Only for administrator
if ($is_allowedToEdit) {
if (!empty($choice)) {
// single exercise choice
// construction of Exercise
$objExerciseTmp = new Exercise();
$exercise_action_locked = api_resource_is_locked_by_gradebook(
$exerciseId,
LINK_EXERCISE
);
if ($objExerciseTmp->read($exerciseId)) {
if ($check) {
switch ($choice) {
case 'enable_launch':
$objExerciseTmp->cleanCourseLaunchSettings();
$objExerciseTmp->enableAutoLaunch();
Display::addFlash(Display::return_message(get_lang('Updated')));
break;
case 'disable_launch':
$objExerciseTmp->cleanCourseLaunchSettings();
break;
case 'delete':
// deletes an exercise
$result = $objExerciseTmp->delete();
if ($result) {
Display::addFlash(Display::return_message(get_lang('ExerciseDeleted'), 'confirmation'));
}
break;
case 'enable':
if ($limitTeacherAccess && !api_is_platform_admin()) {
// Teacher change exercise
break;
}
// Enables an exercise
if (empty($sessionId)) {
$objExerciseTmp->enable();
$objExerciseTmp->save();
} else {
if (!empty($objExerciseTmp->sessionId)) {
$objExerciseTmp->enable();
$objExerciseTmp->save();
}
}
api_item_property_update(
$courseInfo,
TOOL_QUIZ,
$objExerciseTmp->id,
'visible',
$userId
);
Display::addFlash(Display::return_message(get_lang('VisibilityChanged'), 'confirmation'));
break;
case 'disable':
if ($limitTeacherAccess && !api_is_platform_admin()) {
// Teacher change exercise
break;
}
// disables an exercise
if (empty($sessionId)) {
$objExerciseTmp->disable();
$objExerciseTmp->save();
} else {
// Only change active if it belongs to a session
if (!empty($objExerciseTmp->sessionId)) {
$objExerciseTmp->disable();
$objExerciseTmp->save();
}
}
api_item_property_update(
$courseInfo,
TOOL_QUIZ,
$objExerciseTmp->id,
'invisible',
$userId
);
Display::addFlash(Display::return_message(get_lang('The visibility has been changed.'), 'confirmation'));
break;
case 'disable_results':
//disable the results for the learners
$objExerciseTmp->disable_results();
$objExerciseTmp->save();
Display::addFlash(Display::return_message(get_lang('Results disabled for learners'), 'confirmation'));
break;
case 'enable_results':
//disable the results for the learners
$objExerciseTmp->enable_results();
$objExerciseTmp->save();
Display::addFlash(Display::return_message(get_lang('Results enabled for learners'), 'confirmation'));
break;
case 'clean_results':
if ($limitTeacherAccess && !api_is_platform_admin()) {
// Teacher change exercise
break;
}
// Clean student results
if ($exercise_action_locked == false) {
$quantity_results_deleted = $objExerciseTmp->cleanResults(true);
$title = $objExerciseTmp->selectTitle();
Display::addFlash(
Display::return_message(
$title.': '.sprintf(
get_lang('%d results cleaned'),
$quantity_results_deleted
),
'confirmation'
)
);
}
break;
case 'copy_exercise': //copy an exercise
api_set_more_memory_and_time_limits();
$objExerciseTmp->copyExercise();
Display::addFlash(Display::return_message(
get_lang('Test copied'),
'confirmation'
));
break;
}
header('Location: '.$currentUrl);
exit;
}
}
// destruction of Exercise
unset($objExerciseTmp);
Security::clear_token();
}
}
if ($origin !== 'learnpath') {
//so we are not in learnpath tool
Display::display_header($nameTools, get_lang('Test'));

@ -6843,7 +6843,7 @@ This folder contains all sessions that have been opened in the chat. Although th
return Display::url(
Display::return_icon($visibility_icon.'.png', $tip_visibility),
api_get_self()."?$courseParams&id=$parentId&$visibility_command={$documentData['id']}"
api_get_self()."?$courseParams&id=$parentId&action=$visibility_command&document_id={$documentData['id']}"
);
}

@ -174,7 +174,7 @@ class ResourceLink
}
/**
* @return ArrayCollection
* @return ArrayCollection|ResourceRight[]
*/
public function getResourceRight()
{
@ -313,11 +313,19 @@ class ResourceLink
return $this->resourceNode;
}
/**
* @return int
*/
public function getVisibility(): int
{
return $this->visibility;
}
/**
* @param int $visibility
*
* @return ResourceLink
*/
public function setVisibility(int $visibility): ResourceLink
{
$this->visibility = $visibility;

@ -79,6 +79,9 @@ class ResourceRepository extends EntityRepository
return new $this->className();
}
/**
* @return RouterInterface
*/
public function getRouter(): RouterInterface
{
return $this->router;
@ -100,6 +103,9 @@ class ResourceRepository extends EntityRepository
return $this->fs;
}
/**
* @return EntityManager
*/
public function getEntityManager(): EntityManager
{
return $this->getRepository()->getEntityManager();
@ -385,6 +391,10 @@ class ResourceRepository extends EntityRepository
}
/**
* @param Course $course
* @param Session|null $session
* @param CGroupInfo|null $group
*
* @return QueryBuilder
*/
public function getResourcesByCourse(Course $course, Session $session = null, CGroupInfo $group = null)
@ -497,6 +507,19 @@ class ResourceRepository extends EntityRepository
return $action;
}
/**
* @param string $tool
*
* @return Tool|null
*/
private function getTool($tool)
{
return $this
->getEntityManager()
->getRepository('ChamiloCoreBundle:Tool')
->findOneBy(['name' => $tool]);
}
/**
* Deletes several entities: AbstractResource (Ex: CDocument, CQuiz), ResourceNode,
* ResourceLinks and ResourceFile (including files via Flysystem).
@ -517,16 +540,27 @@ class ResourceRepository extends EntityRepository
}
/**
* @param string $tool
*
* @return Tool|null
* @param AbstractResource $resource
*/
private function getTool($tool)
public function setVisibilityPublished(AbstractResource $resource)
{
return $this
->getEntityManager()
->getRepository('ChamiloCoreBundle:Tool')
->findOneBy(['name' => $tool]);
$this->setLinkVisibility($resource, ResourceLink::VISIBILITY_PUBLISHED);
}
/**
* @param AbstractResource $resource
*/
public function setVisibilityDraft(AbstractResource $resource)
{
$this->setLinkVisibility($resource, ResourceLink::VISIBILITY_DRAFT);
}
/**
* @param AbstractResource $resource
*/
public function setVisibilityPending(AbstractResource $resource)
{
$this->setLinkVisibility($resource, ResourceLink::VISIBILITY_PENDING);
}
/**
@ -535,10 +569,8 @@ class ResourceRepository extends EntityRepository
* @param bool $recursive
*
* @return bool
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function setLinkVisibility(AbstractResource $resource, $visibility, $recursive = true)
private function setLinkVisibility(AbstractResource $resource, $visibility, $recursive = true)
{
$resourceNode = $resource->getResourceNode();

@ -171,17 +171,6 @@ final class CDocumentRepository extends ResourceRepository
return $query->getSingleScalarResult();
}
/**
* Changes current document link visibility.
*
* @param CDocument $document
* @param int $visibility
*/
public function updateVisibility($document, $visibility): bool
{
return $this->setLinkVisibility($document, $visibility, false);
}
/**
* @param int $userId
*

Loading…
Cancel
Save