Fix forum creation

pull/3124/head
Julio 6 years ago
parent 4f3b5bfd6e
commit 9d4d64a26e
  1. 74
      public/main/forum/forumfunction.inc.php
  2. 17
      public/main/forum/viewforumcategory.php
  3. 14
      src/CoreBundle/Entity/Course.php
  4. 5
      src/CoreBundle/Entity/Resource/ResourceNode.php
  5. 10
      src/CoreBundle/Repository/ResourceRepository.php
  6. 10
      src/CourseBundle/Repository/CLinkCategoryRepository.php

@ -101,7 +101,7 @@ $(function () {
*/
function handle_forum_and_forumcategories($lp_id = null)
{
$action_forum_cat = isset($_GET['action']) ? $_GET['action'] : '';
$action_forum_cat = $action = isset($_GET['action']) ? $_GET['action'] : '';
$get_content = isset($_GET['content']) ? $_GET['content'] : '';
$post_submit_cat = isset($_POST['SubmitForumCategory']) ? true : false;
$post_submit_forum = isset($_POST['SubmitForum']) ? true : false;
@ -139,44 +139,44 @@ function handle_forum_and_forumcategories($lp_id = null)
$content = show_edit_forumcategory_form($forum_category);
}
// Delete a forum category
if ('delete' === $action_forum_cat) {
$list_threads = get_threads($get_id);
for ($i = 0; $i < count($list_threads); $i++) {
deleteForumCategoryThread('thread', $list_threads[$i]['thread_id']);
$link_info = GradebookUtils::isResourceInCourseGradebook(
api_get_course_id(),
5,
$list_threads[$i]['thread_id'],
api_get_session_id()
switch ($action) {
case 'move':
$return_message = move_up_down($get_content, $_GET['direction'], $get_id);
Display::addFlash(
Display::return_message($return_message, 'confirmation', false)
);
if (false !== $link_info) {
GradebookUtils::remove_resource_from_course_gradebook($link_info['id']);
}
}
deleteForumCategoryThread($get_content, $get_id);
}
header('Location: '. api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq());
exit;
break;
case 'lock':
case 'unlock':
$return_message = change_lock_status($get_content, $get_id, $action_forum_cat);
Display::addFlash(
Display::return_message($return_message, 'confirmation', false)
);
header('Location: '. api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq());
exit;
break;
case 'visible':
case 'invisible':
$return_message = change_visibility($get_content, $get_id, $action_forum_cat);
Display::addFlash(
Display::return_message($return_message, 'confirmation', false)
);
header('Location: '. api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq());
exit;
break;
// Change visibility of a forum or a forum category.
if ('invisible' === $action_forum_cat || 'visible' === $action_forum_cat) {
$return_message = change_visibility($get_content, $get_id, $action_forum_cat);
Display::addFlash(
Display::return_message($return_message, 'confirmation', false)
);
}
// Change lock status of a forum or a forum category.
if ('lock' === $action_forum_cat || 'unlock' === $action_forum_cat) {
$return_message = change_lock_status($get_content, $get_id, $action_forum_cat);
Display::addFlash(
Display::return_message($return_message, 'confirmation', false)
);
}
// Move a forum or a forum category.
if ('move' === $action_forum_cat && isset($_GET['direction'])) {
$return_message = move_up_down($get_content, $_GET['direction'], $get_id);
Display::addFlash(
Display::return_message($return_message, 'confirmation', false)
);
case 'delete':
$repo = Container::getForumCategoryRepository();
$cat = $repo->find($get_id);
if ($cat) {
$repo->delete($cat);
}
Display::addFlash(Display::return_message(get_lang('Forum category deleted'), 'confirmation', false));
header('Location: '. api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq());
exit;
break;
}
return $content;

@ -60,6 +60,14 @@ $hideNotifications = 1 == $hideNotifications;
require_once 'forumfunction.inc.php';
/** @var CForumCategory $forumCategory */
$forumCategory = $repo->find($_GET['forumcategory']);
$categoryId = $forumCategory->getIid();
if (api_is_allowed_to_edit(false, true)) {
handle_forum_and_forumcategories();
}
// Are we in a lp ?
$origin = api_get_origin();
@ -71,10 +79,6 @@ if (api_is_in_gradebook()) {
}
$sessionId = api_get_session_id();
/** @var CForumCategory $forumCategory */
$forumCategory = $repo->find($_GET['forumcategory']);
$categoryId = $forumCategory->getIid();
$interbreadcrumb[] = [
'url' => 'index.php?'.api_get_cidreq().'&search='.Security::remove_XSS(urlencode(isset($_GET['search']) ? $_GET['search'] : '')),
'name' => get_lang('Forum'),
@ -136,9 +140,6 @@ $logInfo = [
];
Event::registerLog($logInfo);
if (api_is_allowed_to_edit(false, true)) {
handle_forum_and_forumcategories();
}
// Notification
if ('notify' === $action && isset($_GET['content']) && isset($_GET['id'])) {
@ -188,7 +189,7 @@ if ('add' !== $action) {
.Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).'</a>';
$iconsEdit .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&forumcategory='
.Security::remove_XSS($_GET['forumcategory'])
.'&action=delete&content=forumcategory&id='.$forumId
.'&action=delete&content=forumcategory&id='.$forumCategory->getIid()
."\" onclick=\"javascript:if(!confirm('"
.addslashes(api_htmlentities(get_lang('Delete forum category ?'), ENT_QUOTES))
."')) return false;\">".Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL)

@ -60,6 +60,8 @@ class Course extends AbstractResource implements ResourceInterface
protected $title;
/**
* @var CourseRelUser[]|ArrayCollection
*
* "orphanRemoval" is needed to delete the CourseRelUser relation
* in the CourseAdmin class. The setUsers, getUsers, removeUsers and
* addUsers methods need to be added.
@ -89,7 +91,7 @@ class Course extends AbstractResource implements ResourceInterface
protected $groups;
/**
* @var CTool[]
* @var CTool[]|ArrayCollection
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CTool", mappedBy="course", cascade={"persist", "remove"})
*/
@ -378,7 +380,7 @@ class Course extends AbstractResource implements ResourceInterface
}
/**
* @return Session[]
* @return Session[]|ArrayCollection
*/
public function getSessions()
{
@ -455,7 +457,7 @@ class Course extends AbstractResource implements ResourceInterface
}
/**
* @return User[]
* @return CourseRelUser[]|ArrayCollection
*/
public function getUsers()
{
@ -463,7 +465,7 @@ class Course extends AbstractResource implements ResourceInterface
}
/**
* @return CGroupInfo[]
* @return CGroupInfo[]|ArrayCollection
*/
public function getGroups()
{
@ -471,7 +473,7 @@ class Course extends AbstractResource implements ResourceInterface
}
/**
* @return User[]
* @return CourseRelUser[]|ArrayCollection
*/
public function getTeachers()
{
@ -482,7 +484,7 @@ class Course extends AbstractResource implements ResourceInterface
}
/**
* @return User[]
* @return CourseRelUser[]|ArrayCollection
*/
public function getStudents()
{

@ -52,6 +52,8 @@ class ResourceNode
protected $resourceType;
/**
* @var ResourceLink[]
*
* @ORM\OneToMany(targetEntity="ResourceLink", mappedBy="resourceNode", cascade={"remove"})
*/
protected $resourceLinks;
@ -130,6 +132,7 @@ class ResourceNode
public function __construct()
{
$this->children = new ArrayCollection();
$this->resourceLinks = new ArrayCollection();
}
/**
@ -200,7 +203,7 @@ class ResourceNode
/**
* Returns the children resource instances.
*
* @return ArrayCollection
* @return ResourceNode[]|ArrayCollection
*/
public function getChildren()
{

@ -707,6 +707,16 @@ class ResourceRepository extends BaseEntityRepository
return $action;
}
public function delete(AbstractResource $resource)
{
$children = $resource->getResourceNode()->getChildren();
foreach ($children as $child) {
$this->getEntityManager()->remove($child);
}
$this->getEntityManager()->remove($resource->getResourceNode());
$this->getEntityManager()->flush();
}
/**
* Deletes several entities: AbstractResource (Ex: CDocument, CQuiz), ResourceNode,
* ResourceLinks and ResourceFile (including files via Flysystem).

@ -65,14 +65,4 @@ final class CLinkCategoryRepository extends ResourceRepository implements Resour
{
return $grid->getColumn('title');
}
public function delete(CLinkCategory $category)
{
$links = $category->getResourceNode()->getChildren();
foreach ($links as $link) {
$this->getEntityManager()->remove($link);
}
$this->getEntityManager()->remove($category->getResourceNode());
$this->getEntityManager()->flush();
}
}

Loading…
Cancel
Save