= 2, new roles may be introduced and used instead. class data_field_base { // Base class for Database Field Types (see field/*/field.class.php) var $type = 'unknown'; // Subclasses must override the type with their name var $data = NULL; // The database object that this field belongs to var $field = NULL; // The field object itself, if we know it var $iconwidth = 16; // Width of the icon for this fieldtype var $iconheight = 16; // Width of the icon for this fieldtype // Constructor function function data_field_base($field=0, $data=0) { // Field or data or both, each can be id or object global $DB; if (empty($field) && empty($data)) { print_error('missingfield', 'data'); } if (!empty($field)) { if (is_object($field)) { $this->field = $field; // Programmer knows what they are doing, we hope } else if (!$this->field = $DB->get_record('data_fields', array('id'=>$field))) { print_error('invalidfieldid', 'data'); } if (empty($data)) { if (!$this->data = $DB->get_record('data', array('id'=>$this->field->dataid))) { print_error('invalidid', 'data'); } } } if (empty($this->data)) { // We need to define this properly if (!empty($data)) { if (is_object($data)) { $this->data = $data; // Programmer knows what they are doing, we hope } else if (!$this->data = $DB->get_record('data', array('id'=>$data))) { print_error('invalidid', 'data'); } } else { // No way to define it! print_error('missingdata', 'data'); } } if (empty($this->field)) { // We need to define some default values $this->define_default_field(); } } // 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'); } $this->field = new object; $this->field->id = 0; $this->field->dataid = $this->data->id; $this->field->type = $this->type; $this->field->param1 = ''; $this->field->param2 = ''; $this->field->param3 = ''; $this->field->name = ''; $this->field->description = ''; return true; } // 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; $this->field->name = trim($data->name); $this->field->description = trim($data->description); if (isset($data->param1)) { $this->field->param1 = trim($data->param1); } if (isset($data->param2)) { $this->field->param2 = trim($data->param2); } if (isset($data->param3)) { $this->field->param3 = trim($data->param3); } if (isset($data->param4)) { $this->field->param4 = trim($data->param4); } if (isset($data->param5)) { $this->field->param5 = trim($data->param5); } return true; } // Insert a new field in the database // We assume the field object is already defined as $this->field function insert_field() { global $DB; if (empty($this->field)) { notify('Programmer error: Field has not been defined yet! See define_field()'); return false; } if (!$this->field->id = $DB->insert_record('data_fields',$this->field)){ notify('Insertion of new field failed!'); return false; } return true; } // Update a field in the database function update_field() { global $DB; if (!$DB->update_record('data_fields', $this->field)) { notify('updating of new field failed!'); return false; } return true; } // Delete a field completely function delete_field() { global $DB; if (!empty($this->field->id)) { $DB->delete_records('data_fields', array('id'=>$this->field->id)); $this->delete_content(); } return true; } // Print the relevant form element in the ADD template for this field function display_add_field($recordid=0){ global $DB; if ($recordid){ $content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)); } else { $content = ''; } $str = '
'; // Yu: commenting this out, the id was wrong and will fix later //if ($template == 'addtemplate') { //$str .= ''; //} else { $str .= $field->name.': '; //} $str .= ' | '; $str .=''; if ($form) { // Print forms instead of data $fieldobj = data_get_field($field, $data); $str .= $fieldobj->display_add_field($recordid); } else { // Just print the tag $str .= '[['.$field->name.']]'; } $str .= ' |
##edit## ##more## ##delete## ##approve## | |
##edit## ##delete## ##approve## | |
'.get_string('authorfirstname', 'data').': | ##firstname## |
'.get_string('authorlastname', 'data').': | ##lastname## |
'; print_user_picture($user, $data->course, $user->picture); echo ' | '; echo '|
'; if ($groups = groups_get_all_groups($data->course, $comment->userid, $cm->groupingid)) { print_group_picture($groups, $data->course, false, false, true); } else { echo ' '; } // Actual content echo ' | '."\n";
// Print whole message
echo format_text($comment->content, $comment->format);
// Commands
echo ' ';
if (data_isowner($comment->recordid) or has_capability('mod/data:managecomments', $context)) {
echo ''.$stredit.'';
echo '| '.$strdelete.'';
}
echo ' ';
echo ' |