]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15758 - added add to portfolio button to resource/text & html
authormjollnir_ <mjollnir_>
Mon, 28 Jul 2008 08:19:14 +0000 (08:19 +0000)
committermjollnir_ <mjollnir_>
Mon, 28 Jul 2008 08:19:14 +0000 (08:19 +0000)
lang/en_utf8/resource.php
mod/resource/lib.php
mod/resource/type/html/resource.class.php
mod/resource/type/text/resource.class.php

index b01d768053404c862a0b9a61dac45e5827584db0..e8342cfb371f6124a188e1b326a1dd7a7a344677 100644 (file)
@@ -98,6 +98,7 @@ $string['parameter'] = 'Parameter';
 $string['parameters'] = 'Parameters';
 $string['popupresource'] = 'This resource should appear in a popup window.';
 $string['popupresourcelink'] = 'If it didn\'t, click here: $a';
+$string['portfolionotimplemented'] = 'You are trying to export content from a resource type that doesn\'t support it!';
 $string['preview'] = 'Preview';
 $string['previous'] = 'Previous';
 $string['redeploy'] = 'Deploy again';
index 82d5aad924665089b502e666888da9769a5d0d81..ecaf5801c107bccb26ab48e7f72144d25aaf859e 100644 (file)
@@ -249,6 +249,23 @@ class resource_base {
         //override to add your own options
     }
 
+    function portfolio_prepare_package_uploaded($tempdir) {
+        // @todo penny implement later - see MDL-15758
+
+    }
+
+    function portfolio_prepare_package_online($tempdir, $text=false) {
+        //@todo penny use the files api here
+        $status = $handle = fopen($tempdir . '/' . clean_filename($this->cm->name . '.' . (($text) ? 'txt' : 'html')), 'w');
+        $formatoptions = new object();
+        $formatoptions->noclean = true;
+        $format = (($text) ? FORMAT_MOODLE : FORMAT_HTML);
+        $content = format_text($this->resource->alltext, $format, $formatoptions, $this->course->id);
+        $status = $status && fwrite($handle, $content);
+        $status = $status && fclose($handle);
+        return $status;
+    }
+
 } /// end of class definition
 
 
@@ -681,4 +698,58 @@ function resource_get_extra_capabilities() {
     return array('moodle/site:accessallgroups');
 }
 
+require_once($CFG->libdir . '/portfoliolib.php');
+class resource_portfolio_caller extends portfolio_module_caller_base {
+
+    private $resource;
+    private $resourcefile;
+
+    public function __construct($callbackargs) {
+        global $CFG;
+        global $DB;
+        if (!array_key_exists('id', $callbackargs) || !$this->cm = get_coursemodule_from_instance('resource', $callbackargs['id'])) {
+            print_error('invalidid');
+        }
+        $this->cm->type = $DB->get_field('resource', 'type', array('id' => $this->cm->instance));
+        $resourceclass = 'resource_'. $this->cm->type;
+        $this->resourcefile = $CFG->dirroot.'/mod/resource/type/'.$this->cm->type.'/resource.class.php';
+        require_once($this->resourcefile);
+        $this->resource= new $resourceclass($this->cm->id);
+    }
+
+    public function __wakeup() {
+        require_once($this->resourcefile);
+        $this->resource = unserialize(serialize($this->resource));
+    }
+
+    public function expected_time() {
+        // @todo penny check filesize if the type is uploadey
+        return PORTFOLIO_TIME_LOW;
+    }
+
+    public function prepare_package($tempdir) {
+        if (!is_callable(array($this->resource, 'portfolio_prepare_package'))) {
+            portfolio_exporter::raise_error('portfolionotimplemented', 'resource');
+        }
+        return $this->resource->portfolio_prepare_package($tempdir);
+    }
+
+    public static function supported_formats() {
+        return array(PORTFOLIO_FORMAT_FILE);
+    }
+
+    public function check_permissions() {
+        return true;
+    }
+
+    public static function add_button($resource, $fullform=true, $return=false) {
+        // @todo penny can we put the capability check in here?
+        if (!is_callable(array($resource, 'portfolio_prepare_package'))) {
+            debugging(get_string('portfolionotimplemented', 'resource'));
+            return false;
+        }
+        return portfolio_add_button('resource_portfolio_caller', array('id' => $resource->cm->instance),  '/mod/resource/lib.php', $fullform, $return);
+    }
+}
+
 ?>
index a89c5820409476da49a4496a3a2501dffee9a968..e1952364cf623801418bf3bf3573f6df7e2f428f 100644 (file)
@@ -65,6 +65,9 @@ function display() {
         parent::display_course_blocks_start();
 
         echo format_text($this->resource->alltext, FORMAT_HTML, $formatoptions, $this->course->id);
+        if (true) { //@todo penny replace later with capability check
+            resource_portfolio_caller::add_button($this);
+        }
 
         parent::display_course_blocks_end();
 
@@ -82,6 +85,9 @@ function display() {
                 print_header();
                 print_simple_box(format_text($resource->alltext, FORMAT_HTML, $formatoptions, $course->id),
                         "center clearfix", "", "", "20");
+                if (true) { //@todo penny replace later with capability check
+                    resource_portfolio_caller::add_button($this);
+                }
                 print_footer($course);
             } else {                           /// Make a page and a pop-up window
                 $navigation = build_navigation($this->navlinks, $cm);
@@ -118,6 +124,9 @@ function display() {
                     navmenu($course, $cm));
 
             print_simple_box(format_text($resource->alltext, FORMAT_HTML, $formatoptions, $course->id), "center clearfix", "", "", "20");
+            if (true) { //@todo penny replace later with capability check
+                resource_portfolio_caller::add_button($this);
+            }
 
             $strlastmodified = get_string("lastmodified");
             echo "<div class=\"modified\">$strlastmodified: ".userdate($resource->timemodified)."</div>";
@@ -184,6 +193,10 @@ function setup_elements(&$mform) {
     }
 }
 
+function portfolio_prepare_package($tempdir) {
+    return parent::portfolio_prepare_package_online($tempdir);
+}
+
 
 }
 
index 0f2d47f4930ef1fc138916cbf510ad002b2f96f8..064d664998a0cc46c60446b2c0a85ada5f022ec1 100644 (file)
@@ -56,6 +56,9 @@ function display() {
 
         if (trim(strip_tags($this->resource->alltext))) {
             echo format_text($this->resource->alltext, FORMAT_MOODLE, $formatoptions, $this->course->id);
+            if (true) { //@todo penny replace later with capability check
+                resource_portfolio_caller::add_button($this);
+            }
         }
 
         parent::display_course_blocks_end();
@@ -81,6 +84,9 @@ function display() {
                 print_simple_box(format_text($resource->alltext, $resource->reference, $formatoptions, $course->id),
                         "center", "", "", "20");
                 print_footer($course);
+                if (true) { //@todo penny replace later with capability check
+                    resource_portfolio_caller::add_button($this);
+                }
             } else {                           /// Make a page and a pop-up window
                 $navigation = build_navigation($this->navlinks, $cm);
 
@@ -120,6 +126,9 @@ function display() {
             print_simple_box(format_text($resource->alltext, $resource->reference, $formatoptions, $course->id),
                     "center", "", "", "20");
 
+            if (true) { //@todo penny replace later with capability check
+                resource_portfolio_caller::add_button($this);
+            }
             $strlastmodified = get_string("lastmodified");
             echo "<div class=\"modified\">$strlastmodified: ".userdate($resource->timemodified)."</div>";
 
@@ -190,6 +199,9 @@ function setup_elements(&$mform) {
 }
 
 
+function portfolio_prepare_package($tempdir) {
+    return parent::portfolio_prepare_package_online($tempdir, true);
+}
 }
 
 ?>