Update work code in order to use entities, remove work.lib.php calls

pull/3844/head
Julio Montoya 5 years ago
parent dee18e118a
commit d085f4a756
  1. 8
      public/main/inc/ajax/model.ajax.php
  2. 26
      public/main/inc/ajax/work.ajax.php
  3. 8
      public/main/inc/lib/internationalization.lib.php
  4. 1
      public/main/work/add_document.php
  5. 3
      public/main/work/add_user.php
  6. 17
      public/main/work/edit.php
  7. 3
      public/main/work/edit_work.php
  8. 1
      public/main/work/pending.php
  9. 1
      public/main/work/publications.php
  10. 1
      public/main/work/show_file.php
  11. 1
      public/main/work/student_work.php
  12. 4
      public/main/work/upload.php
  13. 3
      public/main/work/upload_corrections.php
  14. 4
      public/main/work/upload_from_template.php
  15. 13
      public/main/work/view.php
  16. 570
      public/main/work/work.lib.php
  17. 9
      public/main/work/work.php
  18. 2
      public/main/work/work_list.php
  19. 3
      public/main/work/work_list_all.php
  20. 2
      public/main/work/work_list_others.php
  21. 4
      public/main/work/work_missing.php

@ -543,20 +543,16 @@ switch ($action) {
$count = AnnouncementManager::getNumberAnnouncements();
break;
case 'get_work_teacher':
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$count = getWorkListTeacher(0, $limit, $sidx, $sord, $whereCondition, true);
break;
case 'get_work_student':
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$count = getWorkListStudent(0, $limit, $sidx, $sord, $whereCondition, true);
break;
case 'get_all_work_student':
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$withResults = isset($_REQUEST['with_results']) ? (int) $_REQUEST['with_results'] : 0;
$count = getAllWorkListStudent(0, $limit, $sidx, $sord, $whereCondition, true, $withResults);
break;
case 'get_work_user_list_all':
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$work_id = $_REQUEST['work_id'];
$count = get_count_work($work_id);
break;
@ -575,12 +571,10 @@ switch ($action) {
);
break;
case 'get_work_user_list_others':
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$work_id = $_REQUEST['work_id'];
$count = get_count_work($work_id, api_get_user_id());
break;
case 'get_work_user_list':
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$work_id = $_REQUEST['work_id'];
$courseInfo = api_get_course_info();
$documents = getAllDocumentToWork($work_id, api_get_course_int_id());
@ -618,7 +612,6 @@ switch ($action) {
if (!(api_is_allowed_to_edit() || api_is_coach())) {
return 0;
}
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$workId = isset($_GET['work_id']) ? $_GET['work_id'] : null;
$count = getWorkUserListData(
$workId,
@ -1629,7 +1622,6 @@ switch ($action) {
if (!(api_is_allowed_to_edit() || api_is_coach())) {
return [];
}
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$columns = [
'student', 'works',
];

@ -5,6 +5,9 @@
/**
* Responses to AJAX calls.
*/
use Chamilo\CoreBundle\Framework\Container;
require_once __DIR__.'/../global.inc.php';
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
@ -86,7 +89,7 @@ switch ($action) {
$counter++;
}
}
$router = Container::getRouter();
$resultList = [];
foreach ($fileList as $file) {
$globalFile = [];
@ -98,7 +101,7 @@ switch ($action) {
'description' => '',
];
$result = processWorkForm(
$studentPublication = processWorkForm(
$workInfo,
$values,
$courseInfo,
@ -111,15 +114,22 @@ switch ($action) {
);
$json = [];
if (!empty($result) && is_array($result) && empty($result['error'])) {
$json['name'] = api_htmlentities($result['title']);
if (null !== $studentPublication) {
$url = $router->generate('chamilo_core_resource_download',
[
'id' => $studentPublication->getResourceNode()->getId(),
'tool' => 'student_publication',
'type' => 'student_publications',
]
).'?'.api_get_cidreq();
$json['name'] = api_htmlentities($studentPublication->getTitle());
$json['link'] = Display::url(
api_htmlentities($result['title']),
api_htmlentities($result['view_url']),
api_htmlentities($studentPublication->getTitle()),
api_htmlentities($url),
['target' => '_blank']
);
$json['url'] = $result['view_url'];
$json['url'] = $url;
$json['size'] = '';
//$json['type'] = api_htmlentities($result['filetype']);
$json['result'] = Display::return_icon(
@ -128,7 +138,7 @@ switch ($action) {
);
} else {
$json['url'] = '';
$json['error'] = isset($result['error']) ? $result['error'] : get_lang('Error');
$json['error'] = get_lang('Error');
}
$resultList[] = $json;
}

@ -563,7 +563,7 @@ function api_format_date($time, $format = null, $language = null)
* You can use it like this:
* Display::dateToStringAgoAndLongDate($dateInUtc);.
*
* @param string $date Result of a date function in this format -> date('Y-m-d H:i:s', time());
* @param string|DateTime $date Result of a date function in this format -> date('Y-m-d H:i:s', time());
* @param string $timeZone
* @param bool $returnDateDifference
*
@ -591,12 +591,14 @@ function date_to_str_ago($date, $timeZone = 'UTC', $returnDateDifference = false
$language = new Westsworld\TimeAgo\Translations\En();
}
$timeAgo = new TimeAgo($language);
$date = api_get_utc_datetime($date, null, true);
if (!($date instanceof DateTime)) {
$date = api_get_utc_datetime($date, null, true);
}
$value = $timeAgo->inWords($date);
date_default_timezone_set($getOldTimezone);
if ($returnDateDifference) {
//$value = $timeAgo->dateDifference($date);
$now = new DateTime('now', $date->getTimezone());
$value = $date->diff($now);

@ -6,7 +6,6 @@ use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CDocument;
require_once __DIR__.'/../inc/global.inc.php';
require_once 'work.lib.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;

@ -4,9 +4,6 @@
require_once __DIR__.'/../inc/global.inc.php';
// Including necessary files
require_once 'work.lib.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
$workId = isset($_GET['id']) ? (int) $_GET['id'] : null;

@ -16,7 +16,7 @@ if ($blockEdition && !api_is_platform_admin()) {
api_not_allowed(true);
}
require_once 'work.lib.php';
$this_section = SECTION_COURSES;
@ -193,7 +193,7 @@ if ($is_allowed_to_edit && !empty($item_id)) {
);
// Check if user to qualify has some DRHs
$drhList = UserManager::getDrhListFromUser($studentPublication->getUserId());
$drhList = UserManager::getDrhListFromUser($studentPublication->getUser()->getId());
if (!empty($drhList)) {
$form->addCheckBox(
'send_to_drh_users',
@ -242,11 +242,18 @@ if ($form->validate()) {
if (isset($_POST['send_email'])) {
$url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$item_to_edit_id;
$subject = sprintf(get_lang('There\'s a new feedback in work: %s'), $studentPublication->getTitle());
$message = sprintf(get_lang('There\'s a new feedback in work: %sInWorkXHere'), $studentPublication->getTitle(), $url);
$subject = sprintf(
get_lang('There\'s a new feedback in work: %s'),
$studentPublication->getTitle()
);
$message = sprintf(
get_lang('There\'s a new feedback in work: %sInWorkXHere'),
$studentPublication->getTitle(),
$url
);
MessageManager::send_message_simple(
$studentPublication->getUserId(),
$studentPublication->getUser()->getId(),
$subject,
$message,
api_get_user_id(),

@ -8,9 +8,6 @@ api_protect_course_script(true);
$lib_path = api_get_path(LIBRARY_PATH);
/* Libraries */
require_once 'work.lib.php';
// Section (for the tabs)
$this_section = SECTION_COURSES;

@ -12,7 +12,6 @@ if (false === api_is_teacher()) {
api_not_allowed(true);
}
require_once 'work.lib.php';
$this_section = SECTION_COURSES;
$is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach();

@ -5,7 +5,6 @@
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
require_once 'work.lib.php';
if (false === api_get_configuration_value('allow_my_student_publication_page')) {
api_not_allowed(true);

@ -9,7 +9,6 @@
* rewrite mechanism.
*/
require_once __DIR__.'/../inc/global.inc.php';
require_once 'work.lib.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
$this_section = SECTION_COURSES;

@ -8,7 +8,6 @@ $current_course_tool = TOOL_STUDENTPUBLICATION;
api_protect_course_script(true);
api_protect_course_group(GroupManager::GROUP_TOOL_WORK);
require_once 'work.lib.php';
$this_section = SECTION_COURSES;
$studentId = isset($_GET['studentId']) ? (int) ($_GET['studentId']) : null;

@ -7,11 +7,7 @@ $current_course_tool = TOOL_STUDENTPUBLICATION;
api_protect_course_script(true);
// Including necessary files
require_once 'work.lib.php';
$this_section = SECTION_COURSES;
$work_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : null;
$is_allowed_to_edit = api_is_allowed_to_edit();

@ -7,9 +7,6 @@ $current_course_tool = TOOL_STUDENTPUBLICATION;
api_protect_course_script(true);
// Including necessary files
require_once 'work.lib.php';
$this_section = SECTION_COURSES;
$workId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;

@ -9,11 +9,7 @@ $current_course_tool = TOOL_STUDENTPUBLICATION;
api_protect_course_script(true);
// Including necessary files
require_once 'work.lib.php';
$this_section = SECTION_COURSES;
$work_id = isset($_REQUEST['id']) ? (int) ($_REQUEST['id']) : null;
$documentId = isset($_REQUEST['document_id']) ? (int) ($_REQUEST['document_id']) : null;

@ -10,19 +10,16 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
require_once 'work.lib.php';
$id = isset($_GET['id']) ? (int) $_GET['id'] : null;
$repo = Container::getStudentPublicationRepository();
/** @var CStudentPublication $work */
/** @var CStudentPublication|null $work */
$work = $repo->find($id);
if (empty($work)) {
if (null === $work) {
api_not_allowed(true);
}
$parentId = $work->getParentId();
$parentId = $work->getPublicationParent()->getIid();
protectWork(api_get_course_info(), $parentId);
$action = $_REQUEST['action'] ?? null;
@ -78,7 +75,7 @@ if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id))
$url_dir = api_get_path(WEB_CODE_PATH).'work/work_list.php?id='.$folderData['iid'].'&'.api_get_cidreq();
}
$userInfo = api_get_user_info($work->getUserId());
$userInfo = api_get_user_info($work->getUser()->getId());
$interbreadcrumb[] = ['url' => $url_dir, 'name' => $folderData['title']];
$interbreadcrumb[] = ['url' => '#', 'name' => $userInfo['complete_name']];
$interbreadcrumb[] = ['url' => '#', 'name' => $work->getTitle()];
@ -200,12 +197,10 @@ if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id))
break;
}
$comments = getWorkComments($work);
$commentForm = getWorkCommentForm($work, $folderData);
$tpl = new Template();
$tpl->assign('work', $work);
$tpl->assign('comments', $comments);
$actions = '';
if ($work->getContainsFile()) {

File diff suppressed because it is too large Load Diff

@ -10,8 +10,6 @@ $current_course_tool = TOOL_STUDENTPUBLICATION;
api_protect_course_script(true);
require_once 'work.lib.php';
$courseInfo = api_get_course_info();
$user_id = api_get_user_id();
$sessionId = api_get_session_id();
@ -227,11 +225,12 @@ switch ($action) {
/** @var CStudentPublication $studentPublication */
$studentPublication = $repo->find($_REQUEST['item_id']);
$studentPublication->setParentId($_REQUEST['move_to_id']);
if ($_REQUEST['move_to_id']) {
$parent = $repo->find($_REQUEST['move_to_id']);
$studentPublication->setParent($parent);
}
$studentPublication->getResourceNode()->setParent($newParent->getResourceNode());
$repo->update($studentPublication);
/*api_item_property_update(
$courseInfo,
'work',

@ -9,7 +9,7 @@ $current_course_tool = TOOL_STUDENTPUBLICATION;
api_protect_course_script(true);
require_once 'work.lib.php';
$this_section = SECTION_COURSES;
$workId = isset($_GET['id']) ? (int) $_GET['id'] : null;

@ -9,9 +9,6 @@ require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
api_protect_course_script(true);
// Including necessary files
require_once 'work.lib.php';
$this_section = SECTION_COURSES;
$workId = isset($_GET['id']) ? (int) $_GET['id'] : null;

@ -6,8 +6,6 @@ require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
api_protect_course_script(true);
require_once 'work.lib.php';
$this_section = SECTION_COURSES;
$workId = isset($_GET['id']) ? (int) ($_GET['id']) : null;

@ -6,11 +6,7 @@ require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
api_protect_course_script(true);
// Including necessary files
require_once 'work.lib.php';
$this_section = SECTION_COURSES;
$workId = isset($_GET['id']) ? (int) ($_GET['id']) : null;
$group_id = api_get_group_id();
$user_id = api_get_user_id();

Loading…
Cancel
Save