Skip to content

Commit

Permalink
Add all widgets, add feedback app, styles, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
zenn1989 committed May 18, 2018
1 parent 95ee3fd commit dda09be
Show file tree
Hide file tree
Showing 31 changed files with 507 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Apps/Controller/Admin/Feedback/ActionRead.php
Expand Up @@ -42,7 +42,7 @@ public function read(string $id): ?string
// initialize model with answer add if thread is not closed
$model = null;
if ((int)$record->closed !== 1) {
$model = new FormAnswerAdd($record, App::$User->identity()->getId());
$model = new FormAnswerAdd($record);
if ($model->send()) {
if ($model->validate()) {
$model->make();
Expand Down
2 changes: 1 addition & 1 deletion Apps/Controller/Front/Content/ActionTag.php
Expand Up @@ -43,7 +43,7 @@ public function tag($name): ?string
->take(self::TAG_PER_PAGE);
// check if result is not empty
if ($records->count() < 1) {
throw new NotFoundException(__('Nothing founded'));
throw new NotFoundException(__('Nothing found'));
}

// define tag list event
Expand Down
51 changes: 26 additions & 25 deletions Apps/Controller/Front/Feedback.php
Expand Up @@ -9,7 +9,6 @@
use Ffcms\Core\App;
use Ffcms\Core\Exception\ForbiddenException;
use Ffcms\Core\Exception\NotFoundException;
use Ffcms\Core\Helper\HTML\SimplePagination;
use Ffcms\Core\Helper\Type\Any;
use Ffcms\Core\Helper\Type\Str;

Expand Down Expand Up @@ -45,7 +44,7 @@ public function actionCreate(): ?string
}

// initialize model
$model = new FormFeedbackAdd((int)$configs['useCaptcha'] === 1);
$model = new FormFeedbackAdd((bool)$configs['useCaptcha']);
if ($model->send()) {
if ($model->validate()) {
// if validation is passed save data to db and get row
Expand All @@ -58,9 +57,9 @@ public function actionCreate(): ?string
}

// render output view
return $this->view->render('create', [
return $this->view->render('feedback/create', [
'model' => $model,
'useCaptcha' => (int)$configs['useCaptcha'] === 1
'useCaptcha' => (bool)$configs['useCaptcha']
]);
}

Expand All @@ -80,6 +79,7 @@ public function actionRead(string $id, string $hash): ?string
}

// get feedback post record from database
/** @var FeedbackPost $recordPost */
$recordPost = FeedbackPost::where('id', $id)
->where('hash', $hash)
->first();
Expand All @@ -88,12 +88,11 @@ public function actionRead(string $id, string $hash): ?string
throw new ForbiddenException(__('The feedback request is not founded'));
}

$userId = App::$User->isAuth() ? App::$User->identity()->getId() : 0;
$model = null;
// check if feedback post is not closed for answers
if (!(bool)$recordPost->closed) {
// init new answer add model
$model = new FormAnswerAdd($recordPost, $userId);
$model = new FormAnswerAdd($recordPost);
// if answer is sender lets try to make it model
if ($model->send() && $model->validate()) {
$model->make();
Expand All @@ -103,10 +102,10 @@ public function actionRead(string $id, string $hash): ?string
}

// render output view
return $this->view->render('read', [
return $this->view->render('feedback/read', [
'model' => $model,
'post' => $recordPost,
'answers' => $recordPost->getAnswers()->get() // get feedback answers
'answers' => $recordPost->answers()->get() // get feedback answers
]);
}

Expand All @@ -116,11 +115,11 @@ public function actionRead(string $id, string $hash): ?string
* @param string $hash
* @return string
* @throws ForbiddenException
* @throws \Ffcms\Core\Exception\SyntaxException
*/
public function actionClose(string $id, string $hash): ?string
{
// get feedback post record from database
/** @var FeedbackPost $record */
$record = FeedbackPost::where('id', '=', $id)
->where('hash', '=', $hash)
->where('closed', '=', 0)
Expand All @@ -134,31 +133,33 @@ public function actionClose(string $id, string $hash): ?string
// check if action is submited
if ($this->request->request->get('closeRequest', false)) {
// if created by authorized user
if ((int)$record->user_id !== 0) {
if ((int)$record->user_id > 0) {
$user = App::$User->identity();
// button is pressed not by request creator
if ($user === null || $user->getId() !== (int)$record->user_id) {
if (!$user || $user->getId() !== (int)$record->user_id) {
throw new ForbiddenException(__('This feedback request was created by another user'));
}
}

// switch closed to 1 and make sql query
$record->closed = 1;
$record->closed = true;
$record->save();

// add notification and redirect
App::$Session->getFlashBag()->add('warning', __('Feedback request now is closed!'));
$this->response->redirect('feedback/read/' . $id . '/' . $hash);
}

return $this->view->render('close');
return $this->view->render('feedback/close', [
'id' => (int)$id,
'hash' => $hash
]);
}

/**
* List feedback requests messages from authorized user
* @return string
* @throws ForbiddenException
* @throws \Ffcms\Core\Exception\SyntaxException
*/
public function actionList(): ?string
{
Expand All @@ -176,22 +177,22 @@ public function actionList(): ?string

// initialize query with major condition
$query = FeedbackPost::where('user_id', '=', $user->getId());

// build pagination
$pagination = new SimplePagination([
'url' => ['feedback/list'],
'page' => $page,
'step' => self::ITEM_PER_PAGE,
'total' => $query->count()
]);
$totalCount = $query->count();

// build records object from prepared query using page offset
$records = $query->orderBy('id', 'desc')->skip($offset)->take(self::ITEM_PER_PAGE)->get();
$records = $query->orderBy('id', 'desc')
->skip($offset)
->take(self::ITEM_PER_PAGE)
->get();

// render viewer with parameters
return $this->view->render('list', [
return $this->view->render('feedback/list', [
'records' => $records,
'pagination' => $pagination,
'pagination' => [
'step' => self::ITEM_PER_PAGE,
'total' => $totalCount,
'page' => $page
]
]);
}
}
2 changes: 1 addition & 1 deletion Apps/Controller/Front/Search.php
Expand Up @@ -54,7 +54,7 @@ public function actionIndex()
]);

// render output view with search result
return $this->view->render('index', [
return $this->view->render('search/index', [
'model' => $model,
'query' => $query
]);
Expand Down
7 changes: 4 additions & 3 deletions Apps/Model/Front/Feedback/FormAnswerAdd.php
Expand Up @@ -26,12 +26,13 @@ class FormAnswerAdd extends Model
/**
* FormAnswerAdd constructor. Pass active record of comment post and user id
* @param $recordPost
* @param int $userId
*/
public function __construct($recordPost, $userId = 0)
public function __construct($recordPost)
{
$this->_post = $recordPost;
$this->_userId = (int)$userId;
if (App::$User->isAuth()) {
$this->_userId = App::$User->identity()->getId();
}
parent::__construct();
}

Expand Down
2 changes: 1 addition & 1 deletion Apps/Model/Front/Feedback/FormFeedbackAdd.php
Expand Up @@ -102,7 +102,7 @@ public function make()
$record->save();

// send notification to email
App::$Mailer->tpl('feedback/mail/created', [
App::$Mailer->tpl('feedback/_mail/created', [
'record' => $record
])->send($record->email, App::$Translate->get('Feedback', 'Request #%id% is created', ['id' => $record->id]));

Expand Down
3 changes: 1 addition & 2 deletions Apps/Model/Front/Search/EntitySearchMain.php
Expand Up @@ -3,9 +3,8 @@
namespace Apps\Model\Front\Search;

use Ffcms\Core\Arch\Model;
use Ffcms\Core\Helper\HTML\System\Dom;
use Ffcms\Templex\Helper\Html\Dom;
use Ffcms\Core\Helper\Type\Any;
use Ffcms\Core\Helper\Type\Obj;
use Ffcms\Core\Helper\Type\Str;

/**
Expand Down
26 changes: 21 additions & 5 deletions Apps/View/Front/default/_layouts/default.php
Expand Up @@ -2,6 +2,8 @@

/** @var Ffcms\Templex\Template\Template $this */

use Ffcms\Templex\Url\Url;

?>
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -65,8 +67,8 @@
<small class="text-secondary">Some website description text</small>
</div>
<div class="col">
<form class="form-inline">
<input type="text" class="form-control col-md-9 mr-md-2" id="searchInput" placeholder="query...">
<form class="form-inline" action="<?= Url::to('search/index') ?>" method="GET">
<input type="text" name="query" class="form-control col-md-9 mr-md-1" id="searchInput" value="<?= isset($query) ? $query : null ?>">
<button type="submit" class="btn btn-primary col-md">Submit</button>
</form>
</div>
Expand Down Expand Up @@ -119,14 +121,28 @@
<div class="col-md">
<?php if (\Widgets\Front\Newcontent\Newcontent::enabled()): ?>
<div class="card">
<div class="card-header">
<?= __('New content') ?>
</div>
<div class="card-header"><?= __('New content') ?></div>
<div class="card-body">
<?= \Widgets\Front\Newcontent\Newcontent::widget() ?>
</div>
</div>
<?php endif; ?>
<?php if (\Widgets\Front\Contenttag\Contenttag::enabled()): ?>
<div class="card mt-1">
<div class="card-header"><?= __('Content tags') ?></div>
<div class="card-body">
<?= \Widgets\Front\Contenttag\Contenttag::widget() ?>
</div>
</div>
<?php endif; ?>
<?php if (Widgets\Front\Newcomment\Newcomment::enabled()): ?>
<div class="card mt-1">
<div class="card-header"><?= __('New comments') ?></div>
<div class="card-body">
<?= \Widgets\Front\Newcomment\Newcomment::widget() ?>
</div>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
Expand Down
15 changes: 15 additions & 0 deletions Apps/View/Front/default/assets/css/style.css
Expand Up @@ -253,4 +253,19 @@ footer p {

footer p > a {
color: #000;
}

/** Search results */
.search-result {
border-left: 1px #00ad9c solid;
padding-left: 5px;
}

.search-highlight {
background-color: #ffe1a5;
}

/** lastcomment styles */
.short-comment {
border-bottom: 1px solid #e6e6e6;
}
4 changes: 2 additions & 2 deletions Apps/View/Front/default/content/list.php
Expand Up @@ -47,7 +47,7 @@
<?php if (!Str::likeEmpty($model->category['rss'])): ?>
<small><a href="<?= $model->category['rss'] ?>" target="_blank"><i class="fa fa-rss"></i></a></small>
<?php endif; ?>
<div class="pull-right">
<div class="float-right">
<div class="btn-group">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-sort-amount-desc"></i> <?= __('Sorting')?> <span class="caret"></span>
Expand Down Expand Up @@ -137,7 +137,7 @@
<span class="spaced"><i class="fa fa-comment-o"></i>
<a href="<?= \App::$Alias->baseUrl . $item['uri'] ?>#comments-list"><?= __('Comments') ?>: <span itemprop="commentCount" id="comment-count-<?= $item['id'] ?>">0</span></a>
</span>
<span class="pull-right">
<span class="float-right">
<?php if ((int)$catConfigs['showTags'] === 1 && $item['tags'] !== null && Any::isArray($item['tags'])): ?>
<span class="spaced"><i class="fa fa-tags"></i>
<?php
Expand Down
8 changes: 4 additions & 4 deletions Apps/View/Front/default/content/read.php
Expand Up @@ -113,7 +113,7 @@
<h4 class="modal-title" id="myModalLabel"><?= __('View poster') ?></h4>
</div>
<div class="modal-body">
<img class="img-responsive" src="<?= \App::$Alias->scriptUrl . $model->posterFull ?>" alt="<?= __('Poster image') ?>" style="margin: 0 auto;" />
<img class="img-fluid" src="<?= \App::$Alias->scriptUrl . $model->posterFull ?>" alt="<?= __('Poster image') ?>" style="margin: 0 auto;" />
</div>
</div>
</div>
Expand All @@ -127,7 +127,7 @@
<?php foreach ($model->galleryItems as $thumbPic => $fullPic): ?>
<div class="col-md-2 well">
<a href="#showGallery" class="modalGallery" content="<?= \App::$Alias->scriptUrl . $fullPic ?>" id="gallery-<?= $i ?>">
<img src="<?= \App::$Alias->scriptUrl . $thumbPic ?>" class="img-responsive image-item" />
<img src="<?= \App::$Alias->scriptUrl . $thumbPic ?>" class="img-fluid image-item" />
</a>
</div>
<?php $i++ ?>
Expand All @@ -141,7 +141,7 @@
<h4 class="modal-title" id="showModalLabel"><?= __('View picture') ?></h4>
</div>
<div class="modal-body" id="modal-gallery-body">
<img class="img-responsive" src="<?= \App::$Alias->scriptUrl . $model->posterFull ?>" alt="<?= __('Gallery picture') ?>" style="margin: 0 auto;" />
<img class="img-fluid" src="<?= \App::$Alias->scriptUrl . $model->posterFull ?>" alt="<?= __('Gallery picture') ?>" style="margin: 0 auto;" />
</div>
</div>
</div>
Expand Down Expand Up @@ -232,7 +232,7 @@
var picture = $(this).attr('content');
if (picture != null && picture.length > 0) {
var gallerySelector = $('#modal-gallery-body');
gallerySelector.html('<img class="img-responsive gallery-img" alt="Picture" style="margin: 0 auto;" src="' + picture + '"/>');
gallerySelector.html('<img class="img-fluid gallery-img" alt="Picture" style="margin: 0 auto;" src="' + picture + '"/>');
gallerySelector.append('<hr />');
// add previous & next buttons
var gSelectors = '<p class="text-center">';
Expand Down
8 changes: 8 additions & 0 deletions Apps/View/Front/default/feedback/_authTabs.php
@@ -0,0 +1,8 @@
<?php

/** @var \Ffcms\Templex\Template\Template $this */

echo $this->bootstrap()->nav('ul', ['class' => 'nav-tabs'])
->menu(['text' => __('New request'), 'link' => ['feedback/create']])
->menu(['text' => __('My requests'), 'link' => ['feedback/list']])
->display();

0 comments on commit dda09be

Please sign in to comment.