Restructure example as skel
This commit is contained in:
parent
2f38884798
commit
07b6fa1305
6 changed files with 29 additions and 29 deletions
|
@ -69,7 +69,7 @@ foreach($status_list as $key => $value)
|
||||||
|
|
||||||
require_once('cli.php');
|
require_once('cli.php');
|
||||||
require_once('templates.php');
|
require_once('templates.php');
|
||||||
require_once('url-helpers.php');
|
require_once('views/index.php');
|
||||||
|
|
||||||
Db :: init();
|
Db :: init();
|
||||||
|
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use EesyPHP\Check;
|
|
||||||
use EesyPHP\Log;
|
|
||||||
use EesyPHP\Tpl;
|
|
||||||
|
|
||||||
use EesyPHPExample\Db\Item;
|
|
||||||
|
|
||||||
function get_item_from_url($id, $fatal=false) {
|
|
||||||
if (!Check :: id($id))
|
|
||||||
Log :: fatal(_('Invalid element identifier.'));
|
|
||||||
|
|
||||||
$item = Item :: get($id);
|
|
||||||
if(!$item instanceof Item) {
|
|
||||||
$error = sprintf(_("Item #%s not found."), $id);
|
|
||||||
if ($fatal)
|
|
||||||
Log :: fatal($error);
|
|
||||||
Tpl :: add_error($error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return $item;
|
|
||||||
}
|
|
||||||
|
|
||||||
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab
|
|
|
@ -12,6 +12,7 @@ use function EesyPHP\vardump;
|
||||||
if (php_sapi_name() == "cli")
|
if (php_sapi_name() == "cli")
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search page handler
|
* Search page handler
|
||||||
* @param EesyPHP\UrlRequest $request
|
* @param EesyPHP\UrlRequest $request
|
||||||
|
@ -123,7 +124,7 @@ Url :: add_url_handler('|^item/?$|', 'handle_search');
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function handle_show($request) {
|
function handle_show($request) {
|
||||||
$item = get_item_from_url($request -> id);
|
$item = Item :: get_from_url($request -> id);
|
||||||
if (!$item)
|
if (!$item)
|
||||||
Url :: error_404();
|
Url :: error_404();
|
||||||
|
|
||||||
|
@ -179,7 +180,7 @@ Url :: add_url_handler('|^item/new$|', 'handle_create');
|
||||||
function handle_modify($request) {
|
function handle_modify($request) {
|
||||||
global $status_list;
|
global $status_list;
|
||||||
|
|
||||||
$item = get_item_from_url($request -> id);
|
$item = Item :: get_from_url($request -> id);
|
||||||
if(!$item)
|
if(!$item)
|
||||||
Url :: error_404();
|
Url :: error_404();
|
||||||
if (!can_modify($item)) {
|
if (!can_modify($item)) {
|
||||||
|
@ -228,7 +229,7 @@ Url :: add_url_handler('|^item/(?P<id>[0-9]+)/modify$|', 'handle_modify');
|
||||||
* @return never
|
* @return never
|
||||||
*/
|
*/
|
||||||
function handle_archive($request) {
|
function handle_archive($request) {
|
||||||
$item = get_item_from_url($request -> id);
|
$item = Item :: get_from_url($request -> id);
|
||||||
if(!$item) {
|
if(!$item) {
|
||||||
Tpl :: add_error(_("Item #%s not found."), $request -> id);
|
Tpl :: add_error(_("Item #%s not found."), $request -> id);
|
||||||
Url :: redirect('item');
|
Url :: redirect('item');
|
||||||
|
@ -255,7 +256,7 @@ Url :: add_url_handler('|^item/(?P<id>[0-9]+)/archive$|', 'handle_archive');
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function handle_delete($request) {
|
function handle_delete($request) {
|
||||||
$item = get_item_from_url($request -> id);
|
$item = Item :: get_from_url($request -> id);
|
||||||
if(!$item) {
|
if(!$item) {
|
||||||
Tpl :: add_error(_("Item #%s not found."), $request -> id);
|
Tpl :: add_error(_("Item #%s not found."), $request -> id);
|
||||||
}
|
}
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
namespace EesyPHPExample\Db;
|
namespace EesyPHPExample\Db;
|
||||||
|
|
||||||
|
use EesyPHP\Check;
|
||||||
use EesyPHP\Hook;
|
use EesyPHP\Hook;
|
||||||
use EesyPHP\Log;
|
use EesyPHP\Log;
|
||||||
|
use EesyPHP\Tpl;
|
||||||
|
|
||||||
use EesyPHP\Db\AttrBool;
|
use EesyPHP\Db\AttrBool;
|
||||||
use EesyPHP\Db\AttrInt;
|
use EesyPHP\Db\AttrInt;
|
||||||
|
@ -40,6 +42,27 @@ class Item extends DbObject {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get item from URL
|
||||||
|
* @param mixed $id Item ID as retrieved from URL
|
||||||
|
* @param boolean $fatal Set to true to trigger fatal error if item is not found in DB
|
||||||
|
* @return Item|false
|
||||||
|
*/
|
||||||
|
public static function get_from_url($id, $fatal=false) {
|
||||||
|
if (!Check :: id($id))
|
||||||
|
Log :: fatal(_('Invalid element identifier.'));
|
||||||
|
|
||||||
|
$item = self :: get($id);
|
||||||
|
if(!$item instanceof Item) {
|
||||||
|
$error = sprintf(_("Item #%s not found."), $id);
|
||||||
|
if ($fatal)
|
||||||
|
Log :: fatal($error);
|
||||||
|
Tpl :: add_error($error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change item status in DB
|
* Change item status in DB
|
||||||
* @param string $status New item status
|
* @param string $status New item status
|
||||||
|
|
Loading…
Reference in a new issue