]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14591: changed the definition of portfolio_add_button
authormjollnir_ <mjollnir_>
Fri, 25 Jul 2008 10:31:10 +0000 (10:31 +0000)
committermjollnir_ <mjollnir_>
Fri, 25 Jul 2008 10:31:10 +0000 (10:31 +0000)
        to support passing the callbackfile explicitly if necessary
        and added my name next to some TODOs so I can find them later

lib/portfoliolib.php
mod/assignment/lib.php
mod/assignment/type/online/assignment.class.php
mod/assignment/type/upload/assignment.class.php

index 1f466db1877bc7e801d506eb198620f2a1f95596..3187319af69b276d15758406e495e86d890c43a7 100644 (file)
@@ -135,12 +135,16 @@ define('PORTFOLIO_TIME_HIGH', 'high');
 *                                        back to the callback functions (passed by reference)
 *                                        these MUST be primatives to be added as hidden form fields.
 *                                        and the values get cleaned to PARAM_ALPHAEXT or PARAM_NUMBER or PARAM_PATH
+* @param string $callbackfile            this can be autodetected if it's in the same file as your caller,
+*                                        but more often, the caller is a script.php and the class in a lib.php
+*                                        so you can pass it here if necessary.
+*                                        this path should be relative (ie, not include) dirroot
 * @param boolean $fullform               either display the fullform with the dropmenu of available instances
 *                                        or just a small icon (which will trigger instance selection in a new screen)
 *                                        optional, defaults to true.
 * @param boolean $return                 whether to echo or return content (optional defaults to false (echo)
 */
-function portfolio_add_button($callbackclass, $callbackargs, $fullform=true, $return=false) {
+function portfolio_add_button($callbackclass, $callbackargs, $callbackfile=null, $fullform=true, $return=false) {
 
     global $SESSION, $CFG, $COURSE, $USER;
 
@@ -148,13 +152,20 @@ function portfolio_add_button($callbackclass, $callbackargs, $fullform=true, $re
         return;
     }
 
-    $backtrace = debug_backtrace();
-    if (!array_key_exists(0, $backtrace) || !array_key_exists('file', $backtrace[0]) || !is_readable($backtrace[0]['file'])) {
-        debugging(get_string('nocallbackfile', 'portfolio'));
-        return;
-    }
+    if (empty($callbackfile)) {
+        $backtrace = debug_backtrace();
+        if (!array_key_exists(0, $backtrace) || !array_key_exists('file', $backtrace[0]) || !is_readable($backtrace[0]['file'])) {
+            debugging(get_string('nocallbackfile', 'portfolio'));
+            return;
+        }
 
-    $callbackfile = substr($backtrace[0]['file'], strlen($CFG->dirroot));
+        $callbackfile = substr($backtrace[0]['file'], strlen($CFG->dirroot));
+    } else {
+        if (!is_readable($CFG->dirroot . $callbackfile)) {
+            debugging(get_string('nocallbackfile', 'portfolio'));
+            return;
+        }
+    }
 
     require_once($CFG->dirroot . $callbackfile);
 
index c4d32032ce21a7343ab21ed26cda1373a76878e5..b0efd129fe67886d5bd6ea8150de103a387d45c9 100644 (file)
@@ -1712,13 +1712,13 @@ class assignment_base {
                             '<a href="'.$ffurl.'" >'.$file.'</a>';
                     if ($this->portfolio_exportable() && true) { // @todo replace with capability check
                         $p['file'] = $file;
-                        $output .= portfolio_add_button('assignment_portfolio_caller', $p, false, true);
+                        $output .= portfolio_add_button('assignment_portfolio_caller', $p, null, false, true);
                     }
                     $output .= '<br />';
                 }
                 if ($this->portfolio_exportable() && true) { //@todo replace with check capability
                     unset($p['file']);// for all files
-                    $output .= '<br />' . portfolio_add_button('assignment_portfolio_caller', $p, true, true);
+                    $output .= '<br />' . portfolio_add_button('assignment_portfolio_caller', $p, null, true, true);
                 }
             }
         }
@@ -3154,7 +3154,7 @@ class assignment_portfolio_caller extends portfolio_caller_base {
             return $status;
         }
         $filearea = $CFG->dataroot . '/' . $this->assignment->file_area_name($this->userid);
-        //@todo  this is a dreadful thing to have to call.
+        //@todo  penny this is a dreadful thing to have to call (replace with files api anyway)
         require_once($CFG->dirroot . '/backup/lib.php');
         if ($this->file) {
             return backup_copy_file($filearea . '/' . $this->file, $tempdir . '/' . $this->file);
index b7c9ca56940936fa32a1f6bb1345b11fb1e5b48b..b5316370ac0600e362a6f5816c5391f3a5e6ad4f 100644 (file)
@@ -101,13 +101,13 @@ class assignment_online extends assignment_base {
                 $mform->display();
             } else {
                 print_box_start('generalbox boxwidthwide boxaligncenter', 'online');
-                if ($submission) {
+                if ($submission && true) { // @todo penny replace with capability check later
                     echo format_text($submission->data1, $submission->data2);
                     $p = array(
                         'userid' => $USER->id,
                         'assignmentid' => $this->cm->id,
                     );
-                    portfolio_add_button('assignment_portfolio_caller', $p);
+                    portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php'));
                 } else if (!has_capability('mod/assignment:submit', $context)) { //fix for #4604
                     echo '<div style="text-align:center">'. get_string('guestnosubmit', 'assignment').'</div>';
                 } else if ($this->isopen()){    //fix for #4206
index c9753d2b857c758c4696e46208a981dc51871b0a..1d68566c336d8a215b0a5273d3092e26227cd9f3 100644 (file)
@@ -377,15 +377,15 @@ class assignment_upload extends assignment_base {
                         $output .= '<a href="'.$delurl.'">&nbsp;'
                                   .'<img title="'.$strdelete.'" src="'.$CFG->pixpath.'/t/delete.gif" class="iconsmall" alt="" /></a> ';
                     }
-                    if (true) { // @todo replace with capability check
+                    if (true) { // @todo penny replace with capability check
                         $p['file'] = $file;
-                        $output .= portfolio_add_button('assignment_portfolio_caller', $p, false, true);
+                        $output .= portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php', false, true);
                     }
                     $output .= '<br />';
                 }
-                if (true) { //@todo replace with check capability
+                if (true) { //@todo penny replace with check capability
                     unset($p['file']);// for all files
-                    $output .= '<br />' . portfolio_add_button('assignment_portfolio_caller', $p, true, true);
+                    $output .= '<br />' . portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php', true, true);
                 }
             }
         }