1 | <?php |
||
2 | |||
3 | /** @var \Ffcms\Templex\Template\Template $this */ |
||
4 | /** @var \Apps\ActiveRecord\WallPost[]|\Illuminate\Support\Collection $records */ |
||
5 | /** @var array $pagination */ |
||
6 | |||
7 | use Ffcms\Core\Helper\Date; |
||
8 | use Ffcms\Templex\Url\Url; |
||
0 ignored issues
–
show
|
|||
9 | |||
10 | $this->layout('_layouts/default', [ |
||
11 | 'title' => __('Profile stream'), |
||
12 | 'breadcrumbs' => [ |
||
13 | Url::to('main/index') => __('Home'), |
||
14 | Url::to('profile/show', [\App::$User->identity()->getId()]) => __('Profile'), |
||
15 | __('Profile stream') |
||
16 | ] |
||
17 | ]); |
||
18 | |||
19 | ?> |
||
20 | <?php $this->start('body') ?> |
||
21 | |||
22 | <h1><?= __('Profile stream') ?></h1> |
||
23 | <hr /> |
||
24 | <?php if ($records->count() < 1): ?> |
||
25 | <p class="alert alert-warning"><?= __('No user wall post found yet') ?></p> |
||
26 | <?php endif; ?> |
||
27 | <?php foreach ($records as $post): ?> |
||
28 | <div class="row object-lightborder ml-1" id="wall-post-<?= $post->id ?>"> |
||
29 | <div class="col-xs-4 col-md-2"> |
||
30 | <div class="text-center"> |
||
31 | <?= Url::a(['profile/show', [$post->sender_id]], $post->senderUser->profile->getNickname(), ['style' => 'color: ' . $post->senderUser->role->color]) ?> |
||
32 | <img class="img-fluid img-rounded" alt="Avatar of <?= $post->senderUser->profile->getNickname() ?>" src="<?= $post->senderUser->profile->getAvatarUrl('small') ?>" /> |
||
33 | <div class="text-muted"><?= Date::humanize($post->updated_at); ?></div> |
||
34 | </div> |
||
35 | </div> |
||
36 | <div class="col-xs-8 col-md-10"> |
||
37 | <div class="object-text"> |
||
38 | <?= $post->message ?> |
||
39 | </div> |
||
40 | <hr style="margin: 5px;" /> |
||
41 | <div><i class="glyphicon glyphicon-comment"></i> |
||
42 | <a href="#wall-post-<?= $post->id ?>" id="wall-post-response-<?= $post->id ?>" class="show-wall-response"> |
||
43 | <?= __('Answers') ?> (<span id="wall-post-response-count-<?= $post->id ?>">0</span>) |
||
44 | </a> |
||
45 | </div> |
||
46 | <div id="wall-answer-dom-<?= $post->id; ?>" class="d-none"></div> |
||
47 | </div> |
||
48 | </div> |
||
49 | <?php endforeach; ?> |
||
50 | |||
51 | <?= $this->bootstrap()->pagination(['profile/feed'], ['class' => 'pagination justify-content-center']) |
||
52 | ->size($pagination['total'], $pagination['page'], $pagination['step']) |
||
53 | ->display() ?> |
||
54 | |||
55 | <!-- list answers and add answer dom elements --> |
||
56 | <div id="show-answer-list" class="d-none"> |
||
57 | <div class="row wall-answer"> |
||
58 | <div class="col-md-2 col-xs-4"><img id="wall-answer-avatar" src="<?= \App::$Alias->scriptUrl ?>/upload/user/avatar/small/default.jpg" alt="avatar" class="img-fluid img-rounded avatar" /></div> |
||
59 | <div class="col-md-10 col-xs-8"> |
||
60 | <div class="answer-header"> |
||
61 | <a href="<?= \App::$Alias->baseUrl ?>/profile/index" id="wall-answer-userlink">unknown</a> |
||
62 | <small class="float-right"><span id="wall-answer-date">01.01.1970</span> |
||
63 | <a href="javascript:void(0)" class="delete-answer d-none" id="delete-answer"><i class="glyphicon glyphicon-remove"></i></a> |
||
64 | </small> |
||
65 | </div> |
||
66 | <div id="wall-answer-text"></div> |
||
67 | </div> |
||
68 | </div> |
||
69 | </div> |
||
70 | <div id="add-answer-field" class="d-none"> |
||
71 | <hr style="margin: 5px;"/> |
||
72 | <input type="text" id="make-answer" placeHolder="<?= __('Write comment') ?>" class="form-control wall-answer-text" maxlength="200"/> |
||
73 | <a style="margin-top: 5px;" href="#wall-post" class="send-wall-answer btn btn-primary btn-sm" id="send-wall"> |
||
74 | <?= __('Send') ?> |
||
75 | </a> |
||
76 | <span class="float-right" id="answer-counter">200</span> |
||
77 | </div> |
||
78 | |||
79 | <script> |
||
80 | var hideAnswers = []; |
||
81 | $(document).ready(function () { |
||
82 | var elements = $('.object-lightborder'); |
||
83 | var viewer_id = 0; |
||
84 | var is_self_profile = false; |
||
85 | <?php if (\App::$User->isAuth()): ?> |
||
86 | viewer_id = <?= \App::$User->identity()->getId() ?>; |
||
87 | <?php endif; ?> |
||
88 | var postIds = []; |
||
89 | $.each(elements, function (key, val) { |
||
90 | postIds.push(val.id.replace('wall-post-', '')); |
||
91 | }); |
||
92 | // load answers count via JSON |
||
93 | if (postIds.length > 0) { |
||
94 | $.getJSON(script_url + '/api/profile/wallanswercount/' + postIds.join(',') + '?lang=' + script_lang, function (json) { |
||
95 | // data is successful loaded, lets parse it and set to exist dom elements as text value |
||
96 | if (json.status === 1) { |
||
97 | $.each(json.data, function (key, val) { |
||
98 | $('#wall-post-response-count-' + key).text(val); |
||
99 | }); |
||
100 | } |
||
101 | }); |
||
102 | } |
||
103 | // load answers via JSON and add to current DOM |
||
104 | loadAnswers = function (postId) { |
||
105 | $.getJSON(script_url + '/api/profile/showwallanswers/' + postId + '?lang=' + script_lang, function (json) { |
||
106 | if (json.status !== 1) { |
||
107 | return null; |
||
108 | } |
||
109 | var answerField = $('#add-answer-field').clone(); |
||
110 | var answerDom = $('#show-answer-list').clone(); |
||
111 | answerField.removeAttr('id').removeClass('d-none'); |
||
112 | answerDom.removeAttr('id').removeClass('d-none'); |
||
113 | // add hidden div with wall post object id |
||
114 | answerField.prepend($('<div></div>').attr('id', 'send-wall-object-' + postId)); |
||
115 | // set make answer wall post object id |
||
116 | answerField.find('#make-answer').attr('id', 'make-answer-' + postId); |
||
117 | // build send submit button - set id and href to wall post object anchor |
||
118 | answerField.find('#send-wall').attr('id', 'send-wall-' + postId).attr('href', '#wall-post-' + postId); |
||
119 | // build counter (max chars in input = 200) |
||
120 | answerField.find('#answer-counter').attr('id', 'answer-counter-' + postId); |
||
121 | var addAnswerField = ''; |
||
122 | if (viewer_id > 0) { |
||
123 | addAnswerField = answerField.html(); |
||
124 | } |
||
125 | var answers = ''; |
||
126 | $.each(json.data, function (idx, row) { |
||
127 | // clone general dom element |
||
128 | var dom = answerDom.clone(); |
||
129 | // set avatar src |
||
130 | dom.find('#wall-answer-avatar') |
||
131 | .attr('src', row.user_avatar) |
||
132 | .removeAttr('id'); |
||
133 | // set user link |
||
134 | dom.find('#wall-answer-userlink') |
||
135 | .attr('href', '<?= Url::to('profile/show') ?>/' + row.user_id).text(row.user_nick) |
||
136 | .attr('style', 'color: '+row.user_color) |
||
137 | .removeAttr('id'); |
||
138 | // set date |
||
139 | dom.find('#wall-answer-date').text(row.answer_date).removeAttr('id'); |
||
140 | // set message text |
||
141 | dom.find('#wall-answer-text').text(row.answer_message); |
||
142 | // check if this user can remove answers - answer writer or target user profile |
||
143 | if (is_self_profile || row.user_id === viewer_id) { |
||
144 | dom.find('#delete-answer') |
||
145 | .attr('href', '#send-wall-object-' + postId) |
||
146 | .attr('id', 'delete-answer-' + row.answer_id + '-' + postId) |
||
147 | .removeClass('d-none'); |
||
148 | } |
||
149 | answers += dom.html(); |
||
150 | }); |
||
151 | $('#wall-answer-dom-' + postId).html(addAnswerField + answers); |
||
152 | }) |
||
153 | }; |
||
154 | addAnswer = function (postId, message) { |
||
155 | $.post(script_url + '/api/profile/sendwallanswer/' + postId + '?lang=' + script_lang, {message: message}, function (response) { |
||
156 | if (response.status === 1) { |
||
157 | loadAnswers(postId); |
||
158 | } else { |
||
159 | $('#send-wall-object-' + postId).html('<p class="alert alert-warning"><?= __('Comment send was failed! Try to send it later.') ?></p>'); |
||
160 | } |
||
161 | }, 'json'); |
||
162 | }; |
||
163 | // if clicked on "Answers" - show it and send form |
||
164 | $('.show-wall-response').on('click', function () { |
||
165 | var postId = this.id.replace('wall-post-response-', ''); |
||
166 | // control hide-display on clicking to "Answers" link |
||
167 | if (hideAnswers[postId] === true) { |
||
168 | hideAnswers[postId] = false; |
||
169 | $('#wall-answer-dom-' + postId).addClass('d-none'); |
||
170 | return null; |
||
171 | } else { |
||
172 | hideAnswers[postId] = true; |
||
173 | $('#wall-answer-dom-' + postId).removeClass('d-none'); |
||
174 | } |
||
175 | // load data and set html |
||
176 | loadAnswers(postId); |
||
177 | }); |
||
178 | // calc entered symbols |
||
179 | $(document).on('keyup', '.wall-answer-text', function () { |
||
180 | var postId = this.id.replace('make-answer-', ''); |
||
181 | var msglimit = 200; |
||
182 | var msglength = $(this).val().length; |
||
183 | var limitObject = $('#answer-counter-' + postId); |
||
184 | if (msglength >= msglimit) { |
||
185 | limitObject.html('<span class="badge badge-danger">0</span>'); |
||
186 | } else { |
||
187 | limitObject.text(msglimit - msglength); |
||
188 | } |
||
189 | }); |
||
190 | // delegate live event simple for add-ed dom element |
||
191 | $(document).on('click', '.send-wall-answer', function () { |
||
192 | var answerToId = this.id.replace('send-wall-', ''); |
||
193 | var message = $('#make-answer-' + answerToId).val(); |
||
194 | if (message == null || message.length < 3) { |
||
195 | alert('<?= __('Message is too short') ?>'); |
||
196 | return null; |
||
197 | } |
||
198 | addAnswer(answerToId, message); |
||
199 | }); |
||
200 | }); |
||
201 | </script> |
||
202 | |||
203 | <?php $this->stop() ?> |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: