Use resources to CRUD StudentPublication

pull/3124/head
Julio Montoya 6 years ago
parent fdd164dc3b
commit f34f3b2c66
  1. 2
      public/main/work/edit.php
  2. 2
      public/main/work/view.php
  3. 15
      public/main/work/work.lib.php
  4. 44
      public/main/work/work.php
  5. 2
      src/CourseBundle/Entity/CAnnouncement.php
  6. 17
      src/CourseBundle/Entity/CAnnouncementAttachment.php

@ -253,7 +253,7 @@ if ($form->validate()) {
}
}
if ($_POST['qualification'] > $_POST['qualification_over']) {
if (isset($_POST['qualification']) && $_POST['qualification'] > $_POST['qualification_over']) {
Display::addFlash(Display::return_message(
get_lang('ScoreMustNotBeMoreThanScoreOver'),
'error'

@ -70,7 +70,7 @@ if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_i
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : null;
if ('edit' == $page) {
if ('edit' === $page) {
$url = api_get_path(WEB_CODE_PATH).'work/edit.php?id='.$my_folder_data['id'].'&item_id='.$work['id'].'&'.api_get_cidreq();
} else {
$url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['id'].'&'.api_get_cidreq();

@ -690,6 +690,7 @@ function build_work_move_to_selector($folders, $curdirpath, $move_file, $group_d
$form->addHidden('action', 'move_to');
// Group documents cannot be uploaded in the root
$options = [];
if ('' == $group_dir) {
if (is_array($folders)) {
foreach ($folders as $fid => $folder) {
@ -3378,16 +3379,11 @@ function getWorkComment($id, $courseInfo = [])
if ($commentEntity->getResourceNode()->hasResourceFile()) {
$fileUrl = $repo->getResourceFileUrl($commentEntity);
$workId = $commentEntity->getWorkId();
$work = get_work_data_by_id($workId);
$workParent = get_work_data_by_id($work['parent_id']);
$filePath = '';
//$filePath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/work/'.$workParent['url'].'/'.$comment['file'];
//$fileUrl = api_get_path(WEB_CODE_PATH).'work/download_comment_file.php?comment_id='.$id.'&'.api_get_cidreq();
$deleteUrl = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$workId.'&action=delete_attachment&comment_id='.$id;
///$fileParts = explode('_', $comment['file']);
//$fileName = str_replace($fileParts[0].'_'.$fileParts[1].'_', '', $comment['file']);
$fileName = $commentEntity->getResourceNode()->getResourceFile()->getName();
}
$comment['comment'] = $commentEntity->getComment();
$comment['delete_file_url'] = $deleteUrl;
$comment['file_path'] = $filePath;
$comment['file_url'] = $fileUrl;
@ -4202,14 +4198,11 @@ function processWorkForm(
*/
function addDir($formValues, $user_id, $courseInfo, $groupId, $sessionId = 0)
{
$em = Database::getManager();
$user_id = (int) $user_id;
$groupId = (int) $groupId;
$sessionId = (int) $sessionId;
$groupIid = 0;
$groupInfo = [];
if (!empty($groupId)) {
$groupInfo = GroupManager::get_group_properties($groupId);
$groupIid = $groupInfo['iid'];
@ -4233,7 +4226,6 @@ function addDir($formValues, $user_id, $courseInfo, $groupId, $sessionId = 0)
}
}
//$dirName = '/'.$created_dir;
$today = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC'));
$title = isset($formValues['work_title']) ? $formValues['work_title'] : $formValues['new_dir'];
@ -4967,9 +4959,10 @@ function generateMoveForm($item_id, $path, $courseInfo, $groupId, $sessionId)
WHERE
c_id = $courseId AND
active IN (0, 1) AND
url LIKE '/%' AND
parent_id = 0 AND
post_group_id = $groupIid
$sessionCondition";
$res = Database::query($sql);
while ($folder = Database::fetch_array($res)) {
$title = empty($folder['title']) ? basename($folder['url']) : $folder['title'];

@ -3,6 +3,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CStudentPublication;
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
@ -35,7 +36,6 @@ $item_id = isset($_REQUEST['item_id']) ? (int) $_REQUEST['item_id'] : null;
$origin = api_get_origin();
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'list';
// Download folder
if ('downloadfolder' === $action) {
require 'downloadfolder.inc.php';
@ -212,8 +212,7 @@ switch ($action) {
break;
case 'move':
// Move file form request
if ($is_allowed_to_edit) {
if (!empty($item_id)) {
if ($is_allowed_to_edit && !empty($item_id)) {
$content = generateMoveForm(
$item_id,
$curdirpath,
@ -222,45 +221,34 @@ switch ($action) {
$sessionId
);
}
}
break;
case 'move_to':
/* Move file command */
if ($is_allowed_to_edit) {
$move_to_path = get_work_path($_REQUEST['move_to_id']);
if ($is_allowed_to_edit && isset($_REQUEST['move_to_id'])) {
$moveToParentId = $_REQUEST['move_to_id'];
if (-1 == $move_to_path) {
$move_to_path = '/';
} elseif ('/' != substr($move_to_path, -1, 1)) {
$move_to_path .= '/';
}
/** @var CStudentPublication $newParent */
$newParent = $repo->find($_REQUEST['move_to_id']);
// Security fix: make sure they can't move files that are not in the document table
if ($path = get_work_path($item_id)) {
if (move($course_dir.'/'.$path, $base_work_dir.$move_to_path)) {
// Update db
updateWorkUrl(
$item_id,
'work'.$move_to_path,
$_REQUEST['move_to_id']
);
/** @var CStudentPublication $studentPublication */
$studentPublication = $repo->find($_REQUEST['item_id']);
$studentPublication->setParentId($_REQUEST['move_to_id']);
$studentPublication->getResourceNode()->setParent($newParent->getResourceNode());
api_item_property_update(
$repo->getEntityManager()->persist($studentPublication);
$repo->getEntityManager()->flush();
/*api_item_property_update(
$courseInfo,
'work',
$_REQUEST['move_to_id'],
'FolderUpdated',
$user_id
);
);*/
$message = Display::return_message(get_lang('Element moved'), 'success');
} else {
$message = Display::return_message(get_lang('Operation impossible'), 'error');
}
} else {
$message = Display::return_message(get_lang('Operation impossible'), 'error');
}
Display::addFlash($message);
header('Location: '.$currentUrl);
exit;

@ -110,7 +110,7 @@ class CAnnouncement extends AbstractResource implements ResourceInterface
/**
* @param CAnnouncementAttachment[] $attachments
*/
public function setAttachments(array $attachments): CAnnouncement
public function setAttachments(array $attachments): self
{
$this->attachments = $attachments;

@ -157,26 +157,11 @@ class CAnnouncementAttachment extends AbstractResource implements ResourceInterf
return $this->size;
}
/**
* @return int
*/
public function getIid(): int
{
return $this->iid;
}
/**
* @param int $iid
*
* @return CAnnouncementAttachment
*/
public function setIid(int $iid): CAnnouncementAttachment
{
$this->iid = $iid;
return $this;
}
/**
* Set filename.
*
@ -254,7 +239,7 @@ class CAnnouncementAttachment extends AbstractResource implements ResourceInterf
return $this->announcement;
}
public function setAnnouncement(CAnnouncement $announcement): CAnnouncementAttachment
public function setAnnouncement(CAnnouncement $announcement): self
{
$this->announcement = $announcement;

Loading…
Cancel
Save