Allow dissociate a forum to this LP item - refs BT#10629

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent c22e4cd72e
commit 83de577b26
  1. 9
      main/newscorm/learnpath.class.php
  2. 85
      main/newscorm/learnpathItem.class.php
  3. 38
      main/newscorm/lp_controller.php

@ -5641,10 +5641,15 @@ class learnpath
$this->lp_session_id
)
) {
$forumIconUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
'action' => 'dissociate_forum',
'id' => $arrLP[$i]['id'],
'lp_id' => $this->lp_id
]);
$forumIcon = Display::url(
Display::return_icon('forum.png', get_lang('DissociateForumToLPItem'), [], ICON_SIZE_TINY),
'#',
['class' => 'btn btn-default disabled lp-btn-dissociate-forum']
$forumIconUrl,
['class' => 'btn btn-default lp-btn-dissociate-forum']
);
} else {
$forumIconUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([

@ -4490,7 +4490,11 @@ class learnpathItem
'ip.tool = ? AND ' => TOOL_FORUM_THREAD,
'ft.session_id = ? AND ' => $lpSessionId,
'ft.c_id = ? AND ' => intval($lpCourseId),
'ft.lp_item_id = ?' => intval($this->db_id)
'(ft.lp_item_id = ? OR (ft.thread_title = ? AND ft.lp_item_id = ?))' => [
intval($this->db_id),
"{$this->title}-{$this->db_id}",
intval($this->db_id)
]
]
],
'first'
@ -4512,27 +4516,68 @@ class learnpathItem
{
require_once api_get_path(SYS_CODE_PATH) . '/forum/forumfunction.inc.php';
$forumInfo = get_forum_information($currentForumId);
$em = Database::getManager();
$threadRepo = $em->getRepository('ChamiloCourseBundle:CForumThread');
$forumThread = $threadRepo->findOneBy([
'threadTitle' => "{$this->title}-{$this->db_id}",
'forumId' => intval($currentForumId)
]);
if (!$forumThread) {
$forumInfo = get_forum_information($currentForumId);
store_thread(
$forumInfo,
[
'forum_id' => intval($currentForumId),
'thread_id' => 0,
'gradebook' => 0,
'post_title' => $this->name,
'post_text' => $this->description,
'category_id' => 1,
'numeric_calification' => 0,
'calification_notebook_title' => 0,
'weight_calification' => 0.00,
'thread_peer_qualify' => 0,
'lp_item_id' => $this->db_id
],
[],
false
);
$threadId = store_thread(
$forumInfo,
[
'forum_id' => intval($currentForumId),
'thread_id' => 0,
'gradebook' => 0,
'post_title' => $this->name,
'post_text' => $this->description,
'category_id' => 1,
'numeric_calification' => 0,
'calification_notebook_title' => 0,
'weight_calification' => 0.00,
'thread_peer_qualify' => 0,
'lp_item_id' => $this->db_id
],
[],
false
return;
}
$forumThread->setLpItemId($this->db_id);
$em->persist($forumThread);
$em->flush();
}
/**
* Allow dissociate a forum to this LP item
* @param int $threadIid The thread id
* @return boolean
*/
public function dissociateForumThread($threadIid)
{
$threadIid = intval($threadIid);
$em = Database::getManager();
$forumThread = $em->find('ChamiloCourseBundle:CForumThread', $threadIid);
if (!$forumThread) {
return false;
}
$forumThread->setThreadTitle(
"{$this->get_title()}-{$this->db_id}"
);
$forumThread->setLpItemId(0);
return $threadId;
$em->persist($forumThread);
$em->flush();
return true;
}
}

@ -1340,6 +1340,44 @@ switch ($action) {
case 'report':
require 'lp_report.php';
break;
case 'dissociate_forum':
if (!isset($_GET['id'])) {
break;
}
$selectedItem = null;
foreach ($_SESSION['oLP']->items as $item) {
if ($item->db_id != $_GET['id']) {
continue;
}
$selectedItem = $item;
}
if (!empty($selectedItem)) {
$forumThread = $selectedItem->getForumThread(
$_SESSION['oLP']->course_int_id,
$_SESSION['oLP']->lp_session_id
);
if (!empty($forumThread)) {
$dissoaciated = $selectedItem->dissociateForumThread($forumThread['iid']);
if ($dissoaciated) {
Display::addFlash(
Display::return_message(get_lang('ForumDissociate'), 'success')
);
}
}
}
header('Location:' . api_get_path(WEB_PATH) . api_get_self() . '?' . http_build_query([
'action' => 'add_item',
'type' => 'step',
'lp_id' => $_SESSION['oLP']->lp_id
]));
break;
default:
if ($debug > 0) error_log('New LP - default action triggered', 0);
require 'lp_list.php';

Loading…
Cancel
Save