Skip to content

Commit

Permalink
fixing up themes so there is only one active at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Jan 29, 2010
1 parent 74847d8 commit 17d4bb5
Showing 1 changed file with 78 additions and 75 deletions.
153 changes: 78 additions & 75 deletions infinitas/management/models/theme.php
Original file line number Diff line number Diff line change
@@ -1,76 +1,79 @@
<?php
/**
* Comment Template.
*
* @todo Implement .this needs to be sorted out.
*
* Copyright (c) 2009 Carl Sutton ( dogmatic69 )
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
* @filesource
* @copyright Copyright (c) 2009 Carl Sutton ( dogmatic69 )
* @link http://infinitas-cms.org
* @package sort
* @subpackage sort.comments
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.5a
*/

class Theme extends ManagementAppModel {
var $name = 'Theme';

var $tablePrefix = 'core_';

var $hasMay = array(
'Management.Route'
);

/**
* Get the current Theme
*
* @param array $conditions
* @return array $theme the current theme.
*/
function getCurrnetTheme(){

$theme = Cache::read('currentTheme');

if ($theme == false) {
$theme = $this->find(
'first',
array(
'conditions' => array(
'Theme.active' => 1
)
)
);
}
Cache::write('currentTheme', $theme, 'core');

return $theme;
}

function afterSave($created) {
parent::afterSave($created);

$this->__clearCache();
return true;
}

function afterDelete() {
parent::afterDelete();

$this->__clearCache();
return true;
}

function __clearCache() {
if (is_file(CACHE . 'core' . DS . 'current_theme')) {
unlink(CACHE . 'core' . DS . 'current_theme');
}

return true;
}
}
<?php
/**
* Comment Template.
*
* @todo Implement .this needs to be sorted out.
*
* Copyright (c) 2009 Carl Sutton ( dogmatic69 )
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
* @filesource
* @copyright Copyright (c) 2009 Carl Sutton ( dogmatic69 )
* @link http://infinitas-cms.org
* @package sort
* @subpackage sort.comments
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.5a
*/

class Theme extends ManagementAppModel {
var $name = 'Theme';

var $tablePrefix = 'core_';

var $hasMay = array(
'Management.Route'
);

/**
* Get the current Theme
*
* @param array $conditions
* @return array $theme the current theme.
*/
function getCurrnetTheme(){

$theme = Cache::read('currentTheme');

if ($theme == false) {
$theme = $this->find(
'first',
array(
'conditions' => array(
'Theme.active' => 1
)
)
);
}
Cache::write('currentTheme', $theme, 'core');

return $theme;
}

/**
* Deactivate everything after making something else active
*/
function afterSave($created) {
parent::afterSave($created);

$this->__clearCache();
return true;
}

function afterDelete() {
parent::afterDelete();

$this->__clearCache();
return true;
}

function __clearCache() {
if (is_file(CACHE . 'core' . DS . 'current_theme')) {
unlink(CACHE . 'core' . DS . 'current_theme');
}

return true;
}
}
?>

0 comments on commit 17d4bb5

Please sign in to comment.