}
}
-
+
/// This field just sets up a default field object
function define_default_field() {
if (empty($this->data->id)) {
return true;
}
-
+
/// Insert a new field in the database
/// We assume the field object is already defined as $this->field
function insert_field() {
} else {
$content = '';
}
-
+
$str = '<div title="'.$this->field->description.'">';
$str .= '<input style="width:300px;" type="text" name="field_'.$this->field->id.'" id="field_'.$this->field->id.'" value="'.s($content).'" />';
$str .= '</div>';
}
echo '<input type="hidden" name="type" value="'.$this->type.'" />'."\n";
echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />'."\n";
-
+
print_heading($this->name());
require_once($CFG->dirroot.'/mod/data/field/'.$this->type.'/mod.html');
print_simple_box_end();
}
-
+
/// Display the content of the field in browse mode
function display_browse_field($recordid, $template) {
if ($content = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
- if (isset($content->content)) {
+ if (isset($content->content)) {
if ($this->field->param1 == '1') { // We are autolinking this field, so disable linking within us
//$content->content = '<span class="nolink">'.$content->content.'</span>';
//$content->content1 = FORMAT_HTML;
}
return false;
}
-
+
/// Update the content of one data field in the data_content table
function update_content($recordid, $value, $name=''){
$content = new object;
return insert_record('data_content', $content);
}
}
-
+
/// Delete all content associated with the field
function delete_content($recordid=0) {
$this->delete_content_files($recordid);
-
+
if ($recordid) {
return delete_records('data_content', 'fieldid', $this->field->id, 'recordid', $recordid);
} else {
return fulldelete($dir);
}
-
+
/// Check if a field from an add form is empty
function notemptyfield($value, $name) {
return !empty($value);
}
-
+
/// Just in case a field needs to print something before the whole form
function print_before_form() {
}
/// Just in case a field needs to print something after the whole form
function print_after_form() {
}
-
-
+
+
/// Returns the sortable field for the content. By default, it's just content
/// but for some plugins, it could be content 1 - content4
function get_sort_field() {
function name(){
return get_string('name'.$this->type, 'data');
}
-
+
/// Prints the respective type icon
function image() {
global $CFG;
return $str;
}
-
+
} //end of major class data_field_base
if ($template == 'csstemplate') {
return '';
}
-
+
//get all the fields for that database
if ($fields = get_records('data_fields', 'dataid', $data->id, 'id')) {
-
+
$str = '<div align="center">';
$str .= '<table>';
$str .= '[['.$field->name.']]';
}
$str .= '</td></tr>';
-
+
}
if ($template != 'addtemplate' and $template != 'rsstemplate') { //if not adding, we put tags in there
$str .= '<tr><td align="center" colspan="2">##Edit## ##More## ##Delete## ##Approve##</td></tr>';
$prestring = '';
$poststring = '';
}
-
+
$newdata->id = $data->id;
$newdata->singletemplate = addslashes(str_replace('[['.$searchfieldname.']]',
$prestring.$newfieldname.$poststring, $data->singletemplate));
-
+
$newdata->listtemplate = addslashes(str_replace('[['.$searchfieldname.']]',
$prestring.$newfieldname.$poststring, $data->listtemplate));
-
+
$newdata->addtemplate = addslashes(str_replace('[['.$searchfieldname.']]',
$prestring.$newfieldname.$poststring, $data->addtemplate));
-
+
$newdata->rsstemplate = addslashes(str_replace('[['.$searchfieldname.']]',
$prestring.$newfieldname.$poststring, $data->rsstemplate));
-
+
return update_record('data', $newdata);
}
****************************************************************/
function data_add_record($data, $groupid=0){
global $USER;
-
+
$cm = data_get_cm($data);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$data->timemodified = time();
- if (!empty($data->availablefromenable)) {
- $data->timeavailablefrom = make_timestamp($data->availablefromyear, $data->availablefrommonth, $data->availablefromday,
- $data->availablefromhour, $data->availablefromminute, 0);
- } else {
+ if (empty($data->availablefromenable)) {
$data->timeavailablefrom = 0;
}
- if (!empty($data->availabletoenable)) {
- $data->timeavailableto = make_timestamp($data->availabletoyear, $data->availabletomonth, $data->availabletoday,
- $data->availabletohour, $data->availabletominute, 0);
- } else {
+ if (empty($data->availabletoenable)) {
$data->timeavailableto = 0;
}
- if (!empty($data->viewfromenable)) {
- $data->timeviewfrom = make_timestamp($data->viewfromyear, $data->viewfrommonth, $data->viewfromday,
- $data->viewfromhour, $data->viewfromminute, 0);
- } else {
+ if (empty($data->viewfromenable)) {
$data->timeviewfrom = 0;
}
-
- if (!empty($data->viewtoenable)) {
- $data->timeviewto = make_timestamp($data->viewtoyear, $data->viewtomonth, $data->viewtoday,
- $data->viewtohour, $data->viewtominute, 0);
- } else {
+
+ if (empty($data->viewtoenable)) {
$data->timeviewto = 0;
}
************************************************************************/
function data_update_instance($data) {
global $CFG;
-
+
$data->id = $data->instance;
-
+
if (empty($data->assessed)) {
$data->assessed = 0;
}
-
+
$data->timemodified = time();
- if (!empty($data->availablefromenable)) {
- $data->timeavailablefrom = make_timestamp($data->availablefromyear, $data->availablefrommonth, $data->availablefromday,
- $data->availablefromhour, $data->availablefromminute, 0);
- } else {
+ if (empty($data->availablefromenable)) {
$data->timeavailablefrom = 0;
}
- if (!empty($data->availabletoenable)) {
- $data->timeavailableto = make_timestamp($data->availabletoyear, $data->availabletomonth, $data->availabletoday,
- $data->availabletohour, $data->availabletominute, 0);
- } else {
+ if (empty($data->availabletoenable)) {
$data->timeavailableto = 0;
}
- if (!empty($data->viewfromenable)) {
- $data->timeviewfrom = make_timestamp($data->viewfromyear, $data->viewfrommonth, $data->viewfromday,
- $data->viewfromhour, $data->viewfromminute, 0);
- } else {
+ if (empty($data->viewfromenable)) {
$data->timeviewfrom = 0;
}
-
- if (!empty($data->viewtoenable)) {
- $data->timeviewto = make_timestamp($data->viewtoyear, $data->viewtomonth, $data->viewtoday,
- $data->viewtohour, $data->viewtominute, 0);
- } else {
+
+ if (empty($data->viewtoenable)) {
$data->timeviewto = 0;
}
-
+
if (! $data->instance = update_record('data', $data)) {
return false;
}
return $data->instance;
-
+
}
/************************************************************************
// get all the records in this data
$sql = 'SELECT c.* FROM '.$CFG->prefix.'data_records r LEFT JOIN '.
$CFG->prefix.'data_content c ON c.recordid = r.id WHERE r.dataid = '.$id;
-
+
if ($contents = get_records_sql($sql)){
foreach($contents as $content){
-
+
$field = get_record('data_fields','id',$content->fieldid);
if ($g = data_get_field($field, $data)){
$g->delete_content_files($id, $content->recordid, $content->content);
if ($countrecords = count_records('data_records', 'dataid', $data->id, 'userid', $user->id)) {
$result->info = get_string('numrecords', 'data', $countrecords);
- $lastrecord = get_record_sql('SELECT id,timemodified FROM '.$CFG->prefix.'data_records
- WHERE dataid = '.$data->id.' AND userid = '.$user->id.'
+ $lastrecord = get_record_sql('SELECT id,timemodified FROM '.$CFG->prefix.'data_records
+ WHERE dataid = '.$data->id.' AND userid = '.$user->id.'
ORDER BY timemodified DESC', true);
$result->time = $lastrecord->timemodified;
return $result;
************************************************************************/
function data_user_complete($course, $user, $mod, $data) {
- if ($records = get_records_select('data_records', 'dataid = '.$data->id.' AND userid = '.$user->id,
+ if ($records = get_records_select('data_records', 'dataid = '.$data->id.' AND userid = '.$user->id,
'timemodified DESC')) {
data_print_template('singletemplate', $records, $data);
{$CFG->prefix}data_records r,
{$CFG->prefix}data_comments c
WHERE r.dataid = '$dataid'
- AND u.id = r.userid
+ AND u.id = r.userid
AND r.id = c.recordid");
$ratings = get_records_sql("SELECT DISTINCT u.id, u.id
{$CFG->prefix}data_records r,
{$CFG->prefix}data_ratings a
WHERE r.dataid = '$dataid'
- AND u.id = r.userid
+ AND u.id = r.userid
AND r.id = a.recordid");
$participants = array();
-
+
if ($records){
foreach ($records as $record) {
$participants[$record->id] = $record;
$participants[$rating->id] = $rating;
}
}
-
+
return $participants;
}
} else {
$replacement[] = '';
}
-
+
$patterns[]='/\#\#Comments\#\#/i';
if (($template == 'listtemplate') && ($data->comments)) {
$comments = count_records('data_comments','recordid',$record->id);
if ($return) {
return format_text($newtext, FORMAT_HTML, $options);
} else {
- echo format_text($newtext, FORMAT_HTML, $options);
+ echo format_text($newtext, FORMAT_HTML, $options);
}
/**********************************
$cm = data_get_cm($data);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
+
$ratingsmenuused = false;
if ($data->assessed and !empty($USER->id)) {
if ($ratings->scale = make_grades_menu($data->scale)) {
data_print_comment($data, $comment, $page);
}
}
-
+
if (isloggedin() and !isguest()) {
echo '<div class="newcomment" align="center"><form method="post" action="'.$CFG->wwwroot.'/mod/data/comment.php">';
echo '<input type="hidden" name="mode" value="add" />';
echo '<input type="hidden" name="page" value="'.$page.'" />';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="rid" value="'.$record->id.'" />';
-
+
echo '<textarea rows="8" cols="50" name="commentcontent"></textarea>';
echo '<br /><input type="submit" value="'.get_string('addcomment','data').'" />';
echo '</form></div>';
function data_print_comment($data, $comment, $page=0) {
global $USER, $CFG;
-
+
$cm = data_get_cm($data);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
+
$stredit = get_string('edit');
$strdelete = get_string('delete');
global $CFG;
$LIKE = sql_ilike();
- if ($fieldid) {
- return record_exists_sql("SELECT * from {$CFG->prefix}data_fields df
+ if ($fieldid) {
+ return record_exists_sql("SELECT * from {$CFG->prefix}data_fields df
WHERE df.name $LIKE '$name' AND df.dataid = $dataid
AND ((df.id < $fieldid) OR (df.id > $fieldid))");
} else {
- return record_exists_sql("SELECT * from {$CFG->prefix}data_fields df
+ return record_exists_sql("SELECT * from {$CFG->prefix}data_fields df
WHERE df.name $LIKE '$name' AND df.dataid = $dataid");
}
}
* @return boolean - data module was converted or not
*/
function data_convert_to_roles($data, $teacherroles=array(), $studentroles=array(), $cmid=NULL) {
-
+
global $CFG;
-
+
if (!isset($data->participants) && !isset($data->assesspublic)
&& !isset($data->groupmode)) {
// We assume that this database has already been converted to use the
// upgraded to use Roles.
return false;
}
-
+
if (empty($cmid)) {
// We were not given the course_module id. Try to find it.
if (!$cm = get_coursemodule_from_instance('data', $data->id)) {
}
}
$context = get_context_instance(CONTEXT_MODULE, $cmid);
-
-
+
+
// $data->participants:
// 1 - Only teachers can add entries
// 3 - Teachers and students can add entries
}
break;
}
-
+
// $data->assessed:
// 2 - Only teachers can rate posts
// 1 - Everyone can rate posts
}
break;
}
-
+
// $data->assesspublic:
// 0 - Students can only see their own ratings
// 1 - Students can see everyone's ratings
if (empty($cm)) {
$cm = get_record('course_modules', 'id', $cmid);
}
-
+
// $cm->groupmode:
// 0 - No groups
// 1 - Separate groups
return true;
}
-/*
+/*
* Returns the best name to show for a preset
*/
function data_preset_name($shortname, $path) {
}
}
-/*
+/*
* Returns an array of all the available presets
*/
function data_get_available_presets($context) {
global $CFG, $USER;
$presets = array();
-
+
if ($dirs = get_list_of_plugins('mod/data/preset')) {
foreach ($dirs as $dir) {
$fulldir = $CFG->dirroot.'/mod/data/preset/'.$dir;
$strdata = get_string('modulenameplural','data');
- print_header_simple($data->name, '', "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name",
- '', '', true, update_module_button($cm->id, $course->id, get_string('modulename', 'data')),
+ print_header_simple($data->name, '', "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name",
+ '', '', true, update_module_button($cm->id, $course->id, get_string('modulename', 'data')),
navmenu($course, $cm));
print_heading(format_string($data->name));
--- /dev/null
+<?php
+require_once ($CFG->libdir.'/formslib.php');
+class data_mod_form extends moodleform_mod {
+
+ function definition() {
+
+ global $CFG;
+ $mform =& $this->_form;
+ $renderer =& $mform->defaultRenderer();
+ $course=$this->_customdata['course'];
+
+//-------------------------------------------------------------------------------
+ $mform->addElement('header', 'general', get_string('general', 'form'));
+
+ $mform->addElement('text', 'name', get_string('name'));
+ $mform->setType('name', PARAM_TEXT);
+ $mform->addRule('name', null, 'required', null, 'client');
+
+ $mform->addElement('htmleditor', 'intro', get_string('intro', 'data'));
+ $mform->setType('intro', PARAM_RAW);
+ $mform->addRule('intro', get_string('required'), 'required', null, 'client');
+
+ $availablefromgroup=array();
+ $availablefromgroup[]=&MoodleQuickForm::createElement('date_selector', 'availablefrom', '');
+ $availablefromgroup[]=&MoodleQuickForm::createElement('checkbox', 'availablefromenabled', '', get_string('enable'));
+ $mform->addGroup($availablefromgroup, 'availablefromgroup', get_string('availablefromdate', 'data'), ' ', false);
+
+ $availabletogroup=array();
+ $availabletogroup[]=&MoodleQuickForm::createElement('date_selector', 'availableto', '');
+ $availabletogroup[]=&MoodleQuickForm::createElement('checkbox', 'availabletoenabled', '', get_string('enable'));
+ $mform->addGroup($availabletogroup, 'availabletogroup', get_string('availabletodate', 'data'), ' ', false);
+
+ $viewfromgroup=array();
+ $viewfromgroup[]=&MoodleQuickForm::createElement('date_selector', 'viewfrom', '');
+ $viewfromgroup[]=&MoodleQuickForm::createElement('checkbox', 'viewfromenabled', '', get_string('enable'));
+ $mform->addGroup($viewfromgroup, 'viewfromgroup', get_string('viewfromdate', 'data'), ' ', false);
+
+ $viewtogroup=array();
+ $viewtogroup[]=&MoodleQuickForm::createElement('date_selector', 'viewto', '');
+ $viewtogroup[]=&MoodleQuickForm::createElement('checkbox', 'viewtoenabled', '', get_string('enable'));
+ $mform->addGroup($viewtogroup, 'viewtogroup', get_string('viewtodate', 'data'), ' ', false);
+
+
+ $countoptions= array(0=>get_string('none'))+
+ (array_combine(range(1, DATA_MAX_ENTRIES),//keys
+ range(1, DATA_MAX_ENTRIES)));//values
+ $mform->addElement('select', 'requiredentries', get_string('requiredentries', 'data'), $countoptions);
+ $mform->setHelpButton('requiredentries', array('requiredentries', get_string('requiredentries', 'data'), 'data'));
+
+ $mform->addElement('select', 'requiredentriestoview', get_string('requiredentriestoview', 'data'), $countoptions);
+ $mform->setHelpButton('requiredentriestoview', array('requiredentriestoview', get_string('requiredentriestoview', 'data'), 'data'));
+
+ $mform->addElement('select', 'maxentries', get_string('maxentries', 'data'), $countoptions);
+ $mform->setHelpButton('maxentries', array('maxentries', get_string('maxentries', 'data'), 'data'));
+
+ $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
+ $mform->addElement('select', 'comments', get_string('comments', 'data'), $ynoptions);
+ $mform->setHelpButton('comments', array('comments', get_string('allowcomments', 'data'), 'data'));
+
+ $mform->addElement('select', 'approval', get_string('requireapproval', 'data'), $ynoptions);
+ $mform->setHelpButton('approval', array('requireapproval', get_string('requireapproval', 'data'), 'data'));
+
+ $mform->addElement('select', 'numberrssarticles', get_string('numberrssarticles', 'data') , $countoptions);
+ $mform->setHelpButton('approval', array('requireapproval', get_string('requireapproval', 'data'), 'data'));
+
+ $mform->addElement('checkbox', 'assessed', get_string("allowratings", "data") , get_string('ratingsuse', 'data'));
+
+ $strscale = get_string('scale');
+ $strscales = get_string('scales');
+ $scales = get_scales_menu($course->id);
+ foreach ($scales as $i => $scalename) {
+ $grades[-$i] = $strscale .': '. $scalename;
+ }
+ for ($i=100; $i>=1; $i--) {
+ $grades[$i] = $i;
+ }
+ $mform->addElement('select', 'scale', get_string('grade') , $grades);
+
+
+ $this->standard_coursemodule_elements();
+
+ $buttonarray=array();
+ $buttonarray[] = &MoodleQuickForm::createElement('submit', 'submit', get_string('savechanges'));
+ $buttonarray[] = &MoodleQuickForm::createElement('submit', 'cancel', get_string('cancel'));
+ $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
+ $renderer->addStopFieldsetElements('buttonar');
+ }
+
+
+
+}
+?>
\ No newline at end of file