ILIAS  release_8 Revision v8.23
class.ilCalendarSubscriptionGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
7 
13 {
14  private int $cal_id = 0;
15  private int $ref_id = 0;
16 
17  protected ilObjUser $user;
19  protected ilLanguage $lng;
21  protected Factory $ui_factory;
23 
24  public function __construct(int $a_calendar_id, int $a_ref_id = 0)
25  {
26  global $DIC;
27 
28  $this->cal_id = $a_calendar_id;
29  $this->ref_id = $a_ref_id;
30  $this->user = $DIC->user();
31  $this->ctrl = $DIC->ctrl();
32  $this->lng = $DIC->language();
33  $this->tpl = $DIC->ui()->mainTemplate();
34  $this->ui_factory = $DIC->ui()->factory();
35  $this->ui_renderer = $DIC->ui()->renderer();
36  }
37 
38  public function executeCommand(): void
39  {
40  $next_class = $this->ctrl->getNextClass($this);
41  switch ($next_class) {
42  default:
43  $cmd = $this->ctrl->getCmd("show");
44  $this->$cmd();
45  break;
46  }
47  }
48 
52  protected function show(): void
53  {
54  $this->tpl->setOnScreenMessage('info', $this->lng->txt('cal_subscription_info'));
55 
56  $info = new ilInfoScreenGUI($this);
57  $info->setFormAction($GLOBALS['DIC']['ilCtrl']->getFormAction($this));
58 
59  if ($this->cal_id > 0) {
62  } elseif ($this->ref_id > 0) {
65  $id = $category->getCategoryID();
66  } else {
68  $id = 0;
69  }
70 
71  $hash = $this->createToken($this->user->getId(), $selection, $id);
72  $url = ILIAS_HTTP_PATH . '/calendar.php?client_id=' . CLIENT_ID . '&token=' . $hash;
73  $info->addSection($this->lng->txt("cal_subscription"));
74  $info->addProperty($this->lng->txt('cal_ical_url'), $url, $url);
75 
76  $this->tpl->setContent($info->getHTML());
77  }
78 
79  private function createToken($user_id, $selection, $id): string
80  {
81  $hash = ilCalendarAuthenticationToken::lookupAuthToken($user_id, $selection, $id);
82  if (strlen($hash)) {
83  return $hash;
84  }
85  $token = new ilCalendarAuthenticationToken($user_id);
86  $token->setSelectionType($selection);
87  $token->setCalendar($id);
88  return $token->add();
89  }
90 
91  protected function getModalForSubscription(): void
92  {
93  $tpl = new ilTemplate(
94  'tpl.subscription_dialog.html',
95  true,
96  true,
97  'Services/Calendar'
98  );
99 
100  $tpl->setVariable('TXT_SUBSCRIPTION_INFO', $this->lng->txt('cal_subscription_info'));
101 
102  if ($this->cal_id > 0) {
104  $id = $this->cal_id;
105  } elseif ($this->ref_id > 0) {
108  $id = $category->getCategoryID();
109  } else {
111  $id = 0;
112  }
113  $hash = $this->createToken($this->user->getId(), $selection, $id);
114  $url = ILIAS_HTTP_PATH . '/calendar.php?client_id=' . CLIENT_ID . '&token=' . $hash;
115 
116  $tpl->setVariable('LINK', $url . '&limited=0');
117  $tpl->setVariable('TXT_PERMA', $this->lng->txt('cal_ical_url'));
118 
119  $tpl->setVariable('LINK_LIMITED', $url . '&limited=1');
120  $tpl->setVariable('TXT_PERMA_LIMITED', $this->lng->txt('cal_ical_url_google'));
121 
122  $roundtrip = $this->ui_factory->modal()->roundtrip(
123  $this->lng->txt('cal_calendar_subscription_modal_title'),
124  $this->ui_factory->legacy($tpl->get())
125  );
126  echo $this->ui_renderer->render($roundtrip);
127  exit;
128  }
129 }
An entity that renders components to a string output.
Definition: Renderer.php:30
exit
Definition: login.php:28
Class ilInfoScreenGUI.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
static _getInstanceByObjId(int $a_obj_id)
get instance by obj_id
setVariable(string $variable, $value='')
Sets the given variable to the given value.
static lookupAuthToken(int $a_user_id, int $a_selection, int $a_calendar=0)
static _lookupObjId(int $ref_id)
Show calendar subscription info.
global $DIC
Definition: feed.php:28
$token
Definition: xapitoken.php:70
const CLIENT_ID
Definition: constants.php:41
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
createToken($user_id, $selection, $id)
__construct(int $a_calendar_id, int $a_ref_id=0)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Handles calendar authentication tokens for external calendar subscriptions.
$url