$feedback_names = feedback_load_feedback_items('mod/feedback/item');
/**
-* this will create a new instance and return the id number
+* this will create a new instance and return the id number
* of the new instance.
* @param object $feedback the object given by mod_feedback_mod_form
* @return int
if (!$feedbackid = $DB->insert_record("feedback", $feedback)) {
return false;
}
-
+
+ $feedback->id = $feedbackid;
+
feedback_set_events($feedback);
-
+
return $feedbackid;
}
//create or update the new events
feedback_set_events($feedback);
-
+
return true;
}
//get all referenced items
$feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$id));
-
+
//deleting all referenced items and values
if (is_array($feedbackitems)){
foreach($feedbackitems as $feedbackitem){
}
$DB->delete_records("feedback_item", array("feedback"=>$id));
}
-
+
//deleting the referenced tracking data
$DB->delete_records('feedback_tracking', array('feedback'=>$id));
-
+
//deleting the completeds
$DB->delete_records("feedback_completed", array("feedback"=>$id));
-
+
//deleting the unfinished completeds
$DB->delete_records("feedback_completedtmp", array("feedback"=>$id));
-
+
//deleting old events
$DB->delete_records('event', array('modulename'=>'feedback', 'instance'=>$id));
return $DB->delete_records("feedback", array("id"=>$id));
}
/**
-* Return a small object with summary information about what a
+* Return a small object with summary information about what a
* user has done with a given particular instance of this module
* Used for user activity reports.
* $return->time = the time they did it
*/
function feedback_reset_userdata($data) {
global $CFG, $DB;
-
+
$resetfeedbacks = array();
$dropfeedbacks = array();
$status = array();
$componentstr = get_string('modulenameplural', 'feedback');
-
+
//get the relevant entries from $data
foreach($data as $key => $value) {
switch(true) {
break;
}
}
-
+
//reset the selected feedbacks
foreach($resetfeedbacks as $id) {
$feedback = $DB->get_record('feedback', array('id'=>$id));
feedback_delete_all_completeds($id);
$status[] = array('component'=>$componentstr.':'.$feedback->name, 'item'=>get_string('resetting_data','feedback'), 'error'=>false);
}
-
+
//drop the selected feedbacks
// foreach($dropfeedbacks as $id) {
// $cm = get_coursemodule_from_instance('feedback', $id);
global $COURSE, $DB;
$mform->addElement('header', 'feedbackheader', get_string('modulenameplural', 'feedback'));
-
+
if(!$feedbacks = $DB->get_records('feedback', array('course'=>$COURSE->id), 'name')){
return;
}
return $return;
}
-/**
+/**
* Called by course/reset.php and shows the formdata by coursereset.
* it prints checkboxes for each feedback available at the given course
* there are two checkboxes: 1) delete userdata and keep the feedback 2) delete userdata and drop the feedback
if (!$feedbacks = $DB->get_records('feedback', array('course'=>$course->id), 'name')) {
return;
}
-
+
foreach($feedbacks as $feedback) {
echo '<p>';
echo get_string('name','feedback').': '.$feedback->name.'<br />';
}
}
-/**
+/**
* This creates new events given as timeopen and closeopen by $feedback.
* @param object $feedback
* @return void
} else {
$event->timeduration = 0;
}
-
+
add_event($event);
}
}
}
-/**
+/**
* this function is called by {@link feedback_delete_userdata()}
* it drops the feedback-instance from the course_module table
* @param int $id the id from the coursemodule
//functions to handle capabilities
////////////////////////////////////////////////
-/**
+/**
* returns the context-id related to the given coursemodule-id
* @param int $cmid the coursemodule-id
* @return object $context
*/
function feedback_get_context($cmid) {
static $context;
-
+
if(isset($context)) return $context;
-
+
if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) {
print_error('badcontext');
}
return $context;
}
-/**
+/**
* get the capabilities for the feedback
* @param int $cmid
* @return object the available capabilities from current user
*/
function feedback_load_capabilities($cmid) {
static $cb;
-
+
if(isset($cb)) return $cb;
-
+
$context = feedback_get_context($cmid);
-
+
$cb = new object;
$cb->view = has_capability('mod/feedback:view', $context, NULL, false);
$cb->complete = has_capability('mod/feedback:complete', $context, NULL, false);
$cb->createprivatetemplate = has_capability('mod/feedback:createprivatetemplate', $context, NULL, false);
$cb->createpublictemplate = has_capability('mod/feedback:createpublictemplate', $context, NULL, false);
$cb->deletetemplate = has_capability('mod/feedback:deletetemplate', $context, NULL, false);
-
+
$cb->siteadmin = has_capability('moodle/site:doanything', $context);
-
+
$cb->viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $context, NULL, false);
-
+
return $cb;
}
-/**
+/**
* get the capabilities for the course.
* this is used by feedback/index.php
* @param int $courseid
*/
function feedback_load_course_capabilities($courseid) {
static $ccb;
-
+
if(isset($ccb)) return $ccb;
-
+
$context = get_context_instance(CONTEXT_COURSE, $courseid);
-
+
$ccb = new object;
$ccb->view = has_capability('mod/feedback:view', $context, NULL, false);
$ccb->complete = has_capability('mod/feedback:complete', $context, NULL, false);
$ccb->createprivatetemplate = has_capability('mod/feedback:createprivatetemplate', $context, NULL, false);
$ccb->createpublictemplate = has_capability('mod/feedback:createpublictemplate', $context, NULL, false);
$ccb->deletetemplate = has_capability('mod/feedback:deletetemplate', $context, NULL, false);
-
+
$ccb->siteadmin = has_capability('moodle/site:doanything', $context);
-
+
$ccb->viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $context, NULL, false);
-
+
return $ccb;
}
-/**
+/**
* returns true if the current role is faked by switching role feature
* @return boolean
*/
return false;
}
-/**
+/**
* get users which have the complete-capability
* @param int $cmid
* @param mixed $groups single groupid or array of groupids - group(s) user is in
if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) {
print_error('badcontext');
}
-
+
//description of the call below: get_users_by_capability($context, $capability, $fields='', $sort='', $limitfrom='', $limitnum='', $groups='', $exceptions='', $doanything=true)
return get_users_by_capability($context, 'mod/feedback:complete', '', 'lastname', '', '', $groups, '', false);
}
-/**
+/**
* get users which have the viewreports-capability
* @param int $cmid
* @param mixed $groups single groupid or array of groupids - group(s) user is in
if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) {
print_error('badcontext');
}
-
+
//description of the call below: get_users_by_capability($context, $capability, $fields='', $sort='', $limitfrom='', $limitnum='', $groups='', $exceptions='', $doanything=true)
return get_users_by_capability($context, 'mod/feedback:viewreports', '', 'lastname', '', '', $groups, '', false);
}
-/**
+/**
* get users which have the receivemail-capability
* @param int $cmid
* @param mixed $groups single groupid or array of groupids - group(s) user is in
if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) {
print_error('badcontext');
}
-
+
//description of the call below: get_users_by_capability($context, $capability, $fields='', $sort='', $limitfrom='', $limitnum='', $groups='', $exceptions='', $doanything=true)
return get_users_by_capability($context, 'mod/feedback:receivemail', '', 'lastname', '', '', $groups, '', true);
}
////////////////////////////////////////////////
////////////////////////////////////////////////
-/**
+/**
* creates a new template-record.
* @param int $courseid
* @param string $name the name of template shown in the templatelist
return $DB->insert_record('feedback_template', $templ);
}
-/**
+/**
* creates new template items.
* all items will be copied and the attribute feedback will be set to 0
* and the attribute template will be set to the new templateid
if (!$feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id))) {
return false;
}
-
+
if (!$newtempl = feedback_create_template($feedback->course, $name, $ispublic)) {
return false;
}
return true;
}
-/**
+/**
* deletes all feedback_items related to the given template id
* @param int $id the templateid
* @return void
$DB->delete_records("feedback_template", array("id"=>$id));
}
-/**
+/**
* creates new feedback_item-records from template.
* if $deleteold is set true so the existing items of the given feedback will be deleted
* if $deleteold is set false so the new items will be appanded to the old items
if(!$templitems = $DB->get_records('feedback_item', array('template'=>$templateid))) {
return false;
}
-
+
//if deleteold then delete all old items before
//get all items
if($deleteold) {
//therefor the new position has an offset
$positionoffset = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
}
-
+
foreach($templitems as $newitem) {
unset($newitem->id);
$newitem->feedback = $feedback->id;
}
}
-/**
+/**
* get the list of available templates.
* if the $onlyown param is set true so only templates from own course will be served
* this is important for droping templates
////////////////////////////////////////////////
////////////////////////////////////////////////
-/**
+/**
* load the available item plugins from given subdirectory of $CFG->dirroot
* the default is "mod/feedback/item"
* @param string $dir the subdir
return $ret_names;
}
-/**
+/**
* load the available item plugins to use as dropdown-options
* @return array pluginnames as string
*/
function feedback_load_feedback_items_options() {
global $CFG;
-
+
$feedback_options = array("pagebreak" => get_string('add_pagebreak', 'feedback'));
-
+
if (!$feedback_names = feedback_load_feedback_items('mod/feedback/item')) {
return array();
}
-
+
foreach($feedback_names as $fn) {
$feedback_options[$fn] = get_string($fn,'feedback');
}
asort($feedback_options);
- $feedback_options = array_merge( array(' ' => get_string('select')), $feedback_options );
+ $feedback_options = array_merge( array(' ' => get_string('select')), $feedback_options );
return $feedback_options;
}
-/**
+/**
* creates a new item-record
* @param object $data the data from edit_item_form
* @return int the new itemid
$item->template=0;
if (isset($data->templateid)) {
$item->template = intval($data->templateid);
- }
+ }
$itemname = trim($data->itemname);
$item->name = ($itemname ? $data->itemname : get_string('no_itemname', 'feedback'));
-
+
//get the used class from item-typ
$itemclass = 'feedback_item_'.$data->typ;
//get the instance of the item class
$itemobj = new $itemclass();
$item->presentation = $itemobj->get_presentation($data);
-
+
$item->hasvalue = $itemobj->get_hasvalue();
-
+
$item->typ = $data->typ;
$item->position = $data->position;
$item->required=0;
if (isset($data->required)) {
$item->required=$data->required;
- }
+ }
return $DB->insert_record('feedback_item', $item);
}
-/**
+/**
* save the changes of a given item.
* @param object $item
* @param object $data the data from edit_item_form
if($data != null){
$itemname = trim($data->itemname);
$item->name = ($itemname ? $data->itemname : get_string('no_itemname', 'feedback'));
-
+
//get the used class from item-typ
$itemclass = 'feedback_item_'.$data->typ;
//get the instance of the item class
$item->required=0;
if (isset($data->required)) {
$item->required=$data->required;
- }
+ }
}else {
$item->name = $item->name;
$item->presentation = $item->presentation;
return $DB->update_record("feedback_item", $item);
}
-/**
+/**
* deletes a item and also deletes all related values
* @param int $itemid
* @param boolean $renumber should the kept items renumbered Yes/No
}
}
-/**
+/**
* deletes all items of the given feedbackid
* @param int $feedbackid
* @return void
$DB->delete_records('feedback_completed', array('feedback'=>$feedbackid));
}
-/**
+/**
* this function toggled the item-attribute required (yes/no)
* @param object $item
* @return boolean
return $DB->update_record('feedback_item', $item);
}
-/**
+/**
* renumbers all items of the given feedbackid
* @param int $feedbackid
* @return void
}
}
-/**
+/**
* this decreases the position of the given item
* @param object $item
* @return void
feedback_update_item($item);
}
-/**
+/**
* this increased the position of the given item
* @param object $item
* @return void
if(!$item_after = $DB->get_record('feedback_item', array('feedback'=>$item->feedback, 'position'=>$item->position+1))) {
return;
}
-
+
$item_after->position = $item->position;
$item->position++;
feedback_update_item($item_after);
feedback_update_item($item);
}
-/**
+/**
* here the position of the given item will be set to the value in $pos
* @param object $moveitem
* @param int $pos
$index = 1;
foreach($allitems as $item) {
if($item->id == $moveitem->id) continue; //the moving item is handled special
-
+
if($index == $pos) {
$moveitem->position = $index;
feedback_update_item($moveitem);
return false;
}
-/**
+/**
* prints the given item.
* if $readonly is set true so the ouput only is for showing responses and not for editing or completing.
* each item-class has an own print_item function implemented.
function feedback_print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){
if($item->typ == 'pagebreak') return;
if($readonly)$ro = 'readonly="readonly" disabled="disabled"';
-
+
//get the class of the given item-typ
$itemclass = 'feedback_item_'.$item->typ;
//get the instance of the item-class
$itemobj->print_item($item, $value, $readonly, $edit, $highlightrequire);
}
-/**
+/**
* if the user completes a feedback and there is a pagebreak so the values are saved temporary.
* the values are saved permanently not until the user click on save button
* @param object $feedbackcompleted
return $tmpcpl;
}
-/**
+/**
* this saves the temporary saved values permanently
* @param object $feedbackcompletedtmp the temporary completed
* @param object $feedbackcompleted the target completed
}
}
-/**
+/**
* deletes the given temporary completed and all related temporary values
* @param int $tmpcplid
* @return void
//functions to handle the pagebreaks
////////////////////////////////////////////////
-/**
+/**
* this creates a pagebreak.
* a pagebreak is a special kind of item
* @param int $feedbackid
if($lastposition == feedback_get_last_break_position($feedbackid)) {
return false;
}
-
+
$item = new object();
$item->feedback = $feedbackid;
$item->template=0;
$item->name = '';
-
+
$item->presentation = '';
$item->hasvalue = 0;
-
+
$item->typ = 'pagebreak';
$item->position = $lastposition + 1;
return $DB->insert_record('feedback_item', $item);
}
-/**
+/**
* get all positions of pagebreaks in the given feedback
* @param int $feedbackid
* @return array all ordered pagebreak positions
return array_values($allbreaks);
}
-/**
+/**
* get the position of the last pagebreak
* @param int $feedbackid
* @return int the position of the last pagebreak
return $allbreaks[count($allbreaks) - 1];
}
-/**
+/**
* this returns the position where the user can continue the completing.
* @param int $feedbackid
* @param int $courseid
*/
function feedback_get_page_to_continue($feedbackid, $courseid = false, $guestid) {
global $CFG, $USER, $DB;
-
+
//is there any break?
-
+
if(!$allbreaks = feedback_get_all_break_positions($feedbackid)) return false;
$params = array();
}else {
$courseselect = "1";
}
-
+
if($guestid) {
$userselect = "AND fc.guestid = :guestid";
$usergroup = "GROUP BY fc.guestid";
//functions to handle the values
////////////////////////////////////////////////
-/**
+/**
* this saves the values of an completed.
* if the param $tmp is set true so the values are saved temporary in table feedback_valuetmp
* if there is already a completed and the userid is set so the values are updated
$tmpstr = $tmp ? 'tmp' : '';
$time = time(); //arb
$timemodified = mktime(0, 0, 0, date('m', $time),date('d', $time),date('Y', $time)); //arb
-// $timemodified = time();
+// $timemodified = time();
if($usrid == 0) {
return feedback_create_values($data, $usrid, $timemodified, $tmp);
}
}
}
-/**
+/**
* this saves the values from anonymous user such as guest on the main-site
* @param object $data the data form complete_guest form
* @param string $guestid the unique guestidentifier
}
}
-/**
+/**
* get the value from the given item related to the given completed.
* the value can come as temporary or as permanently value. the deciding is done by $tmp
* @param int $completeid
return $DB->get_field('feedback_value'.$tmpstr, 'value', array('completed'=>$completedid, 'item'=>$itemid));
}
-/**
+/**
* this function checks the correctness of values.
* the rules for this are implemented in the class of each item.
* it can be the required attribute or the value self e.g. numeric.
//<item-typ>_<item-id> eg. numeric_234
//this is the key to get the value for the correct item
$formvalname = $item->typ . '_' . $item->id;
-
+
//check if the value is set
if((!isset($data[$formvalname])) AND ($item->required == 1)) {
return false;
}
-
+
//if there is a value so save it temporary
$value = isset($data[$formvalname]) ? $data[$formvalname] : '';
$itemclass = 'feedback_item_'.$item->typ;
//get the instance of the item-class
$itemobj = new $itemclass();
-
+
//now we let check the value by the item-class
if(!$itemobj->check_value($value, $item)) {
return false;
return true;
}
-/**
+/**
* this function create a complete-record and the related value-records.
* depending on the $tmp (true/false) the values are saved temporary or permanently
* @param object $data the data of the complete form
$completed->guestid = $guestid;
$completed->timemodified = $timemodified;
$completed->anonymous_response = $data['anonymous_response'];
-
+
if (!$completedid = $DB->insert_record('feedback_completed'.$tmpstr, $completed)) {
return false;
}
-
+
$completed = $DB->get_record('feedback_completed'.$tmpstr, array('id'=>$completedid));
//$data includes an associative array. the keys are in the form like abc_xxx
$errcount = 0;
foreach($keys as $key){
//ensure the keys are what we want
- if(eregi('([a-z0-9]{1,})_([0-9]{1,})',$key)){
+ if(eregi('([a-z0-9]{1,})_([0-9]{1,})',$key)){
$value = new object();
$itemnr = explode('_', $key);
$value->item = intval($itemnr[1]);
$value->completed = $completed->id;
$value->course_id = intval($data['courseid']);
-
+
//get the class of item-typ
$itemclass = 'feedback_item_'.$itemnr[0];
//get the instance of item-class
}
}
}
-
+
//if nothing is wrong so we can return the completedid otherwise false
return $errcount == 0 ? $completed->id : false;
}
-/**
+/**
* this function updates a complete-record and the related value-records.
* depending on the $tmp (true/false) the values are saved temporary or permanently
* @param object $data the data of the complete form
global $DB;
$tmpstr = $tmp ? 'tmp' : '';
-
+
$DB->update_record('feedback_completed'.$tmpstr, $completed);
//get the values of this completed
$values = $DB->get_records('feedback_value'.$tmpstr, array('completed'=>$completed->id));
-
+
//$data includes an associative array. the keys are in the form like abc_xxx
//with explode we make an array with(abc, xxx) and (abc=typ und xxx=itemnr)
$keys = array_keys($data);
foreach($keys as $key){
//ensure the keys are what we want
- if(eregi('([a-z0-9]{1,})_([0-9]{1,})',$key)){
+ if(eregi('([a-z0-9]{1,})_([0-9]{1,})',$key)){
//build the new value to update([id], item, completed, value)
$itemnr = explode('_', $key);
$newvalue = new object();
$newvalue->item = $itemnr[1];
$newvalue->completed = $completed->id;
$newvalue->course_id = $data['courseid'];
-
+
//get the class of item-typ
$itemclass = 'feedback_item_'.$itemnr[0];
//get the instace of the item-class
$itemobj = new $itemclass();
//the kind of values can be absolutely different so we run create_value directly by the item-class
$newvalue->value = $itemobj->create_value($data[$key]);
-
+
//check, if we have to create or update the value
$exist = false;
foreach($values as $value){
}else {
$DB->insert_record('feedback_value'.$tmpstr, $newvalue);
}
-
+
}
}
return $completed->id;
}
-/**
+/**
* get the values of an item depending on the given groupid.
* if the feedback is anonymous so the values are shuffled
* @param object $item
$query = 'SELECT fbv . *
FROM {feedback_value} AS fbv, {feedback_completed} AS fbc, {groups_members} AS gm
WHERE fbv.item = ?
- AND fbv.completed = fbc.id
- AND fbc.userid = gm.userid
+ AND fbv.completed = fbc.id
+ AND fbc.userid = gm.userid
AND gm.groupid = ?
ORDER BY fbc.timemodified';
$values = $DB->get_records_sql($query, array($item->id, $groupid));
} else {
$values = $DB->get_records('feedback_value', array('item'=>$item->id));
}
- }
+ }
if ($DB->get_field('feedback', 'anonymous', array('id'=>$item->feedback)) == FEEDBACK_ANONYMOUS_YES) {
if(is_array($values))
shuffle($values);
return $values;
}
-/**
+/**
* check for multiple_submit = false.
* if the feedback is global so the courseid must be given
* @param int $feedbackid
*/
function feedback_is_already_submitted($feedbackid, $courseid = false) {
global $USER, $DB;
-
+
if (!$trackings = $DB->get_records_menu('feedback_tracking', array('userid'=>$USER->id, 'feedback'=>$feedbackid), '', 'id, completed')) {
return false;
}
return true;
}
-/**
+/**
* if the completion of a feedback will be continued eg. by pagebreak or by multiple submit so the complete must be found.
* if the param $tmp is set true so all things are related to temporary completeds
* @param int $feedbackid
*/
function feedback_get_current_completed($feedbackid, $tmp = false, $courseid = false, $guestid = false) {
global $USER, $CFG, $DB;
-
+
$tmpstr = $tmp ? 'tmp' : '';
-
+
if(!$courseid) {
if($guestid) {
return $DB->get_record('feedback_completed'.$tmpstr, array('feedback'=>$feedbackid, 'guestid'=>$guestid));
return $DB->get_record('feedback_completed'.$tmpstr, array('feedback'=>$feedbackid, 'userid'=>$USER->id));
}
}
-
+
$params = array();
-
+
if ($guestid) {
$userselect = "AND fc.guestid = :guestid";
$params['guestid'] = $guestid;
}
}
-/**
+/**
* get the completeds depending on the given groupid.
* @param object $feedback
* @param int $groupid
}
}
-/**
+/**
* get the count of completeds depending on the given groupid.
* @param object $feedback
* @param int $groupid
if ($courseid > 0 AND !$groupid <= 0) {
$sql = "SELECT id, COUNT(item) AS ci
- FROM {feedback_value}
+ FROM {feedback_value}
WHERE course_id = ?
GROUP BY item ORDER BY ci DESC";
if ($foundrecs = $DB->get_records_sql($sql, array($courseid))) {
@param object $cm
function feedback_get_groupid($course, $cm) {
$groupmode = groupmode($course, $cm);
-
+
//get groupid
if($groupmode > 0 && !has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
if($mygroupid = mygroupid($course->id)) {
}
*/
-/**
+/**
* deletes all completed-recordsets from a feedback.
* all related data such as values also will be deleted
* @param int $feedbackid
}
}
-/**
+/**
* deletes a completed given by completedid.
* all related data such values or tracking data also will be deleted
* @param int $completedid
}
//first we delete all related values
$DB->delete_records('feedback_value', array('completed'=>$completed->id));
-
+
//now we delete all tracking data
if($tracking = $DB->get_record('feedback_tracking', array('completed'=>$completed->id, 'feedback'=>$completed->feedback))) {
$DB->delete_records('feedback_tracking', array('completed'=>$completed->id));
}
-
+
//last we delete the completed-record
return $DB->delete_records('feedback_completed', array('id'=>$completed->id));
}
//functions to handle sitecourse mapping
////////////////////////////////////////////////
-/**
+/**
* checks if the course and the feedback is in the table feedback_sitecourse_map.
* @param int $feedbackid
* @param int $courseid
return $DB->count_records('feedback_sitecourse_map', array('feedbackid'=>$feedbackid, 'courseid'=>$courseid));
}
-/**
+/**
* checks if the feedback is in the table feedback_sitecourse_map.
* @param int $feedbackid
* @return boolean
return $DB->record_exists('feedback_sitecourse_map', array('feedbackid'=>$feedbackid));
}
-/**
+/**
* gets the feedbacks from table feedback_sitecourse_map.
* this is used to show the global feedbacks on the feedback block
* all feedbacks with the following criteria will be selected:<br />
*/
function feedback_get_feedbacks_from_sitecourse_map($courseid) {
global $DB;
-
+
//first get all feedbacks listed in sitecourse_map with named courseid
$sql = "SELECT f.id AS id, cm.id AS cmid, f.name AS name, f.timeopen AS timeopen, f.timeclose AS timeclose
FROM {feedback} f, {course_modules} cm, {feedback_sitecourse_map} sm, {modules} m
WHERE f.id = cm.instance
AND f.course = '".SITEID."'
- AND m.id = cm.module
+ AND m.id = cm.module
AND m.name = 'feedback'
- AND sm.courseid = ?
+ AND sm.courseid = ?
AND sm.feedbackid = f.id";
-
+
if (!$feedbacks1 = $DB->get_records_sql($sql, array($courseid))) {
$feedbacks1 = array();
}
-
+
//second get all feedbacks not listed in sitecourse_map
$feedbacks2 = array();
$sql = "SELECT f.id AS id, cm.id AS cmid, f.name AS name, f.timeopen AS timeopen, f.timeclose AS timeclose
$feedbacks2[] = $a;
}
}
-
+
return array_merge($feedbacks1, $feedbacks2);
-
+
}
-/**
+/**
* gets the courses from table feedback_sitecourse_map.
* @param int $feedbackid
* @return array the course-records
*/
function feedback_get_courses_from_sitecourse_map($feedbackid) {
global $DB;
-
+
$sql = "SELECT f.id, f.courseid, c.fullname, c.shortname
FROM {feedback_sitecourse_map} f, {course} c
WHERE c.id = f.courseid
AND f.feedbackid = ?
ORDER BY c.fullname";
-
+
return $DB->get_records_sql($sql, array($feedbackid));
-
+
}
-/**
+/**
* removes non existing courses or feedbacks from sitecourse_map.
* it shouldn't be called all too often
* a good place for it could be the mapcourse.php or unmapcourse.php
$DB->delete_records('feedback_sitecourse_map', array('courseid'=>$map->courseid, 'feedbackid'=>$map->feedbackid));
continue;
}
-
+
}
}
//not relatable functions
////////////////////////////////////////////////
-/**
+/**
* prints the option items of a selection-input item (dropdownlist).
* @param int $startval the first value of the list
* @param int $endval the last value of the list
}
}
-/**
+/**
* sends an email to the teachers of the course where the given feedback is placed.
* @param object $cm the coursemodule-record
* @param $feedback
*/
function feedback_send_email($cm, $feedback, $course, $userid) {
global $CFG, $DB;
-
+
if ($feedback->email_notification == 0) { // No need to do anything
return;
}
-
+
$user = $DB->get_record('user', array('id'=>$userid));
-
+
if (groupmode($course, $cm) == SEPARATEGROUPS) { // Separate groups are being used
$groups = $DB->get_records_sql_menu("SELECT g.name, g.id
FROM {groups} g, {groups_members} m
AND m.userid = ?
ORDER BY name ASC", array($course->id, $userid));
$groups = array_values($groups);
-
+
$teachers = feedback_get_receivemail_users($cm->id, $groups);
} else {
$teachers = feedback_get_receivemail_users($cm->id);
}
-
+
if ($teachers) {
$strfeedbacks = get_string('modulenameplural', 'feedback');
$strfeedback = get_string('modulename', 'feedback');
$strcompleted = get_string('completed', 'feedback');
$printusername = $feedback->anonymous == FEEDBACK_ANONYMOUS_NO ? fullname($user) : get_string('anonymous_user', 'feedback');
-
+
foreach ($teachers as $teacher) {
$info = new object();
$info->username = $printusername;
$postsubject = $strcompleted.': '.$info->username.' -> '.$feedback->name;
$posttext = feedback_send_email_text($info, $course);
$posthtml = ($teacher->mailformat == 1) ? feedback_send_email_html($info, $course, $cm) : '';
-
+
if($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
@email_to_user($teacher, $user, $postsubject, $posttext, $posthtml);
}else {
}
}
-/**
+/**
* sends an email to the teachers of the course where the given feedback is placed.
* @param object $cm the coursemodule-record
* @param $feedback
*/
function feedback_send_email_anonym($cm, $feedback, $course) {
global $CFG;
-
+
if ($feedback->email_notification == 0) { // No need to do anything
return;
}
-
+
$teachers = feedback_get_receivemail_users($cm->id);
if ($teachers) {
$strfeedback = get_string('modulename', 'feedback');
$strcompleted = get_string('completed', 'feedback');
$printusername = get_string('anonymous_user', 'feedback');
-
+
foreach ($teachers as $teacher) {
$info = new object();
$info->username = $printusername;
$postsubject = $strcompleted.': '.$info->username.' -> '.$feedback->name;
$posttext = feedback_send_email_text($info, $course);
$posthtml = ($teacher->mailformat == 1) ? feedback_send_email_html($info, $course, $cm) : '';
-
+
@email_to_user($teacher, $teacher, $postsubject, $posttext, $posthtml);
}
}
}
-/**
+/**
* send the text-part of the email
* @param object $info includes some infos about the feedback you want to send
* @param object $course
}
-/**
+/**
* send the html-part of the email
* @param object $info includes some infos about the feedback you want to send
* @param object $course
return $posthtml;
}
-/**
+/**
* print some errors to inform users about this.
* @return void
*/
function feedback_print_errors() {
-
+
global $SESSION;
-
+
if(empty($SESSION->feedback->errors)) {
return;
}
echo '<p align="center"><b><font color="black"><pre>';
print_r($SESSION->feedback->errors) . "\n";
echo '</pre></font></b></p>';
-
+
// print_simple_box_end();
print_box_end();
echo '<br /><br />';
$SESSION->feedback->errors = array(); //remove errors
-}
+}
function feedback_encode_target_url($url) {
if (strpos($url, '?')) {