Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/outputactions.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00030 defined('MOODLE_INTERNAL') || die();
00031 
00039 class component_action {
00040 
00045     public $event;
00046 
00053     public $jsfunction = false;
00054 
00058     public $jsfunctionargs = array();
00059 
00069     public function __construct($event, $jsfunction, $jsfunctionargs=array()) {
00070         $this->event = $event;
00071 
00072         $this->jsfunction = $jsfunction;
00073         $this->jsfunctionargs = $jsfunctionargs;
00074 
00075         if (!empty($this->jsfunctionargs)) {
00076             if (empty($this->jsfunction)) {
00077                 throw new coding_exception('The component_action object needs a jsfunction value to pass the jsfunctionargs to.');
00078             }
00079         }
00080     }
00081 }
00082 
00083 
00087 class confirm_action extends component_action {
00088     public function __construct($message, $callback = null, $continuelabel = null, $cancellabel = null) {
00089         parent::__construct('click', 'M.util.show_confirm_dialog', array(
00090                 'message' => $message, 'callback' => $callback,
00091                 'continuelabel' => $continuelabel, 'cancellabel' => $cancellabel));
00092     }
00093 }
00094 
00095 
00103 class popup_action extends component_action {
00104 
00105     public $jsfunction = 'openpopup';
00106 
00110     public $params = array(
00111             'height' =>  400,
00112             'width' => 500,
00113             'top' => 0,
00114             'left' => 0,
00115             'menubar' => false,
00116             'location' => false,
00117             'scrollbars' => true,
00118             'resizable' => true,
00119             'toolbar' => true,
00120             'status' => true,
00121             'directories' => false,
00122             'fullscreen' => false,
00123             'dependent' => true);
00124 
00133     public function __construct($event, $url, $name='popup', $params=array()) {
00134         global $CFG;
00135         $this->name = $name;
00136 
00137         $url = new moodle_url($url);
00138 
00139         if ($this->name) {
00140             $_name = $this->name;
00141             if (($_name = preg_replace("/\s/", '_', $_name)) != $this->name) {
00142                 throw new coding_exception('The $name of a popup window shouldn\'t contain spaces - string modified. '. $this->name .' changed to '. $_name);
00143                 $this->name = $_name;
00144             }
00145         } else {
00146             $this->name = 'popup';
00147         }
00148 
00149         foreach ($this->params as $var => $val) {
00150             if (array_key_exists($var, $params)) {
00151                 $this->params[$var] = $params[$var];
00152             }
00153         }
00154 
00155         $attributes = array('url' => $url->out(false), 'name' => $name, 'options' => $this->get_js_options($params));
00156         if (!empty($params['fullscreen'])) {
00157             $attributes['fullscreen'] = 1;
00158         }
00159         parent::__construct($event, $this->jsfunction, $attributes);
00160     }
00161 
00168     public function get_js_options() {
00169         $jsoptions = '';
00170 
00171         foreach ($this->params as $var => $val) {
00172             if (is_string($val) || is_int($val)) {
00173                 $jsoptions .= "$var=$val,";
00174             } elseif (is_bool($val)) {
00175                 $jsoptions .= ($val) ? "$var," : "$var=0,";
00176             }
00177         }
00178 
00179         $jsoptions = substr($jsoptions, 0, strlen($jsoptions) - 1);
00180 
00181         return $jsoptions;
00182     }
00183 }
 All Data Structures Namespaces Files Functions Variables Enumerations