예제 #1
0
 /**
  *  Get the block content
  *  
  *  @global object $CFG
  *  @global object $USER
  *  @return object|string
  */
 public function get_content()
 {
     global $CFG, $USER;
     if ($this->content !== null) {
         return $this->content;
     }
     if (!$this->page->user_is_editing()) {
         return $this->content = '';
     }
     $context = context_course::instance($this->page->course->id);
     if (!has_capability('moodle/backup:backupactivity', $context)) {
         return $this->content = '';
     }
     $controller = new sharing_cart\controller();
     $html = $controller->render_tree($USER->id);
     if (moodle_major_version() >= 2.7) {
         // Moodle 2.7 or later runs always with Ajax
     } elseif (empty($CFG->enableajax)) {
         $html = $this->get_content_noajax();
     } else {
         $noscript = html_writer::tag('noscript', html_writer::tag('div', get_string('requirejs', __CLASS__), array('class' => 'error')));
         $html = $noscript . $html;
     }
     $this->page->requires->css('/blocks/sharing_cart/styles.css');
     $this->page->requires->js('/blocks/sharing_cart/module.js');
     $this->page->requires->yui_module('block_sharing_cart', 'M.block_sharing_cart.init', array(), null, true);
     $this->page->requires->strings_for_js(array('yes', 'no', 'ok', 'cancel', 'error', 'edit', 'move', 'delete', 'movehere'), 'moodle');
     $this->page->requires->strings_for_js(array('copyhere', 'notarget', 'backup', 'restore', 'movedir', 'clipboard', 'confirm_backup', 'confirm_userdata', 'confirm_delete'), __CLASS__);
     $footer = '<div style="display:none;">' . '<div class="header-commands">' . $this->get_header() . '</div>' . '</div>';
     return $this->content = (object) array('text' => $html, 'footer' => $footer);
 }
예제 #2
0
/**
 *  Sharing Cart - REST API
 *  
 *  @author  VERSION2, Inc.
 *  @version $Id: rest.php 859 2012-10-12 06:31:50Z malu $
 */
require_once '../../config.php';
require_once __DIR__ . '/classes/controller.php';
try {
    $controller = new sharing_cart\controller();
    switch (required_param('action', PARAM_TEXT)) {
        case 'render_tree':
            $PAGE->set_context(\context_user::instance($USER->id));
            // pix_url() needs this
            echo $controller->render_tree($USER->id);
            exit;
        case 'is_userdata_copyable':
            $cmid = required_param('cmid', PARAM_INT);
            echo $controller->is_userdata_copyable($cmid);
            exit;
        case 'backup':
            $cmid = required_param('cmid', PARAM_INT);
            $userdata = required_param('userdata', PARAM_BOOL);
            $controller->backup($cmid, $userdata);
            exit;
        case 'movedir':
            $id = required_param('id', PARAM_INT);
            $to = required_param('to', PARAM_TEXT);
            $controller->movedir($id, $to);
            exit;