Add filters in announcements see BT#10951

1.10.x
jmontoya 9 years ago
parent a0d9ceb45c
commit 23173d5ea6
  1. 115
      main/announcements/announcements.php
  2. 15
      main/inc/ajax/model.ajax.php
  3. 58
      main/inc/lib/AnnouncementManager.php

@ -7,8 +7,8 @@
* @author Julio Montoya <gugli100@gmail.com>, MORE code cleaning 2011
*
* @abstract The task of the internship was to integrate the 'send messages to specific users' with the
* Announcements tool and also add the resource linker here. The database also needed refactoring
* as there was no title field (the title was merged into the content field)
* Announcements tool and also add the resource linker here. The database also needed refactoring
* as there was no title field (the title was merged into the content field)
* @package chamilo.announcements
* multiple functions
*/
@ -24,7 +24,7 @@ require_once '../inc/global.inc.php';
$ctok = Security::get_existing_token();
$stok = Security::get_token();
$current_course_tool = TOOL_ANNOUNCEMENT;
$current_course_tool = TOOL_ANNOUNCEMENT;
$this_section = SECTION_COURSES;
$nameTools = get_lang('ToolAnnouncement');
@ -64,7 +64,8 @@ $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : 'list
$announcement_number = AnnouncementManager::getNumberAnnouncements();
$homeUrl = api_get_self().'?action=list&'.api_get_cidreq();
$content = null;
$content = '';
$searchFormToString = '';
switch ($action) {
case 'move':
@ -82,7 +83,7 @@ switch ($action) {
if (!empty($sortDirection)) {
if (!in_array(trim(strtoupper($sortDirection)), array('ASC', 'DESC'))) {
$sortDirection='ASC';
$sortDirection = 'ASC';
}
$announcementInfo = AnnouncementManager::get_by_id($course_id, $thisAnnouncementId);
@ -129,11 +130,43 @@ switch ($action) {
$content = AnnouncementManager::display_announcement($announcement_id);
break;
case 'list':
$htmlHeadXtra[] = api_get_jqgrid_js();
$searchForm = new FormValidator(
'search_simple',
'post',
api_get_self().'?'.api_get_cidreq(),
'',
array(),
FormValidator::LAYOUT_INLINE
);
$searchForm->addElement('text', 'keyword', get_lang('Title'));
$users = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id());
$userList = array('' => '');
if (!empty($users)) {
foreach ($users as $user) {
$userList[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
}
}
$users = [];
$searchForm->addElement('select', 'user_id', get_lang('Users'), $userList);
$searchForm->addButtonSearch(get_lang('Search'));
$filterData = array();
$keyword = '';
$userIdToSearch = 0;
if ($searchForm->validate()) {
$filterData = $searchForm->getSubmitValues();
$keyword = $filterData['keyword'];
$userIdToSearch = $filterData['user_id'];
}
$searchFormToString = $searchForm->returnForm();
// jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_course_announcements&'.api_get_cidreq();
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_course_announcements&'.api_get_cidreq().'&title_to_search='.$keyword.'&user_id_to_search='.$userIdToSearch;
$deleteUrl = api_get_path(WEB_AJAX_PATH).'announcement.ajax.php?a=delete_item&'.api_get_cidreq();
$columns = array(get_lang('Title'), get_lang('By'), get_lang('LastUpdateDate'), get_lang('Actions'));
@ -194,7 +227,16 @@ switch ($action) {
$content = '<script>
$(function() {'.
Display::grid_js('announcements', $url, $columns, $columnModel, $extra_params, array(), '', true).$editOptions.'
Display::grid_js(
'announcements',
$url,
$columns,
$columnModel,
$extra_params,
array(),
'',
true
).$editOptions.'
});
</script>';
@ -207,12 +249,12 @@ switch ($action) {
(empty($_GET['origin']) || $_GET['origin'] !== 'learnpath')
) {
$html .= '<div id="no-data-view">';
$html .= '<h3>' . get_lang('Announcements') . '</h3>';
$html .= '<h3>'.get_lang('Announcements').'</h3>';
$html .= Display::return_icon('valves.png', '', array(), 64);
$html .= '<div class="controls">';
$html .= Display::url(
get_lang('AddAnnouncement'),
api_get_self() . "?" . api_get_cidreq() . "&action=add",
api_get_self()."?".api_get_cidreq()."&action=add",
array('class' => 'btn btn-primary')
);
$html .= '</div>';
@ -228,15 +270,13 @@ switch ($action) {
case 'delete':
/* Delete announcement */
$id = intval($_GET['id']);
if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false, true) == false) {
if (api_get_session_id() != 0 && api_is_allowed_to_session_edit(false, true) == false) {
api_not_allowed();
}
if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $id)) {
AnnouncementManager::delete_announcement($_course, $id);
Display::addFlash(Display::return_message(get_lang('AnnouncementDeleted')));
}
header('Location: '.$homeUrl);
exit;
@ -263,7 +303,8 @@ switch ($action) {
if (!isset($_GET['isStudentView']) || $_GET['isStudentView'] != 'false') {
if (isset($_GET['id']) && $_GET['id']) {
if (api_get_session_id() != 0 &&
api_is_allowed_to_session_edit(false, true) == false) {
api_is_allowed_to_session_edit(false, true) == false
) {
api_not_allowed();
}
@ -293,7 +334,7 @@ switch ($action) {
// DISPLAY ADD ANNOUNCEMENT COMMAND
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$url = api_get_self().'?action='.$action.'&id=' . $id . '&' . api_get_cidreq();
$url = api_get_self().'?action='.$action.'&id='.$id.'&'.api_get_cidreq();
$form = new FormValidator(
'f1',
@ -334,7 +375,7 @@ switch ($action) {
);
// setting the variables for the form elements: the users who need to receive the message
foreach ($to as &$user) {
$user = 'USER:' . $user;
$user = 'USER:'.$user;
}
// setting the variables for the form elements: the message has to be sent by email
$email_ann = '1';
@ -399,7 +440,7 @@ switch ($action) {
'title' => $announcementInfo['title'],
'content' => $announcementInfo['content'],
'id' => $announcementInfo['id'],
'users' => $to
'users' => $to,
);
} else {
$defaults = array();
@ -417,7 +458,9 @@ switch ($action) {
$htmlTags .= "<b>".$tag."</b></br>";
}
$form->addHtml("<div class='form-group'><div class='col-sm-2'></div><div class='col-sm-8'><div class='alert alert-info'>".$htmlTags."</div></div></div>");
$form->addHtml(
"<div class='form-group'><div class='col-sm-2'></div><div class='col-sm-8'><div class='alert alert-info'>".$htmlTags."</div></div></div>"
);
$form->addHtmlEditor(
'content',
get_lang('Description'),
@ -435,7 +478,6 @@ switch ($action) {
}
$form->addCheckBox('send_to_hrm_users', null, get_lang('SendAnnouncementCopyToDRH'));
$form->addButtonSave(get_lang('ButtonPublishAnnouncement'));
$form->setDefaults($defaults);
@ -497,7 +539,7 @@ switch ($action) {
$insert_id = AnnouncementManager::add_group_announcement(
$data['title'],
$data['content'],
array('GROUP:' . $group_id),
array('GROUP:'.$group_id),
$data['users'],
$file,
$file_comment,
@ -524,7 +566,6 @@ switch ($action) {
} // end condition token
}
}
$content = $form->returnForm();
break;
}
@ -534,7 +575,7 @@ if (!empty($_GET['remind_inactive'])) {
}
if (!empty($group_id)) {
$group_properties = GroupManager :: get_group_properties($group_id);
$group_properties = GroupManager:: get_group_properties($group_id);
$interbreadcrumb[] = array(
"url" => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(),
"name" => get_lang('Groups'),
@ -557,41 +598,43 @@ if (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath') {
// Actions
$show_actions = false;
$actionsLeft = '';
if ((api_is_allowed_to_edit(false, true) ||
(api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) &&
(empty($_GET['origin']) || $_GET['origin'] !== 'learnpath')
) {
echo '<div class="actions">';
if (in_array($action, array('add', 'modify','view'))) {
echo "<a href='".api_get_self()."?".api_get_cidreq()."&origin=".$origin."'>".
if (in_array($action, array('add', 'modify', 'view'))) {
$actionsLeft .= "<a href='".api_get_self()."?".api_get_cidreq()."&origin=".$origin."'>".
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM)."</a>";
} else {
echo "<a href='".api_get_self()."?".api_get_cidreq()."&action=add&origin=".$origin."'>".
$actionsLeft .= "<a href='".api_get_self()."?".api_get_cidreq()."&action=add&origin=".$origin."'>".
Display::return_icon('new_announce.png', get_lang('AddAnnouncement'), '', ICON_SIZE_MEDIUM)."</a>";
}
$show_actions = true;
} else {
if (in_array($action, array('view'))) {
echo '<div class="actions">';
echo "<a href='".api_get_self()."?".api_get_cidreq()."&origin=".$origin."'>".
$actionsLeft .= "<a href='".api_get_self()."?".api_get_cidreq()."&origin=".$origin."'>".
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM)."</a>";
echo '</div>';
}
}
if (api_is_allowed_to_edit() && $announcement_number > 1) {
if (api_get_group_id() == 0 ) {
if (!$show_actions)
echo '<div class="actions">';
if (api_get_group_id() == 0) {
if (!isset($_GET['action'])) {
echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=delete_all\" onclick=\"javascript:if(!confirm('".get_lang("ConfirmYourChoice")."')) return false;\">".
Display::return_icon('delete_announce.png',get_lang('AnnouncementDeleteAll'),'',ICON_SIZE_MEDIUM)."</a>";
$actionsLeft .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=delete_all\" onclick=\"javascript:if(!confirm('".get_lang("ConfirmYourChoice")."')) return false;\">".
Display::return_icon(
'delete_announce.png',
get_lang('AnnouncementDeleteAll'),
'',
ICON_SIZE_MEDIUM
)."</a>";
}
}
}
if ($show_actions)
echo '</div>';
if ($show_actions) {
echo Display::toolbarAction('toolbar', array($actionsLeft, $searchFormToString), 2, false);
}
echo $content;

@ -767,7 +767,20 @@ switch ($action) {
'actions'
);
$result = AnnouncementManager::getAnnouncements(null, null, false, $start, $limit, $sidx, $sord);
$titleToSearch = isset($_REQUEST['title_to_search']) ? $_REQUEST['title_to_search'] : '';
$userIdToSearch = isset($_REQUEST['user_id_to_search']) ? $_REQUEST['user_id_to_search'] : 0;
$result = AnnouncementManager::getAnnouncements(
null,
null,
false,
$start,
$limit,
$sidx,
$sord,
$titleToSearch,
$userIdToSearch
);
break;
case 'get_work_teacher':

@ -1388,10 +1388,22 @@ class AnnouncementManager
* @param null $limit
* @param string $sidx
* @param string $sord
* @param string $titleToSearch
* @param int $userIdToSearch
*
* @return array
*/
public static function getAnnouncements($stok, $announcement_number, $getCount = false, $start = null, $limit = null, $sidx = '', $sord = '')
{
public static function getAnnouncements(
$stok,
$announcement_number,
$getCount = false,
$start = null,
$limit = null,
$sidx = '',
$sord = '',
$titleToSearch = '',
$userIdToSearch = 0
) {
$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
$tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
@ -1410,6 +1422,17 @@ class AnnouncementManager
$select = ' COUNT(announcement.iid) count';
}
$searchCondition = '';
if (!empty($titleToSearch)) {
$titleToSearch = Database::escape_string($titleToSearch);
$searchCondition .= " AND (title LIKE '%$titleToSearch%')";
}
if (!empty($userIdToSearch)) {
$userIdToSearch = intval($userIdToSearch);
$searchCondition .= " AND (ip.insert_user_id = $userIdToSearch)";
}
if (api_is_allowed_to_edit(false, true) ||
($allowUserEditSetting && !api_is_anonymous())
) {
@ -1433,6 +1456,7 @@ class AnnouncementManager
) AND
ip.visibility IN ('1', '0')
$condition_session
$searchCondition
ORDER BY display_order DESC";
} else {
$sql = "SELECT $select
@ -1445,6 +1469,7 @@ class AnnouncementManager
(ip.to_user_id = $user_id OR ip.to_group_id='0' OR ip.to_group_id IS NULL) AND
ip.visibility IN ('1', '0')
$condition_session
$searchCondition
ORDER BY display_order DESC";
}
} elseif ($group_id != 0) {
@ -1459,7 +1484,7 @@ class AnnouncementManager
ip.visibility<>'2' AND
(ip.to_group_id = $group_id OR ip.to_group_id='0' OR ip.to_group_id IS NULL)
$condition_session
$searchCondition
ORDER BY display_order DESC";
//GROUP BY ip.ref
} else {
@ -1477,6 +1502,7 @@ class AnnouncementManager
ip.tool='announcement' AND
ip.visibility='1'
$condition_session
$searchCondition
ORDER BY display_order DESC";
//GROUP BY ip.ref
@ -1491,6 +1517,7 @@ class AnnouncementManager
ip.c_id = $course_id AND
(ip.visibility='0' or ip.visibility='1')
$condition_session
$searchCondition
ORDER BY display_order DESC";
//GROUP BY ip.ref
}
@ -1533,8 +1560,9 @@ class AnnouncementManager
announcement.id = ip.ref
AND ip.tool='announcement'
$cond_user_id
$condition_session AND
ip.visibility='1'
$condition_session
$searchCondition
AND ip.visibility='1'
ORDER BY display_order DESC";
} else {
if ($user_id) {
@ -1556,6 +1584,7 @@ class AnnouncementManager
ip.tool='announcement'
$cond_user_id
$condition_session
$searchCondition
AND ip.visibility='1'
AND announcement.session_id IN(0, ".api_get_session_id().")
ORDER BY display_order DESC";
@ -1577,17 +1606,21 @@ class AnnouncementManager
announcement.id = ip.ref AND
ip.tool='announcement'
$cond_user_id
$condition_session AND
$condition_session
$searchCondition
AND
ip.visibility='1' AND
announcement.session_id IN ( 0,".api_get_session_id().")";
}
}
}
if (!is_null($start) && !is_null($limit)) {
$start = intval($start);
$limit = intval($limit);
$sql .= " LIMIT $start, $limit";
}
$result = Database::query($sql);
if ($getCount) {
$result = Database::fetch_array($result, 'ASSOC');
@ -1599,12 +1632,6 @@ class AnnouncementManager
$bottomAnnouncement = $announcement_number;
$origin = null;
/*if (api_is_allowed_to_edit(false,true) OR (api_is_course_coach() &&
api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $myrow['id']))
OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
$ths .= Display::tag('th', get_lang('Modify'));
}*/
$displayed = [];
$results = [];
$actionUrl = api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq();
@ -1620,13 +1647,6 @@ class AnnouncementManager
$item_visibility = api_get_item_visibility($_course, TOOL_ANNOUNCEMENT, $myrow['id'], $session_id);
$myrow['visibility'] = $item_visibility;
// the styles
if ($myrow['visibility'] == '0') {
$style='invisible';
} else {
$style = '';
}
// show attachment list
$attachment_list = AnnouncementManager::get_attachment($myrow['id']);

Loading…
Cancel
Save