Added a parameter to display_browse_field() to pass the template name
to the fields, so they can return different output for different templates. Picture now has two heights/widths for different templates
This commit is contained in:
@@ -145,7 +145,7 @@ class data_field_checkbox extends data_field_base {
|
||||
}
|
||||
|
||||
|
||||
function display_browse_field($fieldid, $recordid) {
|
||||
function display_browse_field($fieldid, $recordid, $template) {
|
||||
global $CFG, $USER, $course;
|
||||
|
||||
$field = get_record('data_fields', 'id', $fieldid);
|
||||
|
||||
@@ -116,7 +116,7 @@ class data_field_file extends data_field_base {// extends
|
||||
parent::display_edit_field($id, $mode);
|
||||
}
|
||||
|
||||
function display_browse_field($fieldid, $recordid){
|
||||
function display_browse_field($fieldid, $recordid, $template) {
|
||||
|
||||
global $CFG, $USER, $course;
|
||||
|
||||
|
||||
@@ -71,17 +71,17 @@ class data_field_menu extends data_field_base {
|
||||
}
|
||||
$str .= get_string('menu','data').'</td><td>';
|
||||
|
||||
$str .= '<SELECT name="field_'.$field->id.' id="field_'.$field->id.'>';
|
||||
$str .= '<select name="field_'.$field->id.' id="field_'.$field->id.'>';
|
||||
$str .= '<option value="">' . get_string('menuchoose', 'data') . '</option>';
|
||||
|
||||
foreach (explode("\n",$field->param1) as $option) {
|
||||
if (trim($content) == trim($option)) { // If selected
|
||||
$str.='<option value="'.ltrim(rtrim($option)).'" SELECTED>'.ltrim(rtrim($option)).'</option>';
|
||||
$str.='<option value="'.ltrim(rtrim($option)).'" selected="selected">'.ltrim(rtrim($option)).'</option>';
|
||||
} else {
|
||||
$str.='<option value="'.ltrim(rtrim($option)).'">'.ltrim(rtrim($option)).'</option>';
|
||||
}
|
||||
}
|
||||
$str .= '</SELECT></td></tr></table>';
|
||||
$str .= '</select></td></tr></table>';
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ class data_field_multimenu extends data_field_base {
|
||||
}
|
||||
|
||||
|
||||
function display_browse_field($fieldid, $recordid) {
|
||||
function display_browse_field($fieldid, $recordid, $template) {
|
||||
global $CFG, $USER, $course;
|
||||
|
||||
$field = get_record('data_fields', 'id', $fieldid);
|
||||
|
||||
@@ -42,7 +42,8 @@ class data_field_picture extends data_field_file {// extends
|
||||
var $type = 'picture';
|
||||
var $id;
|
||||
|
||||
function insert_field($dataid, $type='picture', $name, $des, $width='', $height='', $maxsize=''){
|
||||
function insert_field($dataid, $type='picture', $name, $des, $width='', $height='', $maxsize='',
|
||||
$widthlist='', $heightlist=''){
|
||||
$newfield = new object;
|
||||
$newfield->dataid = $dataid;
|
||||
$newfield->type = $type;
|
||||
@@ -51,7 +52,8 @@ class data_field_picture extends data_field_file {// extends
|
||||
$newfield->param1 = $width;
|
||||
$newfield->param2 = $height;
|
||||
$newfield->param3 = $maxsize;
|
||||
$newfield->param4 = $test;
|
||||
$newfield->param4 = $widthlist;
|
||||
$newfield->param5 = $heightlist;
|
||||
if (!insert_record('data_fields',$newfield)){
|
||||
notify('Insertion of new field failed!');
|
||||
}
|
||||
@@ -108,7 +110,7 @@ class data_field_picture extends data_field_file {// extends
|
||||
parent::display_edit_field($id, $mode);
|
||||
}
|
||||
|
||||
function display_browse_field($fieldid, $recordid){
|
||||
function display_browse_field($fieldid, $recordid, $template) {
|
||||
global $CFG, $USER, $course;
|
||||
|
||||
$field = get_record('data_fields', 'id', $fieldid);
|
||||
@@ -129,9 +131,14 @@ class data_field_picture extends data_field_file {// extends
|
||||
$source = $CFG->wwwroot.'/file.php?file=/'.$course->id.'/'.$CFG->moddata.'/data/'.$field->dataid.'/'.$field->id.'/'.$recordid;
|
||||
}
|
||||
|
||||
$width = $field->param1 ? ' width = "'.$field->param1.'" ':' ';
|
||||
$height = $field->param2 ? ' height = "'.$field->param2.'" ':' ';
|
||||
$str = '<img '.$width.$field->param1.$height.' src="'.$source.'/'.$src.'" alt="'.$alt.'" title="'.$title.'" />';
|
||||
if ($template == 'listtemplate') {
|
||||
$width = $field->param4 ? ' width="'.$field->param4.'" ':' ';
|
||||
$height = $field->param5 ? ' height="'.$field->param5.'" ':' ';
|
||||
} else {
|
||||
$width = $field->param1 ? ' width="'.$field->param1.'" ':' ';
|
||||
$height = $field->param2 ? ' height="'.$field->param2.'" ':' ';
|
||||
}
|
||||
$str = '<img '.$width.$height.' src="'.$source.'/'.$src.'" alt="'.$alt.'" title="'.$title.'" />';
|
||||
return $str;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
<?php echo ($this->name()); ?></td></tr>
|
||||
<tr><td>Name:</td><td><input style="width:300px;" type="text" name="name" id="name" value = "<?php echo($field->name); ?>" /></td></tr>
|
||||
<tr><td>Description:</td><td><input style="width:300px;" type="text" name="description" id="description" value = "<? echo ($field->description);?>" /></td></tr>
|
||||
<tr><td>Width</td><td><input style="width:70px;" type="text" name="param1" id="param1" value = "<? echo ($field->param1);?>" />
|
||||
<tr><td>Height</td><td><input style="width:70px;" type="text" name="param2" id="param2" value = "<? echo ($field->param2);?>" />
|
||||
<tr><td>Width in Single View</td><td><input style="width:70px;" type="text" name="param1" id="param1" value = "<? echo ($field->param1);?>" />
|
||||
<tr><td>Height in Single View</td><td><input style="width:70px;" type="text" name="param2" id="param2" value = "<? echo ($field->param2);?>" />
|
||||
<tr><td>Width in List View</td><td><input style="width:70px;" type="text" name="param4" id="param4" value = "<? echo ($field->param4);?>" />
|
||||
<tr><td>Height in List View</td><td><input style="width:70px;" type="text" name="param5" id="param5" value = "<? echo ($field->param5);?>" />
|
||||
<!-- <tr><td>Maximum Size</td><td><input type="text" name="param3" id="param3" value = "<? echo ($field->param3);?>" /> -->
|
||||
<tr><td>Maximum Size:</td><td>
|
||||
<?php
|
||||
|
||||
@@ -86,7 +86,7 @@ class data_field_url extends data_field_base {// extends
|
||||
parent::display_edit_field($id, $mode);
|
||||
}
|
||||
|
||||
function display_browse_field($fieldid, $recordid){
|
||||
function display_browse_field($fieldid, $recordid, $template) {
|
||||
if ($content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)){
|
||||
$url = empty($content->content)? '':$content->content;
|
||||
$text = empty($content->content1)? '':$content->content1;
|
||||
|
||||
+5
-5
@@ -133,7 +133,7 @@ class data_field_base { //base class (text field)
|
||||
* eg. *
|
||||
* [icon] Word.doc *
|
||||
**********************************************************************/
|
||||
function display_browse_field($fieldid, $recordid){
|
||||
function display_browse_field($fieldid, $recordid, $template){
|
||||
if ($content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)){
|
||||
if (isset($content->content)) {
|
||||
$options->para = false;
|
||||
@@ -653,10 +653,10 @@ function data_get_coursemodule_info($coursemodule) {
|
||||
* input @param array $records *
|
||||
* @param object $data *
|
||||
* @param string $search *
|
||||
* @param string $listmode *
|
||||
* @param string $template *
|
||||
* output null *
|
||||
************************************************************************/
|
||||
function data_print_template($records, $data, $search, $listmode, $sort, $page, $rid, $order){
|
||||
function data_print_template($records, $data, $search, $template, $sort, $page, $rid, $order){
|
||||
global $CFG, $course;
|
||||
|
||||
foreach ($records as $record){ //only 1 record for single mode
|
||||
@@ -674,7 +674,7 @@ function data_print_template($records, $data, $search, $listmode, $sort, $page,
|
||||
foreach ($possiblefields as $cfield) {
|
||||
$patterns[]='/\[\['.$cfield->name.'\]\]/i';
|
||||
$g = data_get_field($cfield);
|
||||
$replacement[] = highlight($search, $g->display_browse_field($cfield->id, $record->id));
|
||||
$replacement[] = highlight($search, $g->display_browse_field($cfield->id, $record->id, $template));
|
||||
unset($g);
|
||||
}
|
||||
|
||||
@@ -699,7 +699,7 @@ function data_print_template($records, $data, $search, $listmode, $sort, $page,
|
||||
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$record->id.'&search='.$search.'&sort='.$sort.'&order='.$order.'&"><img src="'.$CFG->pixpath.'/i/search.gif" height="11" width="11" border="0" alt="'.get_string('more').'" /></a>';
|
||||
|
||||
///actual replacement of the tags
|
||||
$newtext = preg_replace($patterns, $replacement, $data->{$listmode});
|
||||
$newtext = preg_replace($patterns, $replacement, $data->{$template});
|
||||
|
||||
echo $newtext; //prints the template with tags replaced
|
||||
|
||||
|
||||
Reference in New Issue
Block a user