-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Settings part to manage the website.
- Loading branch information
Showing
38 changed files
with
931 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
use Migrations\AbstractMigration; | ||
|
||
class CreateSettings 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() | ||
{ | ||
$table = $this->table('settings'); | ||
$table->addColumn('name', 'string', [ | ||
'default' => null, | ||
'limit' => 255, | ||
'null' => false, | ||
]); | ||
$table->addColumn('value_int', 'integer', [ | ||
'default' => null, | ||
'limit' => 11, | ||
'null' => true, | ||
]); | ||
$table->addColumn('value_str', 'string', [ | ||
'default' => null, | ||
'limit' => 255, | ||
'null' => true, | ||
]); | ||
$table->addColumn('value_bool', 'boolean', [ | ||
'default' => null, | ||
'null' => true, | ||
]); | ||
$table->addColumn('last_updated_user_id', 'integer', [ | ||
'default' => null, | ||
'limit' => 11, | ||
'null' => true, | ||
]); | ||
$table->addColumn('created', 'datetime', [ | ||
'default' => null, | ||
'null' => false, | ||
]); | ||
$table->addColumn('modified', 'datetime', [ | ||
'default' => null, | ||
'null' => false, | ||
]); | ||
$table->addIndex([ | ||
'name', | ||
], [ | ||
'name' => 'UNIQUE_NAME', | ||
'unique' => true, | ||
]); | ||
$table->create(); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
use Phinx\Seed\AbstractSeed; | ||
|
||
class SettingsSeed extends AbstractSeed | ||
{ | ||
/** | ||
* Run Method. | ||
* | ||
* Write your database seeder using this method. | ||
* | ||
* More information on writing seeders is available here: | ||
* http://docs.phinx.org/en/latest/seeding.html | ||
* | ||
* @return void | ||
*/ | ||
public function run() | ||
{ | ||
$data = [ | ||
[ | ||
'name' => 'User.Login.enabled', | ||
'value_int' => null, | ||
'value_str' => null, | ||
'value_bool' => '1', | ||
'last_updated_user_id' => '1', | ||
'created' => '2015-12-08 01:00:00', | ||
'modified' => '2015-12-08 13:30:48' | ||
], | ||
[ | ||
'name' => 'Site.version', | ||
'value_int' => null, | ||
'value_str' => '3.0.1', | ||
'value_bool' => null, | ||
'last_updated_user_id' => '1', | ||
'created' => '2015-12-08 01:00:00', | ||
'modified' => '2015-12-08 10:52:48' | ||
], | ||
[ | ||
'name' => 'Conversations.enabled', | ||
'value_int' => null, | ||
'value_str' => null, | ||
'value_bool' => '1', | ||
'last_updated_user_id' => '1', | ||
'created' => '2015-12-08 10:38:44', | ||
'modified' => '2015-12-08 15:34:40' | ||
] | ||
]; | ||
|
||
$settings = $this->table('settings'); | ||
$settings->insert($data) | ||
->save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
namespace App\Controller\Admin; | ||
|
||
use App\Controller\AppController; | ||
use Cake\Cache\Cache; | ||
use Cake\Core\Configure; | ||
use Cake\Event\Event; | ||
use Cake\Network\Exception\NotFoundException; | ||
|
||
class SettingsController extends AppController | ||
{ | ||
|
||
/** | ||
* Display all settings. | ||
* | ||
* @return void | ||
*/ | ||
public function index() | ||
{ | ||
$this->paginate = [ | ||
'maxLimit' => 20 | ||
]; | ||
|
||
$settings = $this->Settings | ||
->find() | ||
->contain([ | ||
'LastUpdatedUser' => function ($q) { | ||
return $q->find('medium'); | ||
} | ||
]) | ||
->order([ | ||
'Settings.name' => 'ASC' | ||
]); | ||
|
||
$settings = $this->paginate($settings); | ||
|
||
$this->set(compact('settings')); | ||
} | ||
|
||
/** | ||
* Create a setting. | ||
* | ||
* @return \Cake\Network\Response|void | ||
*/ | ||
public function create() | ||
{ | ||
$setting = $this->Settings->newEntity($this->request->data); | ||
|
||
if ($this->request->is('post')) { | ||
$setting->last_updated_user_id = $this->Auth->user('id'); | ||
|
||
if ($this->Settings->save($setting)) { | ||
Cache::delete('settings', 'database'); | ||
$this->Flash->success(__d('admin', 'This setting has been created successfully !')); | ||
|
||
return $this->redirect(['action' => 'index']); | ||
} | ||
} | ||
|
||
$this->set(compact('setting')); | ||
} | ||
|
||
/** | ||
* Edit a setting. | ||
* | ||
* @return \Cake\Network\Response|void | ||
*/ | ||
public function edit() | ||
{ | ||
$setting = $this->Settings | ||
->find() | ||
->where([ | ||
'Settings.id' => $this->request->id | ||
]) | ||
->first(); | ||
|
||
if (is_null($setting)) { | ||
$this->Flash->error(__d('admin', 'This setting doesn\'t exist or has been deleted.')); | ||
|
||
return $this->redirect(['action' => 'index']); | ||
} | ||
|
||
if ($this->request->is(['post', 'put'])) { | ||
$this->Settings->patchEntity($setting, $this->request->data); | ||
|
||
$setting->last_updated_user_id = $this->Auth->user('id'); | ||
|
||
if ($this->Settings->save($setting)) { | ||
Cache::delete('settings', 'database'); | ||
$this->Flash->success(__d('admin', 'This setting has been edited successfully !')); | ||
|
||
return $this->redirect(['action' => 'index']); | ||
} | ||
} | ||
|
||
$this->set(compact('setting')); | ||
} | ||
|
||
/** | ||
* Delete a setting. | ||
* | ||
* @return \Cake\Network\Response|void | ||
*/ | ||
public function delete() | ||
{ | ||
$setting = $this->Settings | ||
->find() | ||
->where([ | ||
'Settings.id' => $this->request->id | ||
]) | ||
->first(); | ||
|
||
if (is_null($setting)) { | ||
$this->Flash->error(__d('admin', 'This setting doesn\'t exist or has been deleted.')); | ||
|
||
return $this->redirect(['action' => 'index']); | ||
} | ||
|
||
if ($this->Settings->delete($setting)) { | ||
$this->Flash->success(__d('admin', 'This setting has been deleted successfully !')); | ||
|
||
return $this->redirect(['action' => 'index']); | ||
} | ||
|
||
return $this->redirect(['action' => 'index']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.