Add subscribe users/group to a LP see BT#5765

1.10.x
Julio Montoya 11 years ago
parent d8539af9ea
commit 53e2b02659
  1. 47
      main/inc/lib/api.lib.php
  2. 137
      main/inc/lib/groupmanager.lib.php
  3. 47
      main/install/database.sql
  4. 81
      main/newscorm/learnpath.class.php
  5. 4
      main/newscorm/learnpathList.class.php
  6. 1
      main/newscorm/lp_controller.php
  7. 5
      main/newscorm/lp_edit.php
  8. 74
      main/newscorm/lp_list.php
  9. 170
      main/newscorm/lp_subscribe_users.php
  10. 49
      main/template/default/learnpath/subscribe_users.tpl
  11. 6
      main/user/user.php
  12. 2
      src/Chamilo/CoreBundle/Entity/Course.php
  13. 2
      src/Chamilo/CoreBundle/Entity/CourseRelUser.php
  14. 3
      src/Chamilo/CoreBundle/Entity/Repository/CourseRepository.php
  15. 326
      src/Chamilo/CoreBundle/Entity/Repository/ItemPropertyRepository.php
  16. 2
      src/Chamilo/CoreBundle/Entity/UsergroupRelUser.php
  17. 25
      src/Chamilo/CoreBundle/Migrations/Schema/V110/Version20150603181728.php
  18. 239
      src/Chamilo/CourseBundle/Entity/CItemProperty.php
  19. 6
      src/Chamilo/UserBundle/Entity/User.php

@ -3451,8 +3451,15 @@ function api_get_datetime($time = null) {
* @param int The session ID (optional)
* @return int -1 on error, 0 if invisible, 1 if visible
*/
function api_get_item_visibility($_course, $tool, $id, $session = 0)
{
function api_get_item_visibility(
$_course,
$tool,
$id,
$session = 0,
$user_id = null,
$type = null,
$group_id = null
) {
if (!is_array($_course) || count($_course) == 0 || empty($tool) || empty($id)) {
return -1;
}
@ -3462,13 +3469,33 @@ function api_get_item_visibility($_course, $tool, $id, $session = 0)
$session = (int) $session;
$TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$course_id = intval($_course['real_id']);
$userCondition = '';
if (!empty($user_id)) {
$user_id = intval($user_id);
$userCondition = " AND to_user_id = $user_id ";
}
$typeCondition = '';
if (!empty($type)) {
$type = Database::escape_string($type);
$typeCondition = " AND lastedit_type = '$type' ";
}
$groupCondition = '';
if (!empty($group_id)) {
$group_id = intval($group_id);
$groupCondition = " AND to_group_id = '$group_id' ";
}
$sql = "SELECT visibility
FROM $TABLE_ITEMPROPERTY
WHERE
c_id = $course_id AND
tool = '$tool' AND
ref = $id AND
(session_id = $session OR session_id = 0)
(session_id = $session OR session_id = 0 OR session_id IS NULL)
$userCondition $typeCondition $groupCondition
ORDER BY session_id DESC, lastedit_date DESC
LIMIT 1";
@ -3567,8 +3594,8 @@ function api_item_property_update(
$user_id,
$to_group_id = 0,
$to_user_id = null,
$start_visible = 0,
$end_visible = 0,
$start_visible = '',
$end_visible = '',
$session_id = 0
) {
if (empty($_course)) {
@ -3591,8 +3618,6 @@ function api_item_property_update(
$to_user_id = intval($to_user_id);
$start_visible = Database::escape_string($start_visible);
$end_visible = Database::escape_string($end_visible);
$start_visible = $start_visible == 0 ? '0000-00-00 00:00:00' : $start_visible;
$end_visible = $end_visible == 0 ? '0000-00-00 00:00:00' : $end_visible;
$to_filter = '';
$time = api_get_utc_datetime();
@ -3675,7 +3700,7 @@ function api_item_property_update(
WHERE $filter";
$result = Database::query($sql);
} else {
$sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id,$to_field, visibility, start_visible, end_visible, session_id)
$sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id, $to_field, visibility, start_visible, end_visible, session_id)
VALUES ($course_id, '$tool','$item_id','$time', '$user_id', '$time', '$lastedit_type','$user_id', '$to_value', '$visibility', '$start_visible','$end_visible', '$session_id')";
$result = Database::query($sql);
@ -3716,7 +3741,7 @@ function api_item_property_update(
WHERE $filter";
$result = Database::query($sql);
} else {
$sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id,$to_field, visibility, start_visible, end_visible, session_id)
$sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id, $to_field, visibility, start_visible, end_visible, session_id)
VALUES ($course_id, '$tool', '$item_id', '$time', '$user_id', '$time', '$lastedit_type', '$user_id', '$to_value', '$visibility', '$start_visible', '$end_visible', '$session_id')";
$result = Database::query($sql);
@ -3792,8 +3817,10 @@ function api_item_property_update(
// Insert if no entries are found (can only happen in case of $lastedit_type switch is 'default').
if (Database::affected_rows($result) == 0) {
$sessionCondition = empty($session_id) ? "NULL" : "'$session_id'";
$toValueCondition = empty($to_value) ? "NULL" : "'$to_value'";
$sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool,ref,insert_date,insert_user_id,lastedit_date,lastedit_type, lastedit_user_id, $to_field, visibility, start_visible, end_visible, session_id)
VALUES ($course_id, '$tool', '$item_id', '$time', '$user_id', '$time', '$lastedit_type', '$user_id', '$to_value', '$visibility', '$start_visible', '$end_visible', '$session_id')";
VALUES ($course_id, '$tool', '$item_id', '$time', '$user_id', '$time', '$lastedit_type', '$user_id', $toValueCondition, '$visibility', '$start_visible', '$end_visible', $sessionCondition)";
$res = Database::query($sql);
if (!$res) {
$id = Database::insert_id();

@ -22,7 +22,7 @@ class GroupManager
/**
* infinite
*/
const INFINITE = 99999;
const INFINITE = 99999;
/**
* No limit on the number of users in a group
*/
@ -54,7 +54,7 @@ class GroupManager
/**
*
*/
private function __construct()
public function __construct()
{
}
@ -161,19 +161,40 @@ class GroupManager
$_course = api_get_course_info();
$session_id = api_get_session_id();
$course_id = $_course['real_id'];
$currentCourseRepository = $_course['path'];
$category = self :: get_category($category_id);
$places = intval($places);
if ($places == 0) {
//if the amount of users per group is not filled in, use the setting from the category
$places = $category['max_student'];
} else {
if ($places > $category['max_student'] && $category['max_student'] != 0) {
if ($category) {
if ($places == 0) {
//if the amount of users per group is not filled in, use the setting from the category
$places = $category['max_student'];
} else {
if ($places > $category['max_student'] && $category['max_student'] != 0) {
$places = $category['max_student'];
}
}
$docState = $category['doc_state'];
$calendarState = $category['calendar_state'];
$workState = $category['work_state'];
$anonuncementState = $category['announcements_state'];
$forumState = $category['forum_state'];
$wikiState = $category['wiki_state'];
$chatState = $category['chat_state'];
$selfRegAllowed = $category['self_reg_allowed'];
$selfUnregAllwoed = $category['self_unreg_allowed'];
} else {
$docState = self::TOOL_PRIVATE;
$calendarState = self::TOOL_PRIVATE;
$workState = self::TOOL_PRIVATE;
$anonuncementState = self::TOOL_PRIVATE;
$forumState = self::TOOL_PRIVATE;
$wikiState = self::TOOL_PRIVATE;
$chatState = self::TOOL_PRIVATE;
$selfRegAllowed = 0;
$selfUnregAllwoed = 0;
}
$table_group = Database :: get_course_table(TABLE_GROUP);
@ -181,16 +202,16 @@ class GroupManager
c_id = $course_id ,
category_id='".Database::escape_string($category_id)."',
max_student = '".$places."',
doc_state = '".$category['doc_state']."',
calendar_state = '".$category['calendar_state']."',
work_state = '".$category['work_state']."',
announcements_state = '".$category['announcements_state']."',
forum_state = '".$category['forum_state']."',
wiki_state = '".$category['wiki_state']."',
chat_state = '".$category['chat_state']."',
self_registration_allowed = '".$category['self_reg_allowed']."',
self_unregistration_allowed = '".$category['self_unreg_allowed']."',
session_id='".Database::escape_string($session_id)."'";
doc_state = '".$docState."',
calendar_state = '".$calendarState."',
work_state = '".$workState."',
announcements_state = '".$anonuncementState."',
forum_state = '".$forumState."',
wiki_state = '".$wikiState."',
chat_state = '".$chatState."',
self_registration_allowed = '".$selfRegAllowed."',
self_unregistration_allowed = '".$selfUnregAllwoed."',
session_id='".intval($session_id)."'";
Database::query($sql);
$lastId = Database::insert_id();
@ -225,7 +246,7 @@ class GroupManager
Database::query($sql);
// create a forum if needed
if ($category['forum_state'] >= 0) {
if ($forumState >= 0) {
require_once api_get_path(SYS_CODE_PATH).'forum/forumconfig.inc.php';
require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
@ -254,11 +275,11 @@ class GroupManager
$values['allow_new_threads_group']['allow_new_threads'] = 1;
$values['default_view_type_group']['default_view_type'] = api_get_setting('default_forum_view');
$values['group_forum'] = $lastId;
if ($category['forum_state'] == '1') {
if ($forumState == '1') {
$values['public_private_group_forum_group']['public_private_group_forum']='public';
} elseif ($category['forum_state'] == '2') {
} elseif ($forumState == '2') {
$values['public_private_group_forum_group']['public_private_group_forum']='private';
} elseif ($category['forum_state'] == '0') {
} elseif ($forumState == '0') {
$values['public_private_group_forum_group']['public_private_group_forum']='unavailable';
}
store_forum($values);
@ -378,17 +399,18 @@ class GroupManager
}
// Unsubscribe all users
self :: unsubscribe_all_users($group_ids);
self ::unsubscribe_all_tutors($group_ids);
self::unsubscribe_all_users($group_ids);
self::unsubscribe_all_tutors($group_ids);
$sql = "SELECT id, secret_directory, session_id FROM $group_table
$sql = "SELECT id, secret_directory, session_id
FROM $group_table
WHERE c_id = $course_id AND id IN (".implode(' , ', $group_ids).")";
$db_result = Database::query($sql);
while ($group = Database::fetch_object($db_result)) {
// move group-documents to garbage
$source_directory = api_get_path(SYS_COURSE_PATH).$course_info['path']."/document".$group->secret_directory;
//File to renamed
// File to renamed
$destination_dir = api_get_path(SYS_COURSE_PATH).$course_info['path']."/document".$group->secret_directory.'_DELETED_'.$group->id;
if (!empty($group->secret_directory)) {
@ -407,15 +429,21 @@ class GroupManager
}
}
$sql = "DELETE FROM ".$forum_table."
WHERE c_id = $course_id AND forum_of_group IN ('".implode("' , '", $group_ids)."')";
$result = Database::query($sql);
// Delete item properties of this group.
$itemPropertyTable = Database::get_course_table(TABLE_ITEM_PROPERTY);
$sql = "DELETE FROM ".$itemPropertyTable."
WHERE c_id = $course_id AND to_group_id IN ('".implode("' , '", $group_ids)."')";
$result = Database::query($sql);
// delete the groups
$sql = "DELETE FROM ".$group_table."
WHERE c_id = $course_id AND id IN ('".implode("' , '", $group_ids)."')";
Database::query($sql);
$sql = "DELETE FROM ".$forum_table."
WHERE c_id = $course_id AND forum_of_group IN ('".implode("' , '", $group_ids)."')";
$result = Database::query($sql);
return Database::affected_rows($result);
}
@ -494,6 +522,7 @@ class GroupManager
if (Database::num_rows($res)) {
$group = Database::fetch_array($res, 'ASSOC');
}
return $group;
}
@ -521,6 +550,7 @@ class GroupManager
}
$sql .= " ORDER BY name";
$result = Database::query($sql);
return Database::store_result($result, 'ASSOC');
}
@ -646,8 +676,9 @@ class GroupManager
if (empty($id)) {
return array();
}
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$course_id = $course_info['real_id'];
$id = intval($id);
$table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY);
$sql = "SELECT * FROM $table_group_cat
@ -802,19 +833,15 @@ class GroupManager
max_student = '".Database::escape_string($maximum_number_of_students)."' ";
Database::query($sql);
$categoryId = Database::insert_id();
if ($categoryId) {
// @todo check if this code do something ... virtual course category?
/*if ($categoryId == self::VIRTUAL_COURSE_CATEGORY) {
$sql = "UPDATE ".$table_group_category." SET id = ". ($categoryId +1)."
WHERE c_id = $course_id AND id = $categoryId";
$sql = "UPDATE $table_group_category SET id = iid
WHERE iid = $categoryId";
Database::query($sql);
$categoryId = $categoryId +1;
}*/
$sql = "UPDATE $table_group_category SET id = iid WHERE iid = $categoryId";
Database::query($sql);
return $categoryId;
}
return $categoryId;
return false;
}
/**
@ -920,6 +947,7 @@ class GroupManager
$sql .= ' GROUP BY gu.user_id ORDER BY current_max DESC LIMIT 1';
$res = Database::query($sql);
$obj = Database::fetch_object($res);
return $obj->current_max;
}
@ -1386,14 +1414,17 @@ class GroupManager
*/
public static function can_user_subscribe($user_id, $group_id)
{
$category = self :: get_category_from_group($group_id);
$result = !self :: is_subscribed($user_id, $group_id);
$result &= (self :: number_of_students($group_id) < self :: maximum_number_of_students($group_id));
if ($category['groups_per_user'] == self::GROUP_PER_MEMBER_NO_LIMIT) {
$category['groups_per_user'] = self::INFINITE;
$category = self::get_category_from_group($group_id);
$result = !self:: is_subscribed($user_id, $group_id);
$result = self :: number_of_students($group_id) < self :: maximum_number_of_students($group_id);
if ($category) {
if ($category['groups_per_user'] == self::GROUP_PER_MEMBER_NO_LIMIT) {
$category['groups_per_user'] = self::INFINITE;
}
$result = (self::user_in_number_of_groups($user_id, $category['id']) < $category['groups_per_user']);
}
$result &= (self :: user_in_number_of_groups($user_id, $category['id']) < $category['groups_per_user']);
$result &= !self :: is_tutor_of_group($user_id, $group_id);
$result = !self::is_tutor_of_group($user_id, $group_id);
return $result;
}
@ -1408,6 +1439,7 @@ class GroupManager
public static function can_user_unsubscribe($user_id, $group_id)
{
$result = self :: is_subscribed($user_id, $group_id);
return $result;
}
@ -2053,7 +2085,7 @@ class GroupManager
$table_group = Database::get_course_table(TABLE_GROUP);
$user_id = intval($user_id);
$course_id = api_get_course_int_id();
$sql = "SELECT DISTINCT name
$sql = "SELECT DISTINCT g.*
FROM $table_group g
LEFT JOIN $table_group_user gu
ON (gu.group_id = g.id AND g.c_id = gu.c_id)
@ -2064,9 +2096,10 @@ class GroupManager
(gu.user_id = $user_id OR tu.user_id = $user_id) ";
$res = Database::query($sql);
$groups = array();
while ($group = Database::fetch_array($res)) {
$groups[] = $group['name'];
while ($group = Database::fetch_array($res, 'ASSOC')) {
$groups[] = $group;
}
return $groups;
}

@ -317,7 +317,6 @@ CREATE TABLE IF NOT EXISTS course_rel_user (
user_id int unsigned NOT NULL default '0',
status tinyint NOT NULL default '5',
role varchar(60) default NULL,
group_id int NOT NULL default '0',
tutor_id int unsigned NOT NULL default '0',
sort int default NULL,
user_course_cat int default '0',
@ -2567,29 +2566,29 @@ CREATE TABLE IF NOT EXISTS group_rel_tag (
ALTER TABLE group_rel_tag ADD INDEX ( group_id );
ALTER TABLE group_rel_tag ADD INDEX ( tag_id );
DROP TABLE IF EXISTS group_rel_user;
CREATE TABLE IF NOT EXISTS group_rel_user (
id int NOT NULL AUTO_INCREMENT,
group_id int NOT NULL,
user_id int NOT NULL,
relation_type int NOT NULL,
PRIMARY KEY (id)
);
ALTER TABLE group_rel_user ADD INDEX ( group_id );
ALTER TABLE group_rel_user ADD INDEX ( user_id );
ALTER TABLE group_rel_user ADD INDEX ( relation_type );
DROP TABLE IF EXISTS group_rel_group;
CREATE TABLE IF NOT EXISTS group_rel_group (
id int NOT NULL AUTO_INCREMENT,
group_id int NOT NULL,
subgroup_id int NOT NULL,
relation_type int NOT NULL,
PRIMARY KEY (id)
);
ALTER TABLE group_rel_group ADD INDEX ( group_id );
ALTER TABLE group_rel_group ADD INDEX ( subgroup_id );
ALTER TABLE group_rel_group ADD INDEX ( relation_type );
# DROP TABLE IF EXISTS group_rel_user;
# CREATE TABLE IF NOT EXISTS group_rel_user (
# id int NOT NULL AUTO_INCREMENT,
# group_id int NOT NULL,
# user_id int NOT NULL,
# relation_type int NOT NULL,
# PRIMARY KEY (id)
# );
# ALTER TABLE group_rel_user ADD INDEX ( group_id );
# ALTER TABLE group_rel_user ADD INDEX ( user_id );
# ALTER TABLE group_rel_user ADD INDEX ( relation_type );
#
# DROP TABLE IF EXISTS group_rel_group;
# CREATE TABLE IF NOT EXISTS group_rel_group (
# id int NOT NULL AUTO_INCREMENT,
# group_id int NOT NULL,
# subgroup_id int NOT NULL,
# relation_type int NOT NULL,
# PRIMARY KEY (id)
# );
# ALTER TABLE group_rel_group ADD INDEX ( group_id );
# ALTER TABLE group_rel_group ADD INDEX ( subgroup_id );
# ALTER TABLE group_rel_group ADD INDEX ( relation_type );
DROP TABLE IF EXISTS announcement_rel_group;
CREATE TABLE IF NOT EXISTS announcement_rel_group (

@ -67,6 +67,7 @@ class learnpath
public $lp_view_session_id = 0; // The specific view might be bound to a session.
public $prerequisite = 0;
public $use_max_score = 1; // 1 or 0
public $subscribeUsers = 0; // Subscribe users or not
public $created_on = '';
public $modified_on = '';
public $publicated_on = '';
@ -142,6 +143,7 @@ class learnpath
$this->hide_toc_frame = $row['hide_toc_frame'];
$this->lp_session_id = $row['session_id'];
$this->use_max_score = $row['use_max_score'];
$this->subscribeUsers = $row['subscribe_users'];
$this->created_on = $row['created_on'];
$this->modified_on = $row['modified_on'];
$this->ref = $row['ref'];
@ -2343,7 +2345,7 @@ class learnpath
$sessionId = null
) {
$lp_id = (int)$lp_id;
$course = api_get_course_info($courseCode);
$courseInfo = api_get_course_info($courseCode);
$sessionId = intval($sessionId);
if (empty($sessionId)) {
@ -2352,12 +2354,12 @@ class learnpath
$tbl_learnpath = Database::get_course_table(TABLE_LP_MAIN);
// Get current prerequisite
$sql = "SELECT id, prerequisite, publicated_on, expired_on
$sql = "SELECT id, prerequisite, subscribe_users, publicated_on, expired_on
FROM $tbl_learnpath
WHERE c_id = ".$course['real_id']." AND id = $lp_id";
WHERE c_id = ".$courseInfo['real_id']." AND id = $lp_id";
$itemInfo = api_get_item_property_info(
$course['real_id'],
$courseInfo['real_id'],
TOOL_LEARNPATH,
$lp_id,
$sessionId
@ -2379,7 +2381,7 @@ class learnpath
$progress = self::getProgress(
$prerequisite,
$student_id,
$course['real_id'],
$courseInfo['real_id'],
$sessionId
);
$progress = intval($progress);
@ -2419,6 +2421,49 @@ class learnpath
}
}
// Check if the subscription users/group to a LP is ON
if (isset($row['subscribe_users']) && $row['subscribe_users'] == 1) {
// Try group
$is_visible = false;
// Checking only the user visibility
$userVisibility = api_get_item_visibility(
$courseInfo,
'learnpath',
$row['id'],
$sessionId,
$student_id,
'LearnpathSubscription'
);
if ($userVisibility == 1) {
$is_visible = true;
} else {
$userGroups = GroupManager::getAllGroupPerUserSubscription($student_id);
if (!empty($userGroups)) {
foreach ($userGroups as $groupInfo) {
$groupId = $groupInfo['iid'];
$userVisibility = api_get_item_visibility(
$courseInfo,
'learnpath',
$row['id'],
$sessionId,
null,
'LearnpathSubscription',
$groupId
);
if ($userVisibility == 1) {
$is_visible = true;
break;
}
}
}
}
}
return $is_visible;
}
@ -10269,6 +10314,32 @@ EOD;
return true;
}
/**
* @return int
*/
public function getSubscribeUsers()
{
return $this->subscribeUsers;
}
/**
* @param int $subscribeUsers
*/
public function setSubscribeUsers($value)
{
if ($this->debug > 0) {
error_log('New LP - In learnpath::set_subscribe_users()', 0);
}
$this->subscribeUsers = intval($value);;
$lp_table = Database :: get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $lp_table SET subscribe_users = '".$this->subscribeUsers."'
WHERE c_id = ".$this->course_int_id." AND id = '$lp_id'";
Database::query($sql);
return true;
}
}
if (!function_exists('trim_value')) {

@ -173,7 +173,9 @@ class LearnpathList
'created_on' => $row['created_on'],
'modified_on' => $row['modified_on'],
'publicated_on' => $row['publicated_on'],
'expired_on' => $row['expired_on']
'expired_on' => $row['expired_on'],
//'category_id' => $row['category_id'],
'subscribe_users' => $row['subscribe_users']
);
$names[$row['name']] = $row['id'];
}

@ -923,6 +923,7 @@ switch ($action) {
$_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame);
$_SESSION['oLP']->set_prerequisite($_REQUEST['prerequisites']);
$_SESSION['oLP']->set_use_max_score($_REQUEST['use_max_score']);
$_SESSION['oLP']->setSubscribeUsers($_REQUEST['subscribe_users']);
if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
$publicated_on = $_REQUEST['publicated_on'];

@ -185,6 +185,8 @@ if (api_is_platform_admin()) {
$defaults['use_max_score'] = $_SESSION['oLP']->use_max_score;
}
$form->addElement('checkbox', 'subscribe_users', null, get_lang('SubscribeUsersToLP'));
$enableLpExtraFields = false;
if ($enableLpExtraFields) {
@ -210,7 +212,8 @@ if ($enableLpExtraFields) {
$defaults['publicated_on'] = ($publicated_on!='0000-00-00 00:00:00' && !empty($publicated_on))? api_get_local_time($publicated_on) : date('Y-m-d 12:00:00');
$defaults['expired_on'] = ($expired_on !='0000-00-00 00:00:00' && !empty($expired_on) )? api_get_local_time($expired_on): date('Y-m-d 12:00:00',time()+84600);
//$defaults['max_attempts'] = $_SESSION['oLP']->get_max_attempts();
$defaults['subscribe_users'] = $_SESSION['oLP']->getSubscribeUsers();
$form->setDefaults($defaults);
Display::display_header(get_lang('CourseSettings'), 'Path');

@ -39,7 +39,6 @@ $nameTools = get_lang('LearningPaths');
Event::event_access_tool(TOOL_LEARNPATH);
api_protect_course_script();
//if (!$is_allowed_in_course) api_not_allowed();
/**
* Display
@ -283,8 +282,7 @@ foreach ($categories as $item) {
$oddclass = 'row_even';
}
$url_start_lp = 'lp_controller.php?'.api_get_cidreq(
).'&action=view&lp_id='.$id;
$url_start_lp = 'lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$id;
$name = Security::remove_XSS($details['lp_name']);
$extra = null;
@ -294,9 +292,7 @@ foreach ($categories as $item) {
$id,
$userId
);
$dsp_desc = '<em>'.$details['lp_maker'].'</em> '.($studentVisibility ? '' : ' - ('.get_lang(
'LPNotVisibleToStudent'
).')');
$dsp_desc = '<em>'.$details['lp_maker'].'</em> '.($studentVisibility ? '' : ' - ('.get_lang('LPNotVisibleToStudent').')');
$extra = '<div class ="lp_content_type_label">'.$dsp_desc.'</div>';
}
@ -366,6 +362,7 @@ foreach ($categories as $item) {
$dsp_edit_lp = null;
$dsp_publish = null;
$dsp_reinit = null;
$subscribeUsers = null;
$dsp_disk = null;
$copy = null;
$lp_auto_launch_icon = null;
@ -394,8 +391,7 @@ foreach ($categories as $item) {
// BUILD
if ($current_session == $details['lp_session']) {
if ($details['lp_type'] == 1 || $details['lp_type'] == 2) {
$dsp_build = '<a href="lp_controller.php?'.api_get_cidreq(
).'&amp;action=add_item&amp;type=step&amp;lp_id='.$id.'&isStudentView=false">'.
$dsp_build = '<a href="lp_controller.php?'.api_get_cidreq().'&action=add_item&type=step&lp_id='.$id.'&isStudentView=false">'.
Display::return_icon(
'edit.png',
get_lang('LearnpathEditLearnpath'),
@ -425,24 +421,14 @@ foreach ($categories as $item) {
paths inside the session.
See http://support.chamilo.org/projects/chamilo-18/wiki/Tools_and_sessions).
*/
if ($details['lp_visibility'] == 0) {
$dsp_visible = "<a href=\"".api_get_self(
)."?".api_get_cidreq(
)."&lp_id=$id&action=toggle_visible&new_status=1\">".Display::return_icon(
'invisible.png',
get_lang('Show'),
'',
ICON_SIZE_SMALL
)."</a>";
} else {
$dsp_visible = "<a href='".api_get_self(
)."?".api_get_cidreq(
)."&lp_id=$id&action=toggle_visible&new_status=0'>".Display::return_icon(
'visible.png',
get_lang('Hide'),
'',
ICON_SIZE_SMALL
)."</a>";
if (!isset($details['subscribe_users']) || $details['subscribe_users'] != 1) {
if ($details['lp_visibility'] == 0) {
$dsp_visible = "<a href=\"".api_get_self()."?".api_get_cidreq()."&lp_id=$id&action=toggle_visible&new_status=1\">".
Display::return_icon('invisible.png', get_lang('Show'), '', ICON_SIZE_SMALL )."</a>";
} else {
$dsp_visible = "<a href='".api_get_self()."?".api_get_cidreq()."&lp_id=$id&action=toggle_visible&new_status=0'>".
Display::return_icon('visible.png', get_lang('Hide'), '', ICON_SIZE_SMALL )."</a>";
}
}
/* PUBLISH COMMAND */
@ -657,6 +643,17 @@ foreach ($categories as $item) {
api_get_self()."?".api_get_cidreq()."&action=copy&lp_id=$id"
);
// Subscribe users
$subscribeUsers = null;
var_dump($details);
if ($details['subscribe_users'] == 1) {
$subscribeUsers = Display::url(
Display::return_icon('user.png', get_lang('SubscribeUsersToLp')),
api_get_path(WEB_CODE_PATH)."newscorm/lp_subscribe_users.php?lp_id=$id&".api_get_cidreq()
);
}
/* Auto launch LP code */
if (api_get_course_setting('enable_lp_auto_launch') == 1) {
if ($details['autolaunch'] == 1 && $autolaunch_exists == false) {
@ -790,8 +787,29 @@ foreach ($categories as $item) {
$export_icon = null;
}
echo $dsp_line.$start_time.$end_time.$dsp_progress.$dsp_desc.$dsp_export.$dsp_edit.$dsp_build.$dsp_edit_lp.$dsp_visible.$dsp_publish.$dsp_reinit.
$dsp_default_view.$dsp_debug.$dsp_disk.$copy.$lp_auto_launch_icon.$export_icon.$dsp_delete.$dsp_order.$dsp_edit_close;
echo
$dsp_line.
$start_time.
$end_time.
$dsp_progress.
$dsp_desc.
$dsp_export.
$dsp_edit.
$dsp_build.
$dsp_edit_lp.
$dsp_visible.
$dsp_publish.
$subscribeUsers.
$dsp_reinit.
$dsp_default_view.
$dsp_debug.
$dsp_disk.
$copy.
$lp_auto_launch_icon.
$export_icon.
$dsp_delete.
$dsp_order.
$dsp_edit_close;
$lp_showed = true;

@ -0,0 +1,170 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CItemProperty;
use Chamilo\UserBundle\Entity\User;
require_once '../inc/global.inc.php';
api_protect_course_script();
$is_allowed_to_edit = api_is_allowed_to_edit(false, true, false, false);
if (!$is_allowed_to_edit) {
api_not_allowed(true);
}
$lpId = isset($_GET['lp_id']) ? intval($_GET['lp_id']) : 0;
if (empty($lpId)) {
api_not_allowed(true);
}
$oLP = new learnpath(api_get_course_id(), $lpId, api_get_user_id());
$interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
$interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=".$oLP->get_id(), 'name' => $oLP->get_name());
$courseId = api_get_course_int_id();
$courseCode = api_get_course_id();
$url = api_get_self().'?'.api_get_cidreq().'&lp_id='.$lpId;
$lp = new \learnpath($courseCode, $lpId, api_get_user_id());
$em = Database::getManager();
$session = null;
if (!empty($sessionId)) {
$session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId);
}
// Find course.
$course = $em->getRepository('ChamiloCoreBundle:Course')->find($courseId);
// Getting subscribe users to the course.
$subscribedUsers = $em->getRepository('ChamiloCoreBundle:Course')->getSubscribedStudents($course);
$subscribedUsers = $subscribedUsers->getQuery();
$subscribedUsers = $subscribedUsers->execute();
// Getting all users in a nice format.
$choices = array();
/** @var User $user */
foreach ($subscribedUsers as $user) {
$choices[$user->getUserId()] = $user->getCompleteNameWithClasses();
}
// Getting subscribed users to a LP.
$subscribedUsersInLp = $em->getRepository('ChamiloCourseBundle:CItemProperty')->getUsersSubscribedToItem(
'learnpath',
$lpId,
$course,
$session
);
$selectedChoices = array();
foreach ($subscribedUsersInLp as $itemProperty) {
$selectedChoices[] = $itemProperty->getToUser()->getId();
}
//Building the form for Users
$formUsers = new \FormValidator('lp_edit', 'post', $url);
$formUsers->addElement('hidden', 'user_form', 1);
$formUsers->addElement('header', get_lang('SubscribeUsersToLp'));
$userMultiSelect = $formUsers->addElement('advmultiselect', 'users', get_lang('Users'), $choices);
$formUsers->addButtonSave(get_lang('Save'));
$defaults = array();
if (!empty($selectedChoices)) {
$defaults['users'] = $selectedChoices;
}
$formUsers->setDefaults($defaults);
//Building the form for Groups
$form = new \FormValidator('lp_edit', 'post', $url);
$form->addElement('header', get_lang('SubscribeGroupsToLp'));
$form->addElement('hidden', 'group_form', 1);
// Group list
$groupList = \CourseManager::get_group_list_of_course(
api_get_course_id(),
api_get_session_id(),
1
);
$groupChoices = array_column($groupList, 'name', 'id');
// Subscribed groups to a LP
$subscribedGroupsInLp = $em->getRepository('ChamiloCourseBundle:CItemProperty')->getGroupsSubscribedToItem(
'learnpath',
$lpId,
$course,
$session
);
$selectedGroupChoices = array();
/** @var CItemProperty $itemProperty */
foreach ($subscribedGroupsInLp as $itemProperty) {
$selectedGroupChoices[] = $itemProperty->getGroup()->getId();
}
$groupMultiSelect = $form->addElement('advmultiselect', 'groups', get_lang('Groups'), $groupChoices);
// submit button
$form->addButtonSave(get_lang('Save'));
$defaults = array();
if (!empty($selectedGroupChoices)) {
$defaults['groups'] = $selectedGroupChoices;
}
$form->setDefaults($defaults);
$tpl = new Template();
$currentUser = $em->getRepository('ChamiloUserBundle:User')->find(api_get_user_id());
if ($form->validate()) {
$values = $form->getSubmitValues();
// Subscribing users
$users = isset($values['users']) ? $values['users'] : [];
$userForm = isset($values['user_form']) ? $values['user_form'] : [];
if (!empty($userForm)) {
$em->getRepository('ChamiloCourseBundle:CItemProperty')->subscribeUsersToItem(
$currentUser,
'learnpath',
$course,
$session,
$lpId,
$users
);
}
// Subscribing groups
$groups = isset($values['groups']) ? $values['groups'] : [];
$groupForm = isset($values['group_form']) ? $values['group_form'] : [];
if (!empty($groupForm)) {
$em->getRepository('ChamiloCourseBundle:CItemProperty')->subscribeGroupsToItem(
$currentUser,
'learnpath',
$course,
$session,
$lpId,
$groups
);
}
header("Location: $url");
exit;
} else {
$tpl->assign('form_users', $formUsers->toHtml());
$tpl->assign('form_groups', $form->toHtml());
}
$layout = $tpl->get_template('learnpath/subscribe_users.tpl');
$tpl->display($layout);

@ -0,0 +1,49 @@
{% extends template ~ "/layout/layout_1_col.tpl" %}
{% block content %}
{#
<h2>{{ 'SubscribeUsersToLp' | trans }}</h2>
<script>
$().ready(function() {
$('#add').click(function() {
return !$('#{{ form.origin.vars.id }} option:selected').remove().appendTo('#{{ form.destination.vars.id }}');
});
$('#remove').click(function() {
return !$('#{{ form.destination.vars.id }} option:selected').remove().appendTo('#{{ form.origin.vars.id }}');
});
$('#send').click(function() {
$("#{{ form.destination.vars.id }}").each(function(){
$("#{{ form.destination.vars.id }} option").attr("selected","selected");
});
});
});
</script>
<form method="POST" {{ form_enctype(form) }}>
{{ form_errors(form) }}
<div class="row">
<div class="span4">
{{ form_label(form.origin) }}
{{ form_widget(form.origin) }}
</div>
<div class="span1">
<br />
<button id="add" class="btn btn-block"><i class="icon-arrow-right icon-large"></i></button>
<button id="remove" class="btn btn-block"><i class="icon-arrow-left icon-large"></i></button>
</div>
<div class="span4">
{{ form_label(form.destination) }}
{{ form_widget(form.destination) }}
</div>
</div>
<div class="row">
<div class="span12">
<button id="send" type="submit" class="btn btn-primary"><i class="icon-arrow-lef icon-large"></i>{{ 'Save' | trans }}</button>
</div>
</div>
{{ form_rest(form) }}
</form>
#}
{{ form_users }}
{{ form_groups }}
{% endblock %}

@ -634,7 +634,11 @@ function get_user_data($from, $number_of_items, $column, $direction)
$temp[] = $o_course_user['username'];
// Groups.
$temp[] = implode(', ', $groupsNameList);
$groupsNameListParsed = [];
if (!empty($groupsNameList)) {
$groupsNameListParsed = array_column($groupsNameList, 'name');
}
$temp[] = implode(', ', $groupsNameListParsed);
// Status
$default_status = get_lang('Student');

@ -240,7 +240,7 @@ class Course
protected $sessions;
/**
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SessionRelCourseRelUser", mappedBy="course", cascade={"persist"})
* @ORM\OneToMany(targetEntity="SessionRelCourseRelUser", mappedBy="course", cascade={"persist"})
**/
protected $sessionUserSubscriptions;

@ -26,7 +26,7 @@ class CourseRelUser
*
* @ORM\Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\GeneratedValue
*/
private $id;

@ -24,6 +24,7 @@ class CourseRepository extends EntityRepository
*/
public function getSubscribedUsers(Course $course)
{
// Course builder
$queryBuilder = $this->createQueryBuilder('a');
// Selecting user info.
@ -41,7 +42,7 @@ class CourseRepository extends EntityRepository
$wherePart = $queryBuilder->expr()->andx();
// Get only users subscribed to this course
$wherePart->add($queryBuilder->expr()->eq('c.cId', $course->getId()));
$wherePart->add($queryBuilder->expr()->eq('a.id', $course->getId()));
// $wherePart->add($queryBuilder->expr()->eq('c.status', $status));

@ -0,0 +1,326 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity\Repository;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Group;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CourseBundle\Entity\CItemProperty;
use Doctrine\ORM\EntityRepository;
/**
* Class ItemPropertyRepository
*
*/
class ItemPropertyRepository extends EntityRepository
{
/**
*
* Get users subscribed to a item LP, Document, etc (item_property)
*
* @param $tool learnpath | document | etc
* @param $itemId
* @param Course $course
* @param int $sessionId
* @param int $groupId
*
* @return \Doctrine\ORM\QueryBuilder
*/
public function getUsersSubscribedToItem(
$tool,
$itemId,
Course $course,
Session $session = null,
Group $group = null
) {
$criteria = array(
'tool' => $tool,
'lasteditType' => 'LearnpathSubscription',
'ref' => $itemId,
'course' => $course,
'session' => $session,
'group' => $group,
);
return $this->findBy($criteria);
}
/**
* Get Groups subscribed to a item: LP, Doc, etc
* @param $tool learnpath | document | etc
* @param $itemId
* @param Course $course
* @param Session $session
* @return array
*/
public function getGroupsSubscribedToItem(
$tool,
$itemId,
Course $course,
Session $session = null
) {
$criteria = array(
'tool' => $tool,
'lasteditType' => 'LearnpathSubscription',
'ref' => $itemId,
'course' => $course,
'session' => $session,
'toUser' => null,
);
return $this->findBy($criteria);
}
/**
* Subscribe groups to a LP, doc (itemproperty)
* @param User $currentUser
* @param $tool learnpath | document | etc
* @param Course $course
* @param Session $session
* @param $itemId
* @param array $newList
*/
public function subscribeGroupsToItem(
$currentUser,
$tool,
Course $course,
Session $session = null,
$itemId,
$newList = array()
) {
$em = $this->getEntityManager();
$groupsSubscribedToItem = $this->getGroupsSubscribedToItem(
$tool,
$itemId,
$course,
$session
);
$alreadyAdded = array();
if ($groupsSubscribedToItem) {
/** @var CItemProperty $itemProperty */
foreach ($groupsSubscribedToItem as $itemProperty) {
$alreadyAdded[] = $itemProperty->getGroup()->getId();
}
}
$toDelete = $alreadyAdded;
if (!empty($newList)) {
$toDelete = array_diff($alreadyAdded, $newList);
}
if ($toDelete) {
$this->unsubscribeGroupsToItem(
$tool,
$course,
$session,
$itemId,
$toDelete,
true
);
}
foreach ($newList as $groupId) {
if (!in_array($groupId, $alreadyAdded)) {
$item = new CItemProperty($course);
$groupObj = $em->find('ChamiloCourseBundle:CGroupInfo', $groupId);
$item->setGroup($groupObj);
$item->setTool($tool);
$item->setRef($itemId);
$item->setInsertUser($currentUser);
if (!empty($session)) {
$item->setSession($session);
}
$item->setLasteditType('LearnpathSubscription');
$item->setVisibility('1');
$em->persist($item); //$em is an instance of EntityManager
}
//Adding users from this group to the item
/*$users = \GroupManager::getStudentsAndTutors($groupId);
$newUserList = array();
if (!empty($users)) {
foreach ($users as $user) {
$newUserList[] = $user['user_id'];
}
$this->subscribeUsersToItem(
$currentUser,
'learnpath',
$course,
$session,
$itemId,
$newUserList
);
}*/
}
$em->flush();
}
/**
* Unsubscribe groups to item
* @param $tool
* @param Course $course
* @param Session $session
* @param $itemId
* @param $groups
*/
public function unsubscribeGroupsToItem(
$tool,
Course $course,
Session $session = null,
$itemId,
$groups,
$unsubscribeUserToo = false
) {
if (!empty($groups)) {
$em = $this->getEntityManager();
foreach ($groups as $groupId) {
$item = $this->findOneBy(array(
'tool' => $tool,
'session' => $session,
'ref' => $itemId,
'group' => $groupId,
));
if ($item) {
$em->remove($item);
}
if ($unsubscribeUserToo) {
//Adding users from this group to the item
$users = \GroupManager::getStudentsAndTutors($groupId);
$newUserList = array();
if (!empty($users)) {
foreach($users as $user) {
$newUserList[] = $user['user_id'];
}
$this->unsubcribeUsersToItem(
'learnpath',
$course,
$session,
$itemId,
$newUserList
);
}
}
}
$em->flush();
}
}
/**
* Subscribe users to a LP, doc (itemproperty)
*
* @param User $currentUser
* @param $tool
* @param Course $course
* @param Session $session
* @param $itemId
* @param array $newUserList
*/
public function subscribeUsersToItem(
$currentUser,
$tool,
Course $course,
Session $session = null,
$itemId,
$newUserList = array()
) {
$em = $this->getEntityManager();
$user = $em->getRepository('ChamiloUserBundle:User');
$usersSubscribedToItem = $this->getUsersSubscribedToItem(
$tool,
$itemId,
$course,
$session
);
$alreadyAddedUsers = array();
if ($usersSubscribedToItem) {
/** @var CItemProperty $itemProperty */
foreach ($usersSubscribedToItem as $itemProperty) {
$alreadyAddedUsers[] = $itemProperty->getToUser()->getId();
}
}
$usersToDelete = $alreadyAddedUsers;
if (!empty($newUserList)) {
$usersToDelete = array_diff($alreadyAddedUsers, $newUserList);
}
if ($usersToDelete) {
$this->unsubcribeUsersToItem(
$tool,
$course,
$session,
$itemId,
$usersToDelete
);
}
foreach ($newUserList as $userId) {
if (!in_array($userId, $alreadyAddedUsers)) {
$userObj = $user->find($userId);
$item = new CItemProperty($course);
$item
->setToUser($userObj)
->setTool($tool)
->setInsertUser($currentUser)
->setRef($itemId);
if (!empty($session)) {
$item->setSession($session);
}
$item->setLasteditType('LearnpathSubscription');
$item->setVisibility('1');
$em->persist($item); //$em is an instance of EntityManager
}
}
$em->flush();
}
/**
* Unsubscribe users to item
*
* @param $tool
* @param Course $course
* @param Session $session
* @param $itemId
* @param $usersToDelete
*/
public function unsubcribeUsersToItem(
$tool,
Course $course,
Session $session = null,
$itemId,
$usersToDelete
) {
$em = $this->getEntityManager();
if (!empty($usersToDelete)) {
foreach ($usersToDelete as $userId) {
$item = $this->findOneBy(
array(
'tool' => $tool,
'session' => $session,
'ref' => $itemId,
'toUser' => $userId,
)
);
if ($item) {
$em->remove($item);
}
}
$em->flush();
}
}
}

@ -29,7 +29,7 @@ class UsergroupRelUser
*
* @ORM\Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\GeneratedValue
*/
protected $id;

@ -16,6 +16,20 @@ class Version20150603181728 extends AbstractMigration
public function up(Schema $schema)
{
$this->addSql('ALTER TABLE c_lp ADD max_attempts INT NOT NULL, ADD subscribe_users INT NOT NULL DEFAULT 0');
$this->addSql('DELETE FROM c_item_property TABLE c_lp ADD max_attempts INT NOT NULL, ADD subscribe_users INT NOT NULL DEFAULT 0');
$this->addSql('ALTER TABLE c_item_property CHANGE c_id c_id INT DEFAULT NULL, CHANGE insert_user_id insert_user_id INT DEFAULT NULL, CHANGE start_visible start_visible DATETIME DEFAULT NULL, CHANGE end_visible end_visible DATETIME DEFAULT NULL, CHANGE session_id session_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C18191D79BD3 FOREIGN KEY (c_id) REFERENCES course (id)');
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C181330D47E9 FOREIGN KEY (to_group_id) REFERENCES c_group_info (iid)');
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C18129F6EE60 FOREIGN KEY (to_user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C1819C859CC3 FOREIGN KEY (insert_user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C181613FECDF FOREIGN KEY (session_id) REFERENCES session (id)');
$this->addSql('CREATE INDEX IDX_1D84C18191D79BD3 ON c_item_property (c_id)');
$this->addSql('CREATE INDEX IDX_1D84C181330D47E9 ON c_item_property (to_group_id)');
$this->addSql('CREATE INDEX IDX_1D84C18129F6EE60 ON c_item_property (to_user_id)');
$this->addSql('CREATE INDEX IDX_1D84C1819C859CC3 ON c_item_property (insert_user_id)');
$this->addSql('CREATE INDEX IDX_1D84C181613FECDF ON c_item_property (session_id)');
}
/**
@ -24,5 +38,16 @@ class Version20150603181728 extends AbstractMigration
public function down(Schema $schema)
{
$this->addSql('ALTER TABLE c_lp DROP max_attempts, DROP subscribe_users');
$this->addSql('ALTER TABLE c_item_property DROP FOREIGN KEY FK_1D84C18191D79BD3');
$this->addSql('ALTER TABLE c_item_property DROP FOREIGN KEY FK_1D84C181330D47E9');
$this->addSql('ALTER TABLE c_item_property DROP FOREIGN KEY FK_1D84C18129F6EE60');
$this->addSql('ALTER TABLE c_item_property DROP FOREIGN KEY FK_1D84C1819C859CC3');
$this->addSql('ALTER TABLE c_item_property DROP FOREIGN KEY FK_1D84C181613FECDF');
$this->addSql('DROP INDEX IDX_1D84C18191D79BD3 ON c_item_property');
$this->addSql('DROP INDEX IDX_1D84C181330D47E9 ON c_item_property');
$this->addSql('DROP INDEX IDX_1D84C18129F6EE60 ON c_item_property');
$this->addSql('DROP INDEX IDX_1D84C1819C859CC3 ON c_item_property');
$this->addSql('DROP INDEX IDX_1D84C181613FECDF ON c_item_property');
$this->addSql('ALTER TABLE c_item_property CHANGE c_id c_id INT NOT NULL, CHANGE insert_user_id insert_user_id INT NOT NULL, CHANGE session_id session_id INT NOT NULL, CHANGE start_visible start_visible DATETIME NOT NULL, CHANGE end_visible end_visible DATETIME NOT NULL');
}
}

@ -3,13 +3,15 @@
namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
/**
* CItemProperty
*
* @ORM\Table(name="c_item_property", indexes={@ORM\Index(name="idx_item_property_toolref", columns={"tool", "ref"})})
* @ORM\Entity
* @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Entity\Repository\ItemPropertyRepository")
*/
class CItemProperty
{
@ -29,12 +31,11 @@ class CItemProperty
*/
private $id;
/**
* @var integer
*
* @ORM\Column(name="c_id", type="integer")
/** //, inversedBy="users",
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", cascade={"persist"})
* @ORM\JoinColumn(name="c_id", referencedColumnName="id")
*/
private $cId;
protected $course;
/**
* @var string
@ -43,13 +44,6 @@ class CItemProperty
*/
private $tool;
/**
* @var integer
*
* @ORM\Column(name="insert_user_id", type="integer", nullable=false)
*/
private $insertUserId;
/**
* @var \DateTime
*
@ -85,19 +79,23 @@ class CItemProperty
*/
private $lasteditUserId;
/** //, inversedBy="users",
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CGroupInfo", cascade={"persist"})
* @ORM\JoinColumn(name="to_group_id", referencedColumnName="iid")
*/
protected $group;
/**
* @var integer
*
* @ORM\Column(name="to_group_id", type="integer", nullable=true)
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", cascade={"persist"})
* @ORM\JoinColumn(name="to_user_id", referencedColumnName="id")
*/
private $toGroupId;
protected $toUser;
/**
* @var integer
*
* @ORM\Column(name="to_user_id", type="integer", nullable=true)
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", cascade={"persist"})
* @ORM\JoinColumn(name="insert_user_id", referencedColumnName="id")
*/
private $toUserId;
protected $insertUser;
/**
* @var boolean
@ -109,28 +107,38 @@ class CItemProperty
/**
* @var \DateTime
*
* @ORM\Column(name="start_visible", type="datetime", nullable=false)
* @ORM\Column(name="start_visible", type="datetime", nullable=true)
*/
private $startVisible;
/**
* @var \DateTime
*
* @ORM\Column(name="end_visible", type="datetime", nullable=false)
* @ORM\Column(name="end_visible", type="datetime", nullable=true)
*/
private $endVisible;
/** //, inversedBy="users",
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session", cascade={"persist"})
* @ORM\JoinColumn(name="session_id", referencedColumnName="id")
*/
protected $session;
/**
* @var integer
*
* @ORM\Column(name="session_id", type="integer", nullable=false)
* CItemProperty constructor.
*/
private $idSession;
public function __construct(Course $course)
{
$this->course = $course;
$this->insertDate = new \DateTime();
$this->lasteditDate = new \DateTime();
}
/**
* Set tool
*
* @param string $tool
*
* @return CItemProperty
*/
public function setTool($tool)
@ -150,33 +158,11 @@ class CItemProperty
return $this->tool;
}
/**
* Set insertUserId
*
* @param integer $insertUserId
* @return CItemProperty
*/
public function setInsertUserId($insertUserId)
{
$this->insertUserId = $insertUserId;
return $this;
}
/**
* Get insertUserId
*
* @return integer
*/
public function getInsertUserId()
{
return $this->insertUserId;
}
/**
* Set insertDate
*
* @param \DateTime $insertDate
*
* @return CItemProperty
*/
public function setInsertDate($insertDate)
@ -200,6 +186,7 @@ class CItemProperty
* Set lasteditDate
*
* @param \DateTime $lasteditDate
*
* @return CItemProperty
*/
public function setLasteditDate($lasteditDate)
@ -223,6 +210,7 @@ class CItemProperty
* Set ref
*
* @param integer $ref
*
* @return CItemProperty
*/
public function setRef($ref)
@ -246,6 +234,7 @@ class CItemProperty
* Set lasteditType
*
* @param string $lasteditType
*
* @return CItemProperty
*/
public function setLasteditType($lasteditType)
@ -269,6 +258,7 @@ class CItemProperty
* Set lasteditUserId
*
* @param integer $lasteditUserId
*
* @return CItemProperty
*/
public function setLasteditUserId($lasteditUserId)
@ -289,186 +279,199 @@ class CItemProperty
}
/**
* Set toGroupId
* Set visibility
*
* @param boolean $visibility
*
* @param integer $toGroupId
* @return CItemProperty
*/
public function setToGroupId($toGroupId)
public function setVisibility($visibility)
{
$this->toGroupId = $toGroupId;
$this->visibility = $visibility;
return $this;
}
/**
* Get toGroupId
* Get visibility
*
* @return integer
* @return boolean
*/
public function getToGroupId()
public function getVisibility()
{
return $this->toGroupId;
return $this->visibility;
}
/**
* Set toUserId
* Set startVisible
*
* @param \DateTime $startVisible
*
* @param integer $toUserId
* @return CItemProperty
*/
public function setToUserId($toUserId)
public function setStartVisible($startVisible)
{
$this->toUserId = $toUserId;
$this->startVisible = $startVisible;
return $this;
}
/**
* Get toUserId
* Get startVisible
*
* @return integer
* @return \DateTime
*/
public function getToUserId()
public function getStartVisible()
{
return $this->toUserId;
return $this->startVisible;
}
/**
* Set visibility
* Set endVisible
*
* @param \DateTime $endVisible
*
* @param boolean $visibility
* @return CItemProperty
*/
public function setVisibility($visibility)
public function setEndVisible($endVisible)
{
$this->visibility = $visibility;
$this->endVisible = $endVisible;
return $this;
}
/**
* Get visibility
* Get endVisible
*
* @return boolean
* @return \DateTime
*/
public function getVisibility()
public function getEndVisible()
{
return $this->visibility;
return $this->endVisible;
}
/**
* Set startVisible
* Set id
*
* @param integer $id
*
* @param \DateTime $startVisible
* @return CItemProperty
*/
public function setStartVisible($startVisible)
public function setId($id)
{
$this->startVisible = $startVisible;
$this->id = $id;
return $this;
}
/**
* Get startVisible
* Get id
*
* @return \DateTime
* @return integer
*/
public function getStartVisible()
public function getId()
{
return $this->startVisible;
return $this->id;
}
/**
* Set endVisible
* @return Session
*/
public function getSession()
{
return $this->session;
}
/**
* @param Session $session
*
* @param \DateTime $endVisible
* @return CItemProperty
*/
public function setEndVisible($endVisible)
public function setSession($session)
{
$this->endVisible = $endVisible;
$this->session = $session;
return $this;
}
/**
* Get endVisible
*
* @return \DateTime
* @return Course
*/
public function getEndVisible()
public function getCourse()
{
return $this->endVisible;
return $this->course;
}
/**
* Set idSession
* @param Course $course
*
* @param integer $idSession
* @return CItemProperty
*/
public function setIdSession($idSession)
public function setCourse($course)
{
$this->idSession = $idSession;
$this->course = $course;
return $this;
}
/**
* Get idSession
*
* @return integer
* @return CgroupInfo
*/
public function getIdSession()
public function getGroup()
{
return $this->idSession;
return $this->group;
}
/**
* Set id
* @param CgroupInfo $group
*
* @param integer $id
* @return CItemProperty
*/
public function setId($id)
public function setGroup($group)
{
$this->id = $id;
$this->group = $group;
return $this;
}
/**
* Get id
*
* @return integer
* @return User
*/
public function getId()
public function getToUser()
{
return $this->id;
return $this->toUser;
}
/**
* Set cId
* @param User $toUser
*
* @param integer $cId
* @return CItemProperty
* @return $this
*/
public function setCId($cId)
public function setToUser($toUser)
{
$this->cId = $cId;
$this->toUser = $toUser;
return $this;
}
/**
* Get cId
* @return User
*/
public function getInsertUser()
{
return $this->insertUser;
}
/**
* @param User $insertUser
*
* @return integer
* @return $this
*/
public function getCId()
public function setInsertUser(User $insertUser)
{
return $this->cId;
$this->insertUser = $insertUser;
$this->lasteditUserId = $insertUser->getId();
return $this;
}
}

@ -5,6 +5,7 @@ namespace Chamilo\UserBundle\Entity;
//use Chamilo\CoreBundle\Entity\UserFieldValues;
use Chamilo\CoreBundle\Entity\ExtraFieldValues;
use Chamilo\CoreBundle\Entity\UsergroupRelUser;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Mapping as ORM;
@ -481,7 +482,7 @@ class User extends BaseUser //implements ParticipantInterface, ThemeUser
new Assert\Regex(array(
'pattern' => '/[0-9]{2}/',
'htmlPattern' => '/[0-9]{2}/')
)
),
)
;
}
@ -704,8 +705,9 @@ class User extends BaseUser //implements ParticipantInterface, ThemeUser
{
$classSubscription = $this->getClasses();
$classList = array();
/** @var UsergroupRelUser $subscription */
foreach ($classSubscription as $subscription) {
$class = $subscription->getClass();
$class = $subscription->getUsergroup();
$classList[] = $class->getName();
}
$classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null;

Loading…
Cancel
Save