Minor - format code, remove unused functions

pull/2487/head
jmontoyaa 9 years ago
parent 82ae9c3cf1
commit 64bde06f4b
  1. 7
      main/announcements/announcements.php
  2. 10
      main/inc/lib/AnnouncementEmail.php
  3. 241
      main/inc/lib/AnnouncementManager.php
  4. 70
      main/inc/lib/agenda.lib.php
  5. 37
      tests/main/announcements/announcements.inc.test.php

@ -40,7 +40,6 @@ if (!empty($sessionId) && $drhHasAccessToSessionContent) {
$allowToEdit = $allowToEdit || api_is_drh();
}
/* ACCESS RIGHTS */
api_protect_course_script(true);
@ -214,17 +213,15 @@ switch ($action) {
'width' => '150',
'align' => 'left',
//'formatter' => 'action_formatter',
'sortable' => 'false',
),
'sortable' => 'false'
)
);
// Autowidth
$extra_params['autowidth'] = 'true';
// height auto
$extra_params['height'] = 'auto';
$editOptions = '';
if (api_is_allowed_to_edit()) {
$extra_params['multiselect'] = true;
$editOptions = '

@ -238,9 +238,8 @@ class AnnouncementEmail
);
$user_email = $this->sender('mail');
//$course_param = api_get_cidreq();
// Build the link by hand because api_get_cidreq() doesn't accept course params
$course_param = 'cidReq='.api_get_course_id().'&id_session='.$session_id.'&gidReq='.api_get_group_id();
$course_param = 'cidReq='.api_get_course_id().'&id_session='.$session_id.'&gidReq='.api_get_group_id();
$course_name = $this->course('title');
$result = "<div>$content</div>";
@ -250,9 +249,10 @@ class AnnouncementEmail
if (!empty($attachment)) {
$result .= '<br />';
$result .= Display::url(
$attachment['filename'],
api_get_path(WEB_CODE_PATH).'announcements/download.php?file='.basename($attachment['path']).'&'.$course_param
).'<br />';
$attachment['filename'],
api_get_path(WEB_CODE_PATH).'announcements/download.php?file='.basename($attachment['path']).'&'.$course_param
);
$result .= '<br />';
}
$result .= '<hr />';

@ -17,7 +17,6 @@ class AnnouncementManager
*/
public function __construct()
{
}
/**
@ -659,10 +658,8 @@ class AnnouncementManager
}
// store in item_property (first the groups, then the users
if (!is_null($to)) {
// !is_null($to): when no user is selected we send it to everyone
$send_to = CourseManager::separateUsersGroups($to);
// storing the selected groups
@ -817,206 +814,6 @@ class AnnouncementManager
return false;
}
/**
* This function shows the form for sending a message to a specific group or user.
* @param $to_already_selected
*/
public static function show_to_form($to_already_selected)
{
$userList = self::get_course_users();
$groupList = self::get_course_groups();
if ($to_already_selected == '' || $to_already_selected == 'everyone') {
$to_already_selected = array();
}
echo "<table id=\"recipient_list\" >";
echo '<tr>';
echo '<td>';
echo '<label><input type="checkbox" id="send_to_all_users">'.get_lang('SendToAllUsers') . "</label>";
echo "</td>";
echo '</tr>';
echo '<tr>';
// the form containing all the groups and all the users of the course
echo '<td>';
echo "<strong>" . get_lang('Users') . "</strong><br />";
self::construct_not_selected_select_form($groupList, $userList, $to_already_selected);
echo "</td>";
// the buttons for adding or removing groups/users
echo '<td valign="middle">';
echo '<button class="btn btn-default" type="button" onClick="javascript: move(this.form.elements[1], this.form.elements[4])" onClick="javascript: move(this.form.elements[1], this.form.elements[4])"><em class="fa fa-arrow-right"></em></button>';
echo '<br /> <br />';
echo '<button class="btn btn-default" type="button" onClick="javascript: move(this.form.elements[4], this.form.elements[1])" onClick="javascript: move(this.form.elements[4], this.form.elements[1])"><em class="fa fa-arrow-left"></em></button>';
echo "</td>";
echo "<td>";
// the form containing the selected groups and users
echo "<strong>" . get_lang('DestinationUsers') . "</strong><br />";
self::construct_selected_select_form($groupList, $userList, $to_already_selected);
echo "</td>";
echo "</tr>";
echo "</table>";
}
/**
* this function shows the form for sending a message to a specific group or user.
*/
public static function show_to_form_group($group_id)
{
echo "<table id=\"recipient_list\" >";
echo "<tr>";
echo "<td>";
echo "<select id=\"not_selected_form\" name=\"not_selected_form[]\" size=5 style=\"width:200px\" multiple>";
$group_users = GroupManager::getStudentsAndTutors($group_id);
foreach ($group_users as $user) {
echo '<option value="' . $user['user_id'] . '" title="' . sprintf(get_lang('LoginX'), $user['username']) . '" >' .
api_get_person_name($user['firstname'], $user['lastname']) .
'</option>';
}
echo '</select>';
echo "</td>";
// the buttons for adding or removing groups/users
echo "<td valign=\"middle\">";
echo '<button class="btn btn-default" type="button" onClick="javascript: move(this.form.elements[1], this.form.elements[4])" onClick="javascript: move(this.form.elements[1], this.form.elements[4])"><em class="fa fa-arrow-right"></em></button>';
echo '<br /> <br />';
echo '<button class="btn btn-default" type="button" onClick="javascript: move(this.form.elements[4], this.form.elements[1])" onClick="javascript: move(this.form.elements[4], this.form.elements[1])"><em class="fa fa-arrow-left"></em></button>';
echo "</td>";
echo "<td>";
echo "<select id=\"selectedform\" name=\"selectedform[]\" size=5 style=\"width:200px\" multiple>";
echo '</select>';
echo "</td>";
echo "</tr>";
echo "</table>";
}
/**
* Shows the form for sending a message to a specific group or user.
* @param array $groupList
* @param array $userList
* @param array $to_already_selected
*/
public static function construct_not_selected_select_form(
$groupList = array(),
$userList = array(),
$to_already_selected = array()
) {
echo '<select id="not_selected_form" name="not_selected_form[]" size="7" class="form-control" multiple>';
// adding the groups to the select form
if (!empty($groupList)) {
foreach ($groupList as $this_group) {
if (is_array($to_already_selected)) {
if (!in_array("GROUP:" . $this_group['id'], $to_already_selected)) {
// $to_already_selected is the array containing the groups (and users) that are already selected
$user_label = ($this_group['userNb'] > 0) ? get_lang('Users') : get_lang('LowerCaseUser') ;
$user_disabled = ($this_group['userNb'] > 0) ? "" : "disabled=disabled" ;
echo "<option $user_disabled value=\"GROUP:" . $this_group['id'] . "\">",
"G: ", $this_group['name'], " - " . $this_group['userNb'] . " " . $user_label .
"</option>";
}
}
}
// a divider
echo "<option value=\"\">---------------------------------------------------------</option>";
}
// adding the individual users to the select form
if (!empty($userList)) {
foreach ($userList as $user) {
if (is_array($to_already_selected)) {
if (!in_array("USER:" . $user['user_id'], $to_already_selected)) {
// $to_already_selected is the array containing the users (and groups) that are already selected
echo "<option value=\"USER:" . $user['user_id'] . "\" title='" . sprintf(get_lang('LoginX'), $user['username']) . "'>",
"", api_get_person_name($user['firstname'], $user['lastname']),
"</option>";
if (isset($user['drh_list']) && !empty($user['drh_list'])) {
foreach ($user['drh_list'] as $drh) {
echo "<option value=\"USER:" . $drh['user_id'] . "\" title='" . sprintf(get_lang('LoginX'), $drh['username']) . "'>&nbsp;&nbsp;&nbsp;&nbsp;",
"", api_get_person_name($drh['firstname'], $drh['lastname']),
"</option>";
}
}
}
}
}
}
echo "</select>";
}
/**
* this function shows the form for sending a message to a specific group or user.
*/
/**
* @param null $groupList
* @param null $userList
* @param $to_already_selected
*/
public static function construct_selected_select_form($groupList = null, $userList = null, $to_already_selected = array())
{
// we load all the groups and all the users into a reference array that we use to search the name of the group / user
$ref_array_groups = self::get_course_groups();
$ref_array_users = self::get_course_users();
// we construct the form of the already selected groups / users
echo '<select id="selectedform" name="selectedform[]" size="7" multiple class="form-control">';
if (is_array($to_already_selected)) {
foreach ($to_already_selected as $groupuser) {
list($type, $id) = explode(":", $groupuser);
if ($type == "GROUP") {
echo "<option value=\"" . $groupuser . "\">G: " . $ref_array_groups[$id]['name'] . "</option>";
} else {
foreach ($ref_array_users as $key => $value) {
if ($value['user_id'] == $id) {
echo "<option value=\"" . $groupuser . "\" title='" . sprintf(get_lang('LoginX'), $value['username']) . "'>" .
api_get_person_name($value['firstname'], $value['lastname']) . "</option>";
if (isset($value['drh_list']) && !empty($value['drh_list'])) {
foreach ($value['drh_list'] as $drh) {
echo "<option value=\"USER:" . $drh['user_id'] . "\" title='" . sprintf(get_lang('LoginX'), $drh['username']) . "'>&nbsp;&nbsp;&nbsp;&nbsp;",
"", api_get_person_name($drh['firstname'], $drh['lastname']),
"</option>";
}
}
break;
}
}
}
}
} else {
if ($to_already_selected == 'everyone') {
// adding the groups to the select form
if (is_array($ref_array_groups)) {
foreach ($ref_array_groups as $this_group) {
//api_display_normal_message("group " . $thisGroup[id] . $thisGroup[name]);
if (!is_array($to_already_selected) || !in_array("GROUP:" . $this_group['id'], $to_already_selected)) { // $to_already_selected is the array containing the groups (and users) that are already selected
echo "<option value=\"GROUP:" . $this_group['id'] . "\">",
"G: ", $this_group['name'], " &ndash; " . $this_group['userNb'] . " " . get_lang('Users') .
"</option>";
}
}
}
// adding the individual users to the select form
foreach ($ref_array_users as $this_user) {
if (!is_array($to_already_selected) || !in_array("USER:" . $this_user['user_id'], $to_already_selected)) { // $to_already_selected is the array containing the users (and groups) that are already selected
echo "<option value=\"USER:", $this_user['user_id'], "\" title='" . sprintf(get_lang('LoginX'), $this_user['username']) . "'>",
"", api_get_person_name($this_user['firstname'], $this_user['lastname']),
"</option>";
}
}
}
}
echo "</select>";
}
/**
* Returns announcement info from its id
*
@ -1133,23 +930,6 @@ class AnnouncementManager
return $to;
}
/**
* returns the javascript for setting a filter
* this goes into the $htmlHeadXtra[] array
*/
public static function user_group_filter_javascript()
{
return "<script language=\"JavaScript\" type=\"text/JavaScript\">
<!--
function jumpMenu(targ,selObj,restore)
{
eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>";
}
/**
* constructs the form to display all the groups and users the message has been sent to
* input: $sent_to_array is a 2 dimensional array containing the groups and the users
@ -1223,8 +1003,6 @@ class AnnouncementManager
}
}
/**
* Returns all the users and all the groups a specific announcement item
* has been sent to
@ -1275,19 +1053,19 @@ class AnnouncementManager
/**
* Show a list with all the attachments according to the post's id
* @param int announcement id
* @param int $announcementId
* @return array with the post info
* @author Arthur Portugal
* @version November 2009, dokeos 1.8.6.2
*/
public static function get_attachment($announcement_id)
public static function get_attachment($announcementId)
{
$tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
$announcement_id = intval($announcement_id);
$announcementId = intval($announcementId);
$course_id = api_get_course_int_id();
$row = array();
$sql = 'SELECT id, path, filename, comment FROM ' . $tbl_announcement_attachment . '
WHERE c_id = ' . $course_id . ' AND announcement_id = ' . $announcement_id . '';
WHERE c_id = ' . $course_id . ' AND announcement_id = ' . $announcementId;
$result = Database::query($sql);
if (Database::num_rows($result) != 0) {
$row = Database::fetch_array($result, 'ASSOC');
@ -1684,8 +1462,6 @@ class AnnouncementManager
$iterator = 1;
$bottomAnnouncement = $announcement_number;
$origin = null;
$displayed = [];
$results = [];
$actionUrl = api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq();
@ -1784,7 +1560,7 @@ class AnnouncementManager
public static function getNumberAnnouncements()
{
// Maximum title messages to display
$maximum = '12';
$maximum = '12';
// Database Table Definitions
$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
$tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
@ -1800,7 +1576,7 @@ class AnnouncementManager
if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
if (api_get_group_id() == 0) {
$group_condition = "";
$group_condition = '';
} else {
$group_condition = " AND (ip.to_group_id='".api_get_group_id()."' OR ip.to_group_id = 0 OR ip.to_group_id IS NULL)";
}
@ -1816,7 +1592,7 @@ class AnnouncementManager
$condition_session
GROUP BY ip.ref
ORDER BY display_order DESC
LIMIT 0,$maximum";
LIMIT 0, $maximum";
}
} else {
// students only get to see the visible announcements
@ -1857,7 +1633,8 @@ class AnnouncementManager
}
}
// the user is member of several groups => display personal announcements AND his group announcements AND the general announcements
// the user is member of several groups => display personal announcements AND
// his group announcements AND the general announcements
if (is_array($group_memberships) && count($group_memberships)>0) {
$sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
FROM $tbl_announcement announcement, $tbl_item_property ip

@ -146,7 +146,7 @@ class Agenda
) {
$start = api_get_utc_datetime($start);
$end = api_get_utc_datetime($end);
$allDay = isset($allDay) && $allDay == 'true' ? 1 : 0;
$allDay = isset($allDay) && $allDay === 'true' ? 1 : 0;
$id = null;
switch ($this->type) {
@ -1116,8 +1116,8 @@ class Agenda
return $this->events;
break;
}
}
return '';
}
@ -1854,54 +1854,6 @@ class Agenda
return $eventDate->format(DateTime::ISO8601);
}
/**
* this function shows the form with the user that were not selected
* @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @return string code
*/
public static function construct_not_selected_select_form($group_list = null, $user_list = null, $to_already_selected = array())
{
$html = '<select id="users_to_send_id" data-placeholder="'.get_lang('Select').'" name="users_to_send[]" multiple="multiple">';
if ($to_already_selected == 'everyone') {
$html .= '<option value="everyone" checked="checked">'.get_lang('Everyone').'</option>';
} else {
$html .= '<option value="everyone">'.get_lang('Everyone').'</option>';
}
if (is_array($group_list)) {
$html .= '<optgroup label="'.get_lang('Groups').'">';
foreach ($group_list as $this_group) {
if (!is_array($to_already_selected) || !in_array("GROUP:".$this_group['id'], $to_already_selected)) {
// $to_already_selected is the array containing the groups (and users) that are already selected
$count_users = isset($this_group['count_users']) ? $this_group['count_users'] : $this_group['userNb'];
$count_users = " &ndash; $count_users ".get_lang('Users');
$html .= '<option value="GROUP:'.$this_group['id'].'"> '.$this_group['name'].$count_users.'</option>';
}
}
$html .= '</optgroup>';
}
// adding the individual users to the select form
if (is_array($group_list)) {
$html .= '<optgroup label="'.get_lang('Users').'">';
}
foreach ($user_list as $this_user) {
// $to_already_selected is the array containing the users (and groups) that are already selected
if (!is_array($to_already_selected) || !in_array("USER:".$this_user['user_id'], $to_already_selected)) {
$username = api_htmlentities(sprintf(get_lang('LoginX'), $this_user['username']), ENT_QUOTES);
// @todo : add title attribute $username in the jqdialog window. wait for a chosen version to inherit title attribute
$html .= '<option title="'.$username.'" value="USER:'.$this_user['user_id'].'">'.api_get_person_name($this_user['firstname'], $this_user['lastname']).' ('.$this_user['username'].') </option>';
}
}
if (is_array($group_list)) {
$html .= '</optgroup>';
$html .= "</select>";
}
return $html;
}
/**
* @param FormValidator $form
* @param array $groupList
@ -1913,10 +1865,10 @@ class Agenda
*/
public function setSendToSelect(
$form,
$groupList = null,
$userList = null,
$sendTo = array(),
$attributes = array(),
$groupList = [],
$userList = [],
$sendTo = [],
$attributes = [],
$addOnlyItemsInSendTo = false,
$required = false
) {
@ -2051,7 +2003,7 @@ class Agenda
* @param array $params
* @return FormValidator
*/
public function getForm($params = array())
public function getForm($params = [])
{
$action = isset($params['action']) ? Security::remove_XSS($params['action']) : null;
$id = isset($params['id']) ? intval($params['id']) : null;
@ -2351,7 +2303,6 @@ class Agenda
return $list;
}
/**
* Show a list with all the attachments according to the post's id
* @param int $attachmentId
@ -2386,7 +2337,7 @@ class Agenda
* Add an attachment file into agenda
* @param int $eventId
* @param array $fileUserUpload ($_FILES['user_upload'])
* @param string comment about file
* @param string $comment about file
* @param array $courseInfo
* @return string
*/
@ -2797,7 +2748,6 @@ class Agenda
/** @var Sabre\VObject\Property\ICalendar\Recur $repeat */
$repeat = $event->RRULE;
if ($id && !empty($repeat)) {
$repeat = $repeat->getParts();
$freq = $trans[$repeat['FREQ']];
@ -3466,10 +3416,9 @@ class Agenda
return $items;
}
/**
* This function retrieves one personal agenda item returns it.
* @param int The agenda item ID
* @param int $id The agenda item ID
* @return array The results of the database query, or null if not found
*/
public static function get_personal_agenda_item($id)
@ -3488,7 +3437,6 @@ class Agenda
return $item;
}
/**
* This function calculates the startdate of the week (monday)
* and the enddate of the week (sunday)

@ -7,43 +7,6 @@ class TestAnnouncements extends UnitTestCase {
$this->UnitTestCase('Displays one specific announcement test');
}
public function Testconstruct_not_selected_select_form(){
$courseSysCode= '123';
$course_code = $courseSysCode;
ob_start();
$to_already_selected="";
$_SESSION['_cid'] = 'CURSO1';
$user_list = array( 0=>array(
0 => '1','user_id' => '1',
1 =>'Doe','lastname' =>'Doe',
2 =>'John','firstname' =>'John',
3 => 'admin','username' =>'admin'
));
$res = construct_not_selected_select_form($group_list=null, $user_list,$to_already_selected);
ob_end_clean();
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function Testconstruct_selected_select_form(){
$to_already_selected="";
ob_start();
$res = construct_selected_select_form($group_list=null, $user_list=null,$to_already_selected);
ob_end_clean();
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function Testshow_to_form_group(){
ob_start();
$group_id=1;
$group_users=GroupManager::get_subscribed_users($group_id);
$res = show_to_form_group($group_id);
ob_end_clean();
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function Testget_course_users(){
$_SESSION['id_session'] = 'CURSO1';

Loading…
Cancel
Save