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. 74
      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( Display::addFlash(Display::return_message(
get_lang('ScoreMustNotBeMoreThanScoreOver'), get_lang('ScoreMustNotBeMoreThanScoreOver'),
'error' '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; $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 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(); $url = api_get_path(WEB_CODE_PATH).'work/edit.php?id='.$my_folder_data['id'].'&item_id='.$work['id'].'&'.api_get_cidreq();
} else { } else {
$url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['id'].'&'.api_get_cidreq(); $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'); $form->addHidden('action', 'move_to');
// Group documents cannot be uploaded in the root // Group documents cannot be uploaded in the root
$options = [];
if ('' == $group_dir) { if ('' == $group_dir) {
if (is_array($folders)) { if (is_array($folders)) {
foreach ($folders as $fid => $folder) { foreach ($folders as $fid => $folder) {
@ -3378,16 +3379,11 @@ function getWorkComment($id, $courseInfo = [])
if ($commentEntity->getResourceNode()->hasResourceFile()) { if ($commentEntity->getResourceNode()->hasResourceFile()) {
$fileUrl = $repo->getResourceFileUrl($commentEntity); $fileUrl = $repo->getResourceFileUrl($commentEntity);
$workId = $commentEntity->getWorkId(); $workId = $commentEntity->getWorkId();
$work = get_work_data_by_id($workId);
$workParent = get_work_data_by_id($work['parent_id']);
$filePath = ''; $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; $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(); $fileName = $commentEntity->getResourceNode()->getResourceFile()->getName();
} }
$comment['comment'] = $commentEntity->getComment();
$comment['delete_file_url'] = $deleteUrl; $comment['delete_file_url'] = $deleteUrl;
$comment['file_path'] = $filePath; $comment['file_path'] = $filePath;
$comment['file_url'] = $fileUrl; $comment['file_url'] = $fileUrl;
@ -4202,14 +4198,11 @@ function processWorkForm(
*/ */
function addDir($formValues, $user_id, $courseInfo, $groupId, $sessionId = 0) function addDir($formValues, $user_id, $courseInfo, $groupId, $sessionId = 0)
{ {
$em = Database::getManager();
$user_id = (int) $user_id; $user_id = (int) $user_id;
$groupId = (int) $groupId; $groupId = (int) $groupId;
$sessionId = (int) $sessionId; $sessionId = (int) $sessionId;
$groupIid = 0; $groupIid = 0;
$groupInfo = [];
if (!empty($groupId)) { if (!empty($groupId)) {
$groupInfo = GroupManager::get_group_properties($groupId); $groupInfo = GroupManager::get_group_properties($groupId);
$groupIid = $groupInfo['iid']; $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')); $today = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC'));
$title = isset($formValues['work_title']) ? $formValues['work_title'] : $formValues['new_dir']; $title = isset($formValues['work_title']) ? $formValues['work_title'] : $formValues['new_dir'];
@ -4967,9 +4959,10 @@ function generateMoveForm($item_id, $path, $courseInfo, $groupId, $sessionId)
WHERE WHERE
c_id = $courseId AND c_id = $courseId AND
active IN (0, 1) AND active IN (0, 1) AND
url LIKE '/%' AND parent_id = 0 AND
post_group_id = $groupIid post_group_id = $groupIid
$sessionCondition"; $sessionCondition";
$res = Database::query($sql); $res = Database::query($sql);
while ($folder = Database::fetch_array($res)) { while ($folder = Database::fetch_array($res)) {
$title = empty($folder['title']) ? basename($folder['url']) : $folder['title']; $title = empty($folder['title']) ? basename($folder['url']) : $folder['title'];

@ -3,6 +3,7 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container; use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CStudentPublication;
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION; $current_course_tool = TOOL_STUDENTPUBLICATION;
@ -35,7 +36,6 @@ $item_id = isset($_REQUEST['item_id']) ? (int) $_REQUEST['item_id'] : null;
$origin = api_get_origin(); $origin = api_get_origin();
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'list'; $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'list';
// Download folder // Download folder
if ('downloadfolder' === $action) { if ('downloadfolder' === $action) {
require 'downloadfolder.inc.php'; require 'downloadfolder.inc.php';
@ -212,55 +212,43 @@ switch ($action) {
break; break;
case 'move': case 'move':
// Move file form request // Move file form request
if ($is_allowed_to_edit) { if ($is_allowed_to_edit && !empty($item_id)) {
if (!empty($item_id)) { $content = generateMoveForm(
$content = generateMoveForm( $item_id,
$item_id, $curdirpath,
$curdirpath, $courseInfo,
$courseInfo, $groupId,
$groupId, $sessionId
$sessionId );
);
}
} }
break; break;
case 'move_to': case 'move_to':
/* Move file command */ /* Move file command */
if ($is_allowed_to_edit) { if ($is_allowed_to_edit && isset($_REQUEST['move_to_id'])) {
$move_to_path = get_work_path($_REQUEST['move_to_id']); $moveToParentId = $_REQUEST['move_to_id'];
if (-1 == $move_to_path) { /** @var CStudentPublication $newParent */
$move_to_path = '/'; $newParent = $repo->find($_REQUEST['move_to_id']);
} elseif ('/' != substr($move_to_path, -1, 1)) {
$move_to_path .= '/'; /** @var CStudentPublication $studentPublication */
} $studentPublication = $repo->find($_REQUEST['item_id']);
$studentPublication->setParentId($_REQUEST['move_to_id']);
$studentPublication->getResourceNode()->setParent($newParent->getResourceNode());
$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');
// 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']
);
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); Display::addFlash($message);
header('Location: '.$currentUrl); header('Location: '.$currentUrl);
exit; exit;

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

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

Loading…
Cancel
Save