-
Notifications
You must be signed in to change notification settings - Fork 36
/
comment.php
89 lines (83 loc) · 2.66 KB
/
comment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Blog Comment Model class file.
*
* This is the main model for Blog Comments. There are a number of
* methods for getting the counts of all comments, active comments, pending
* comments etc. It extends {@see BlogAppModel} for some all round
* functionality. look at {@see BlogAppModel::afterSave} for an example
*
* 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 blog
* @subpackage blog.models.comment
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class Comment extends BlogAppModel
{
var $name = 'Comment';
var $validate = array(
'name' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'Please enter your name'
)
),
'email' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'Please enter your email address'
),
'email' => array(
'rule' => array( 'email' ),
'message' => 'Please enter a valid email address'
)
),
'comment' => array(
'rule' => 'notEmpty',
'message' => 'Please enter your comments'
)
);
var $belongsTo = array(
'Post' => array(
'className' => 'Blog.Post',
'counterCache' => true,
'counterScope' => array( 'Comment.active' => 1 )
)
);
function getCounts()
{
$counts = Cache::read( 'comments_count' );
if ( $counts !== false )
{
return $counts;
}
$counts['active'] = $this->find(
'count',
array(
'conditions' => array(
'Comment.active' => 1
),
'contain' => false
)
);
$counts['pending'] = $this->find(
'count',
array(
'conditions' => array(
'Comment.active' => 0
),
'contain' => false
)
);
Cache::write( 'comments_count', $counts, 'blog' );
return $counts;
}
}
?>