field = $field; // Programmer knows what they are doing, we hope } else if (!$this->field = get_record('data_fields','id',$field)) { error('Bad field ID encountered: '.$field); } if (empty($data)) { if (!$this->data = get_record('data','id',$this->field->dataid)) { error('Bad data ID encountered in field 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 = get_record('data','id',$data)) { error('Bad data ID encountered: '.$data); } } else { // No way to define it! error('Data id or object must be provided to field class'); } } 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() { if (empty($this->field)) { notify('Programmer error: Field has not been defined yet! See define_field()'); return false; } if (!$this->field->id = 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() { if (!update_record('data_fields', $this->field)) { notify('updating of new field failed!'); return false; } return true; } /// Delete a field completely function delete_field() { if (!empty($this->field->id)) { delete_records('data_fields', '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){ if ($recordid){ $content = get_field('data_content', 'content', '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## |
'; print_user_picture($comment->userid, $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 ' |