示例#1
0
/**
 * Upgrade function.
 *
 * @param int $oldversion the version we are upgrading from.
 * @return bool result
 */
function xmldb_portfolio_boxnet_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2013110602) {
        require_once $CFG->libdir . '/portfoliolib.php';
        require_once $CFG->dirroot . '/portfolio/boxnet/db/upgradelib.php';
        $existing = $DB->get_record('portfolio_instance', array('plugin' => 'boxnet'), '*', IGNORE_MULTIPLE);
        if ($existing) {
            // Only disable or message the admins when the portfolio hasn't been set for APIv2.
            $instance = portfolio_instance($existing->id, $existing);
            if ($instance->get_config('clientid') === null && $instance->get_config('clientsecret') === null) {
                // Disable Box.net.
                $instance->set('visible', 0);
                $instance->save();
                // Message the admins.
                portfolio_boxnet_admin_upgrade_notification();
            }
        }
        upgrade_plugin_savepoint(true, 2013110602, 'portfolio', 'boxnet');
    }
    // Moodle v2.6.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.7.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.9.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
/**
* helper function to check all the instances for sanity and set any insane ones to invisible.
*
* @param array $instances to check (if null, defaults to all)
*              one instance or id will work too
*
* @return array array of insane instances (keys= id, values = reasons (keys for plugin lang)
*/
function portfolio_instance_sanity_check($instances = null)
{
    global $DB;
    if (empty($instances)) {
        $instances = portfolio_instances(false);
    } else {
        if (!is_array($instances)) {
            $instances = array($instances);
        }
    }
    $insane = array();
    foreach ($instances as $instance) {
        if (is_object($instance) && !$instance instanceof portfolio_plugin_base) {
            $instance = portfolio_instance($instance->id, $instance);
        } else {
            if (is_numeric($instance)) {
                $instance = portfolio_instance($instance);
            }
        }
        if (!$instance instanceof portfolio_plugin_base) {
            debugging('something weird passed to portfolio_instance_sanity_check, not subclass or id');
            continue;
        }
        if ($result = $instance->instance_sanity_check()) {
            $insane[$instance->get('id')] = $result;
        }
    }
    if (empty($insane)) {
        return array();
    }
    list($where, $params) = $DB->get_in_or_equal(array_keys($insane));
    $where = ' id ' . $where;
    $DB->set_field_select('portfolio_instance', 'visible', 0, $where, $params);
    portfolio_insane_notify_admins($insane, true);
    return $insane;
}
示例#3
0
 /**
  * Wrapper function to print a friendly error to users
  *
  * @param stdClass $log portfolio_log object
  * @param portfolio_plugin_base $instance portfolio instance
  * @uses exit
  */
 public static function print_cleaned_export($log, $instance = null)
 {
     global $CFG, $OUTPUT, $PAGE;
     if (empty($instance) || !$instance instanceof portfolio_plugin_base) {
         $instance = portfolio_instance($log->portfolio);
     }
     $title = get_string('exportalreadyfinished', 'portfolio');
     $PAGE->navbar->add($title);
     $PAGE->set_title($title);
     $PAGE->set_heading($title);
     echo $OUTPUT->header();
     echo $OUTPUT->notification(get_string('exportalreadyfinished', 'portfolio'));
     self::print_finish_info($log->returnurl, $instance->resolve_static_continue_url($log->continueurl));
     echo $OUTPUT->continue_button($CFG->wwwroot);
     echo $OUTPUT->footer();
     exit;
 }
            // This branch is where you process validated data.
            $instance->set_user_config($fromform, $USER->id);
            core_plugin_manager::reset_caches();
            redirect($baseurl, get_string('instancesaved', 'portfolio'), 3);
            exit;
        } else {
            echo $OUTPUT->heading(get_string('configplugin', 'portfolio'));
            echo $OUTPUT->box_start();
            $mform->display();
            echo $OUTPUT->box_end();
            $display = false;
        }
    }
} else {
    if (!empty($hide)) {
        $instance = portfolio_instance($hide);
        $instance->set_user_config(array('visible' => !$instance->get_user_config('visible', $USER->id)), $USER->id);
        core_plugin_manager::reset_caches();
    }
}
if ($display) {
    echo $OUTPUT->heading($configstr);
    echo $OUTPUT->box_start();
    if (!($instances = portfolio_instances(true, false))) {
        print_error('noinstances', 'portfolio', $CFG->wwwroot . '/user/view.php');
    }
    $table = new html_table();
    $table->head = array($namestr, $pluginstr, '');
    $table->data = array();
    foreach ($instances as $i) {
        $visible = $i->get_user_config('visible', $USER->id);
示例#5
0
 $logs = $DB->get_records('portfolio_log', array('userid' => $USER->id), 'time DESC', '*', $page * $perpage, $perpage);
 foreach ($logs as $log) {
     if (!empty($log->caller_file)) {
         portfolio_include_callback_file($log->caller_file);
     } else {
         if (!empty($log->caller_component)) {
             portfolio_include_callback_file($log->caller_component);
         } else {
             // Errrmahgerrrd - this should never happen. Skipping.
             continue;
         }
     }
     $class = $log->caller_class;
     $pluginname = '';
     try {
         $plugin = portfolio_instance($log->portfolio);
         $url = $plugin->resolve_static_continue_url($log->continueurl);
         if ($url) {
             $pluginname = '<a href="' . $url . '">' . $plugin->get('name') . '</a>';
         } else {
             $pluginname = $plugin->get('name');
         }
     } catch (portfolio_exception $e) {
         // May have been deleted.
         $pluginname = get_string('unknownplugin', 'portfolio');
     }
     $table->data[] = array($pluginname, '<a href="' . $log->returnurl . '">' . call_user_func(array($class, 'display_name')) . '</a>', userdate($log->time));
 }
 echo $OUTPUT->heading(get_string('logsummary', 'portfolio'));
 $pagingbar = new paging_bar($logcount, $page, $perpage, $CFG->wwwroot . '/user/portfoliologs.php?');
 echo $OUTPUT->render($pagingbar);
示例#6
0
 if (!empty($hide)) {
     if (!confirm_sesskey()) {
         print_error('confirmsesskeybad', '', $baseurl);
     }
     $instance = portfolio_instance($hide);
     $current = $instance->get('visible');
     if (empty($current) && $instance->instance_sanity_check()) {
         print_error('cannotsetvisible', 'portfolio', $baseurl);
     }
     $instance->set('visible', !$instance->get('visible'));
     $instance->save();
     $return = true;
 } else {
     if (!empty($delete)) {
         admin_externalpage_print_header();
         $instance = portfolio_instance($delete);
         if ($sure) {
             if (!confirm_sesskey()) {
                 print_error('confirmsesskeybad', '', $baseurl);
             }
             if ($instance->delete()) {
                 $deletedstr = get_string('instancedeleted', 'portfolio');
                 echo $OUTPUT->heading($deletedstr);
                 redirect($baseurl, $deletedstr, 3);
             } else {
                 print_error('instancenotdeleted', 'portfolio', $baseurl);
             }
             exit;
         }
         echo $OUTPUT->confirm(get_string('sure', 'portfolio', $instance->get('name')), $sesskeyurl . '&delete=' . $delete . '&sure=yes', $baseurl);
         $return = false;
示例#7
0
文件: add.php 项目: evltuma/moodle
            $exporter->save();
        }
    }
    portfolio_export_pagesetup($PAGE, $exporter->get('caller'));
    // this calls require_login($course) if it can..
    // completely new request, look to see what information we've been passed and set up the exporter object.
} else {
    // you cannot get here with no information for us, we must at least have the caller.
    if (empty($_GET) && empty($_POST)) {
        portfolio_exporter::print_expired_export();
    }
    // we'e just posted here for the first time and have might the instance already
    if ($instanceid) {
        // this can throw exceptions but there's no point catching and rethrowing here
        // as the exporter isn't created yet.
        $instance = portfolio_instance($instanceid);
        if ($broken = portfolio_instance_sanity_check($instance)) {
            throw new portfolio_exception($broken[$instance->get('id')], 'portfolio_' . $instance->get('plugin'));
        }
        $instance->set('user', $USER);
    } else {
        $instance = null;
    }
    // we must be passed this from the caller, we cannot start a new export
    // without knowing information about what part of moodle we come from.
    if (empty($callbackcomponent) || empty($callbackclass)) {
        debugging('no callback file or class');
        portfolio_exporter::print_expired_export();
    }
    // so each place in moodle can pass callback args here
    // process the entire request looking for ca_*
示例#8
0
     $current = $instance->get('visible');
     if (empty($current) && $instance->instance_sanity_check()) {
         print_error('cannotsetvisible', 'portfolio', $baseurl);
     }
     if ($action == 'show') {
         $visible = 1;
     } else {
         $visible = 0;
     }
     $instance->set('visible', $visible);
     $instance->save();
     core_plugin_manager::reset_caches();
     $return = true;
 } else {
     if ($action == 'delete') {
         $instance = portfolio_instance($portfolio);
         if ($sure) {
             if (!confirm_sesskey()) {
                 print_error('confirmsesskeybad', '', $baseurl);
             }
             if ($instance->delete()) {
                 $deletedstr = get_string('instancedeleted', 'portfolio');
                 redirect($baseurl, $deletedstr, 1);
             } else {
                 print_error('instancenotdeleted', 'portfolio', $baseurl);
             }
             exit;
         } else {
             echo $OUTPUT->header();
             echo $OUTPUT->confirm(get_string('sure', 'portfolio', $instance->get('name')), $sesskeyurl . '&pf=' . $portfolio . '&action=delete&sure=yes', $baseurl);
             $return = false;
 function is_enabled()
 {
     $instance = portfolio_instance($this->plugin);
     return $instance->get('visible');
 }