Associate LP with forums - refs BT#9892 #TMI

Angel Fernando Quiroz Campos 11 years ago
parent 5df4f28ca2
commit 314e2f7789
  1. 122
      main/forum/forumfunction.inc.php
  2. 27
      main/inc/ajax/lp.ajax.php
  3. 1
      main/lang/english/trad4all.inc.php
  4. 1
      main/lang/spanish/trad4all.inc.php
  5. 65
      main/newscorm/learnpath.class.php
  6. 73
      main/newscorm/learnpathItem.class.php
  7. 2
      main/newscorm/lp_add.php
  8. 27
      main/newscorm/lp_controller.php
  9. 32
      src/Chamilo/CoreBundle/Migrations/Schema/V110/Version20150603151200.php
  10. 29
      src/Chamilo/CourseBundle/Entity/CForumForum.php
  11. 29
      src/Chamilo/CourseBundle/Entity/CForumThread.php

@ -673,27 +673,32 @@ function store_forum($values, $courseInfo = array(), $returnId = false)
if (empty($_FILES['picture']['name'])) { if (empty($_FILES['picture']['name'])) {
$sql_image = " "; $sql_image = " ";
} else { } else {
$sql_image = " forum_image='".Database::escape_string($new_file_name)."', "; $sql_image = $new_file_name;
delete_forum_image($values['forum_id']); delete_forum_image($values['forum_id']);
} }
} }
// Storing after edition. // Storing after edition.
$sql = "UPDATE ".$table_forums." SET Database::update(
forum_title='".$clean_title."', $table_forums,
".$sql_image." [
forum_comment='".Database::escape_string(stripslashes($values['forum_comment']))."', 'forum_title' => $clean_title,
forum_category='".Database::escape_string(stripslashes($values['forum_category']))."', 'forum_image' => $new_file_name,
allow_anonymous='".Database::escape_string(isset($values['allow_anonymous_group']['allow_anonymous']) ? $values['allow_anonymous_group']['allow_anonymous'] : null)."', 'forum_comment' => stripslashes($values['forum_comment']),
allow_edit='".Database::escape_string($values['students_can_edit_group']['students_can_edit'])."', 'forum_category' => stripslashes($values['forum_category']),
approval_direct_post='".Database::escape_string(isset($values['approval_direct_group']['approval_direct']) ? $values['approval_direct_group']['approval_direct'] : null)."', 'allow_anonymous' => isset($values['allow_anonymous_group']['allow_anonymous']) ? $values['allow_anonymous_group']['allow_anonymous'] : null,
allow_attachments='".Database::escape_string(isset($values['allow_attachments_group']['allow_attachments']) ? $values['allow_attachments_group']['allow_attachments'] : null)."', 'allow_edit' => $values['students_can_edit_group']['students_can_edit'],
allow_new_threads='".Database::escape_string($values['allow_new_threads_group']['allow_new_threads'])."', 'approval_direct_post' => isset($values['approval_direct_group']['approval_direct']) ? $values['approval_direct_group']['approval_direct'] : null,
forum_group_public_private='".Database::escape_string($values['public_private_group_forum_group']['public_private_group_forum'])."', 'allow_attachments' => isset($values['allow_attachments_group']['allow_attachments']) ? $values['allow_attachments_group']['allow_attachments'] : null,
default_view='".Database::escape_string($values['default_view_type_group']['default_view_type'])."', 'allow_new_threads' => $values['allow_new_threads_group']['allow_new_threads'],
forum_of_group='".Database::escape_string($values['group_forum'])."' 'forum_group_public_private' => $values['public_private_group_forum_group']['public_private_group_forum'],
WHERE c_id = $course_id AND forum_id = ".intval($values['forum_id']).""; 'default_view' => $values['default_view_type_group']['default_view_type'],
Database::query($sql); 'forum_of_group' => $values['group_forum']
],
[
'c_id = ? AND forum_id = ?' => [$course_id, intval($values['forum_id'])]
]
);
api_item_property_update( api_item_property_update(
$courseInfo, $courseInfo,
@ -709,28 +714,30 @@ function store_forum($values, $courseInfo = array(), $returnId = false)
$sql_image = ''; $sql_image = '';
if ($image_moved) { if ($image_moved) {
$new_file_name = isset($new_file_name) ? $new_file_name : ''; $new_file_name = isset($new_file_name) ? $new_file_name : '';
$sql_image = "'".$new_file_name."', "; $sql_image = $new_file_name;
} }
$sql = "INSERT INTO ".$table_forums." (c_id, forum_title, forum_image, forum_comment, forum_category, allow_anonymous, allow_edit, approval_direct_post, allow_attachments, allow_new_threads, default_view, forum_of_group, forum_group_public_private, forum_order, session_id) $last_id = Database::insert(
VALUES ( $table_forums,
".$course_id.", [
'".$clean_title."', 'c_id' => $course_id,
".$sql_image." 'forum_title' => $clean_title,
'".Database::escape_string(isset($values['forum_comment']) ? $values['forum_comment'] : null)."', 'forum_image' => $sql_image,
'".Database::escape_string(isset($values['forum_category']) ? $values['forum_category'] : null)."', 'forum_comment' => isset($values['forum_comment']) ? $values['forum_comment'] : null,
'".Database::escape_string(isset($values['allow_anonymous_group']['allow_anonymous']) ? $values['allow_anonymous_group']['allow_anonymous'] : null)."', 'forum_category' => isset($values['forum_category']) ? $values['forum_category'] : null,
'".Database::escape_string(isset($values['students_can_edit_group']['students_can_edit']) ? $values['students_can_edit_group']['students_can_edit'] : null)."', 'allow_anonymous' => isset($values['allow_anonymous_group']['allow_anonymous']) ? $values['allow_anonymous_group']['allow_anonymous'] : null,
'".Database::escape_string(isset($values['approval_direct_group']['approval_direct']) ? $values['approval_direct_group']['approval_direct'] : null)."', 'allow_edit' => isset($values['students_can_edit_group']['students_can_edit']) ? $values['students_can_edit_group']['students_can_edit'] : null,
'".Database::escape_string(isset($values['allow_attachments_group']['allow_attachments']) ? $values['allow_attachments_group']['allow_attachments'] : null)."', 'approval_direct_post' => isset($values['approval_direct_group']['approval_direct']) ? $values['approval_direct_group']['approval_direct'] : null,
'".Database::escape_string(isset($values['allow_new_threads_group']['allow_new_threads']) ? $values['allow_new_threads_group']['allow_new_threads'] : null)."', 'allow_attachments' => isset($values['allow_attachments_group']['allow_attachments']) ? $values['allow_attachments_group']['allow_attachments'] : null,
'".Database::escape_string(isset($values['default_view_type_group']['default_view_type']) ? $values['default_view_type_group']['default_view_type'] : null)."', 'allow_new_threads' => isset($values['allow_new_threads_group']['allow_new_threads']) ? $values['allow_new_threads_group']['allow_new_threads'] : null,
'".Database::escape_string(isset($values['group_forum']) ? $values['group_forum'] : null)."', 'default_view' => isset($values['default_view_type_group']['default_view_type']) ? $values['default_view_type_group']['default_view_type'] : null,
'".Database::escape_string(isset($values['public_private_group_forum_group']['public_private_group_forum']) ? $values['public_private_group_forum_group']['public_private_group_forum'] : null)."', 'forum_of_group' => isset($values['group_forum']) ? $values['group_forum'] : null,
'".Database::escape_string(isset($new_max) ? $new_max : null)."', 'forum_group_public_private' => isset($values['public_private_group_forum_group']['public_private_group_forum']) ? $values['public_private_group_forum_group']['public_private_group_forum'] : null,
".intval($session_id).")"; 'forum_order' => isset($new_max) ? $new_max : null,
Database::query($sql); 'session_id' => $session_id,
$last_id = Database::insert_id(); 'lp_id' => isset($values['lp_id']) ? $values['lp_id'] : 0
]
);
if ($last_id > 0) { if ($last_id > 0) {
$sql = "UPDATE $table_forums SET forum_id = $last_id $sql = "UPDATE $table_forums SET forum_id = $last_id
@ -2313,7 +2320,8 @@ function store_thread($current_forum, $values, $courseInfo = array(), $showMessa
'thread_qualify_max' => $values['numeric_calification'], 'thread_qualify_max' => $values['numeric_calification'],
'thread_weight' => $values['weight_calification'], 'thread_weight' => $values['weight_calification'],
'thread_peer_qualify' => $values['thread_peer_qualify'], 'thread_peer_qualify' => $values['thread_peer_qualify'],
'session_id' => api_get_session_id() 'session_id' => api_get_session_id(),
'lp_item_id' => isset($values['lp_item_id']) ? intval($values['lp_item_id']) : 0
] ]
); );
@ -5555,3 +5563,43 @@ function getAttachmentIdsByPostId($postId, $courseId = null) {
} }
return $array; return $array;
} }
/**
* Check if the forum category exists looking for its title
* @param string $title The forum category title
* @param int $courseId The course ID
* @param int $sessionId Optional. The session ID
* @return boolean
*/
function getForumCategoryByTitle($title, $courseId, $sessionId = 0)
{
$forumCategoryTable = Database::get_course_table(TABLE_FORUM_CATEGORY);
$itemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
$fakeFrom = <<<SQL
$forumCategoryTable fc
INNER JOIN $itemProperty ip
ON (fc.cat_id = ip.ref AND fc.c_id = ip.c_id AND fc.session_id = ip.session_id)
SQL;
$resultData = Database::select(
'fc.*',
$fakeFrom,
[
'where' => [
'ip.visibility != ? AND ' => 2,
'ip.tool = ? AND ' => TOOL_FORUM_CATEGORY,
'fc.session_id = ? AND ' => $sessionId,
'fc.cat_title = ? AND ' => $title,
'fc.c_id = ?' => intval($courseId)
]
],
'first'
);
if (empty($resultData)) {
return false;
}
return $resultData;
}

@ -44,7 +44,32 @@ switch ($action) {
if ($_REQUEST['type'] == TOOL_QUIZ) { if ($_REQUEST['type'] == TOOL_QUIZ) {
$title = Exercise::format_title_variable($title); $title = Exercise::format_title_variable($title);
} }
echo $_SESSION['oLP']->add_item($_REQUEST['parent_id'], $_REQUEST['previous_id'], $_REQUEST['type'], $_REQUEST['id'], $title, null); $itemId = $_SESSION['oLP']->add_item(
$_REQUEST['parent_id'],
$_REQUEST['previous_id'],
$_REQUEST['type'],
$_REQUEST['id'],
$title,
null
);
if ($_REQUEST['type'] == 'document') {
$forum = $_SESSION['oLP']->getForum();
if (!empty($forum)) {
$lpItem = new learnpathItem($itemId);
$forumTheme = $lpItem->getForumThread(
$_SESSION['oLP']->lp_session_id,
$_SESSION['oLP']->course_int_id
);
if (empty($forumTheme)) {
$lpItem->createForumTthread($forum['forum_id']);
}
}
}
echo $itemId;
} }
} }
break; break;

@ -7357,4 +7357,5 @@ $LevelX = "Level %s";
$SeeCourse = "View course"; $SeeCourse = "View course";
$XPoints = "%s points"; $XPoints = "%s points";
$FromXUntilY = "From %s until %s"; $FromXUntilY = "From %s until %s";
$CreateForumForThisLearningPath = "Create forum for this learning path";
?> ?>

@ -7386,4 +7386,5 @@ $LevelX = "Nivel %s";
$SeeCourse = "Ver curso"; $SeeCourse = "Ver curso";
$XPoints = "%s puntos"; $XPoints = "%s puntos";
$FromXUntilY = "De %s a %s"; $FromXUntilY = "De %s a %s";
$CreateForumForThisLearningPath = "Crear foro para esta lección";
?> ?>

@ -10641,6 +10641,71 @@ EOD;
return $totalExercisesResult + $totalEvaluationResult; return $totalExercisesResult + $totalEvaluationResult;
} }
/**
* Get the forum for this learning path
* @return boolean
*/
public function getForum()
{
$forumTable = Database::get_course_table(TABLE_FORUM);
$itemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
$fakeFrom = <<<SQL
$forumTable f
INNER JOIN $itemProperty ip
ON (f.forum_id = ip.ref AND f.c_id = ip.c_id AND f.session_id = ip.session_id)
SQL;
$resultData = Database::select(
'f.*',
$fakeFrom,
[
'where' => [
'ip.visibility != ? AND ' => 2,
'ip.tool = ? AND ' => TOOL_FORUM,
'f.session_id = ? AND ' => $this->lp_session_id,
'f.c_id = ? AND ' => intval($this->course_int_id),
'f.lp_id = ?' => intval($this->lp_id)
]
],
'first'
);
if (empty($resultData)) {
return false;
}
return $resultData;
}
/**
* Create a forum for this learning path
* @param type $forumCategoryId
* @return boolean
*/
public function createForum($forumCategoryId)
{
require_once api_get_path(SYS_CODE_PATH) . '/forum/forumfunction.inc.php';
$forumId = store_forum(
[
'lp_id' => $this->lp_id,
'forum_title' => $this->name,
'forum_comment' => null,
'forum_category' => intval($forumCategoryId),
'students_can_edit_group' => ['students_can_edit' => 0],
'allow_new_threads_group' => ['allow_new_threads' => 0],
'default_view_type_group' => ['default_view_type' => 'flat'],
'group_forum' => 0,
'public_private_group_forum_group' => ['public_private_group_forum' => 'public']
],
[],
true
);
return $forumId > 0;
}
} }
if (!function_exists('trim_value')) { if (!function_exists('trim_value')) {

@ -4409,4 +4409,77 @@ class learnpathItem
{ {
$this->prerequisiteMinScore = $prerequisiteMinScore; $this->prerequisiteMinScore = $prerequisiteMinScore;
} }
/**
* Get the forum thread info
* @param int $lpCourseId The course ID from the learning path
* @param int $lpSessionId Optional. The session ID from the learning path
* @return boolean
*/
public function getForumThread($lpCourseId, $lpSessionId = 0)
{
$forumThreadTable = Database::get_course_table(TABLE_FORUM_THREAD);
$itemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
$fakeFrom = <<<SQL
$forumThreadTable ft
INNER JOIN $itemProperty ip
ON (ft.thread_id = ip.ref AND ft.c_id = ip.c_id AND ft.session_id = ip.session_id)
SQL;
$resultData = Database::select(
'ft.*',
$fakeFrom,
[
'where' => [
'ip.visibility != ? AND ' => 2,
'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)
]
],
'first'
);
if (empty($resultData)) {
return false;
}
return $resultData;
}
/**
* Create a forum thread for this learning path item
* @param int $currentForumId The forum ID to add the new thread
* @return boolean
*/
public function createForumTthread($currentForumId)
{
require_once api_get_path(SYS_CODE_PATH) . '/forum/forumfunction.inc.php';
$forumInfo = get_forum_information($currentForumId);
$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' => null,
'calification_notebook_title' => null,
'weight_calification' => 0.00,
'thread_peer_qualify' => 0,
'lp_item_id' => $this->db_id
],
[],
false
);
return $threadId > 0;
}
} }

@ -130,6 +130,8 @@ $form->addElement('html','<div id="end_date_div" style="display:none;">');
$form->addElement('DatePicker', 'expired_on', get_lang('ExpirationDate')); $form->addElement('DatePicker', 'expired_on', get_lang('ExpirationDate'));
$form->addElement('html','</div>'); $form->addElement('html','</div>');
$form->addCheckBox('create_forum', null, get_lang('CreateForumForThisLearningPath'));
$form->addElement('html','</div>'); $form->addElement('html','</div>');
$defaults['activate_start_date_check'] = 1; $defaults['activate_start_date_check'] = 1;

@ -565,6 +565,33 @@ switch ($action) {
$new_lp_id, $new_lp_id,
api_get_user_id() api_get_user_id()
); );
if (isset($_REQUEST['create_forum'])) {
require '../forum/forumfunction.inc.php';
$forumCategory = getForumCategoryByTitle(
get_lang('LearningPaths'),
$_SESSION['oLP']->course_int_id,
$_SESSION['oLP']->lp_session_id
);
if (empty($forumCategory)) {
$forumCategoryId = store_forumcategory(
[
'lp_id' => 0,
'forum_category_title' => get_lang('LearningPaths'),
'forum_category_comment' => null
],
[],
false
);
} else {
$forumCategoryId = $forumCategory['cat_id'];
}
$_SESSION['oLP']->createForum($forumCategoryId);
}
//require 'lp_build.php'; //require 'lp_build.php';
$url = api_get_self().'?action=add_item&type=step&lp_id='.intval($new_lp_id).'&'.api_get_cidreq(); $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($new_lp_id).'&'.api_get_cidreq();
header("Location: $url&isStudentView=false"); header("Location: $url&isStudentView=false");

@ -0,0 +1,32 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Migrations\Schema\V110;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
/**
* Session date changes
*/
class Version20150603151200 extends AbstractMigrationChamilo
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->addSql('ALTER TABLE c_forum_forum ADD lp_id INTEGER UNSIGNED NOT NULL');
$this->addSql('ALTER TABLE c_forum_thread ADD lp_item_id INTEGER UNSIGNED NOT NULL');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$this->addSql('ALTER TABLE c_forum_forum DROP lp_id');
$this->addSql('ALTER TABLE c_forum_thread DROP lp_item_id');
}
}

@ -176,6 +176,13 @@ class CForumForum
*/ */
private $endTime; private $endTime;
/**
* @var integer
*
* @ORM\Column(name="lp_id", type="integer", options={"unsigned":true})
*/
private $lpId;
/** /**
* Set forumTitle * Set forumTitle
* *
@ -681,4 +688,26 @@ class CForumForum
{ {
return $this->cId; return $this->cId;
} }
/**
* Set lpId
* @param integer $lpId
* @return \Chamilo\CourseBundle\Entity\CForumForum
*/
public function setLpId($lpId)
{
$this->lpId = $lpId;
return $this;
}
/**
* Get lpId
* @return integer
*/
public function getLpId()
{
return $this->lpId;
}
} }

@ -148,6 +148,13 @@ class CForumThread
*/ */
private $threadPeerQualify; private $threadPeerQualify;
/**
* @var integer
*
* @ORM\Column(name="lp_item_id", type="integer", options={"unsigned":true})
*/
private $lpItemId;
/** /**
* Constructor * Constructor
*/ */
@ -564,4 +571,26 @@ class CForumThread
{ {
return $this->cId; return $this->cId;
} }
/**
* Set lpItemId
* @param integer $lpItemId
* @return \Chamilo\CourseBundle\Entity\CForumThread
*/
public function setLpItemId($lpItemId)
{
$this->lpItemId = $lpItemId;
return $this;
}
/**
* Get lpId
* @return integer
*/
public function getLpItemId()
{
return $this->lpItemId;
}
} }

Loading…
Cancel
Save