Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of git://github.com/ceeram/infinitas into dev
- Loading branch information
Showing
3 changed files
with
74 additions
and
106 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
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 |
---|---|---|
|
@@ -76,7 +76,7 @@ | |
?> | ||
</td> | ||
</tr> | ||
<? | ||
<?php | ||
$i++; | ||
} | ||
?> | ||
|
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 |
---|---|---|
@@ -1,68 +1,79 @@ | ||
<?php | ||
/** | ||
* Comment Template. | ||
* | ||
* @todo -c 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://www.dogmatic.co.za | ||
* @package sort | ||
* @subpackage sort.comments | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
* @since 0.5a | ||
*/ | ||
/** | ||
* Comment Template. | ||
* | ||
* @todo -c 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://www.dogmatic.co.za | ||
* @package sort | ||
* @subpackagesort.comments | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
* @since 0.5a | ||
*/ | ||
|
||
class LockableBehavior extends ModelBehavior | ||
{ | ||
class LockableBehavior extends ModelBehavior { | ||
|
||
/** | ||
* Contain settings indexed by model name. | ||
* | ||
* @var array | ||
* @access private | ||
*/ | ||
var $__settings = array(); | ||
/** | ||
* Contain default settings. | ||
* | ||
* @var array | ||
* @access protected | ||
*/ | ||
var $_defaults = array( | ||
'fields' => array( | ||
'locked_by' => 'locked_by', | ||
'locked_since' => 'locked_since', | ||
'locked' => 'locked' | ||
) | ||
); | ||
|
||
/** | ||
* Initiate behavior for the model using specified settings. Available settings: | ||
* | ||
* - locked_by: int field name of the peson that locked the field | ||
* - locked_since: datetime field name of the date the record was locked. | ||
* - locked: bool field name of the locked status field. | ||
* | ||
* @param object $Model Model using the behaviour | ||
* @param array $settings Settings to override for model. | ||
* @access public | ||
*/ | ||
function setup(&$Model, $settings = array()) | ||
{ | ||
$default = array( | ||
'locked_by' => 'locked_by', | ||
'locked_since' => 'locked_since', | ||
'locked' => 'locked' | ||
); | ||
/** | ||
* @param object $Model Model using the behavior | ||
* @param array $settings Settings to override for model. | ||
* @access public | ||
* @return void | ||
*/ | ||
function setup(&$Model, $config = null) { | ||
if (is_array($config)) { | ||
$this->settings[$Model->alias] = array_merge($this->_defaults, $config); | ||
} else { | ||
$this->settings[$Model->alias] = $this->_defaults; | ||
} | ||
} | ||
|
||
if ( !isset( $this->__settings[$Model->alias] ) ) | ||
{ | ||
$this->__settings[$Model->alias] = $default; | ||
} | ||
function lock(&$Model, $fields = null, $id = null){ | ||
$old_recursive = $Model->recursive; | ||
$Model->recursive = -1; | ||
$data = $Model->read($this->_defaults['fields'], $id); | ||
$this->Session = new CakeSession(); | ||
$user_id = $this->Session->read('Auth.User.id'); | ||
if($data[$Model->name]['locked'] && $data[$Model->name]['locked_by'] != $user_id){ | ||
return false; | ||
} | ||
$data[$Model->name] = array( | ||
'id' => $id, | ||
'locked' => 1, | ||
'locked_by' => $user_id, | ||
'locked_since' => date('Y-m-d H:i:s') | ||
); | ||
$Model->save($data, array('validate' => false, 'callbacks' => false)); | ||
$Model->recursive = $old_recursive; | ||
$data = $Model->read($fields, $id); | ||
return $data; | ||
} | ||
|
||
$this->__settings[$Model->alias] = am( | ||
$this->__settings[$Model->alias], | ||
ife( is_array( $settings ), $settings, array() ) | ||
); | ||
} | ||
|
||
function read( $fields, $id ) | ||
{ | ||
pr( 'lockable read' ); | ||
exit; | ||
} | ||
} | ||
function beforeSave($Model){ | ||
$Model->data[$Model->name]['locked'] = 0; | ||
$Model->data[$Model->name]['locked_by'] = null; | ||
$Model->data[$Model->name]['locked_since'] = null; | ||
return true; | ||
} | ||
} | ||
?> |