Skip to content

Commit

Permalink
Allow dissociate a forum to this LP item - refs BT#10629
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Dec 23, 2015
1 parent c22e4cd commit 83de577
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 22 deletions.
9 changes: 7 additions & 2 deletions main/newscorm/learnpath.class.php
Expand Up @@ -5641,10 +5641,15 @@ public function return_new_tree($update_audio = 'false', $drop_element_here = fa
$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([
Expand Down
85 changes: 65 additions & 20 deletions main/newscorm/learnpathItem.class.php
Expand Up @@ -4490,7 +4490,11 @@ public function getForumThread($lpCourseId, $lpSessionId = 0)
'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'
Expand All @@ -4512,27 +4516,68 @@ public function createForumTthread($currentForumId)
{
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;
}
}
38 changes: 38 additions & 0 deletions main/newscorm/lp_controller.php
Expand Up @@ -1340,6 +1340,44 @@ function(reponse){
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';
Expand Down

0 comments on commit 83de577

Please sign in to comment.