MDL-15758 - added add to portfolio button to resource/text & html
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user