Ejemplo n.º 1
0
 /**
  * prepare form
  */
 public function definition()
 {
     global $CFG;
     $this->plugin = $this->_customdata['plugin'];
     $this->instance = isset($this->_customdata['instance']) && is_subclass_of($this->_customdata['instance'], 'portfolio_plugin_base') ? $this->_customdata['instance'] : null;
     $this->portfolio = $this->_customdata['portfolio'];
     $this->action = $this->_customdata['action'];
     $this->visible = $this->_customdata['visible'];
     $mform =& $this->_form;
     $strrequired = get_string('required');
     $mform->addElement('hidden', 'pf', $this->portfolio);
     $mform->setType('pf', PARAM_ALPHA);
     $mform->addElement('hidden', 'action', $this->action);
     $mform->setType('action', PARAM_ALPHA);
     $mform->addElement('hidden', 'visible', $this->visible);
     $mform->setType('visible', PARAM_INT);
     $mform->addElement('hidden', 'plugin', $this->plugin);
     $mform->setType('plugin', PARAM_PLUGIN);
     if (!$this->instance) {
         $insane = portfolio_instance_sanity_check($this->instance);
     } else {
         $insane = portfolio_plugin_sanity_check($this->plugin);
     }
     if (isset($insane) && is_array($insane)) {
         $insane = array_shift($insane);
     }
     if (isset($insane) && is_string($insane)) {
         // something went wrong, warn...
         $mform->addElement('warning', 'insane', null, get_string($insane, 'portfolio_' . $this->plugin));
     }
     $mform->addElement('text', 'name', get_string('name'), 'maxlength="100" size="30"');
     $mform->addRule('name', $strrequired, 'required', null, 'client');
     // let the plugin add the fields they want (either statically or not)
     if (portfolio_static_function($this->plugin, 'has_admin_config')) {
         if (!$this->instance) {
             require_once $CFG->libdir . '/portfolio/plugin.php';
             require_once $CFG->dirroot . '/portfolio/' . $this->plugin . '/lib.php';
             call_user_func(array('portfolio_plugin_' . $this->plugin, 'admin_config_form'), $mform);
         } else {
             $this->instance->admin_config_form($mform);
         }
     }
     // and set the data if we have some.
     if ($this->instance) {
         $data = array('name' => $this->instance->get('name'));
         foreach ($this->instance->get_allowed_config() as $config) {
             $data[$config] = $this->instance->get_config($config);
         }
         $this->set_data($data);
     } else {
         $this->set_data(array('name' => portfolio_static_function($this->plugin, 'get_name')));
     }
     $this->add_action_buttons(true, get_string('save', 'portfolio'));
 }
/**
* returns a drop menu with a list of available instances.
*
* @param array          $instances      array of portfolio plugin instance objects - the instances to put in the menu
* @param array          $callerformats  array of PORTFOLIO_FORMAT_XXX constants - the formats the caller supports (this is used to filter plugins)
* @param array          $callbackclass  the callback class name - used for debugging only for when there are no common formats
* @param mimetype       $mimetype       if we already know we have exactly one file, or are going to write one, pass it here to do mime filtering.
* @param string         $selectname     the name of the select element. Optional, defaults to instance.
* @param boolean        $return         whether to print or return the output. Optional, defaults to print.
* @param booealn        $returnarray    if returning, whether to return the HTML or the array of options. Optional, defaults to HTML.
*
* @return string the html, from <select> to </select> inclusive.
*/
function portfolio_instance_select($instances, $callerformats, $callbackclass, $mimetype = null, $selectname = 'instance', $return = false, $returnarray = false)
{
    global $CFG, $USER;
    if (empty($CFG->enableportfolios)) {
        return;
    }
    $insane = portfolio_instance_sanity_check();
    $pinsane = portfolio_plugin_sanity_check();
    $count = 0;
    $selectoutput = "\n" . '<select name="' . $selectname . '">' . "\n";
    $existingexports = portfolio_existing_exports_by_plugin($USER->id);
    foreach ($instances as $instance) {
        $formats = portfolio_supported_formats_intersect($callerformats, $instance->supported_formats());
        if (count($formats) == 0) {
            // bail. no common formats.
            continue;
        }
        if (array_key_exists($instance->get('id'), $insane)) {
            // bail, plugin is misconfigured
            //debugging(get_string('instanceismisconfigured', 'portfolio', get_string($insane[$instance->get('id')], 'portfolio_' . $instance->get('plugin'))));
            continue;
        } else {
            if (array_key_exists($instance->get('plugin'), $pinsane)) {
                // bail, plugin is misconfigured
                //debugging(get_string('pluginismisconfigured', 'portfolio', get_string($pinsane[$instance->get('plugin')], 'portfolio_' . $instance->get('plugin'))));
                continue;
            }
        }
        if (!$instance->allows_multiple_exports() && in_array($instance->get('plugin'), $existingexports)) {
            // bail, already exporting something with this plugin and it doesn't support multiple exports
            continue;
        }
        if ($mimetype && !$instance->file_mime_check($mimetype)) {
            //debugging(get_string('mimecheckfail', 'portfolio', (object)array('plugin' => $instance->get('plugin'), 'mimetype' => $mimetype())));
            // bail, we have a specific file and this plugin doesn't support it
            continue;
        }
        $count++;
        $selectoutput .= "\n" . '<option value="' . $instance->get('id') . '">' . $instance->get('name') . '</option>' . "\n";
        $options[$instance->get('id')] = $instance->get('name');
    }
    if (empty($count)) {
        // bail. no common formats.
        //debugging(get_string('nocommonformats', 'portfolio', (object)array('location' => $callbackclass, 'formats' => implode(',', $callerformats))));
        return;
    }
    $selectoutput .= "\n" . "</select>\n";
    if (!empty($returnarray)) {
        return $options;
    }
    if (!empty($return)) {
        return $selectoutput;
    }
    echo $selectoutput;
}
Ejemplo n.º 3
0
 /**
  * Builds XHTML to display the control
  *
  * @param string $data Unused
  * @param string $query
  * @return string XHTML to display the control
  */
 public function output_html($data, $query = '')
 {
     global $CFG, $OUTPUT;
     $output = $OUTPUT->box_start('generalbox');
     $namestr = get_string('name');
     $pluginstr = get_string('plugin', 'portfolio');
     $plugins = get_plugin_list('portfolio');
     $plugins = array_keys($plugins);
     $instances = portfolio_instances(false, false);
     $alreadyplugins = array();
     // to avoid notifications being sent out while admin is editing the page
     define('ADMIN_EDITING_PORTFOLIO', true);
     $insane = portfolio_plugin_sanity_check($plugins);
     $insaneinstances = portfolio_instance_sanity_check($instances);
     $output .= portfolio_report_insane($insane, null, true);
     $output .= portfolio_report_insane($insaneinstances, $instances, true);
     $table = new html_table();
     $table->head = array($namestr, $pluginstr, '');
     $table->data = array();
     foreach ($instances as $i) {
         $row = '';
         $row .= '<a href="' . $this->baseurl . '&edit=' . $i->get('id') . '"><img src="' . $OUTPUT->old_icon_url('t/edit') . '" alt="' . get_string('edit') . '" /></a>' . "\n";
         $row .= '<a href="' . $this->baseurl . '&delete=' . $i->get('id') . '"><img src="' . $OUTPUT->old_icon_url('t/delete') . '" alt="' . get_string('delete') . '" /></a>' . "\n";
         if (array_key_exists($i->get('plugin'), $insane) || array_key_exists($i->get('id'), $insaneinstances)) {
             $row .= '<img src="' . $OUTPUT->old_icon_url('t/show') . '" alt="' . get_string('hidden', 'portfolio') . '" />' . "\n";
         } else {
             $row .= ' <a href="' . $this->baseurl . '&hide=' . $i->get('id') . '"><img src="' . $OUTPUT->old_icon_url('t/' . ($i->get('visible') ? 'hide' : 'show')) . '" alt="' . get_string($i->get('visible') ? 'hide' : 'show') . '" /></a>' . "\n";
         }
         $table->data[] = array($i->get('name'), $i->get_name() . ' (' . $i->get('plugin') . ')', $row);
         if (!in_array($i->get('plugin'), $alreadyplugins)) {
             $alreadyplugins[] = $i->get('plugin');
         }
     }
     $output .= $OUTPUT->table($table);
     $instancehtml = '<br /><br />' . get_string('addnewportfolio', 'portfolio') . ': <br /><br />';
     $addable = 0;
     foreach ($plugins as $p) {
         if (!portfolio_static_function($p, 'allows_multiple') && in_array($p, $alreadyplugins)) {
             continue;
         }
         if (array_key_exists($p, $insane)) {
             continue;
         }
         $instancehtml .= '<a href="' . $this->baseurl . '&amp;new=' . $p . '">' . portfolio_static_function($p, 'get_name') . ' (' . s($p) . ')' . '</a><br />' . "\n";
         $addable++;
     }
     if ($addable) {
         $output .= $instancehtml;
     }
     $output .= $OUTPUT->box_end();
     return highlight($query, $output);
 }
Ejemplo n.º 4
0
/**
* returns a drop menu with a list of available instances.
*
* @param array    $instances     array of portfolio plugin instance objects - the instances to put in the menu
* @param array    $callerformats array of PORTFOLIO_FORMAT_XXX constants - the formats the caller supports (this is used to filter plugins)
* @param array    $callbackclass the callback class name - used for debugging only for when there are no common formats
* @param string   $selectname    the name of the select element. Optional, defaults to instance.
* @param boolean  $return        whether to print or return the output. Optional, defaults to print.
* @param booealn  $returnarray   if returning, whether to return the HTML or the array of options. Optional, defaults to HTML.
*
* @return string the html, from <select> to </select> inclusive.
*/
function portfolio_instance_select($instances, $callerformats, $callbackclass, $selectname = 'instance', $return = false, $returnarray = false)
{
    global $CFG;
    if (empty($CFG->enableportfolios)) {
        return;
    }
    $insane = portfolio_instance_sanity_check();
    $pinsane = portfolio_plugin_sanity_check();
    $count = 0;
    $selectoutput = "\n" . '<select name="' . $selectname . '">' . "\n";
    foreach ($instances as $instance) {
        $formats = portfolio_supported_formats_intersect($callerformats, $instance->supported_formats());
        if (count($formats) == 0) {
            // bail. no common formats.
            continue;
        }
        if (array_key_exists($instance->get('id'), $insane)) {
            // bail, plugin is misconfigured
            debugging(get_string('instanceismisconfigured', 'portfolio', get_string($insane[$instance->get('id')], 'portfolio_' . $instance->get('plugin'))));
            continue;
        } else {
            if (array_key_exists($instance->get('plugin'), $pinsane)) {
                // bail, plugin is misconfigured
                debugging(get_string('pluginismisconfigured', 'portfolio', get_string($pinsane[$instance->get('plugin')], 'portfolio_' . $instance->get('plugin'))));
                continue;
            }
        }
        $count++;
        $selectoutput .= "\n" . '<option value="' . $instance->get('id') . '">' . $instance->get('name') . '</option>' . "\n";
        $options[$instance->get('id')] = $instance->get('name');
    }
    if (empty($count)) {
        // bail. no common formats.
        debugging(get_string('nocommonformats', 'portfolio', $callbackclass));
        return;
    }
    $selectoutput .= "\n" . "</select>\n";
    if (!empty($returnarray)) {
        return $options;
    }
    if (!empty($return)) {
        return $selectoutput;
    }
    echo $selectoutput;
}
Ejemplo n.º 5
0
 echo $OUTPUT->heading(get_string('manageportfolios', 'portfolio'));
 // Get strings that are used
 $strshow = get_string('on', 'portfolio');
 $strhide = get_string('off', 'portfolio');
 $strdelete = get_string('disabledinstance', 'portfolio');
 $strsettings = get_string('settings');
 $actionchoicesforexisting = array('show' => $strshow, 'hide' => $strhide, 'delete' => $strdelete);
 $actionchoicesfornew = array('newon' => $strshow, 'newoff' => $strhide, 'delete' => $strdelete);
 $output = $OUTPUT->box_start('generalbox');
 $plugins = core_component::get_plugin_list('portfolio');
 $plugins = array_keys($plugins);
 $instances = portfolio_instances(false, false);
 $usedplugins = array();
 // to avoid notifications being sent out while admin is editing the page
 define('ADMIN_EDITING_PORTFOLIO', true);
 $insane = portfolio_plugin_sanity_check($plugins);
 $insaneinstances = portfolio_instance_sanity_check($instances);
 $table = new html_table();
 $table->head = array(get_string('plugin', 'portfolio'), '', '');
 $table->data = array();
 foreach ($instances as $i) {
     $settings = '<a href="' . $sesskeyurl . '&amp;action=edit&amp;pf=' . $i->get('id') . '">' . $strsettings . '</a>';
     // Set some commonly used variables
     $pluginid = $i->get('id');
     $plugin = $i->get('plugin');
     $pluginname = $i->get('name');
     // Check if the instance is misconfigured
     if (array_key_exists($plugin, $insane) || array_key_exists($pluginid, $insaneinstances)) {
         if (!empty($insane[$plugin])) {
             $information = $insane[$plugin];
         } else {