]> git.mjollnir.org Git - moodle.git/commitdiff
webservice MDL-20803 add "Print All" button
authorjerome mouneyrac <jerome@moodle.com>
Tue, 22 Dec 2009 03:52:28 +0000 (03:52 +0000)
committerjerome mouneyrac <jerome@moodle.com>
Tue, 22 Dec 2009 03:52:28 +0000 (03:52 +0000)
lang/en_utf8/webservice.php
webservice/renderer.php
webservice/wsdoc.php

index e1ba2b8521091d10c7d84d338cd1196bdf095690..0a111e2fd1a714053375c0380d2ba92b97a14d77 100644 (file)
@@ -35,6 +35,7 @@ $string['phpresponse'] = 'XML-RPC (PHP structure)';
 $string['postrestparam'] = 'PHP code for REST (POST request)';
 $string['potusers'] = 'Not authorised users';
 $string['potusersmatching'] = 'Not authorised users matching';
+$string['print'] = 'Print All';
 $string['protocol'] = 'Protocol';
 $string['removefunction'] = 'Remove';
 $string['removefunctionconfirm'] = 'Do you really want to remove function \"$a->function\" from service \"$a->service\"?';
index 07292e117af937c39973b1b75cbb935025bc8822..86ebb6b61af5f86c39035aa4082ada85f15f4ee7 100644 (file)
@@ -255,10 +255,13 @@ EOF;
      * This display all the documentation
      * @param array $functions contains all decription objects
      * @param string $username
+     * @param string $password
+     * @param boolean $printableformat true if we want to display the documentation in a printable format
+     * @param array $activatedprotocol
      * @return string the html to diplay
      */
-    public function documentation_html($functions, $username, $activatedprotocol) {
-
+    public function documentation_html($functions, $username, $password, $printableformat, $activatedprotocol) {
+        global $OUTPUT, $CFG;
         $brakeline = <<<EOF
 
 
@@ -270,11 +273,29 @@ EOF;
         $documentationhtml .= get_string('wsdocumentationintro', 'webservice', $username);
         $documentationhtml .= $this->output_empty_tag('br', array());
         $documentationhtml .= $this->output_empty_tag('br', array());
+        
+
+    /// Print button
+        $form = new html_form();
+        $parameters = array ('wsusername' => $username, 'wspassword' => $password, 'print' => true);
+        $form->url = new moodle_url($CFG->wwwroot.'/webservice/wsdoc.php', $parameters); // Required
+        $form->button = new html_button();
+        $form->button->text = get_string('print','webservice'); // Required
+        $form->button->disabled = false;
+        $form->button->title = get_string('print','webservice');
+        $form->method = 'post';
+        $documentationhtml .= $OUTPUT->button($form);
         $documentationhtml .= $this->output_empty_tag('br', array());
         
-    /// each functions will be display into a collapsible region
+        
+    /// each functions will be displayed into a collapsible region (opened if printableformat = true)
         foreach ($functions as $functionname => $description) {
-            $documentationhtml .= print_collapsible_region_start('', 'aera_'.$functionname, $this->output_start_tag('strong', array()).$functionname.$this->output_end_tag('strong'),false,true,true);
+            $documentationhtml .= print_collapsible_region_start('',
+                                                                 'aera_'.$functionname,
+                                                                 $this->output_start_tag('strong', array()).$functionname.$this->output_end_tag('strong'),
+                                                                 false,
+                                                                 !$printableformat,
+                                                                 true);
 
         /// function global description
             $documentationhtml .= $this->output_empty_tag('br', array());
@@ -302,14 +323,20 @@ EOF;
                 $documentationhtml .= $this->output_empty_tag('br', array());
                 $documentationhtml .= $this->output_empty_tag('br', array());
                 ///general structure of the argument
-                $documentationhtml .= $this->colored_box_with_pre_tag(get_string('generalstructure', 'webservice'), $this->detailed_description_html($paramdesc), 'FFF1BC');
+                $documentationhtml .= $this->colored_box_with_pre_tag(get_string('generalstructure', 'webservice'), 
+                                                                      $this->detailed_description_html($paramdesc),
+                                                                      'FFF1BC');
                 ///xml-rpc structure of the argument in PHP format
                 if (!empty($activatedprotocol['xmlrpc'])) {
-                    $documentationhtml .= $this->colored_box_with_pre_tag(get_string('phpparam', 'webservice'), htmlentities('['.$paramname.'] =>'.$this->xmlrpc_param_description_html($paramdesc)), 'DFEEE7');
+                    $documentationhtml .= $this->colored_box_with_pre_tag(get_string('phpparam', 'webservice'), 
+                                                                          htmlentities('['.$paramname.'] =>'.$this->xmlrpc_param_description_html($paramdesc)),
+                                                                          'DFEEE7');
                 }
                 ///POST format for the REST protocol for the argument
                 if (!empty($activatedprotocol['rest'])) {
-                    $documentationhtml .= $this->colored_box_with_pre_tag(get_string('restparam', 'webservice'), htmlentities($this->rest_param_description_html($paramdesc,$paramname)), 'FEEBE5');
+                    $documentationhtml .= $this->colored_box_with_pre_tag(get_string('restparam', 'webservice'), 
+                                                                          htmlentities($this->rest_param_description_html($paramdesc,$paramname)),
+                                                                          'FEEBE5');
                 }
                 $documentationhtml .= $this->output_end_tag('span');
             }
@@ -331,17 +358,23 @@ EOF;
             }
             if (!empty($description->returns_desc)) {
                 ///general structure of the response
-                $documentationhtml .= $this->colored_box_with_pre_tag(get_string('generalstructure', 'webservice'), $this->detailed_description_html($description->returns_desc), 'FFF1BC');
+                $documentationhtml .= $this->colored_box_with_pre_tag(get_string('generalstructure', 'webservice'), 
+                                                                      $this->detailed_description_html($description->returns_desc),
+                                                                      'FFF1BC');
                 ///xml-rpc structure of the response in PHP format
                 if (!empty($activatedprotocol['xmlrpc'])) {
-                     $documentationhtml .= $this->colored_box_with_pre_tag(get_string('phpresponse', 'webservice'), htmlentities($this->xmlrpc_param_description_html($description->returns_desc)), 'DFEEE7');
+                     $documentationhtml .= $this->colored_box_with_pre_tag(get_string('phpresponse', 'webservice'),
+                                                                           htmlentities($this->xmlrpc_param_description_html($description->returns_desc)),
+                                                                           'DFEEE7');
                 }
                 ///XML response for the REST protocol
                 if (!empty($activatedprotocol['rest'])) {
                     $restresponse  = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>".$brakeline."<RESPONSE>".$brakeline;
                     $restresponse .= $this->description_in_indented_xml_format($description->returns_desc);
                     $restresponse .="</RESPONSE>".$brakeline;
-                    $documentationhtml .= $this->colored_box_with_pre_tag(get_string('restcode', 'webservice'), htmlentities($restresponse), 'FEEBE5');
+                    $documentationhtml .= $this->colored_box_with_pre_tag(get_string('restcode', 'webservice'), 
+                                                                          htmlentities($restresponse),
+                                                                          'FEEBE5');
                 }
             }
             $documentationhtml .= $this->output_end_tag('span');
@@ -364,7 +397,9 @@ EOF;
     <DEBUGINFO></DEBUGINFO>
 </EXCEPTION>
 EOF;
-                $documentationhtml .= $this->colored_box_with_pre_tag(get_string('restexception', 'webservice'), htmlentities($restexceptiontext), 'FEEBE5');
+                $documentationhtml .= $this->colored_box_with_pre_tag(get_string('restexception', 'webservice'), 
+                                                                      htmlentities($restexceptiontext),
+                                                                      'FEEBE5');
 
             $documentationhtml .= $this->output_end_tag('span');
             }
@@ -378,6 +413,7 @@ EOF;
         $documentationhtml .= $this->output_end_tag('td');
         $documentationhtml .= $this->output_end_tag('tr');
         $documentationhtml .= $this->output_end_tag('table');
+
         return $documentationhtml;
 
     }
index e94053cca9a626900e6e3c46fc052b123e87f6bc..a01717c45343a427f6e719e318787b0bf1014cd8 100644 (file)
@@ -238,7 +238,17 @@ class webservice_documentation_generator {
         $activatedprotocol['rest'] = webservice_protocol_is_enabled('rest');
         $activatedprotocol['xmlrpc'] = webservice_protocol_is_enabled('xmlrpc');
         $renderer = $PAGE->get_renderer('core', 'webservice');
-        echo $renderer->documentation_html($this->functions, $this->username, $activatedprotocol);
+        /// Check if we are in printable mode
+        $printableformat = false;
+        if (isset($_REQUEST['print'])) {
+            $printableformat = $_REQUEST['print'];
+        }
+        echo $renderer->documentation_html($this->functions, $this->username, $this->password, $printableformat, $activatedprotocol);
+
+        /// trigger browser print operation
+        if (!empty($printableformat)) {
+            $PAGE->requires->js_function_call('window.print', array());
+        }
 
         echo $OUTPUT->footer();