Skip to content

Commit

Permalink
Rework profile views,actions
Browse files Browse the repository at this point in the history
  • Loading branch information
zenn1989 committed Apr 11, 2018
1 parent 05584df commit 66e6786
Show file tree
Hide file tree
Showing 15 changed files with 575 additions and 71 deletions.
28 changes: 20 additions & 8 deletions Apps/Controller/Front/Profile.php
Expand Up @@ -22,9 +22,10 @@ class Profile extends FrontAppController
const EVENT_CHANGE_PASSWORD = 'profile.changepassword.success';
const NOTIFY_PER_PAGE = 25;
const FEED_PER_PAGE = 10;
const LOG_PER_PAGE = 5;

/**
* Fatty action like actionIndex(), actionShow() are located in standalone traits.
* Fat actions like actionIndex(), actionShow() are located in standalone traits.
* This feature allow provide better read&write accessibility
*/

Expand Down Expand Up @@ -72,7 +73,6 @@ class Profile extends FrontAppController
/**
* Show user messages (based on ajax, all in template)
* @return string
* @throws \Ffcms\Core\Exception\SyntaxException
* @throws ForbiddenException
*/
public function actionMessages()
Expand Down Expand Up @@ -117,7 +117,6 @@ public function actionSettings()
/**
* Show user logs
* @return string
* @throws \Ffcms\Core\Exception\SyntaxException
* @throws ForbiddenException
*/
public function actionLog()
Expand All @@ -129,13 +128,26 @@ public function actionLog()

// get log records
$records = UserLog::where('user_id', App::$User->identity()->getId());
if ($records->count() > 0) {
$records = $records->orderBy('id', 'DESC');
}

// build pagination info
$totalCount = $records->count();
$page = (int)$this->request->query->get('page', 0);
$offset = $page * static::LOG_PER_PAGE;

// apply pagination limits
$records = $records->skip($offset)
->take(static::LOG_PER_PAGE)
->orderBy('id', 'DESC')
->get();

// render output view
return $this->view->render('log', [
'records' => $records
return $this->view->render('profile/log', [
'records' => $records,
'pagination' => [
'step' => static::LOG_PER_PAGE,
'total' => $totalCount,
'page' => $page
]
]);
}

Expand Down
19 changes: 8 additions & 11 deletions Apps/Controller/Front/Profile/ActionIgnore.php
Expand Up @@ -7,7 +7,6 @@
use Ffcms\Core\App;
use Ffcms\Core\Arch\View;
use Ffcms\Core\Exception\ForbiddenException;
use Ffcms\Core\Helper\HTML\SimplePagination;
use Ffcms\Core\Network\Response;
use Ffcms\Core\Network\Request;

Expand Down Expand Up @@ -57,16 +56,10 @@ public function ignore(): ?string
// get blocked users
$query = Blacklist::where('user_id', '=', $user->getId());

// prepare pagination data
$page = (int)$this->request->query->get('page');
$offset = $page * static::BLOCK_PER_PAGE;

// build pagination
$pagination = new SimplePagination([
'url' => ['profile/ignore'],
'page' => $page,
'step' => static::BLOCK_PER_PAGE,
'total' => $query->count()
]);
$totalCount = $query->count();

// get records as object
$records = $query->with(['targetUser', 'targetUser.profile'])
Expand All @@ -75,10 +68,14 @@ public function ignore(): ?string
->get();

// render output view
return $this->view->render('ignore', [
return $this->view->render('profile/ignore', [
'records' => $records,
'model' => $model,
'pagination' => $pagination
'pagination' => [
'total' => $totalCount,
'page' => $page,
'step' => static::BLOCK_PER_PAGE
]
]);
}
}
18 changes: 8 additions & 10 deletions Apps/Controller/Front/Profile/ActionIndex.php
Expand Up @@ -24,7 +24,6 @@ trait ActionIndex
* @param null|string|int $value
* @return string
* @throws NotFoundException
* @throws \Ffcms\Core\Exception\SyntaxException
*/
public function index(string $name, ?string $value = null): ?string
{
Expand Down Expand Up @@ -72,13 +71,8 @@ public function index(string $name, ?string $value = null): ?string
break;
}

// build pagination
$pagination = new SimplePagination([
'url' => ['profile/index', $name, $value],
'page' => $page,
'step' => $userPerPage,
'total' => $records->count()
]);
// get total records count
$totalCount = $records->count();

// get profile list with relation for user and role tables in 1 query
$profiles = $records->with(['user', 'user.role'])
Expand All @@ -87,9 +81,13 @@ public function index(string $name, ?string $value = null): ?string
->get();

// render output view
return $this->view->render('index', [
return $this->view->render('profile/index', [
'records' => $profiles,
'pagination' => $pagination,
'pagination' => [
'page' => $page,
'total' => $totalCount,
'step' => $userPerPage
],
'id' => $name,
'add' => $value,
'ratingOn' => (int)$cfgs['rating']
Expand Down
24 changes: 8 additions & 16 deletions Apps/Controller/Front/Profile/ActionNotifications.php
@@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: zenn1
* Date: 09.01.2018
* Time: 21:05
*/

namespace Apps\Controller\Front\Profile;

Expand All @@ -13,7 +7,6 @@
use Ffcms\Core\App;
use Ffcms\Core\Arch\View;
use Ffcms\Core\Exception\ForbiddenException;
use Ffcms\Core\Helper\HTML\SimplePagination;
use Ffcms\Core\Network\Request;
use Ffcms\Core\Network\Response;

Expand All @@ -31,7 +24,6 @@ trait ActionNotifications
* @param string $type
* @return string
* @throws ForbiddenException
* @throws \Ffcms\Core\Exception\SyntaxException
*/
public function notifications(?string $type = 'all'): ?string
{
Expand All @@ -51,12 +43,8 @@ public function notifications(?string $type = 'all'): ?string
$query = $query->where('readed', '=', 0);
}

$pagination = new SimplePagination([
'url' => ['profile/notifications'],
'page' => $page,
'step' => static::NOTIFY_PER_PAGE,
'total' => $query->count()
]);
// get total row count for pagination
$totalCount = $query->count();

// get current records as object and build response
$records = $query->skip($offset)->take(static::NOTIFY_PER_PAGE);
Expand All @@ -67,9 +55,13 @@ public function notifications(?string $type = 'all'): ?string
// update reader records
$records->update(['readed' => 1]);

return $this->view->render('notifications', [
return $this->view->render('profile/notifications', [
'model' => $model,
'pagination' => $pagination
'pagination' => [
'page' => $page,
'step' => static::NOTIFY_PER_PAGE,
'total' => $totalCount
]
]);
}
}
15 changes: 6 additions & 9 deletions Apps/Controller/Front/Profile/ActionSearch.php
Expand Up @@ -3,11 +3,8 @@
namespace Apps\Controller\Front\Profile;

use Apps\Model\Front\Profile\FormUserSearch;
use Extend\Core\Arch\FrontAppController;
use Ffcms\Core\App;
use Ffcms\Core\Arch\View;
use Apps\ActiveRecord\Profile as ProfileRecords;
use Ffcms\Core\Helper\HTML\SimplePagination;
use Ffcms\Core\Network\Response;
use Ffcms\Core\Network\Request;

Expand All @@ -30,7 +27,7 @@ public function search(): ?string
{
// create model object
$model = new FormUserSearch();
$model->setSubmitMethod('GET');
$model->setSubmitMethod('get');

// get app configs
$cfgs = $this->getConfigs();
Expand All @@ -49,24 +46,24 @@ public function search(): ?string

$offset = $page * $userPerPage;
// build pagination
$pagination = new SimplePagination([
'url' => ['profile/search', null, null, [$model->getFormName().'[query]' => $model->query, $model->getFormName().'[submit]' => true]],
$pagination = [
'url' => ['profile/search', null, [$model->getFormName().'[query]' => $model->query, $model->getFormName().'[submit]' => true]],
'page' => $page,
'step' => $userPerPage,
'total' => $records->count()
]);
];
// make query finally
$records = $records->skip($offset)
->take($userPerPage)
->get();
}

// display response
return $this->view->render('search', [
return $this->view->render('profile/search', [
'model' => $model,
'records' => $records,
'pagination' => $pagination,
'ratingOn' => (int)$cfgs['rating']
'ratingOn' => (bool)$cfgs['rating']
]);
}
}
1 change: 0 additions & 1 deletion Apps/Controller/Front/Profile/ActionShow.php
Expand Up @@ -9,7 +9,6 @@
use Ffcms\Core\Arch\View;
use Ffcms\Core\Exception\ForbiddenException;
use Ffcms\Core\Exception\NotFoundException;
use Ffcms\Core\Helper\HTML\SimplePagination;
use Ffcms\Core\Network\Response;

/**
Expand Down
2 changes: 1 addition & 1 deletion Apps/Controller/Front/Profile/ActionUnblock.php
Expand Up @@ -54,7 +54,7 @@ public function unblock(string $targetId): ?string
$this->response->redirect('profile/ignore');
}

return $this->view->render('unblock', [
return $this->view->render('profile/unblock', [
'model' => $model
]);
}
Expand Down
2 changes: 1 addition & 1 deletion Apps/Controller/Front/Profile/ActionWallDelete.php
Expand Up @@ -59,7 +59,7 @@ public function wallDelete(string $postId): ?string
$this->response->redirect('profile/show/' . $wallPost->target_id);
}

return $this->view->render('wall_delete', [
return $this->view->render('profile/wall_delete', [
'post' => $wallPost,
'model' => $wallModel
]);
Expand Down
17 changes: 9 additions & 8 deletions Apps/Model/Front/Profile/EntityNotificationsList.php
Expand Up @@ -6,8 +6,9 @@
use Ffcms\Core\App;
use Ffcms\Core\Arch\Model;
use Ffcms\Core\Helper\Date;
use Ffcms\Core\Helper\Type\Str;
use Ffcms\Core\Helper\Url;
use Ffcms\Core\Helper\Type\Any;
use Ffcms\Templex\Url\Url;
use Illuminate\Support\Collection;

/**
* Class EntityNotificationsList. Build notification messages from active record object
Expand All @@ -17,12 +18,12 @@ class EntityNotificationsList extends Model
{
public $items;

/** @var UserNotification|null */
/** @var UserNotification[]|Collection */
private $_records;

/**
* EntityNotificationsList constructor. Pass records object inside.
* @param bool $records
* @param Collection|UserNotification[] $records
*/
public function __construct($records)
{
Expand All @@ -44,19 +45,19 @@ public function make()
foreach ($this->_records as $record) {
/** @var UserNotification $record */
$vars = null;
if (!Str::likeEmpty($record->vars)) {
if (!Any::isEmpty($record->vars)) {
$vars = $record->vars;
}
if (!$vars !== null && isset($vars['snippet'])) {
$vars['snippet'] = Url::standaloneLink($vars['snippet'], $record->uri, App::$Request->getLanguage());
if (isset($vars['snippet'])) {
$vars['snippet'] = Url::a([App::$Alias->baseUrl . $record->uri], $vars['snippet']);
}

$text = App::$Translate->get('Profile', $record->msg, $vars);

$this->items[] = [
'text' => $text,
'date' => Date::humanize($record->created_at),
'new' => (bool)$record->readed === false
'new' => !(bool)$record->readed
];
}
}
Expand Down
5 changes: 2 additions & 3 deletions Apps/View/Front/default/profile/ignore.php
Expand Up @@ -61,9 +61,8 @@
}
echo $table->display();
?>
<?= $this->bootstrap()->pagination(['profile/ignore'])
<?= $this->bootstrap()->pagination(['profile/ignore'], ['class' => 'pagination justify-content-center'])
->size($pagination['total'], $pagination['page'], $pagination['step'])
->display();
?>
->display(); ?>
</div>
<?php $this->stop() ?>
4 changes: 4 additions & 0 deletions Apps/View/Front/default/profile/index.php
Expand Up @@ -81,4 +81,8 @@
<hr/>
<?php endforeach; ?>

<?= $this->bootstrap()->pagination(['profile/index', [$id]], ['class' => 'pagination justify-content-center'])
->size($pagination['total'], $pagination['page'], $pagination['step'])
->display(); ?>

<?php $this->stop() ?>
12 changes: 9 additions & 3 deletions Apps/View/Front/default/profile/log.php
Expand Up @@ -3,7 +3,8 @@
use Ffcms\Templex\Url\Url;

/** @var \Ffcms\Templex\Template\Template $this */
/** @var Apps\ActiveRecord\UserLog $records */
/** @var Apps\ActiveRecord\UserLog[]|\Illuminate\Support\Collection $records */
/** @var array $pagination */

$this->layout('_layouts/default', [
'title' => __('Logs'),
Expand All @@ -22,7 +23,7 @@
<h2><?= __('My logs') ?></h2>
<hr />
<?php if(!$records || $records->count() < 1) {
echo $this->bootstrap()->alert('info', __('No logs is available'));
echo $this->bootstrap()->alert('info', __('No logs available'));
$this->stop();
return;
} ?>
Expand All @@ -35,7 +36,7 @@
['text' => __('Message')],
['text' => __('Date')]
]);
foreach ($records->get() as $log) {
foreach ($records as $log) {
$table->row([
['type' => 'text', 'text' => $log->id],
['type' => 'text', 'text' => $log->type],
Expand All @@ -47,4 +48,9 @@
?>
</div>

<?= $this->bootstrap()->pagination(['profile/log'], ['class' => 'pagination justify-content-center'])
->size($pagination['total'], $pagination['page'], $pagination['step'])
->display()
?>

<?php $this->stop() ?>

0 comments on commit 66e6786

Please sign in to comment.