Skip to content

Commit

Permalink
fixing up more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Nov 14, 2012
1 parent 62c9246 commit 83c34db
Show file tree
Hide file tree
Showing 23 changed files with 1,748 additions and 1,300 deletions.
81 changes: 37 additions & 44 deletions Core/Configs/Controller/ConfigsAppController.php
@@ -1,47 +1,40 @@
<?php
/**
* ConfigsAppController
*
* @package Infinitas.Configs.Controller
*/

/**
* @page Configs-Plugin Configs Plugin
*
* @section configs-overview What is it
*
* The configs plugin provides a way to overload configuration options from the
* admin backend. The configs plugin uses the normal Configure class from
* CakePHP. This is done to allow normal usage within the code but have the
* ability to overload options in the backend.
*
* @link http://api.cakephp.org/class/configure
*
* @section configs-usage How to use it
*
* You can use all the normal Configure methods within the code including
* Configure::load(), Configure::read('debug') and Configure::write(). There are some
* Event callbacks that are triggered early on in the request so if you would
* like the data to be cached it should be loaded in these calls.
*
* Configs plugin provides a number of things to manage configs, including
* adding new ones from the backend, overloading options and seeing what has
* changed from the defaults.
*
* @image html sql_configs_plugin.png "Configs Plugin table structure"
*
* @section configs-see-also Also see
* @ref AppEvents
* @ref EventCore
*/
App::uses('AppController', 'Controller');

/**
* ConfigsAppController is the main controller class that all other
* configuration related controllers extend.
*
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 )
* @link http://www.infinitas-cms.org
* @package Infinitas.Configs
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.5a
*
* @author Carl Sutton <dogmatic69@infinitas-cms.org>
*/
App::uses('AppController', 'Controller');
class ConfigsAppController extends AppController {
}
/**
* ConfigsAppController
*
* The configs plugin provides a way to overload configuration options from the
* admin backend. The configs plugin uses the normal Configure class from
* CakePHP. This is done to allow normal usage within the code but have the
* ability to overload options in the backend.
*
* You can use all the normal Configure methods within the code including
* Configure::load(), Configure::read('debug') and Configure::write(). There are some
* Event callbacks that are triggered early on in the request so if you would
* like the data to be cached it should be loaded in these calls.
*
* Configs plugin provides a number of things to manage configs, including
* adding new ones from the backend, overloading options and seeing what has
* changed from the defaults.
*
* @image html sql_configs_plugin.png "Configs Plugin table structure"
*
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 )
* @link http://www.infinitas-cms.org
* @package Infinitas.Configs.Controller
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.5a
*
* @author Carl Sutton <dogmatic69@infinitas-cms.org>
*/

class ConfigsAppController extends AppController {

}
215 changes: 121 additions & 94 deletions Core/Configs/Controller/ConfigsController.php
@@ -1,104 +1,131 @@
<?php
/**
* The ConfigsController is for managing the site configs from the backend
*
* @copyright Copyright (c) 2009 Carl Sutton ( dogmatic69 )
* @link http://infinitas-cms.org
* @package Infinitas.Configs.controllers
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.5a
*
* @author Carl Sutton <dogmatic69@infinitas-cms.org>
*/

class ConfigsController extends ConfigsAppController {
/**
* dont see where this is used
*
* @deprecated
*/
public $configOptions = array();

public function admin_index() {
$configs = $this->Paginator->paginate(null, $this->Filter->filter);

$filterOptions = $this->Filter->filterOptions;
$filterOptions['fields'] = array(
'key',
'value',
'type' => $this->Config->_configTypes
);

$this->set(compact('configs', 'filterOptions'));
}

public function admin_available() {
$this->set('configs', $this->Config->availableConfigs());
$this->set('overloaded', $this->Config->find('list', array('fields' => array('Config.key', 'Config.value'))));
}
/**
* ConfigsController
*
* @package Infinitas.Configs.Controller
*/

/**
* ConfigsController
*
* The ConfigsController is for managing the site configs from the backend
*
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 )
* @link http://www.infinitas-cms.org
* @package Infinitas.Configs.Controller
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.5a
*
* @author Carl Sutton <dogmatic69@infinitas-cms.org>
*/

class ConfigsController extends ConfigsAppController {
/**
* List configs in the database
*
* These are the overloaded and additional configs from the defaults found in
* `PluginName/Config/config.php`
*
* @return void
*/
public function admin_index() {
$configs = $this->Paginator->paginate(null, $this->Filter->filter);

$filterOptions = $this->Filter->filterOptions;
$filterOptions['fields'] = array(
'key',
'value',
'type' => $this->Config->_configTypes
);

$this->set(compact('configs', 'filterOptions'));
}

/**
* List available configs
*
* @return void
*/
public function admin_available() {
$this->set('configs', $this->Config->availableConfigs());
$this->set('overloaded', $this->Config->find('list', array('fields' => array('Config.key', 'Config.value'))));
}

/**
* Add a new config option
*
* @return void
*/
public function admin_add() {
parent::admin_add();

if(isset($this->request->params['named']['Config.key'])) {
$this->request->data['Config']['key'] = $this->request->params['named']['Config.key'];
$value = Configure::read($this->request->params['named']['Config.key']);
switch(true) {
case is_int($value):
$this->request->data['Config']['type'] = 'integer';
break;

case is_bool($value):
$this->request->data['Config']['type'] = 'bool';
break;

default:
$array = explode(',', $value);
if(count($array) > 1) {
$this->request->data['Config']['type'] = 'array';
$this->request->data['Config']['value'] = $array[0];
$this->request->data['Config']['options'] = $value;
}
else{
$this->request->data['Config']['type'] = 'string';
}
}

public function admin_add() {
parent::admin_add();

if(isset($this->request->params['named']['Config.key'])) {
$this->request->data['Config']['key'] = $this->request->params['named']['Config.key'];
$value = Configure::read($this->request->params['named']['Config.key']);
switch(true) {
case is_int($value):
$this->request->data['Config']['type'] = 'integer';
break;

case is_bool($value):
$this->request->data['Config']['type'] = 'bool';
break;

default:
$array = explode(',', $value);
if(count($array) > 1) {
$this->request->data['Config']['type'] = 'array';
$this->request->data['Config']['value'] = $array[0];
$this->request->data['Config']['options'] = $value;
}
else{
$this->request->data['Config']['type'] = 'string';
}
}

if(!isset($this->request->data['Config']['value'])) {
$this->request->data['Config']['value'] = $value;
}
if(!isset($this->request->data['Config']['value'])) {
$this->request->data['Config']['value'] = $value;
}
}

$this->set('types', $this->Config->_configTypes);
$this->set('types', $this->Config->_configTypes);
}

/**
* Edit config option
*
* @param string $id the config id
*
* @return void
*/
public function admin_edit($id = null) {
if (!$id) {
$this->notice('invalid');
}

public function admin_edit($id = null) {
if (!$id) {
$this->notice('invalid');
if (!empty($this->request->data)) {
switch($this->request->data['Config']['type']) {
case 'bool':
switch($this->request->data['Config']['value']) {
case 1:
$this->request->data['Config']['value'] = 'true';
break;

default:
$this->request->data['Config']['value'] = 'false';
}
break;
}

if (!empty($this->request->data)) {
switch($this->request->data['Config']['type']) {
case 'bool':
switch($this->request->data['Config']['value']) {
case 1:
$this->request->data['Config']['value'] = 'true';
break;

default:
$this->request->data['Config']['value'] = 'false';
} // switch
break;
} // switch
if ($this->Config->save($this->request->data)) {
$this->notice('saved');
}

$this->notice('not_saved');
if ($this->Config->save($this->request->data)) {
$this->notice('saved');
}

if ($id && empty($this->request->data)) {
$this->request->data = $this->Config->read(null, $id);
}
$this->notice('not_saved');
}
}

if ($id && empty($this->request->data)) {
$this->request->data = $this->Config->read(null, $id);
}
}

}
21 changes: 17 additions & 4 deletions Core/Configs/Lib/ConfigsEvents.php
@@ -1,12 +1,20 @@
<?php
/**
* ConfigsEvents
*
* @package Infinitas.Configs.Lib
*/

/**
* ConfigsEvents
*
* ConfigsEvents for the Configs plugin to attach into the application
*
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 )
* @link http://www.infinitas-cms.org
* @package Infinitas.Configs
* @package Infinitas.Configs.Lib
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.8a
* @since 0.7a
*
* @author Carl Sutton <dogmatic69@infinitas-cms.org>
*/
Expand All @@ -29,9 +37,11 @@ public function onSetupCache() {
/**
* get the admin menu
*
* @param Event $Event
*
* @return array
*/
public function onAdminMenu($event) {
public function onAdminMenu(Event $Event) {
$menu['main'] = array(
'Dashboard' => array('plugin' => 'management', 'controller' => 'management', 'action' => 'site'),
'Configuration' => array('plugin' => 'configs', 'controller' => 'configs', 'action' => 'index'),
Expand All @@ -43,12 +53,15 @@ public function onAdminMenu($event) {

/**
* get required fixtures
*
* @param Event $Event
*
* @return array
*/
public function onGetRequiredFixtures($event) {
public function onGetRequiredFixtures(Event $Event) {
return array(
'Configs.Config',
);
}

}

0 comments on commit 83c34db

Please sign in to comment.