diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index 2bcac1e167..72ba39ab9f 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -14213,6 +14213,82 @@ EOD; return Database::fetch_assoc($result); } + /** + * Returns the list of users that are registered in the learningpaths at the time they are subscribed, taking into + * account that the LearnpathSubscription element must be in the table item_property in lastedit_type. + * + * @param int $lpId + * @param int $sessionId + * @param null $extraWhere + * @param false $withHRM + */ + public static function getStudentsByLearnpathSubscription($lpId = 0, $sessionId = 0, $extraWhere = null, $withHRM = false) + { + if ($sessionId == 0) { + $sessionId = (int) api_get_session_id(); + } + $lpTable = Database::get_course_table(TABLE_LP_MAIN); + $courseTable = Database::get_main_table(TABLE_MAIN_COURSE); + $tblItempProperty = Database::get_course_table(TABLE_ITEM_PROPERTY); + + $whereSession = " AND (z.session_id = 0 or z.session_id is null ) "; + if ($sessionId != 0) { + $whereSession = " AND z.session_id = $sessionId "; + } + $sql = " +SELECT + z.session_id as session_id, + z.to_user_id as user_id, + z.insert_user_id as from_user_id, + a.id AS l_id, + a.c_id AS c_id, + a.session_id AS session_id, + a.`name` AS `name`, + d.title AS course_name, + d.`code` AS `code`, + d.id AS course_id +FROM + $tblItempProperty as z + INNER JOIN $lpTable as a ON a.iid = z.ref + INNER JOIN $courseTable as d ON a.c_id = d.id +WHERE + z.lastedit_type ='LearnpathSubscription' + AND a.id = $lpId + $extraWhere + $whereSession +"; + $result = Database::query($sql); + $data = Database::store_result($result); + Database::free_result($result); + if ($withHRM == true) { + $totalData = count($data); + for ($i = 0; $i < $totalData; $i++) { + $dataTemp = []; + $userId = $data[$i]['user_id']; + if ($userId != 0) { + $relationStudenHRTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER); + $sql = "SELECT + friend_user_id +FROM + $relationStudenHRTable +WHERE + user_id = $userId + AND relation_type = ".USER_RELATION_TYPE_RRHH; + $result = Database::query($sql); + $dataHR = Database::store_result($result); + Database::free_result($result); + $totalHr = count($dataHR); + for ($j = 0; $j < $totalHr; $j++) { + $dataTemp[] = api_get_user_info($dataHR[$j]['friend_user_id']); + } + } + $data[$i]['HRM'] = $dataTemp; + } + } + + return $data; + } + /** * Get the depth level of LP item. * @@ -14351,80 +14427,4 @@ EOD; $author->setOptions($options); } } - - /** - * Returns the list of users that are registered in the learningpaths at the time they are subscribed, taking into - * account that the LearnpathSubscription element must be in the table item_property in lastedit_type - * - * @param int $lpId - * @param int $sessionId - * @param null $extraWhere - * @param false $withHRM - */ - public static function getStudentsByLearnpathSubscription($lpId = 0, $sessionId = 0, $extraWhere = null, $withHRM = false) - { - if ($sessionId == 0) { - $sessionId = (int)api_get_session_id(); - } - $lpTable = Database::get_course_table(TABLE_LP_MAIN); - $courseTable = Database::get_main_table(TABLE_MAIN_COURSE); - $tblItempProperty = Database::get_course_table(TABLE_ITEM_PROPERTY); - - $whereSession = " AND (z.session_id = 0 or z.session_id is null ) "; - if ($sessionId != 0) { - $whereSession = " AND z.session_id = $sessionId "; - } - $sql = " -SELECT - z.session_id as session_id, - z.to_user_id as user_id, - z.insert_user_id as from_user_id, - a.id AS l_id, - a.c_id AS c_id, - a.session_id AS session_id, - a.`name` AS `name`, - d.title AS course_name, - d.`code` AS `code`, - d.id AS course_id -FROM - $tblItempProperty as z - INNER JOIN $lpTable as a ON a.iid = z.ref - INNER JOIN $courseTable as d ON a.c_id = d.id -WHERE - z.lastedit_type ='LearnpathSubscription' - AND a.id = $lpId - $extraWhere - $whereSession -"; - $result = Database::query($sql); - $data = Database::store_result($result); - Database::free_result($result); - if ($withHRM == true) { - $totalData = count($data); - for ($i = 0; $i < $totalData; $i++) { - $dataTemp = []; - $userId = $data[$i]['user_id']; - if ($userId != 0) { - $relationStudenHRTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER); - $sql = "SELECT - friend_user_id -FROM - $relationStudenHRTable -WHERE - user_id = $userId - AND relation_type = ".USER_RELATION_TYPE_RRHH; - $result = Database::query($sql); - $dataHR = Database::store_result($result); - Database::free_result($result); - $totalHr = count($dataHR); - for($j=0;$j<$totalHr;$j++){ - $dataTemp[] = api_get_user_info($dataHR[$j]['friend_user_id']); - } - } - $data[$i]['HRM']=$dataTemp; - } - } - - return $data; - } } diff --git a/main/lp/lp_controller.php b/main/lp/lp_controller.php index ad00f3f528..f3588729c0 100755 --- a/main/lp/lp_controller.php +++ b/main/lp/lp_controller.php @@ -1689,7 +1689,7 @@ switch ($action) { $date = new DateTime(); $date = $date->format('Y-m-d H:i:s'); $extraWhere = " AND publicated_on <= '$date'"; - $dataReminder = learnpath::getStudentsByLearnpathSubscription($lp_id,$session_id,$extraWhere,true); + $dataReminder = learnpath::getStudentsByLearnpathSubscription($lp_id, $session_id, $extraWhere, true); foreach ($dataReminder as $row) { $lpId = $row['l_id']; $sessionId = $row['session_id']; diff --git a/main/lp/lp_list.php b/main/lp/lp_list.php index f8f3cad0fb..686d39f6e4 100755 --- a/main/lp/lp_list.php +++ b/main/lp/lp_list.php @@ -850,13 +850,13 @@ foreach ($categories as $item) { ); } } - $session_id = (int)api_get_session_id(); + $session_id = (int) api_get_session_id(); $date = new DateTime(); $date = $date->format('Y-m-d H:i:s'); $extraWhere = " AND publicated_on <= '$date'"; - $dataReminder = learnpath::getStudentsByLearnpathSubscription($id,$session_id,$extraWhere,true); + $dataReminder = learnpath::getStudentsByLearnpathSubscription($id, $session_id, $extraWhere, true); - if(count($dataReminder)!=0) { + if (count($dataReminder) != 0) { $dsp_order .= Display::url( Display::return_icon('announce.png', get_lang('EmailNotifySubscription')), "lp_controller.php?$cidReq&action=remind_lp_users&lp_id=$id&category_id=$categoryId"