28 changed files with 363 additions and 6 deletions
@ -0,0 +1,87 @@
|
||||
<?php |
||||
|
||||
namespace Miniflux\Controller; |
||||
|
||||
use Miniflux\Session\SessionStorage; |
||||
use Miniflux\Validator; |
||||
use Miniflux\Router; |
||||
use Miniflux\Response; |
||||
use Miniflux\Request; |
||||
use Miniflux\Template; |
||||
use Miniflux\Handler; |
||||
use Miniflux\Model; |
||||
|
||||
// Display all groups |
||||
Router\get_action('groups', function () { |
||||
$user_id = SessionStorage::getInstance()->getUserId(); |
||||
|
||||
Response\html(Template\layout('groups/list', array( |
||||
'groups' => Model\Group\get_all($user_id), |
||||
'menu' => 'feeds', |
||||
'title' => t('Groups'), |
||||
))); |
||||
}); |
||||
|
||||
// Confirmation dialog to remove a group |
||||
Router\get_action('confirm-remove-group', function () { |
||||
$user_id = SessionStorage::getInstance()->getUserId(); |
||||
$group_id = Request\int_param('group_id'); |
||||
|
||||
Response\html(Template\layout('groups/remove', array( |
||||
'group' => Model\Group\get_group($user_id, $group_id), |
||||
'menu' => 'feeds', |
||||
'title' => t('Confirmation') |
||||
))); |
||||
}); |
||||
|
||||
// Remove a group |
||||
Router\get_action('remove-group', function () { |
||||
$user_id = SessionStorage::getInstance()->getUserId(); |
||||
$group_id = Request\int_param('group_id'); |
||||
|
||||
if (Model\Group\remove_group($user_id, $group_id)) { |
||||
SessionStorage::getInstance()->setFlashMessage(t('This group has been removed successfully.')); |
||||
} else { |
||||
SessionStorage::getInstance()->setFlashErrorMessage(t('Unable to remove this group.')); |
||||
} |
||||
|
||||
Response\redirect('?action=groups'); |
||||
}); |
||||
|
||||
// Edit group form |
||||
Router\get_action('edit-group', function () { |
||||
$user_id = SessionStorage::getInstance()->getUserId(); |
||||
$group_id = Request\int_param('group_id'); |
||||
$values = Model\Group\get_group($user_id, $group_id); |
||||
|
||||
Response\html(Template\layout('groups/edit', array( |
||||
'values' => $values, |
||||
'errors' => array(), |
||||
'menu' => 'feeds', |
||||
'title' => t('Edit group') |
||||
))); |
||||
}); |
||||
|
||||
// Submit edit group form |
||||
Router\post_action('edit-group', function () { |
||||
$user_id = SessionStorage::getInstance()->getUserId(); |
||||
$values = Request\values(); |
||||
|
||||
list($valid, $errors) = Validator\Group\validate_modification($values); |
||||
|
||||
if ($valid) { |
||||
if (Model\Group\update_group($user_id, $values['id'], $values['title'])) { |
||||
SessionStorage::getInstance()->setFlashMessage(t('Group updated successfully.')); |
||||
Response\redirect('?action=groups'); |
||||
} else { |
||||
SessionStorage::getInstance()->setFlashErrorMessage(t('Unable to edit this group.')); |
||||
} |
||||
} |
||||
|
||||
Response\html(Template\layout('groups/edit', array( |
||||
'values' => $values, |
||||
'errors' => $errors, |
||||
'menu' => 'feeds', |
||||
'title' => t('Edit group') |
||||
))); |
||||
}); |
@ -0,0 +1,24 @@
|
||||
<div class="page-header"> |
||||
<h2><?php echo t('Edt group') ?></h2>
|
||||
<nav> |
||||
<ul> |
||||
<li><a href="?action=add"><?php echo t('add') ?></a></li>
|
||||
<li><a href="?action=feeds"><?php echo t('feeds') ?></a></li>
|
||||
<li class="active"><a href="?action=groups"><?php echo t('groups') ?></a></li>
|
||||
<li><a href="?action=import"><?php echo t('import') ?></a></li>
|
||||
<li><a href="?action=export"><?php echo t('export') ?></a></li>
|
||||
</ul> |
||||
</nav> |
||||
</div> |
||||
|
||||
<form method="post" action="?action=edit-group" autocomplete="off"> |
||||
<?php echo Miniflux\Helper\form_hidden('id', $values) ?> |
||||
|
||||
<?php echo Miniflux\Helper\form_label(t('Title'), 'title') ?> |
||||
<?php echo Miniflux\Helper\form_text('title', $values, $errors, array('required', 'autofocus')) ?> |
||||
|
||||
<div class="form-actions"> |
||||
<button type="submit" class="btn btn-blue"><?php echo t('Save') ?></button>
|
||||
<?php echo t('or') ?> <?php echo Miniflux\Helper\link(t('cancel'), 'groups') ?> |
||||
</div> |
||||
</form> |
@ -0,0 +1,32 @@
|
||||
<div class="page-header"> |
||||
<h2><?php echo t('Groups') ?></h2>
|
||||
<nav> |
||||
<ul> |
||||
<li><a href="?action=add"><?php echo t('add') ?></a></li>
|
||||
<li><a href="?action=feeds"><?php echo t('feeds') ?></a></li>
|
||||
<li class="active"><a href="?action=groups"><?php echo t('groups') ?></a></li>
|
||||
<li><a href="?action=import"><?php echo t('import') ?></a></li>
|
||||
<li><a href="?action=export"><?php echo t('export') ?></a></li>
|
||||
</ul> |
||||
</nav> |
||||
</div> |
||||
|
||||
<?php if (empty($groups)): ?> |
||||
<p class="alert alert-info"><?php echo t('There is no group.') ?></p>
|
||||
<?php else: ?> |
||||
<section class="items"> |
||||
<?php foreach ($groups as $group): ?> |
||||
<article> |
||||
<h2><?php echo Miniflux\Helper\escape($group['title']) ?></h2>
|
||||
<ul class="item-menu"> |
||||
<li> |
||||
<?php echo Miniflux\Helper\link(t('edit'), 'edit-group', array('group_id' => $group['id'])) ?> |
||||
</li> |
||||
<li> |
||||
<?php echo Miniflux\Helper\link(t('remove'), 'confirm-remove-group', array('group_id' => $group['id'])) ?> |
||||
</li> |
||||
</ul> |
||||
</article> |
||||
<?php endforeach ?> |
||||
</section> |
||||
<?php endif ?> |
@ -0,0 +1,10 @@
|
||||
<div class="page-header"> |
||||
<h2><?php echo t('Confirmation') ?></h2>
|
||||
</div> |
||||
|
||||
<p class="alert alert-info"><?php echo t('Do you really want to remove this group: "%s"?', Miniflux\Helper\escape($group['title'])) ?></p>
|
||||
|
||||
<div class="form-actions"> |
||||
<?php echo Miniflux\Helper\button('red', t('Remove'), 'remove-group', array('group_id' => $group['id'])) ?> |
||||
<?php echo t('or') ?> <?php echo Miniflux\Helper\link(t('cancel'), 'groups') ?> |
||||
</div> |
@ -0,0 +1,21 @@
|
||||
<?php |
||||
|
||||
namespace Miniflux\Validator\Group; |
||||
|
||||
use SimpleValidator\Validator; |
||||
use SimpleValidator\Validators; |
||||
|
||||
function validate_modification(array $values) |
||||
{ |
||||
$v = new Validator($values, array( |
||||
new Validators\Required('id', t('This field is required')), |
||||
new Validators\Integer('id', t('This value must be an integer')), |
||||
new Validators\Required('title', t('The title is required')), |
||||
new Validators\MaxLength('title', t('This text is too long (max. %d)', 255), 255), |
||||
)); |
||||
|
||||
return array( |
||||
$v->execute(), |
||||
$v->getErrors(), |
||||
); |
||||
} |
Loading…
Reference in new issue