ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
PresentationLinkBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
29{
30 protected const string PAR_MONTH = "bmn";
31 protected const string PAR_POSTING = "blpg";
32 protected const string PAR_KEYWORD = "kwd";
33 protected const string PAR_AUTHOR = "ath";
34
35 protected const string VIEW_MAIN = "main";
36 protected const string VIEW_POSTING = "posting";
37
38
39 public function __construct(
40 protected \ilCtrl $ctrl
41 ) {
42 }
43
44 protected function getPathForView(string $view): array
45 {
46 return match ($view) {
47 self::VIEW_MAIN => [
48 \ilObjBlogGUI::class,
49 PresentationGUI::class
50 ],
51 self::VIEW_POSTING => [
52 \ilObjBlogGUI::class,
53 PresentationGUI::class,
54 \ilBlogPostingGUI::class
55 ],
56 };
57 }
58
59 protected function getCmdForView(string $view): string
60 {
61 return match ($view) {
62 self::VIEW_MAIN => "preview",
63 self::VIEW_POSTING => "previewFullscreen",
64 };
65 }
66
67 protected function setParameter(
68 string $view,
69 string $par,
70 string $value
71 ): void {
72 $path = $this->getPathForView($view);
73 $class = end($path);
74 $this->ctrl->setParameterByClass($class, $par, $value);
75 }
76
77 protected function getLinkForView(string $view): string
78 {
79 return $this->ctrl->getLinkTargetByClass(
80 $this->getPathForView($view),
81 $this->getCmdForView($view)
82 );
83 }
84
85 public function forMonth(string $month): string
86 {
87 $this->setParameter(self::VIEW_MAIN, self::PAR_MONTH, $month);
88 $this->setParameter(self::VIEW_MAIN, self::PAR_POSTING, "");
89 return $this->getLinkForView(self::VIEW_MAIN);
90 }
91
92 public function forPosting(int $posting_id, string $month = ""): string
93 {
94 $this->setParameter(self::VIEW_POSTING, self::PAR_MONTH, $month);
95 $this->setParameter(self::VIEW_POSTING, self::PAR_POSTING, (string) $posting_id);
96 return $this->getLinkForView(self::VIEW_POSTING);
97 }
98
99 public function forKeyword(string $keyword): string
100 {
101 $this->setParameter(self::VIEW_MAIN, self::PAR_KEYWORD, urlencode($keyword));
102 $this->setParameter(self::VIEW_MAIN, self::PAR_POSTING, "");
103 $link = $this->getLinkForView(self::VIEW_MAIN);
104 $this->setParameter(self::VIEW_MAIN, self::PAR_KEYWORD, "");
105 return $link;
106 }
107
108 public function forAuthor(int $user_id): string
109 {
110 $this->setParameter(self::VIEW_MAIN, self::PAR_AUTHOR, (string) $user_id);
111 $this->setParameter(self::VIEW_MAIN, self::PAR_POSTING, "");
112 $link = $this->getLinkForView(self::VIEW_MAIN);
113 $this->setParameter(self::VIEW_MAIN, self::PAR_AUTHOR, "");
114 return $link;
115 }
116
117 public function forMainList(): string
118 {
119 $this->setParameter(self::VIEW_MAIN, self::PAR_MONTH, "");
120 $this->setParameter(self::VIEW_MAIN, self::PAR_POSTING, "");
121 return $this->getLinkForView(self::VIEW_MAIN);
122 }
123}
@ilCtrl_Calls ILIAS\Blog\Presentation\PresentationGUI: ilBlogPostingGUI
Class ilCtrl provides processing control methods.