Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added admin user to migrations and read me, reformatted to PSR-1/PSR-2 #3

Open
wants to merge 3 commits into
base: rewrite
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ The recommended way to install composer packages is:
$ composer require bakkerij/cakeadmin:dev-rewrite
```

## Load Plugin
## Load Plugins

```
$ bin/cake plugin load -b -r Bakkerij/CakeAdmin
$ bin/cake plugin load Crud
$ bin/cake plugin load Gourmet/KnpMenu
$ bin/cake plugin load Bootstrap

```

## Update Database Info
Expand All @@ -34,3 +38,9 @@ Navigate to the new project's config/app.php and update your Datasources usernam
$ bin/cake migrations migrate -p Bakkerij/CakeAdmin
```

After migrations you will have a default Admin user with the following credentials:

Email - [email protected]

Password - test

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"php": ">=5.4.16",
"cakephp/cakephp": "~3.0",
"friendsofcake/crud": "^4.3",
"gourmet/knp-menu": "~0.4"
"gourmet/knp-menu": "~0.4",
"holt59/cakephp3-bootstrap-helpers": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "*"
Expand Down
4 changes: 4 additions & 0 deletions config/Migrations/20160716113123_Initial.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

use Migrations\AbstractMigration;

class Initial extends AbstractMigration
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a standard according to brackets {?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just used NetBeans auto format

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CakePHP has its own standard: http://book.cakephp.org/3.0/en/intro/conventions.html

You can validate your code using: https://github.com/cakephp/cakephp-codesniffer

It might be a good idea to follow those standards and conventions... Probably there is a plugin for Netbeans to auto format to CakePHP's conventions, else you should do it manually (http://blog.bobbyallen.me/2013/03/24/configuring-netbeans-for-psr-1-and-psr-2-coding-guidelines/).

/**
* Change Method.
*
Expand Down Expand Up @@ -48,4 +50,6 @@ public function change()
->addColumn('modified', 'datetime')
->create();
}

}

26 changes: 26 additions & 0 deletions config/Migrations/20161123183707_AddAdminUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Cake\ORM\TableRegistry;
use Migrations\AbstractMigration;

class AddAdminUser extends AbstractMigration
{
/**
* Change Method.
*
* More information on this method is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-change-method
* @return void
*/
public function change()
{
$AdminTable = TableRegistry::get('Bakkerij/CakeAdmin.Administrators');
$user = $AdminTable->newEntity([
'name' => 'admin',
'email' => '[email protected]',
'password' => 'test',
'active' => 1
]);
$AdminTable->save($user);
}
}
6 changes: 6 additions & 0 deletions src/Controller/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@

use Bakkerij\CakeAdmin\Controller\AppController;
use Cake\Datasource\ConnectionManager;
use \Cake\Event\Event;

/**
* Dashboard Controller
*
*/
class DashboardController extends AppController
{
public function beforeRender(Event $event)
{
parent::beforeRender($event);
$this->viewBuilder()->layout('admin');
}

/**
* Index method
Expand Down
9 changes: 6 additions & 3 deletions src/Controller/Admin/PostTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ public function beforeFilter(Event $event)

public function beforeRender(Event $event)
{
$this->viewBuilder()->helpers(['Bakkerij/CakeAdmin.PostType' => [
'data' => $this->postType
]]);
$this->viewBuilder()->layout('admin');
$this->viewBuilder()->helpers([
'Bakkerij/CakeAdmin.PostType' => [
'data' => $this->postType
]
]);

parent::beforeRender($event);
}
Expand Down
18 changes: 17 additions & 1 deletion src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,25 @@ class AppController extends BaseController
{

use ControllerTrait;

use CakeAdminTrait;

// https://holt59.github.io/cakephp3-bootstrap-helpers/
public $helpers = [
'Html' => [
'className' => 'Bootstrap.BootstrapHtml',
'useCustomFileInput' => true
],
'Form' => [
'className' => 'Bootstrap.BootstrapForm'
],
'Paginator' => [
'className' => 'Bootstrap.BootstrapPaginator'
],
'Modal' => [
'className' => 'Bootstrap.BootstrapModal'
]
];

/**
* Initialize AppController
*
Expand Down
38 changes: 21 additions & 17 deletions src/Controller/CakeAdminTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,28 @@ public function initializeCakeAdmin()
{
$namespace = 'App\CakeAdmin';

if(class_exists($namespace)) {
if (class_exists($namespace)) {
$init = new $namespace();

$this->eventManager()->on($init);
}

$this->__trigger('CakeAdmin.Controller.startup');
}

public function buildMenu()
{
/** @var MenuItem $menu */
$menu = $this->Menu->get('cakeadmin_main');

$menu->addChild('Dashboard', ['uri' => [
'plugin' => 'Bakkerij/CakeAdmin',
'prefix' => 'admin',
'controller' => 'Dashboard',
'action' => 'index'
]]);
$menu->addChild('Dashboard', [
'uri' => [
'plugin' => 'Bakkerij/CakeAdmin',
'prefix' => 'admin',
'controller' => 'Dashboard',
'action' => 'index'
]
]);

$this->addPostTypesToMenu();

Expand All @@ -49,13 +51,15 @@ public function addPostTypesToMenu()
$postTypes = PostTypeRegistry::getAll();

foreach ($postTypes as $postType) {
$menu->addChild($postType->name(), ['uri' => [
'plugin' => 'Bakkerij/CakeAdmin',
'prefix' => 'admin',
'controller' => 'PostTypes',
'action' => 'index',
'type' => $postType->slug()
]]);
$menu->addChild($postType->name(), [
'uri' => [
'plugin' => 'Bakkerij/CakeAdmin',
'prefix' => 'admin',
'controller' => 'PostTypes',
'action' => 'index',
'type' => $postType->slug()
]
]);
}
}

Expand All @@ -64,9 +68,9 @@ public function addConfigurationsToMenu()
/** @var MenuItem $menu */
$menu = $this->Menu->get('cakeadmin_main');

$configurations = (array) Configure::read('CA.menu.main');
$configurations = (array)Configure::read('CA.menu.main');

foreach($configurations as $label => $options) {
foreach ($configurations as $label => $options) {
$menu->addChild($label, $options);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Component/CakeAdminComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class CakeAdminComponent extends Component

public function loadPostTypesFromConfig()
{
$list = (array) Configure::read('CA.postTypes');
$list = (array)Configure::read('CA.postTypes');

foreach($list as $key => $value) {
foreach ($list as $key => $value) {
PostTypeRegistry::register($key, $value);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/PostTypesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public function setPostTypeActions()
{
$actions = $this->postType->actions();

foreach($actions as $action => $state) {
if($state) {
foreach ($actions as $action => $state) {
if ($state) {
$this->Crud->enable($action);
} else {
$this->Crud->disable($action);
Expand Down
44 changes: 22 additions & 22 deletions src/PostType/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function name($name = null)
if ($name) {
$this->_name = $name;
}
if(!$this->_name) {
if (!$this->_name) {
$this->_name = $this->table()->alias();
}
return $this->_name;
Expand All @@ -149,10 +149,10 @@ public function alias($alias = null)
*/
public function slug($slug = null)
{
if($slug) {
if ($slug) {
$this->_slug = Text::slug($slug);
}
if(!$this->_slug) {
if (!$this->_slug) {
$this->_slug = Text::slug($this->name());
}
return $this->_slug;
Expand All @@ -169,10 +169,10 @@ public function slug($slug = null)
*/
public function menu($menu = null)
{
if($menu) {
$this->_menu = (bool) $menu;
if ($menu) {
$this->_menu = (bool)$menu;
}
if(!$this->_menu) {
if (!$this->_menu) {
$this->_menu = true;
}
return $this->_menu;
Expand All @@ -186,10 +186,10 @@ public function menu($menu = null)
*/
public function description($description = null)
{
if($description) {
if ($description) {
$this->_description = $description;
}
if(!$this->_description) {
if (!$this->_description) {
$this->_description = true;
}
return $this->_description;
Expand All @@ -204,16 +204,16 @@ public function description($description = null)
*/
public function action($action, $enabled = null)
{
if(is_array($action)) {
foreach($action as $key => $value) {
if (is_array($action)) {
foreach ($action as $key => $value) {
$this->action($key, $value);
}
}

if($enabled !== null) {
$this->_actions[$action] = (bool) $enabled;
if ($enabled !== null) {
$this->_actions[$action] = (bool)$enabled;
}
if(!array_key_exists($action, $this->_actions)) {
if (!array_key_exists($action, $this->_actions)) {
$this->_actions[$action] = true;
}
return $this->_actions[$action];
Expand Down Expand Up @@ -247,10 +247,10 @@ public function filter()
*/
public function tableColumns(array $columns = null)
{
if($columns) {
if ($columns) {
$this->_columns = $this->_normalizeTableColumns($columns);
}
if(!$this->_columns) {
if (!$this->_columns) {
$this->_columns = $this->_generateTableColumns();
}
return $this->_columns;
Expand All @@ -264,10 +264,10 @@ public function tableColumns(array $columns = null)
*/
public function formFields(array $fields = null)
{
if($fields) {
if ($fields) {
$this->_fields = $this->_normalizeFormFields($fields);
}
if(!$this->_fields) {
if (!$this->_fields) {
$this->_fields = $this->_generateFormFields();
}
return $this->_fields;
Expand All @@ -281,10 +281,10 @@ public function formFields(array $fields = null)
*/
public function table($table = null)
{
if($table) {
if ($table) {
$this->_table = $table;
}
if(!$this->_table) {
if (!$this->_table) {
$this->_table = TableRegistry::get($this->model());
}
return $this->_table;
Expand Down Expand Up @@ -358,11 +358,11 @@ protected function _generateTableColumns()
$columns[] = reset($pk);
$columns[] = $table->displayField();

if($table->hasBehavior('Timestamp')) {
if($schema->column('created')) {
if ($table->hasBehavior('Timestamp')) {
if ($schema->column('created')) {
$columns[] = 'created';
}
if($schema->column('modified')) {
if ($schema->column('modified')) {
$columns[] = 'modified';
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/PostType/PostTypeRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public static function getBySlug($slug)
{
$all = self::getAll();

foreach($all as $class => $type) {
if($type->slug() === $slug) {
foreach ($all as $class => $type) {
if ($type->slug() === $slug) {
return self::get($class);
}
}
Expand All @@ -64,7 +64,7 @@ public static function getAll()

$all = [];

foreach($list as $class) {
foreach ($list as $class) {
$all[$class] = self::get($class);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Shell/CakeadminShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getOptionParser()
*
* @return bool|int Success or error code.
*/
public function main()
public function main()
{
$this->out($this->OptionParser->help());
}
Expand Down
Loading