]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14320, improve coding style, thanks Petr, merged from MOODLE_19_STABLE
authordongsheng <dongsheng>
Wed, 16 Apr 2008 02:46:03 +0000 (02:46 +0000)
committerdongsheng <dongsheng>
Wed, 16 Apr 2008 02:46:03 +0000 (02:46 +0000)
mod/data/field/file/field.class.php

index 25bbd14f34c975a36ea77f98c2ae06b4109a541d..8cbb4cb5efd94d37417842df7ce193cd5e9ef79f 100755 (executable)
@@ -97,35 +97,29 @@ class data_field_file extends data_field_base {
 
         global $CFG;
 
-        if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
-            $contents[0] = $content->content;
-            $contents[1] = $content->content1;
+        if (!$content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+            return false;
+        }
 
-            $src = empty($contents[0])? '':$contents[0];
-            $name = empty($contents[1])? $src:$contents[1];
+        $width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' ';
+        $height = $this->field->param2 ? ' height = "'.s($this->field->param2).'" ':' ';
 
-            $path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
+        if (empty($content->content)) {
+            return '';
+        }
 
-            if ($CFG->slasharguments) {
-                $source = $CFG->wwwroot.'/file.php/'.$path;
-            } else {
-                $source = $CFG->wwwroot.'/file.php?file=/'.$path;
-            }
+        require_once($CFG->libdir.'/filelib.php');
 
-            $width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' ';
-            $height = $this->field->param2 ? ' height = "'.s($this->field->param2).'" ':' ';
+        $src  = $content->content;
+        $name = empty($content->content1) ? $src : $content->content1;
 
-            if (isset($contents[0])) {
-                require_once($CFG->libdir.'/filelib.php');
-                $icon = mimeinfo('icon', $src);
-                $str = '<img src="'.$CFG->pixpath.'/f/'.$icon.'" height="16" width="16" alt="'.$icon.'" />&nbsp;'.
-                                '<a href="'.$source.'/'.$src.'" >'.$name.'</a>';
-            } else {
-                $str = '';
-            }
-            return $str;
-        }
-        return false;
+        $source = get_file_url($this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid);
+
+        $icon = mimeinfo('icon', $src);
+        $str = '<img src="'.$CFG->pixpath.'/f/'.$icon.'" height="16" width="16" alt="'.$icon.'" />&nbsp;'.
+                        '<a href="'.$source.'/'.$src.'" >'.$name.'</a>';
+
+        return $str;
     }