// //
///////////////////////////////////////////////////////////////////////////
-/// Some constants
+// Some constants
define ('DATA_MAX_ENTRIES', 50);
define ('DATA_PERPAGE_SINGLE', 1);
var $iconheight = 16; /// Width of the icon for this fieldtype
-/// Constructor function
+// Constructor function
function data_field_base($field=0, $data=0) { // Field or data or both, each can be id or object
if (empty($field) && empty($data)) {
}
-/// This field just sets up a default field object
+// This field just sets up a default field object
function define_default_field() {
if (empty($this->data->id)) {
notify('Programmer error: dataid not defined in field class');
return true;
}
-/// Set up the field object according to data in an object. Now is the time to clean it!
+// Set up the field object according to data in an object. Now is the time to clean it!
function define_field($data) {
$this->field->type = $this->type;
$this->field->dataid = $this->data->id;
return true;
}
-/// Insert a new field in the database
-/// We assume the field object is already defined as $this->field
+// Insert a new field in the database
+// We assume the field object is already defined as $this->field
function insert_field() {
if (empty($this->field)) {
notify('Programmer error: Field has not been defined yet! See define_field()');
}
-/// Update a field in the database
+// Update a field in the database
function update_field() {
if (!update_record('data_fields', $this->field)) {
notify('updating of new field failed!');
return true;
}
-/// Delete a field completely
+// Delete a field completely
function delete_field() {
if (!empty($this->field->id)) {
delete_records('data_fields', 'id', $this->field->id);
return true;
}
-/// Print the relevant form element in the ADD template for this field
+// Print the relevant form element in the ADD template for this field
function display_add_field($recordid=0){
if ($recordid){
$content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
return $str;
}
-/// Print the relevant form element to define the attributes for this field
-/// viewable by teachers only.
+// Print the relevant form element to define the attributes for this field
+// viewable by teachers only.
function display_edit_field() {
global $CFG;
print_simple_box_end();
}
-/// Display the content of the field in browse mode
+// 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)) {
return false;
}
-/// Update the content of one data field in the data_content table
+// Update the content of one data field in the data_content table
function update_content($recordid, $value, $name=''){
$content = new object();
$content->fieldid = $this->field->id;
}
}
-/// Delete all content associated with the field
+// Delete all content associated with the field
function delete_content($recordid=0) {
$this->delete_content_files($recordid);
}
}
-/// Deletes any files associated with this field
+// Deletes any files associated with this field
function delete_content_files($recordid='') {
global $CFG;
}
-/// Check if a field from an add form is empty
+// 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
+// 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
+// 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
+// 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() {
return 'content';
}
-/// Returns the SQL needed to refer to the column. Some fields may need to CAST() etc.
+// Returns the SQL needed to refer to the column. Some fields may need to CAST() etc.
function get_sort_sql($fieldname) {
return $fieldname;
}
-/// Returns the name/type of the field
- function name(){
+// Returns the name/type of the field
+ function name() {
return get_string('name'.$this->type, 'data');
}
-/// Prints the respective type icon
+// Prints the respective type icon
function image() {
global $CFG;
return $str;
}
+// Per default, it is assumed that fields support text exporting. Override this (return false) on fields not supporting text exporting.
+ function text_export_supported() {
+ return true;
+ }
-} //end of major class data_field_base
+// Per default, return the record's text value only from the "content" field. Override this in fields class if necesarry.
+ function export_text_value($record) {
+ if ($this->text_export_supported()) {
+ return $record->content;
+ }
+ }
+}
/*****************************************************************************
return '';
}
- //get all the fields for that database
+ // get all the fields for that database
if ($fields = get_records('data_fields', 'dataid', $data->id, 'id')) {
$str = '<div class="defaulttemplate">';
$str .= '</td>';
$str .='<td>';
- if ($form) { /// Print forms instead of data
+ if ($form) { // Print forms instead of data
$fieldobj = data_get_field($field, $data);
$str .= $fieldobj->display_add_field($recordid);
- } else { /// Just print the tag
+ } else { // Just print the tag
$str .= '[['.$field->name.']]';
}
$str .= '</td></tr>';
* output bool *
*******************************************************************/
function data_tags_check($dataid, $template){
- //first get all the possible tags
+ // first get all the possible tags
$fields = get_records('data_fields','dataid',$dataid);
- ///then we generate strings to replace
- $tagsok = true; //let's be optimistic
+ // then we generate strings to replace
+ $tagsok = true; // let's be optimistic
foreach ($fields as $field){
$pattern="/\[\[".$field->name."\]\]/i";
if (preg_match_all($pattern, $template, $dummy)>1){
notify ('[['.$field->name.']] - '.get_string('multipletags','data'));
}
}
- //else return true
+ // else return true
return $tagsok;
}
/************************************************************************
* deletes an instance of a data *
************************************************************************/
-function data_delete_instance($id) { //takes the dataid
+function data_delete_instance($id) { // takes the dataid
global $CFG;
return false;
}
- /// Delete all the associated information
+ // Delete all the associated information
// get all the records in this data
$sql = 'SELECT c.* FROM '.$CFG->prefix.'data_records r LEFT JOIN '.
* returns a summary of data activity of this user *
************************************************************************/
function data_user_outline($course, $user, $mod, $data) {
-
global $CFG;
-
if ($countrecords = count_records('data_records', 'dataid', $data->id, 'userid', $user->id)) {
$result = new object();
$result->info = get_string('numrecords', 'data', $countrecords);
return $result;
}
return NULL;
-
}
/************************************************************************
* Prints all the records uploaded by this user *
************************************************************************/
function data_user_complete($course, $user, $mod, $data) {
-
if ($records = get_records_select('data_records', 'dataid = '.$data->id.' AND userid = '.$user->id,
'timemodified DESC')) {
-
data_print_template('singletemplate', $records, $data);
-
}
}
* returns a list of participants of this database *
************************************************************************/
function data_get_participants($dataid) {
-//Returns the users with data in one data
-//(users with records in data_records, data_comments and data_ratings)
+// Returns the users with data in one data
+// (users with records in data_records, data_comments and data_ratings)
global $CFG;
$records = get_records_sql("SELECT DISTINCT u.id, u.id
return $participants;
}
-///junk functions
+// junk functions
/************************************************************************
* takes a list of records, the current data, a search string, *
* and mode to display prints the translated template *
foreach ($records as $record) { /// Might be just one for the single template
- /// Replacing tags
+ // Replacing tags
$patterns = array();
$replacement = array();
- /// Then we generate strings to replace for normal tags
+ // Then we generate strings to replace for normal tags
foreach ($fields as $field) {
$patterns[]='[['.$field->field->name.']]';
$replacement[] = highlight($search, $field->display_browse_field($record->id, $template));
}
- /// Replacing special tags (##Edit##, ##Delete##, ##More##)
+ // Replacing special tags (##Edit##, ##Delete##, ##More##)
$patterns[]='##edit##';
$patterns[]='##delete##';
if (has_capability('mod/data:manageentries', $context) or data_isowner($record->id)) {
$replacement[] = '';
}
- ///actual replacement of the tags
+ // actual replacement of the tags
$newtext = str_ireplace($patterns, $replacement, $data->{$template});
- /// no more html formatting and filtering - see MDL-6635
+ // no more html formatting and filtering - see MDL-6635
if ($return) {
return $newtext;
} else {
}
echo ';" > <label for="pref_search">'.get_string('search').'</label> <input type="text" size="16" name="search" id= "pref_search" value="'.s($search).'" /></div>';
echo ' <label for="pref_sortby">'.get_string('sortby').'</label> ';
- //foreach field, print the option
+ // foreach field, print the option
echo '<select name="sort" id="pref_sortby">';
if ($fields = get_records('data_fields','dataid',$data->id, 'name')) {
echo '<optgroup label="'.get_string('fields', 'data').'">';
$isteacher = has_capability('mod/data:managetemplates', $context);
}
- /// Replacing tags
+ // Replacing tags
$patterns = array();
$replacement = array();
- /// Then we generate strings to replace for normal tags
+ // Then we generate strings to replace for normal tags
foreach ($fields as $field) {
$fieldname = $field->field->name;
$fieldname = preg_quote($fieldname, '/');
echo '</div>';
echo '</div>';
echo '</form>';
- echo '</div>';
-
-
+ echo '</div>';
}
function data_print_ratings($data, $record) {
}
function data_print_ratings_mean($recordid, $scale, $link=true) {
-/// Print the multiple ratings on a post given to the current user by others.
-/// Scale is an array of ratings
+// Print the multiple ratings on a post given to the current user by others.
+// Scale is an array of ratings
static $strrate;
function data_get_ratings_mean($recordid, $scale, $ratings=NULL) {
-/// Return the mean rating of a post given to the current user by others.
-/// Scale is an array of possible ratings in the scale
-/// Ratings is an optional simple array of actual ratings (just integers)
+// Return the mean rating of a post given to the current user by others.
+// Scale is an array of possible ratings in the scale
+// Ratings is an optional simple array of actual ratings (just integers)
if (!$ratings) {
$ratings = array();
function data_print_rating_menu($recordid, $userid, $scale) {
-/// Print the menu of ratings as part of a larger form.
-/// If the post has already been - set that value.
-/// Scale is an array of ratings
+// Print the menu of ratings as part of a larger form.
+// If the post has already been - set that value.
+// Scale is an array of ratings
static $strrate;
function data_get_ratings($recordid, $sort="u.firstname ASC") {
-/// Returns a list of ratings for a particular post - sorted.
+// Returns a list of ratings for a particular post - sorted.
global $CFG;
return get_records_sql("SELECT u.*, r.rating
FROM {$CFG->prefix}data_ratings r,
}
-//prints all comments + a text box for adding additional comment
+// prints all comments + a text box for adding additional comment
function data_print_comments($data, $record, $page=0, $mform=false) {
global $CFG;
}
}
-//prints a single comment entry
+// prints a single comment entry
function data_print_comment($data, $comment, $page=0) {
global $USER, $CFG;
echo ' ';
}
-/// Actual content
+// Actual content
echo '</td><td class="content" align="left">'."\n";
// Print whole message
echo format_text($comment->content, $comment->format);
-/// Commands
+// Commands
echo '<div class="commands">';
if (data_isowner($comment->recordid) or has_capability('mod/data:managecomments', $context)) {
print_heading(format_string($data->name));
-/// Groups needed for Add entry tab
+// Groups needed for Add entry tab
$currentgroup = groups_get_activity_group($cm);
$groupmode = groups_get_activity_groupmode($cm);
- /// Print the tabs
+ ///Print the tabs
if ($currenttab) {
include('tabs.php');
}
- /// Print any notices
+ // Print any notices
if (!empty($displaynoticegood)) {
notify($displaynoticegood, 'notifysuccess'); // good (usually green)
}
}
-// pulled directly out of preset.php Penny 20070426
function is_directory_a_preset($directory) {
$directory = rtrim($directory, '/\\') . '/';
}
}
- /// handle special settings here
+ // handle special settings here
if (!empty($settings->defaultsort)) {
if (is_numeric($settings->defaultsort)) {
//old broken value
$status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallcomments'), 'error'=>false);
}
- /// updating dates - shift may be negative too
+ // updating dates - shift may be negative too
if ($data->timeshift) {
shift_course_mod_dates('data', array('timeavailablefrom', 'timeavailableto', 'timeviewfrom', 'timeviewto'), $data->timeshift, $data->courseid);
$status[] = array('component'=>$componentstr, 'item'=>get_string('datechanged'), 'error'=>false);