MDL-60158 calendar: Fix footer options when viewing as guest
authorAndrew Nicols <andrew@nicols.co.uk>
Mon, 18 Sep 2017 05:08:43 +0000 (13:08 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Mon, 25 Sep 2017 03:44:32 +0000 (11:44 +0800)
calendar/classes/external/footer_options_exporter.php
calendar/templates/footer_options.mustache

index 23bb42f..e4478bb 100644 (file)
@@ -82,9 +82,10 @@ class footer_options_exporter extends exporter {
      * @return string The iCal url.
      */
     protected function get_ical_url() {
-        return new moodle_url('/calendar/export_execute.php', ['preset_what' => 'all',
-                'preset_time' => 'recentupcoming', 'userid' => $this->userid, 'authtoken' => $this->token]);
-
+        if ($this->token) {
+            return new moodle_url('/calendar/export_execute.php', ['preset_what' => 'all',
+                    'preset_time' => 'recentupcoming', 'userid' => $this->userid, 'authtoken' => $this->token]);
+        }
     }
 
     /**
@@ -113,10 +114,12 @@ class footer_options_exporter extends exporter {
         $values = new stdClass();
 
         if (!empty($CFG->enablecalendarexport)) {
-            $exportbutton = $this->get_export_calendar_button();
-            $managesubscriptionbutton = $this->get_manage_subscriptions_button();
-            $values->exportcalendarbutton = $exportbutton->export_for_template($output);
-            $values->managesubscriptionbutton = $managesubscriptionbutton->export_for_template($output);
+            if ($exportbutton = $this->get_export_calendar_button()) {
+                $values->exportcalendarbutton = $exportbutton->export_for_template($output);
+            }
+            if ($managesubscriptionbutton = $this->get_manage_subscriptions_button()) {
+                $values->managesubscriptionbutton = $managesubscriptionbutton->export_for_template($output);
+            }
             $values->icalurl = $this->get_ical_url()->out(false);
         }
 
@@ -132,12 +135,15 @@ class footer_options_exporter extends exporter {
         return array(
             'exportcalendarbutton' => [
                 'type' => PARAM_RAW,
+                'default' => null,
             ],
             'managesubscriptionbutton' => [
                 'type' => PARAM_RAW,
+                'default' => null,
             ],
             'icalurl' => [
                 'type' => PARAM_URL,
+                'default' => null,
             ],
         );
     }
index 05c2941..d9769b2 100644 (file)
@@ -33,5 +33,7 @@
     {{#managesubscriptionbutton}}
         {{> core/single_button }}
     {{/managesubscriptionbutton}}
-    <a href="{{icalurl}}" title="{{#str}} quickdownloadcalendar, calendar {{/str}}" class="ical-link m-l-1">iCal</a>
+    {{#icalurl}}
+        <a href="{{icalurl}}" title="{{#str}} quickdownloadcalendar, calendar {{/str}}" class="ical-link m-l-1">iCal</a>
+    {{/icalurl}}
 </div>