Add events for favor and disfavor
Added events to core code for when someone favors or disfavors a notice.
This commit is contained in:
parent
866b647062
commit
36d21fa716
19
EVENTS.txt
19
EVENTS.txt
|
@ -729,3 +729,22 @@ StartGetProfileUri: When determining the canonical URI for a given profile
|
|||
EndGetProfileUri: After determining the canonical URI for a given profile
|
||||
- $profile: the current profile
|
||||
- &$uri: the URI
|
||||
|
||||
StartFavorNotice: Saving a notice as a favorite
|
||||
- $profile: profile of the person faving (can be remote!)
|
||||
- $notice: notice being faved
|
||||
- &$fave: Favor object; null to start off with, but feel free to override.
|
||||
|
||||
EndFavorNotice: After saving a notice as a favorite
|
||||
- $profile: profile of the person faving (can be remote!)
|
||||
- $notice: notice being faved
|
||||
|
||||
StartDisfavorNotice: Saving a notice as a favorite
|
||||
- $profile: profile of the person faving (can be remote!)
|
||||
- $notice: notice being faved
|
||||
- &$result: result of the disfavoring (if you override)
|
||||
|
||||
EndDisfavorNotice: After saving a notice as a favorite
|
||||
- $profile: profile of the person faving (can be remote!)
|
||||
- $notice: notice being faved
|
||||
|
||||
|
|
|
@ -21,17 +21,47 @@ class Fave extends Memcached_DataObject
|
|||
/* the code above is auto generated do not remove the tag below */
|
||||
###END_AUTOCODE
|
||||
|
||||
static function addNew($user, $notice) {
|
||||
$fave = new Fave();
|
||||
$fave->user_id = $user->id;
|
||||
$fave->notice_id = $notice->id;
|
||||
if (!$fave->insert()) {
|
||||
common_log_db_error($fave, 'INSERT', __FILE__);
|
||||
return false;
|
||||
static function addNew($profile, $notice) {
|
||||
|
||||
$fave = null;
|
||||
|
||||
if (Event::handle('StartFavorNotice', array($profile, $notice, &$fave))) {
|
||||
|
||||
$fave = new Fave();
|
||||
|
||||
$fave->user_id = $profile->id;
|
||||
$fave->notice_id = $notice->id;
|
||||
|
||||
if (!$fave->insert()) {
|
||||
common_log_db_error($fave, 'INSERT', __FILE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
Event::handle('EndFavorNotice', array($profile, $notice));
|
||||
}
|
||||
|
||||
return $fave;
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
$profile = Profile::staticGet('id', $this->user_id);
|
||||
$notice = Notice::staticGet('id', $this->notice_id);
|
||||
|
||||
$result = null;
|
||||
|
||||
if (Event::handle('StartDisfavorNotice', array($profile, $notice, &$result))) {
|
||||
|
||||
$result = parent::delete();
|
||||
|
||||
if ($result) {
|
||||
Event::handle('EndDisfavorNotice', array($profile, $notice));
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function pkeyGet($kv)
|
||||
{
|
||||
return Memcached_DataObject::pkeyGet('Fave', $kv);
|
||||
|
|
Loading…
Reference in New Issue
Block a user