diff --git a/app/controllers/groups.php b/app/controllers/groups.php new file mode 100644 index 0000000..6dc72a3 --- /dev/null +++ b/app/controllers/groups.php @@ -0,0 +1,87 @@ +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') + ))); +}); diff --git a/app/helpers/template.php b/app/helpers/template.php index 6d6b5c8..6ec6d8e 100644 --- a/app/helpers/template.php +++ b/app/helpers/template.php @@ -126,3 +126,9 @@ function link($label, $action, array $params = array()) $params['action'] = $action; return sprintf('%s', http_build_query($params, '', '&'), escape($label)); } + +function button($type, $label, $action, array $params = array()) +{ + $params['action'] = $action; + return sprintf('%s', http_build_query($params, '', '&'), $type, escape($label)); +} diff --git a/app/locales/ar_AR/translations.php b/app/locales/ar_AR/translations.php index f0f2fca..df710e3 100644 --- a/app/locales/ar_AR/translations.php +++ b/app/locales/ar_AR/translations.php @@ -255,4 +255,15 @@ return array( // 'New Password' => '', // 'Wrong password' => '', // 'Duplicated feed' => '', + // 'This group has been removed successfully.' => '', + // 'Unable to remove this group.' => '', + // 'Edit group' => '', + // 'Group updated successfully.' => '', + // 'Unable to edit this group.' => '', + // 'groups' => '', + // 'There is no group.' => '', + // 'Do you really want to remove this group: "%s"?' => '', + // 'This field is required' => '', + // 'This value must be an integer' => '', + // 'This text is too long (max. %d)' => '', ); diff --git a/app/locales/cs_CZ/translations.php b/app/locales/cs_CZ/translations.php index 76e46b0..e050797 100644 --- a/app/locales/cs_CZ/translations.php +++ b/app/locales/cs_CZ/translations.php @@ -255,4 +255,15 @@ return array( 'New Password' => 'Nové heslo', 'Wrong password' => 'Špatné heslo', // 'Duplicated feed' => '', + // 'This group has been removed successfully.' => '', + // 'Unable to remove this group.' => '', + // 'Edit group' => '', + // 'Group updated successfully.' => '', + // 'Unable to edit this group.' => '', + // 'groups' => '', + // 'There is no group.' => '', + // 'Do you really want to remove this group: "%s"?' => '', + // 'This field is required' => '', + // 'This value must be an integer' => '', + // 'This text is too long (max. %d)' => '', ); diff --git a/app/locales/de_DE/translations.php b/app/locales/de_DE/translations.php index dc1a266..7cb19aa 100644 --- a/app/locales/de_DE/translations.php +++ b/app/locales/de_DE/translations.php @@ -255,4 +255,15 @@ return array( // 'New Password' => '', // 'Wrong password' => '', // 'Duplicated feed' => '', + // 'This group has been removed successfully.' => '', + // 'Unable to remove this group.' => '', + // 'Edit group' => '', + // 'Group updated successfully.' => '', + // 'Unable to edit this group.' => '', + // 'groups' => '', + // 'There is no group.' => '', + // 'Do you really want to remove this group: "%s"?' => '', + // 'This field is required' => '', + // 'This value must be an integer' => '', + // 'This text is too long (max. %d)' => '', ); diff --git a/app/locales/es_ES/translations.php b/app/locales/es_ES/translations.php index c09629f..dd98eff 100644 --- a/app/locales/es_ES/translations.php +++ b/app/locales/es_ES/translations.php @@ -255,4 +255,15 @@ return array( // 'New Password' => '', // 'Wrong password' => '', // 'Duplicated feed' => '', + // 'This group has been removed successfully.' => '', + // 'Unable to remove this group.' => '', + // 'Edit group' => '', + // 'Group updated successfully.' => '', + // 'Unable to edit this group.' => '', + // 'groups' => '', + // 'There is no group.' => '', + // 'Do you really want to remove this group: "%s"?' => '', + // 'This field is required' => '', + // 'This value must be an integer' => '', + // 'This text is too long (max. %d)' => '', ); diff --git a/app/locales/fr_FR/translations.php b/app/locales/fr_FR/translations.php index a3ac831..808ed76 100644 --- a/app/locales/fr_FR/translations.php +++ b/app/locales/fr_FR/translations.php @@ -255,4 +255,15 @@ return array( 'New Password' => 'Nouveau mot de passe', 'Wrong password' => 'Mauvais mot de passe', 'Duplicated feed' => 'Abonnement dupliqué', + 'This group has been removed successfully.' => 'Ce libellé a été supprimé avec succès.', + 'Unable to remove this group.' => 'Impossible de supprimer ce libellé.', + 'Edit group' => 'Modifier un libellé', + 'Group updated successfully.' => 'Libellé modifié avec succès.', + 'Unable to edit this group.' => 'Impossible de modifier ce libellé.', + 'groups' => 'libellés', + 'There is no group.' => 'Il n\'y a aucun libellé.', + 'Do you really want to remove this group: "%s"?' => 'Voulez-vous vraiment supprimer ce libellé : « %s » ?', + 'This field is required' => 'Ce champ est requis', + 'This value must be an integer' => 'Cette valeur doit être un entier', + 'This text is too long (max. %d)' => 'Ce texte est trop long (max. %d)', ); diff --git a/app/locales/it_IT/translations.php b/app/locales/it_IT/translations.php index 6119e49..c57e82f 100644 --- a/app/locales/it_IT/translations.php +++ b/app/locales/it_IT/translations.php @@ -255,4 +255,15 @@ return array( // 'New Password' => '', // 'Wrong password' => '', // 'Duplicated feed' => '', + // 'This group has been removed successfully.' => '', + // 'Unable to remove this group.' => '', + // 'Edit group' => '', + // 'Group updated successfully.' => '', + // 'Unable to edit this group.' => '', + // 'groups' => '', + // 'There is no group.' => '', + // 'Do you really want to remove this group: "%s"?' => '', + // 'This field is required' => '', + // 'This value must be an integer' => '', + // 'This text is too long (max. %d)' => '', ); diff --git a/app/locales/ja_JP/translations.php b/app/locales/ja_JP/translations.php index 5614b14..98a8098 100644 --- a/app/locales/ja_JP/translations.php +++ b/app/locales/ja_JP/translations.php @@ -257,4 +257,15 @@ return array( // 'New Password' => '', // 'Wrong password' => '', // 'Duplicated feed' => '', + // 'This group has been removed successfully.' => '', + // 'Unable to remove this group.' => '', + // 'Edit group' => '', + // 'Group updated successfully.' => '', + // 'Unable to edit this group.' => '', + // 'groups' => '', + // 'There is no group.' => '', + // 'Do you really want to remove this group: "%s"?' => '', + // 'This field is required' => '', + // 'This value must be an integer' => '', + // 'This text is too long (max. %d)' => '', ); diff --git a/app/locales/pt_BR/translations.php b/app/locales/pt_BR/translations.php index c431e51..4c587c8 100644 --- a/app/locales/pt_BR/translations.php +++ b/app/locales/pt_BR/translations.php @@ -255,4 +255,15 @@ return array( // 'New Password' => '', // 'Wrong password' => '', // 'Duplicated feed' => '', + // 'This group has been removed successfully.' => '', + // 'Unable to remove this group.' => '', + // 'Edit group' => '', + // 'Group updated successfully.' => '', + // 'Unable to edit this group.' => '', + // 'groups' => '', + // 'There is no group.' => '', + // 'Do you really want to remove this group: "%s"?' => '', + // 'This field is required' => '', + // 'This value must be an integer' => '', + // 'This text is too long (max. %d)' => '', ); diff --git a/app/locales/ru_RU/translations.php b/app/locales/ru_RU/translations.php index efca595..992edc8 100644 --- a/app/locales/ru_RU/translations.php +++ b/app/locales/ru_RU/translations.php @@ -255,4 +255,15 @@ return array( 'New Password' => 'Новый пароль', 'Wrong password' => 'Неверный пароль', 'Duplicated feed' => 'Дублирующийся канал', + // 'This group has been removed successfully.' => '', + // 'Unable to remove this group.' => '', + // 'Edit group' => '', + // 'Group updated successfully.' => '', + // 'Unable to edit this group.' => '', + // 'groups' => '', + // 'There is no group.' => '', + // 'Do you really want to remove this group: "%s"?' => '', + // 'This field is required' => '', + // 'This value must be an integer' => '', + // 'This text is too long (max. %d)' => '', ); diff --git a/app/locales/sr_RS/translations.php b/app/locales/sr_RS/translations.php index 1e23374..32e4e4b 100644 --- a/app/locales/sr_RS/translations.php +++ b/app/locales/sr_RS/translations.php @@ -255,4 +255,15 @@ return array( // 'New Password' => '', // 'Wrong password' => '', // 'Duplicated feed' => '', + // 'This group has been removed successfully.' => '', + // 'Unable to remove this group.' => '', + // 'Edit group' => '', + // 'Group updated successfully.' => '', + // 'Unable to edit this group.' => '', + // 'groups' => '', + // 'There is no group.' => '', + // 'Do you really want to remove this group: "%s"?' => '', + // 'This field is required' => '', + // 'This value must be an integer' => '', + // 'This text is too long (max. %d)' => '', ); diff --git a/app/locales/sr_RS@latin/translations.php b/app/locales/sr_RS@latin/translations.php index 015a828..35773be 100644 --- a/app/locales/sr_RS@latin/translations.php +++ b/app/locales/sr_RS@latin/translations.php @@ -255,4 +255,15 @@ return array( // 'New Password' => '', // 'Wrong password' => '', // 'Duplicated feed' => '', + // 'This group has been removed successfully.' => '', + // 'Unable to remove this group.' => '', + // 'Edit group' => '', + // 'Group updated successfully.' => '', + // 'Unable to edit this group.' => '', + // 'groups' => '', + // 'There is no group.' => '', + // 'Do you really want to remove this group: "%s"?' => '', + // 'This field is required' => '', + // 'This value must be an integer' => '', + // 'This text is too long (max. %d)' => '', ); diff --git a/app/locales/tr_TR/translations.php b/app/locales/tr_TR/translations.php index eab512f..f73de71 100644 --- a/app/locales/tr_TR/translations.php +++ b/app/locales/tr_TR/translations.php @@ -255,4 +255,15 @@ return array( // 'New Password' => '', // 'Wrong password' => '', // 'Duplicated feed' => '', + // 'This group has been removed successfully.' => '', + // 'Unable to remove this group.' => '', + // 'Edit group' => '', + // 'Group updated successfully.' => '', + // 'Unable to edit this group.' => '', + // 'groups' => '', + // 'There is no group.' => '', + // 'Do you really want to remove this group: "%s"?' => '', + // 'This field is required' => '', + // 'This value must be an integer' => '', + // 'This text is too long (max. %d)' => '', ); diff --git a/app/locales/zh_CN/translations.php b/app/locales/zh_CN/translations.php index fe3d2f0..2cf458e 100644 --- a/app/locales/zh_CN/translations.php +++ b/app/locales/zh_CN/translations.php @@ -255,4 +255,15 @@ return array( 'New Password' => '新密码', 'Wrong password' => '密码错误', // 'Duplicated feed' => '', + // 'This group has been removed successfully.' => '', + // 'Unable to remove this group.' => '', + // 'Edit group' => '', + // 'Group updated successfully.' => '', + // 'Unable to edit this group.' => '', + // 'groups' => '', + // 'There is no group.' => '', + // 'Do you really want to remove this group: "%s"?' => '', + // 'This field is required' => '', + // 'This value must be an integer' => '', + // 'This text is too long (max. %d)' => '', ); diff --git a/app/models/group.php b/app/models/group.php index 36f3933..f2fa765 100644 --- a/app/models/group.php +++ b/app/models/group.php @@ -16,6 +16,33 @@ function get_all($user_id) ->findAll(); } +function get_group($user_id, $group_id) +{ + return Database::getInstance('db') + ->table(TABLE) + ->eq('user_id', $user_id) + ->eq('id', $group_id) + ->findOne(); +} + +function remove_group($user_id, $group_id) +{ + return Database::getInstance('db') + ->table(TABLE) + ->eq('user_id', $user_id) + ->eq('id', $group_id) + ->remove(); +} + +function update_group($user_id, $group_id, $title) +{ + return Database::getInstance('db') + ->table(TABLE) + ->eq('user_id', $user_id) + ->eq('id', $group_id) + ->update(array('title' => $title)); +} + function get_groups_feed_ids($user_id) { $result = array(); diff --git a/app/templates/feeds/create.php b/app/templates/feeds/create.php index 36bf1b3..de3694b 100644 --- a/app/templates/feeds/create.php +++ b/app/templates/feeds/create.php @@ -4,6 +4,7 @@ diff --git a/app/templates/feeds/edit.php b/app/templates/feeds/edit.php index b43e7f3..449814e 100644 --- a/app/templates/feeds/edit.php +++ b/app/templates/feeds/edit.php @@ -3,6 +3,7 @@ diff --git a/app/templates/feeds/list.php b/app/templates/feeds/list.php index e2af71a..872db33 100644 --- a/app/templates/feeds/list.php +++ b/app/templates/feeds/list.php @@ -4,6 +4,7 @@