Add LP category see BT#5763

1.10.x
Julio Montoya 10 years ago
parent 3f3dc24b02
commit eb859c335d
  1. 206
      main/newscorm/learnpath.class.php
  2. 37
      main/newscorm/learnpathList.class.php
  3. 5
      main/newscorm/learnpath_functions.inc.php
  4. 8
      main/newscorm/lp_add.php
  5. 113
      main/newscorm/lp_add_category.php
  6. 58
      main/newscorm/lp_controller.php
  7. 14
      main/newscorm/lp_edit.php
  8. 962
      main/newscorm/lp_list.php
  9. 30
      src/Chamilo/CoreBundle/Migrations/Schema/V110/Version20150527114220.php
  10. 26
      src/Chamilo/CourseBundle/Entity/CLp.php
  11. 123
      src/Chamilo/CourseBundle/Entity/CLpCategory.php

@ -1,6 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CLpCategory;
use ChamiloSession as Session;
/**
@ -73,6 +74,7 @@ class learnpath
public $ref = null;
public $course_int_id;
public $course_info = array();
public $categoryId;
/**
* Constructor.
@ -143,6 +145,7 @@ class learnpath
$this->created_on = $row['created_on'];
$this->modified_on = $row['modified_on'];
$this->ref = $row['ref'];
$this->categoryId = $row['category_id'];
if ($row['publicated_on'] != '0000-00-00 00:00:00') {
$this->publicated_on = $row['publicated_on'];
@ -708,7 +711,8 @@ class learnpath
$origin = 'zip',
$zipname = '',
$publicated_on = '',
$expired_on = ''
$expired_on = '',
$categoryId = 0
) {
global $charset;
$course_id = api_get_course_int_id();
@ -717,6 +721,7 @@ class learnpath
// Check lp_name doesn't exist, otherwise append something.
$i = 0;
$name = Database::escape_string($name);
$categoryId = intval($categoryId);
// Session id.
$session_id = api_get_session_id();
@ -782,8 +787,8 @@ class learnpath
$dsp = $row[0] + 1;
}
$sql = "INSERT INTO $tbl_lp (c_id, lp_type,name,description,path,default_view_mod, default_encoding,display_order,content_maker,content_local,js_lib,session_id, created_on, publicated_on, expired_on)
VALUES ($course_id, $type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."')";
$sql = "INSERT INTO $tbl_lp (c_id, lp_type,name,description,path,default_view_mod, default_encoding,display_order,content_maker,content_local,js_lib,session_id, created_on, publicated_on, expired_on, category_id)
VALUES ($course_id, $type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."', $categoryId)";
Database::query($sql);
$id = Database :: insert_id();
if ($id > 0) {
@ -10022,6 +10027,179 @@ EOD;
}
}
/**
* @param array $params
*/
public static function createCategory($params)
{
$em = Database::getManager();
$item = new CLpCategory();
$item->setName($params['name']);
$item->setCId($params['c_id']);
$em->persist($item);
$em->flush();
}
/**
* @param array $params
*/
public static function updateCategory($params)
{
$em = Database::getManager();
$item = $em->find('ChamiloCourseBundle:CLpCategory', $params['id']);
if ($item) {
$item->setName($params['name']);
$item->setCId($params['c_id']);
$em->persist($item);
$em->flush();
}
}
/**
* @param int $id
*/
public static function moveUpCategory($id)
{
$em = Database::getManager();
$item = $em->find('ChamiloCourseBundle:CLpCategory', $id);
if ($item) {
$position = $item->getPosition() - 1;
$item->setPosition($position);
$em->persist($item);
$em->flush();
}
}
/**
* @param int $id
*/
public static function moveDownCategory($id)
{
$em = Database::getManager();
$item = $em->find('ChamiloCourseBundle:CLpCategory', $id);
if ($item) {
$position = $item->getPosition() + 1;
$item->setPosition($position);
$em->persist($item);
$em->flush();
}
}
/**
* @param int $courseId
* @return int|mixed
*/
public static function getCountCategories($courseId)
{
if (empty($course_id)) {
return 0;
}
$em = Database::getManager();
$query = $em->createQuery('SELECT COUNT(u.id) FROM ChamiloCourseBundle:CLpCategory u WHERE u.cId = :id');
$query->setParameter('id', $courseId);
return $query->getSingleScalarResult();
}
/**
* @param int $courseId
*
* @return mixed
*/
public static function getCategories($courseId)
{
$em = Database::getManager();
//Default behaviour
/*$items = $em->getRepository('ChamiloCourseBundle:CLpCategory')->findBy(
array('cId' => $course_id),
array('name' => 'ASC')
);*/
//Using doctrine extensions
$items = $em->getRepository('ChamiloCourseBundle:CLpCategory')->getBySortableGroupsQuery(
array('cId' => $courseId)
)->getResult();
return $items;
}
/**
* @param int $id
*
* @return mixed
*/
public static function getCategory($id)
{
$em = Database::getManager();
$item = $em->find('ChamiloCourseBundle:CLpCategory', $id);
return $item;
}
/**
* @param int $courseId
* @return array
*/
public static function getCategoryByCourse($courseId)
{
$em = Database::getManager();
$items = $em->getRepository('ChamiloCourseBundle:CLpCategory')->findBy(array('cId' => $courseId));
return $items;
}
/**
* @param int $id
*
* @return mixed
*/
public static function deleteCategory($id)
{
$em = Database::getManager();
$item = $em->find('ChamiloCourseBundle:CLpCategory', $id);
if ($item) {
$courseId = $item->getCId();
$query = $em->createQuery('SELECT u FROM ChamiloCourseBundle:CLp u WHERE u.cId = :id AND u.categoryId = :catId');
$query->setParameter('id', $courseId);
$query->setParameter('catId', $item->getId());
$lps = $query->getResult();
// Setting category = 0.
if ($lps) {
foreach ($lps as $lpItem) {
$lpItem->setCategoryId(0);
}
}
// Removing category.
$em->remove($item);
$em->flush();
}
}
/**
* @param int $courseId
* @param bool $addSelectOption
*
* @return mixed
*/
static function getCategoryFromCourseIntoSelect($courseId, $addSelectOption = false)
{
$items = self::getCategoryByCourse($courseId);
$cats = array();
if ($addSelectOption) {
$cats = array(get_lang('SelectACategory'));
}
if (!empty($items)) {
foreach ($items as $cat) {
$cats[$cat->getId()] = $cat->getName();
}
}
return $cats;
}
/**
* Return the scorm item type object with spaces replaced with _
* The return result is use to build a css classname like scorm_type_$return
@ -10063,6 +10241,28 @@ EOD;
return false;
}
/**
* @return int
*/
public function getCategoryId()
{
return $this->categoryId;
}
public function setCategoryId($categoryId)
{
$this->categoryId = $categoryId;
$courseId = api_get_course_int_id();
$lp_table = Database :: get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $lp_table SET category_id = '".intval($categoryId)."'
WHERE c_id = ".$courseId." AND id = '$lp_id'";
Database::query($sql);
return true;
}
}
if (!function_exists('trim_value')) {

@ -26,15 +26,23 @@ class LearnpathList
* This method is the constructor for the learnpathList. It gets a list of available learning paths from
* the database and creates the learnpath objects. This list depends on the user that is connected
* (only displays) items if he has enough permissions to view them.
* @param integer $user_id
* @param string $course_code Optional course code (otherwise we use api_get_course_id())
* @param int $session_id Optional session id (otherwise we use api_get_session_id())
* @param string $order_by
* @param string $check_publication_dates
* @param integer $user_id
* @param string $course_code Optional course code (otherwise we use api_get_course_id())
* @param int $session_id Optional session id (otherwise we use api_get_session_id())
* @param string $order_by
* @param string $check_publication_dates
* @param int $categoryId
*
* @return void
*/
public function __construct($user_id, $course_code = '', $session_id = null, $order_by = null, $check_publication_dates = false)
{
public function __construct(
$user_id,
$course_code = '',
$session_id = null,
$order_by = null,
$check_publication_dates = false,
$categoryId = null
) {
$course_info = api_get_course_info($course_code);
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
@ -74,8 +82,21 @@ class LearnpathList
";
}
$categoryFilter = '';
if (!is_null($categoryId) && is_numeric($categoryId)) {
$categoryId = intval($categoryId);
$categoryFilter = " AND category_id = $categoryId";
}
$sql = "SELECT * FROM $lp_table
WHERE c_id = $course_id $time_conditions $condition_session $order";
WHERE
c_id = $course_id
$time_conditions
$condition_session
$categoryFilter
$order
";
$res = Database::query($sql);
$names = array();

@ -24,7 +24,7 @@
* @todo remove code duplication
*/
use \ChamiloSession as Session;
use ChamiloSession as Session;
/**
* This function deletes an item
@ -547,7 +547,8 @@ function display_learnpath_chapters($parent_item_id = 0, $tree = array (), $leve
* @return void
* @todo eliminate all global $lang declarations, use get_lang, improve structure.
*/
function display_learnpath_items($categoryid) {
function display_learnpath_items($categoryid)
{
global $xml_output;
global $lg_prerequisites, $lg_move_down, $lg_move_up, $lg_edit_learnpath_item, $lg_delete_learnpath_item, $learnpath_id, $lg_add_prereq, $lg_prereq_deleted_error, $lg_pre_short, $langThisItem;
$course_id = api_get_course_int_id();

@ -115,7 +115,13 @@ $form->addElement('hidden', 'action', 'add_lp');
$form->addButtonAdvancedSettings('advanced_params');
$form->addElement('html', '<div id="advanced_params_options" style="display:none">');
//Start date
$items = learnpath::getCategoryFromCourseIntoSelect(api_get_course_int_id());
if (!empty($items)) {
$items = array_merge(array(get_lang('SelectACategory')), $items);
}
$form->addElement('select', 'category_id', get_lang('Category'), $items);
// Start date
$form->addElement('checkbox', 'activate_start_date_check', null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()'));
$form->addElement('html','<div id="start_date_div" style="display:block;">');
$form->addElement('DatePicker', 'publicated_on', get_lang('PublicationDate'));

@ -0,0 +1,113 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @author Julio Montoya <gugli100@gmail.com> Adding formvalidator support
*
* @package chamilo.learnpath
*/
$this_section = SECTION_COURSES;
api_protect_course_script();
require 'learnpath_functions.inc.php';
require 'resourcelinker.inc.php';
$language_file = 'learnpath';
/* Header and action code */
$currentstyle = api_get_setting('stylesheets');
$htmlHeadXtra[] = '<script>
function setFocus(){
$("#learnpath_title").focus();
}
$(document).ready(function () {
setFocus();
});
function activate_start_date() {
if(document.getElementById(\'start_date_div\').style.display == \'none\') {
document.getElementById(\'start_date_div\').style.display = \'block\';
} else {
document.getElementById(\'start_date_div\').style.display = \'none\';
}
}
function activate_end_date() {
if(document.getElementById(\'end_date_div\').style.display == \'none\') {
document.getElementById(\'end_date_div\').style.display = \'block\';
} else {
document.getElementById(\'end_date_div\').style.display = \'none\';
}
}
</script>';
/* Constants and variables */
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
$learnpath_id = isset($_REQUEST['lp_id']) ? $_REQUEST['lp_id'] : null;
/* MAIN CODE */
if ((!$is_allowed_to_edit) || ($isStudentView)) {
//error_log('New LP - User not authorized in lp_add.php');
header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
exit;
}
$interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
$form = new FormValidator('lp_add_category', 'post', 'lp_controller.php');
// Form title
$form->addElement('header', null, get_lang('AddLPCategory'));
// Title
$form->addElement('text', 'name', api_ucfirst(get_lang('Name')), array('class' => 'span6'));
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('hidden', 'action', 'add_lp_category');
$form->addElement('hidden', 'c_id', api_get_course_int_id());
$form->addElement('hidden', 'id', 0);
$form->addElement('style_submit_button', 'Submit', get_lang('Save'),'class="save"');
if ($form->validate()) {
$values = $form->getSubmitValues();
if (!empty($values['id'])) {
learnpath::updateCategory($values);
$url = api_get_self().'?action=list&'.api_get_cidreq();
header('Location: '.$url);
exit;
} else {
learnpath::createCategory($values);
$url = api_get_self().'?action=list&'.api_get_cidreq();
header('Location: '.$url);
exit;
}
} else {
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
if ($id) {
$item = learnpath::getCategory($id);
$defaults = array(
'id' => $item->getId(),
'name' => $item->getName()
);
$form->setDefaults($defaults);
}
}
Display::display_header(get_lang('LearnpathAddLearnpath'), 'Path');
echo '<div class="actions">';
echo '<a href="lp_controller.php?'.api_get_cidreq().'">'.
Display::return_icon('back.png', get_lang('ReturnToLearningPaths'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
$form->display();
Display::display_footer();

@ -483,6 +483,39 @@ switch ($action) {
}
}
break;
case 'add_lp_category':
if (!$is_allowed_to_edit) {
api_not_allowed(true);
}
require 'lp_add_category.php';
break;
case 'move_up_category':
if (!$is_allowed_to_edit) {
api_not_allowed(true);
}
if (isset($_REQUEST['id'])) {
learnpath::moveUpCategory($_REQUEST['id']);
}
require 'lp_list.php';
break;
case 'move_down_category':
if (!$is_allowed_to_edit) {
api_not_allowed(true);
}
if (isset($_REQUEST['id'])) {
learnpath::moveDownCategory($_REQUEST['id']);
}
require 'lp_list.php';
break;
case 'delete_lp_category':
if (!$is_allowed_to_edit) {
api_not_allowed(true);
}
if (isset($_REQUEST['id'])) {
learnpath::deleteCategory($_REQUEST['id']);
}
require 'lp_list.php';
break;
case 'add_lp':
if (!$is_allowed_to_edit) {
api_not_allowed(true);
@ -497,13 +530,17 @@ switch ($action) {
} else {
$_SESSION['post_time'] = $_REQUEST['post_time'];
if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
if (isset($_REQUEST['activate_start_date_check']) &&
$_REQUEST['activate_start_date_check'] == 1
) {
$publicated_on = $_REQUEST['publicated_on'];
} else {
$publicated_on = null;
}
if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
if (isset($_REQUEST['activate_end_date_check']) &&
$_REQUEST['activate_end_date_check'] == 1
) {
$expired_on = $_REQUEST['expired_on'];
} else {
$expired_on = null;
@ -517,12 +554,17 @@ switch ($action) {
'manual',
'',
$publicated_on,
$expired_on
$expired_on,
$_REQUEST['category_id']
);
if (is_numeric($new_lp_id)) {
// TODO: Maybe create a first module directly to avoid bugging the user with useless queries
$_SESSION['oLP'] = new learnpath(api_get_course_id(),$new_lp_id,api_get_user_id());
$_SESSION['oLP'] = new learnpath(
api_get_course_id(),
$new_lp_id,
api_get_user_id()
);
//require 'lp_build.php';
$url = api_get_self().'?action=add_item&type=step&lp_id='.intval($new_lp_id).'&'.api_get_cidreq();
header("Location: $url&isStudentView=false");
@ -884,18 +926,16 @@ switch ($action) {
if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
$publicated_on = $_REQUEST['publicated_on'];
$publicated_on = $publicated_on['Y'].'-'.$publicated_on['F'].'-'.$publicated_on['d'].' '.$publicated_on['H'].':'.$publicated_on['i'].':00';
} else {
$publicated_on = null;
}
if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
$expired_on = $_REQUEST['expired_on'];
$expired_on = $expired_on['Y'].'-'.$expired_on['F'].'-'.$expired_on['d'].' '.$expired_on['H'].':'.$expired_on['i'].':00';
$expired_on = $_REQUEST['expired_on'];
} else {
$expired_on = null;
$expired_on = null;
}
$_SESSION['oLP']->setCategoryId($_REQUEST['category_id']);
$_SESSION['oLP']->set_modified_on();
$_SESSION['oLP']->set_publicated_on($publicated_on);
$_SESSION['oLP']->set_expired_on($expired_on);

@ -65,6 +65,9 @@ $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('hidden', 'lp_encoding');
$items = learnpath::getCategoryFromCourseIntoSelect(api_get_course_int_id(), true);
$form->addElement('select', 'category_id', get_lang('Category'), $items);
// Origin
/*
$origin_select = $form->addElement('select', 'lp_maker', get_lang('Origin'));
@ -136,13 +139,14 @@ if (api_get_setting('search_enabled') === 'true') {
}
}
$defaults['lp_encoding'] = Security::remove_XSS($_SESSION['oLP']->encoding);
$defaults['lp_name'] = Security::remove_XSS($_SESSION['oLP']->get_name());
$defaults['lp_author'] = Security::remove_XSS($_SESSION['oLP']->get_author());
$defaults['lp_encoding'] = Security::remove_XSS($_SESSION['oLP']->encoding);
$defaults['lp_name'] = Security::remove_XSS($_SESSION['oLP']->get_name());
$defaults['lp_author'] = Security::remove_XSS($_SESSION['oLP']->get_author());
$defaults['hide_toc_frame'] = Security::remove_XSS($_SESSION['oLP']->get_hide_toc_frame());
$defaults['category_id'] = intval($_SESSION['oLP']->getCategoryId());
$expired_on = $_SESSION['oLP'] ->expired_on;
$publicated_on = $_SESSION['oLP'] ->publicated_on;
$expired_on = $_SESSION['oLP']->expired_on;
$publicated_on = $_SESSION['oLP']->publicated_on;
// Prerequisites
$form->addElement('html','<div class="form-group">');

File diff suppressed because it is too large Load Diff

@ -0,0 +1,30 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Migrations\Schema\V110;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20150527114220 extends AbstractMigrationChamilo
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->addSql('CREATE TABLE c_lp_category (iid INT AUTO_INCREMENT NOT NULL, c_id INT NOT NULL, name VARCHAR(255) NOT NULL, position INT NOT NULL, PRIMARY KEY(iid)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
$this->addSql('ALTER TABLE c_lp ADD category_id INT NOT NULL DEFAULT 0');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$this->addSql('DROP TABLE c_lp_category');
$this->addSql('ALTER TABLE c_lp DROP category_id');
}
}

@ -204,6 +204,13 @@ class CLp
*/
private $autolunch;
/**
* @var integer
*
* @ORM\Column(name="category_id", type="integer", precision=0, scale=0, nullable=false, unique=false)
*/
private $categoryId;
/**
* @var \DateTime
*
@ -935,4 +942,23 @@ class CLp
{
return $this->cId;
}
/**
* @return int
*/
public function getCategoryId()
{
return $this->categoryId;
}
/**
* @param int $categoryId
* @return CLp
*/
public function setCategoryId($categoryId)
{
$this->categoryId = $categoryId;
return $this;
}
}

@ -0,0 +1,123 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CourseBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* CLpCategory
*
* @ORM\Table(name="c_lp_category")
* @ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
*/
class CLpCategory
{
/**
* @var integer
*
* @ORM\Column(name="iid", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $iid;
/**
* @Gedmo\SortableGroup
* @ORM\Column(name="c_id", type="integer")
*/
private $cId;
/**
* @var string
*
* @ORM\Column(name="name")
*/
private $name;
/**
* @Gedmo\SortablePosition
* @ORM\Column(name="position", type="integer")
*/
private $position;
/**
* Set cId
*
* @param integer $cId
* @return CLpCategory
*/
public function setCId($cId)
{
$this->cId = $cId;
return $this;
}
/**
* Get cId
*
* @return integer
*/
public function getCId()
{
return $this->cId;
}
/**
* Set id
*
* @param integer $id
* @return CLpCategory
*/
public function setId($id)
{
$this->iid = $id;
return $this;
}
/**
* Get blogId
*
* @return integer
*/
public function getId()
{
return $this->iid;
}
/**
* Set category name
*
* @param string $blogName
*
* @return CLpCategory
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get category name
*
* @return string
*/
public function getName()
{
return $this->name;
}
public function setPosition($position)
{
$this->position = $position;
}
public function getPosition()
{
return $this->position;
}
}
Loading…
Cancel
Save