ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
MonthBlockGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Blog\Navigation;
22
28
30{
31 public function __construct(
32 protected InternalDomainService $domain,
33 protected InternalGUIService $gui,
34 protected LinkBuilder $link_builder,
35 protected bool $is_repository
36 ) {
37 }
38
39 protected function isExport(): bool
40 {
41 return $this->link_builder instanceof ExportLinkBuilder;
42 }
43
47 public function render(
48 array $items,
49 bool $show_inactive = false,
50 int $blpg = 0
51 ): string {
52 $ctrl = $this->gui->ctrl();
53 $lng = $this->domain->lng();
54 if ($this->is_repository) {
55 $obj_id = \ilObject::_lookupObjId($this->gui->standardRequest()->getRefId());
56 } else {
57 $obj_id = $this->domain->getObjectIdForWspId($this->gui->standardRequest()->getWspId());
58 }
59 $settings = $this->domain->blogSettings()->getByObjId($obj_id);
60
61 if (!$show_inactive) {
62 $items = $this->domain->postingList($obj_id, false)->getPostingsGroupedByMonth();
63 }
64
65 // list month (incl. postings)
66 if ($settings->getNavMode() === \ilObjBlog::NAV_MODE_LIST ||
67 $this->isExport()) {
68 $max_months = $settings->getNavModeListMonths();
69
70 $wtpl = new \ilTemplate("tpl.blog_list_navigation_by_date.html", true, true, "components/ILIAS/Blog");
71
72 $ctrl->setParameterByClass(\ilObjBlogGUI::class, "blpg", "");
73
74 $counter = $mon_counter = $last_year = 0;
75 foreach ($items as $month => $postings) {
76 if (!$this->isExport() && $max_months && $mon_counter >= $max_months) {
77 break;
78 }
79
80 $add_year = false;
81 $year = substr((string) $month, 0, 4);
82 if (!$last_year || $year != $last_year) {
83 $add_year = true;
84 $last_year = $year;
85 }
86
87 $mon_counter++;
88
89 $month_name = \ilCalendarUtil::_numericMonthToString((int) substr((string) $month, 5));
90 $month_url = $this->link_builder->forMonth($month);
91
92 if ($mon_counter <= $settings->getNavModeListMonthsWithPostings()) {
93 if ($add_year) {
94 $wtpl->setCurrentBlock("navigation_year_details");
95 $wtpl->setVariable("YEAR", $year);
96 $wtpl->parseCurrentBlock();
97 }
98
99 foreach ($postings as $id => $posting) {
100 $caption = $posting->getTitle();
101 $url = $this->link_builder->forPosting($posting->getId());
102 if (!$posting->isActive()) {
103 $wtpl->setVariable("NAV_ITEM_DRAFT", $lng->txt("blog_draft"));
104 } elseif ($settings->getApproval() && !$posting->isApproved()) {
105 $wtpl->setVariable("NAV_ITEM_APPROVAL", $lng->txt("blog_needs_approval"));
106 }
107
108 $wtpl->setCurrentBlock("navigation_item");
109 $wtpl->setVariable("NAV_ITEM_URL", $url);
110 $wtpl->setVariable("NAV_ITEM_CAPTION", $caption);
111 $wtpl->parseCurrentBlock();
112 }
113
114 $wtpl->setCurrentBlock("navigation_month_details");
115 $wtpl->setVariable("NAV_MONTH", $month_name);
116 $wtpl->setVariable("URL_MONTH", $month_url);
117 $wtpl->parseCurrentBlock();
118 }
119 // summarized month
120 else {
121 if ($add_year) {
122 $wtpl->setCurrentBlock("navigation_year");
123 $wtpl->setVariable("YEAR", $year);
124 $wtpl->parseCurrentBlock();
125 }
126
127 $wtpl->setCurrentBlock("navigation_month");
128 $wtpl->setVariable("MONTH_NAME", $month_name);
129 $wtpl->setVariable("URL_MONTH", $month_url);
130 $wtpl->setVariable("MONTH_COUNT", (string) count($postings));
131 $wtpl->parseCurrentBlock();
132 }
133 }
134 $url = $this->link_builder->forMainList();
135
136 $wtpl->setVariable(
137 "STARTING_PAGE",
138 $this->gui->ui()->renderer()->render(
139 $this->gui->ui()->factory()->link()->standard(
140 $lng->txt("blog_starting_page"),
141 $url
142 )
143 )
144 );
145 $ctrl->setParameterByClass(\ilObjBlogGUI::class, "bmn", $this->gui->standardRequest()->getMonth());
146 $ctrl->setParameterByClass(\ilBlogPostingGUI::class, "bmn", "");
147 return $wtpl->get();
148 }
149 // single month
150 else {
151 $wtpl = new \ilTemplate("tpl.blog_list_navigation_month.html", true, true, "components/ILIAS/Blog");
152
153 $ctrl->setParameterByClass(\ilObjBlogGUI::class, "blpg", "");
154
155 $month_options = array();
156 foreach ($items as $month => $postings) {
157 $month_name = $this->gui->presentation()->util()->getMonthPresentation((string) $month);
158
159 $month_options[(string) $month] = $month_name;
160
161 if ($month == $this->gui->standardRequest()->getMonth()) {
162 $month_url = $this->link_builder->forMonth($month);
163
164 foreach ($postings as $id => $posting) {
165 $caption = $posting->getTitle();
166 $url = $this->link_builder->forPosting($id);
167
168 if (!$posting->isActive()) {
169 $wtpl->setVariable("NAV_ITEM_DRAFT", $lng->txt("blog_draft"));
170 } elseif ($settings->getApproval() && !$posting->isApproved()) {
171 $wtpl->setVariable("NAV_ITEM_APPROVAL", $lng->txt("blog_needs_approval"));
172 }
173
174 $wtpl->setCurrentBlock("navigation_item");
175 $wtpl->setVariable("NAV_ITEM_URL", $url);
176 $wtpl->setVariable("NAV_ITEM_CAPTION", $caption);
177 $wtpl->parseCurrentBlock();
178 }
179
180 $wtpl->setCurrentBlock("navigation_month_details");
181 if ($blpg > 0) {
182 $wtpl->setVariable("NAV_MONTH", $month_name);
183 $wtpl->setVariable("URL_MONTH", $month_url);
184 }
185 $wtpl->parseCurrentBlock();
186 }
187 }
188
189 /*
190 if ($blpg === 0) {
191 $wtpl->setCurrentBlock("option_bl");
192 foreach ($month_options as $value => $caption) {
193 $wtpl->setVariable("OPTION_VALUE", $value);
194 $wtpl->setVariable("OPTION_CAPTION", $caption);
195 if ($value == $this->gui->standardRequest()->getMonth()) {
196 $wtpl->setVariable("OPTION_SEL", ' selected="selected"');
197 }
198 $wtpl->parseCurrentBlock();
199 }
200
201 $wtpl->setVariable("FORM_ACTION", $ctrl->getFormActionByClass(\ilObjBlogGUI::class, $list_cmd));
202 }
203 */
204 }
205 $ctrl->setParameterByClass(\ilObjBlogGUI::class, "bmn", $this->gui->standardRequest()->getMonth());
206 $ctrl->setParameterByClass(\ilBlogPostingGUI::class, "bmn", "");
207 return $wtpl->get();
208 }
209}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$settings
Definition: index.php:44
__construct(protected InternalDomainService $domain, protected InternalGUIService $gui, protected LinkBuilder $link_builder, protected bool $is_repository)
render(array $items, bool $show_inactive=false, int $blpg=0)
static _numericMonthToString(int $a_month, bool $a_long=true, ?ilLanguage $lng=null)
numeric month to string
const NAV_MODE_LIST
static _lookupObjId(int $ref_id)
global $lng
Definition: privfeed.php:26