Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/message/renderer.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00025 defined('MOODLE_INTERNAL') || die();
00026 
00036 class core_message_renderer extends plugin_renderer_base {
00037 
00044     public function manage_messageoutputs($processors) {
00045         global $CFG;
00046         // Display the current workflows
00047         $table = new html_table();
00048         $table->attributes['class'] = 'generaltable';
00049         $table->data        = array();
00050         $table->head        = array(
00051             get_string('name'),
00052             get_string('enable'),
00053             get_string('settings'),
00054         );
00055         $table->colclasses = array(
00056             'displayname', 'availability', 'settings',
00057         );
00058 
00059         foreach ($processors as $processor) {
00060             $row = new html_table_row();
00061             $row->attributes['class'] = 'messageoutputs';
00062 
00063             // Name
00064             $name = new html_table_cell(get_string('pluginname', 'message_'.$processor->name));
00065 
00066             // Enable
00067             $enable = new html_table_cell();
00068             $enable->attributes['class'] = 'mdl-align';
00069             if (!$processor->available) {
00070                 $enable->text = html_writer::nonempty_tag('span', get_string('outputnotavailable', 'message'), array('class' => 'error'));
00071             } else if (!$processor->configured) {
00072                 $enable->text = html_writer::nonempty_tag('span', get_string('outputnotconfigured', 'message'), array('class' => 'error'));
00073             } else if ($processor->enabled) {
00074                 $url = new moodle_url('/admin/message.php', array('disable' => $processor->id, 'sesskey' => sesskey()));
00075                 $enable->text = html_writer::link($url, html_writer::empty_tag('img',
00076                     array('src'   => $this->output->pix_url('i/hide'),
00077                           'class' => 'icon',
00078                           'title' => get_string('outputenabled', 'message'),
00079                           'alt'   => get_string('outputenabled', 'message'),
00080                     )
00081                 ));
00082             } else {
00083                 $name->attributes['class'] = 'dimmed_text';
00084                 $url = new moodle_url('/admin/message.php', array('enable' => $processor->id, 'sesskey' => sesskey()));
00085                 $enable->text = html_writer::link($url, html_writer::empty_tag('img',
00086                     array('src'   => $this->output->pix_url('i/show'),
00087                           'class' => 'icon',
00088                           'title' => get_string('outputdisabled', 'message'),
00089                           'alt'   => get_string('outputdisabled', 'message'),
00090                     )
00091                 ));
00092             }
00093             // Settings
00094             $settings = new html_table_cell();
00095             if ($processor->available && $processor->hassettings) {
00096                 $settingsurl = new moodle_url('settings.php', array('section' => 'messagesetting'.$processor->name));
00097                 $settings->text = html_writer::link($settingsurl, get_string('settings', 'message'));
00098             }
00099 
00100             $row->cells = array($name, $enable, $settings);
00101             $table->data[] = $row;
00102         }
00103         return html_writer::table($table);
00104     }
00105 
00114     public function manage_defaultmessageoutputs($processors, $providers, $preferences) {
00115         global $CFG;
00116 
00117         // Prepare list of options for dropdown menu
00118         $options = array();
00119         foreach (array('disallowed', 'permitted', 'forced') as $setting) {
00120             $options[$setting] = get_string($setting, 'message');
00121         }
00122 
00123         $output = html_writer::start_tag('form', array('id'=>'defaultmessageoutputs', 'method'=>'post'));
00124         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
00125 
00126         // Display users outputs table
00127         $table = new html_table();
00128         $table->attributes['class'] = 'generaltable';
00129         $table->data        = array();
00130         $table->head        = array('');
00131 
00132         // Populate the header row
00133         foreach ($processors as $processor) {
00134             $table->head[]  = get_string('pluginname', 'message_'.$processor->name);
00135         }
00136         // Generate the matrix of settings for each provider and processor
00137         foreach ($providers as $provider) {
00138             $row = new html_table_row();
00139             $row->attributes['class'] = 'defaultmessageoutputs';
00140             $row->cells = array();
00141 
00142             // Provider Name
00143             $providername = get_string('messageprovider:'.$provider->name, $provider->component);
00144             $row->cells[] = new html_table_cell($providername);
00145 
00146             // Settings for each processor
00147             foreach ($processors as $processor) {
00148                 $cellcontent = '';
00149                 foreach (array('permitted', 'loggedin', 'loggedoff') as $setting) {
00150                     // pepare element and preference names
00151                     $elementname = $provider->component.'_'.$provider->name.'_'.$setting.'['.$processor->name.']';
00152                     $preferencebase = $provider->component.'_'.$provider->name.'_'.$setting;
00153                     // prepare language bits
00154                     $processorname = get_string('pluginname', 'message_'.$processor->name);
00155                     $statename = get_string($setting, 'message');
00156                     $labelparams = array(
00157                         'provider'  => $providername,
00158                         'processor' => $processorname,
00159                         'state'     => $statename
00160                     );
00161                     if ($setting == 'permitted') {
00162                         $label = get_string('sendingvia', 'message', $labelparams);
00163                         // determine the current setting or use default
00164                         $select = MESSAGE_DEFAULT_PERMITTED;
00165                         $preference = $processor->name.'_provider_'.$preferencebase;
00166                         if (array_key_exists($preference, $preferences)) {
00167                             $select = $preferences->{$preference};
00168                         }
00169                         // dropdown menu
00170                         $cellcontent = html_writer::label($label, $elementname, true, array('class' => 'accesshide'));
00171                         $cellcontent .= html_writer::select($options, $elementname, $select, false, array('id' => $elementname));
00172                         $cellcontent .= html_writer::tag('div', get_string('defaults', 'message'));
00173                     } else {
00174                         $label = get_string('sendingviawhen', 'message', $labelparams);
00175                         // determine the current setting based on the 'permitted' setting above
00176                         $checked = false;
00177                         if ($select == 'forced') {
00178                             $checked = true;
00179                         } else if ($select == 'permitted') {
00180                             $preference = 'message_provider_'.$preferencebase;
00181                             if (array_key_exists($preference, $preferences)) {
00182                                 $checked = (int)in_array($processor->name, explode(',', $preferences->{$preference}));
00183                             }
00184                         }
00185                         // generate content
00186                         $cellcontent .= html_writer::start_tag('div');
00187                         $cellcontent .= html_writer::label($label, $elementname, true, array('class' => 'accesshide'));
00188                         $cellcontent .= html_writer::checkbox($elementname, 1, $checked, '', array('id' => $elementname));
00189                         $cellcontent .= $statename;
00190                         $cellcontent .= html_writer::end_tag('div');
00191                     }
00192                 }
00193                 $row->cells[] = new html_table_cell($cellcontent);
00194             }
00195             $table->data[] = $row;
00196         }
00197 
00198         $output .= html_writer::table($table);
00199         $output .= html_writer::start_tag('div', array('class' => 'form-buttons'));
00200         $output .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('savechanges','admin'), 'class' => 'form-submit'));
00201         $output .= html_writer::end_tag('div');
00202         $output .= html_writer::end_tag('form');
00203         return $output;
00204     }
00205 
00217     public function manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences, $notificationsdisabled = false) {
00218         // Filter out enabled, available system_configured and user_configured processors only.
00219         $readyprocessors = array_filter($processors, create_function('$a', 'return $a->enabled && $a->configured && $a->object->is_user_configured();'));
00220 
00221         // Start the form.  We're not using mform here because of our special formatting needs ...
00222         $output = html_writer::start_tag('form', array('method'=>'post', 'class' => 'mform'));
00223         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
00224 
00226         $output .= html_writer::start_tag('fieldset', array('id' => 'providers', 'class' => 'clearfix'));
00227         $output .= html_writer::nonempty_tag('legend', get_string('providers_config', 'message'), array('class' => 'ftoggler'));
00228 
00229         // Display the messging options table
00230         $table = new html_table();
00231         $table->attributes['class'] = 'generaltable';
00232         $table->data        = array();
00233         $table->head        = array('');
00234 
00235         foreach ($readyprocessors as $processor) {
00236             $table->head[]  = get_string('pluginname', 'message_'.$processor->name);
00237         }
00238 
00239         $number_procs = count($processors);
00240         // Populate the table with rows
00241         foreach ( $providers as $provider) {
00242             $preferencebase = $provider->component.'_'.$provider->name;
00243 
00244             $headerrow = new html_table_row();
00245             $providername = get_string('messageprovider:'.$provider->name, $provider->component);
00246             $providercell = new html_table_cell($providername);
00247             $providercell->header = true;
00248             $providercell->colspan = $number_procs + 1;
00249             $providercell->attributes['class'] = 'c0';
00250             $headerrow->cells = array($providercell);
00251             $table->data[] = $headerrow;
00252 
00253             foreach (array('loggedin', 'loggedoff') as $state) {
00254                 $optionrow = new html_table_row();
00255                 $optionname = new html_table_cell(get_string($state.'description', 'message'));
00256                 $optionname->attributes['class'] = 'c0';
00257                 $optionrow->cells = array($optionname);
00258                 foreach ($readyprocessors as $processor) {
00259                     // determine the default setting
00260                     $permitted = MESSAGE_DEFAULT_PERMITTED;
00261                     $defaultpreference = $processor->name.'_provider_'.$preferencebase.'_permitted';
00262                     if (isset($defaultpreferences->{$defaultpreference})) {
00263                         $permitted = $defaultpreferences->{$defaultpreference};
00264                     }
00265                     // If settings are disallowed, just display the message that
00266                     // the setting is not permitted, if not use user settings or
00267                     // force them.
00268                     if ($permitted == 'disallowed') {
00269                         if ($state == 'loggedoff') {
00270                             // skip if we are rendering the second line
00271                             continue;
00272                         }
00273                         $cellcontent = html_writer::nonempty_tag('div', get_string('notpermitted', 'message'), array('class' => 'dimmed_text'));
00274                         $optioncell = new html_table_cell($cellcontent);
00275                         $optioncell->rowspan = 2;
00276                         $optioncell->attributes['class'] = 'disallowed';
00277                     } else {
00278                         // determine user preferences and use then unless we force
00279                         // the preferences.
00280                         $disabled = array();
00281                         if ($permitted == 'forced') {
00282                             $checked = true;
00283                             $disabled['disabled'] = 1;
00284                         } else {
00285                             $checked = false;
00286                             if ($notificationsdisabled) {
00287                                 $disabled['disabled'] = 1;
00288                             }
00289                             // See if user has touched this preference
00290                             if (isset($preferences->{$preferencebase.'_'.$state})) {
00291                                 // User have some preferneces for this state in the database, use them
00292                                 $checked = isset($preferences->{$preferencebase.'_'.$state}[$processor->name]);
00293                             } else {
00294                                 // User has not set this preference yet, using site default preferences set by admin
00295                                 $defaultpreference = 'message_provider_'.$preferencebase.'_'.$state;
00296                                 if (isset($defaultpreferences->{$defaultpreference})) {
00297                                     $checked = (int)in_array($processor->name, explode(',', $defaultpreferences->{$defaultpreference}));
00298                                 }
00299                             }
00300                         }
00301                         $elementname = $preferencebase.'_'.$state.'['.$processor->name.']';
00302                         // prepare language bits
00303                         $processorname = get_string('pluginname', 'message_'.$processor->name);
00304                         $statename = get_string($state, 'message');
00305                         $labelparams = array(
00306                             'provider'  => $providername,
00307                             'processor' => $processorname,
00308                             'state'     => $statename
00309                         );
00310                         $label = get_string('sendingviawhen', 'message', $labelparams);
00311                         $cellcontent = html_writer::label($label, $elementname, true, array('class' => 'accesshide'));
00312                         $cellcontent .= html_writer::checkbox($elementname, 1, $checked, '', array_merge(array('id' => $elementname, 'class' => 'notificationpreference'), $disabled));
00313                         $optioncell = new html_table_cell($cellcontent);
00314                         $optioncell->attributes['class'] = 'mdl-align';
00315                     }
00316                     $optionrow->cells[] = $optioncell;
00317                 }
00318                 $table->data[] = $optionrow;
00319             }
00320         }
00321         $output .= html_writer::start_tag('div');
00322         $output .= html_writer::table($table);
00323         $output .= html_writer::end_tag('div');
00324 
00325         $disableallcheckbox = $this->output->help_icon('disableall', 'message') . get_string('disableall', 'message') . html_writer::checkbox('disableall', 1, $notificationsdisabled, '', array('class'=>'disableallcheckbox'));
00326         $output .= html_writer::nonempty_tag('div', $disableallcheckbox, array('class'=>'disableall'));
00327 
00328         $output .= html_writer::end_tag('fieldset');
00329 
00330         foreach ($processors as $processor) {
00331             if (($processorconfigform = $processor->object->config_form($preferences)) && $processor->enabled) {
00332                 $output .= html_writer::start_tag('fieldset', array('id' => 'messageprocessor_'.$processor->name, 'class' => 'clearfix'));
00333                 $output .= html_writer::nonempty_tag('legend', get_string('pluginname', 'message_'.$processor->name), array('class' => 'ftoggler'));
00334                 $output .= html_writer::start_tag('div');
00335                 $output .= $processorconfigform;
00336                 $output .= html_writer::end_tag('div');
00337                 $output .= html_writer::end_tag('fieldset');
00338             }
00339         }
00340 
00341         $output .= html_writer::start_tag('fieldset', array('id' => 'messageprocessor_general', 'class' => 'clearfix'));
00342         $output .= html_writer::nonempty_tag('legend', get_string('generalsettings','admin'), array('class' => 'ftoggler'));
00343         $output .= html_writer::start_tag('div');
00344         $output .= get_string('blocknoncontacts', 'message').': ';
00345         $output .= html_writer::checkbox('blocknoncontacts', 1, $preferences->blocknoncontacts, '');
00346         $output .= html_writer::end_tag('div');
00347         $output .= html_writer::end_tag('fieldset');
00348         $output .= html_writer::start_tag('div', array('class' => 'mdl-align'));
00349         $output .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('updatemyprofile'), 'class' => 'form-submit'));
00350         $output .= html_writer::end_tag('div');
00351         $output .= html_writer::end_tag('form');
00352         return $output;
00353     }
00354 
00355 }
 All Data Structures Namespaces Files Functions Variables Enumerations