Skip to content

Commit

Permalink
spring cleaning & refactoring, #2, #4, #5, #8
Browse files Browse the repository at this point in the history
  • Loading branch information
ikkez committed Mar 8, 2015
1 parent a5df14a commit caf6063
Show file tree
Hide file tree
Showing 80 changed files with 1,772 additions and 970 deletions.
35 changes: 21 additions & 14 deletions app/config.ini
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
[globals]

; prefix all your db table names to avoid conflict
; with other apps that are using the same database
db_table_prefix = fblg_

; use 'md5' for PHP < 5.3.7 and 'bcrypt' for best security
password_hash_engine = md5
password_md5_salt = jK$N!Lx5

; 'summernote'
text_editor = sommernote

;##########################
; additional system config

; general settings
AUTOLOAD = app/;app/inc/
UI = ui/
BACKEND_UI = app/ui/
UPLOADS = res/
LOCALES = app/dict/
# overwrite auto-detection of language
;LANGUAGE=de-DE

DEV = true
DEBUG = 2
CACHE = false
TZ = Europe/Berlin
; CORTEX.smartLoading = false

ONERROR = \Error->render

;##########################
; additional app config

; prefix all your db table names to avoid conflict
; with other apps that are using the same database
db_table_prefix = fblg_

; use 'md5' for PHP < 5.3.7 and 'bcrypt' for best security
password_hash_engine = md5
password_md5_salt = jK$N!Lx5

; 'summernote'
text_editor = sommernote
9 changes: 8 additions & 1 deletion app/controller/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ class Auth extends Base {
protected
$response;

/**
* init the View
*/
public function beforeroute() {
$this->response = new \View\Backend();
}

/**
* check login state
* @return bool
Expand Down Expand Up @@ -51,7 +58,7 @@ public function login($f3,$params) {
else $f3->reroute('/admin');
}
}
\FlashMessage::instance()->addMessage('Wrong Username/Password', 'danger');
\Flash::instance()->addMessage('Wrong Username/Password', 'danger');
}
$this->response->setTemplate('templates/login.html');
}
Expand Down
43 changes: 28 additions & 15 deletions app/controller/backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@

class Backend extends Base {

/** @var \Controller\Base */
protected $module;

/**
* init the backend view, so the module controller can care about it
*/
public function beforeroute() {
$module_name = \Base::instance()->get('PARAMS.module');
$this->response = new \View\Backend();
$this->response->data['LAYOUT'] = $module_name.'_layout.html';
$this->module = $this->loadModule($module_name);
$this->module->setView($this->response);
}

/**
* load module controller class
* @param $name
* @return bool
*/
protected function loadModule($name) {
$class = '\Controller\\'.ucfirst($name);
if(!class_exists($class)) {
Expand All @@ -16,26 +35,20 @@ protected function loadModule($name) {
}

/**
* create a response that displays a list of module records
* pass method calls to module
* @param $name
* @param $args
* @return mixed
*/
public function getList($f3,$params) {
$module = $this->loadModule($params['module']);
$module->setView($this->response);
$module->getList($f3,$params);
$this->response->data['SUBPART'] = $params['module'].'_list.html';
$this->response->data['LAYOUT'] = $params['module'].'_layout.html';
public function __call($name,$args) {
return call_user_func_array(array($this->module,$name),$args);
}

/**
* return an create/edit form for a given module
* give the module control about the view
*/
public function getSingle($f3,$params) {
$module = $this->loadModule($params['module']);
$module->setView($this->response);
$module->getSingle($f3, $params);
$this->response->data['SUBPART'] = $params['module'].'_edit.html';
$this->response->data['LAYOUT'] = $params['module'].'_layout.html';
public function afterroute() {
$this->module->afterroute();
}


}
9 changes: 6 additions & 3 deletions app/controller/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ public function setView(\View\Base $view) {
* init the View
*/
public function beforeroute() {
$this->response = \View\Backend::instance();
$this->response = new \View\Frontend();
}

/**
* kick start the View, which finally creates the response
* based on our previously set content data
* kick start the View, which creates the response
* based on our previously set content data.
* finally echo the response or overwrite this method
* and do something else with it.
* @return string
*/
public function afterroute() {
if (!$this->response)
Expand Down
54 changes: 35 additions & 19 deletions app/controller/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,66 @@

class Comment extends Resource {

public function __construct()
{
public function __construct() {
$mapper = new \Model\Comment();
parent::__construct($mapper);
}

public function approve($f3,$params)
{
public function beforeroute() {
$this->response = new \View\Backend();
$this->response->data['LAYOUT'] = 'comment_layout.html';
}

/**
* @param \Base $f3
* @param $params
*/
public function approve(\Base $f3, $params) {
if($this->resource->updateProperty(array('_id = ?', $params['id']),'approved',1)) {
\FlashMessage::instance()->addMessage('Comment approved', 'success');
\Flash::instance()->addMessage('Comment approved', 'success');
} else {
\FlashMessage::instance()->addMessage('Unknown Comment ID', 'danger');
\Flash::instance()->addMessage('Unknown Comment ID', 'danger');
}
$f3->reroute($f3->get('SESSION.LastPageURL'));
}

public function reject($f3,$params)
{
/**
* @param \Base $f3
* @param $params
*/
public function reject(\Base $f3, $params) {
if ($this->resource->updateProperty(array('_id = ?', $params['id']), 'approved', 2)) {
\FlashMessage::instance()->addMessage('Comment rejected', 'success');
\Flash::instance()->addMessage('Comment rejected', 'success');
} else {
\FlashMessage::instance()->addMessage('Unknown Comment ID', 'danger');
\Flash::instance()->addMessage('Unknown Comment ID', 'danger');
}
$f3->reroute($f3->get('SESSION.LastPageURL'));
}

public function getSingle($f3,$params)
{
/**
* @param \Base $f3
* @param array $params
* @return bool
*/
public function getSingle(\Base $f3,$params) {
$this->response->data['SUBPART'] = 'comment_edit.html';

if (isset($params['id'])) {
$this->response->data['content'] = $this->resource->load(array('_id = ?',$params['id']));
$this->response->data['comment'] = $this->resource->load(array('_id = ?',$params['id']));
if(!$this->resource->dry())
return true;
}
\FlashMessage::instance()->addMessage('Unknown Comment ID', 'danger');
\Flash::instance()->addMessage('Unknown Comment ID', 'danger');
$f3->reroute($f3->get('SESSION.LastPageURL'));
}

/**
* display list of comments
* @param \Base $f3
* @param array $params
*/
public function getList($f3, $params)
{
public function getList(\Base $f3, $params) {
$this->response->data['SUBPART'] = 'comment_list.html';
$this->response->data['LAYOUT'] = 'comment_layout.html';
$filter = array('approved = ?',0); // new
if (isset($params['viewtype'])) {
if ($params['viewtype'] == 'published')
Expand All @@ -61,8 +77,8 @@ public function getList($f3, $params)
}

$page = \Pagination::findCurrentPage();
$limit = 3;
$this->response->data['content'] =
$limit = 10;
$this->response->data['comments'] =
$this->resource->paginate($page-1,$limit,$filter, array('order' => 'datetime desc'));
}

Expand Down
7 changes: 7 additions & 0 deletions app/controller/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ class Dashboard extends Base {
protected
$response;

/**
* init the View
*/
public function beforeroute() {
$this->response = new \View\Backend();
}

/**
* fetch data for an overview page
*/
Expand Down
Loading

0 comments on commit caf6063

Please sign in to comment.