Skip to content

Commit

Permalink
moving the binding into the behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Sep 15, 2010
1 parent c9450b5 commit e3330be
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 39 deletions.
33 changes: 0 additions & 33 deletions core/comments/comments_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,6 @@ public function onSetupConfig(){
public function onAttachBehaviors(&$event) {
if(is_subclass_of($event->Handler, 'Model')) {
if ($event->Handler->hasField('comment_count')) {
$event->Handler->bindModel(
array(
'hasMany' => array(
$event->Handler->name.'Comment' => array(
'className' => 'Comments.Comment',
'foreignKey' => 'foreign_id',
'limit' => 5,
'order' => array(
$event->Handler->name.'Comment.created' => 'desc'
),
'fields' => array(
$event->Handler->name.'Comment.id',
$event->Handler->name.'Comment.class',
$event->Handler->name.'Comment.foreign_id',
$event->Handler->name.'Comment.user_id',
$event->Handler->name.'Comment.email',
$event->Handler->name.'Comment.comment',
$event->Handler->name.'Comment.active',
$event->Handler->name.'Comment.status',
$event->Handler->name.'Comment.created'
),
'conditions' => array(
'or' => array(
$event->Handler->name.'Comment.active' => 1
)
),
'dependent' => true
)
)
),
false
);

if(!$event->Handler->Behaviors->enabled('Comments.Commentable')){
$event->Handler->Behaviors->attach('Comments.Commentable');
}
Expand Down
47 changes: 41 additions & 6 deletions core/comments/models/behaviors/commentable.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,53 @@ class CommentableBehavior extends ModelBehavior{
* @param array $settings Settings to override for model.
* @access public
*/
public function setup(&$model, $settings = array()) {
public function setup(&$Model, $settings = array()) {
$default = $this->defaults;
$default['blacklist_keywords'] = explode(',', Configure::read('Website.blacklist_keywords'));
$default['blacklist_words'] = explode(',', Configure::read('Website.blacklist_words'));
$default['conditions'] = array('Comment.class' => $model->alias);
$default['class'] = $model->name.'Comment';
$default['conditions'] = array('Comment.class' => $Model->alias);
$default['class'] = $Model->name.'Comment';

if (!isset($this->__settings[$model->alias])) {
$this->__settings[$model->alias] = $default;
if (!isset($this->__settings[$Model->alias])) {
$this->__settings[$Model->alias] = $default;
}

$this->__settings[$model->alias] = array_merge($this->__settings[$model->alias], (array)$settings);
$this->__settings[$Model->alias] = array_merge($this->__settings[$Model->alias], (array)$settings);

pr($Model->alias);
exit;
$Model->bindModel(
array(
'hasMany' => array(
$Model->name.'Comment' => array(
'className' => 'Comments.Comment',
'foreignKey' => 'foreign_id',
'limit' => 5,
'order' => array(
$Model->name.'Comment.created' => 'desc'
),
'fields' => array(
$Model->name.'Comment.id',
$Model->name.'Comment.class',
$Model->name.'Comment.foreign_id',
$Model->name.'Comment.user_id',
$Model->name.'Comment.email',
$Model->name.'Comment.comment',
$Model->name.'Comment.active',
$Model->name.'Comment.status',
$Model->name.'Comment.created'
),
'conditions' => array(
'or' => array(
$Model->name.'Comment.active' => 1
)
),
'dependent' => true
)
)
),
false
);
}

public function createComment(&$model, $data = array()) {
Expand Down

0 comments on commit e3330be

Please sign in to comment.