3 * Table Definition for profile_tag_subscription
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Profile_tag_subscription extends Memcached_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'profile_tag_subscription'; // table name
13 public $profile_tag_id; // int(4) not_null
14 public $profile_id; // int(4) not_null
15 public $created; // datetime not_null default_0000-00-00%2000%3A00%3A00
16 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
19 function staticGet($k,$v=null)
20 { return Memcached_DataObject::staticGet('Profile_tag_subscription',$k,$v); }
22 /* the code above is auto generated do not remove the tag below */
27 return Memcached_DataObject::pkeyGet('Profile_tag_subscription', $kv);
30 static function add($peopletag, $profile)
32 if ($peopletag->private) {
36 if (Event::handle('StartSubscribePeopletag', array($peopletag, $profile))) {
37 $args = array('profile_tag_id' => $peopletag->id,
38 'profile_id' => $profile->id);
39 $existing = Profile_tag_subscription::pkeyGet($args);
40 if(!empty($existing)) {
44 $sub = new Profile_tag_subscription();
45 $sub->profile_tag_id = $peopletag->id;
46 $sub->profile_id = $profile->id;
47 $sub->created = common_sql_now();
49 $result = $sub->insert();
52 common_log_db_error($sub, 'INSERT', __FILE__);
53 // TRANS: Exception thrown when inserting a list subscription in the database fails.
54 throw new Exception(_('Adding list subscription failed.'));
57 $ptag = Profile_list::staticGet('id', $peopletag->id);
58 $ptag->subscriberCount(true);
60 Event::handle('EndSubscribePeopletag', array($peopletag, $profile));
65 static function remove($peopletag, $profile)
67 $sub = Profile_tag_subscription::pkeyGet(array('profile_tag_id' => $peopletag->id,
68 'profile_id' => $profile->id));
75 if (Event::handle('StartUnsubscribePeopletag', array($peopletag, $profile))) {
76 $result = $sub->delete();
79 common_log_db_error($sub, 'DELETE', __FILE__);
80 // TRANS: Exception thrown when deleting a list subscription from the database fails.
81 throw new Exception(_('Removing list subscription failed.'));
84 $peopletag->subscriberCount(true);
86 Event::handle('EndUnsubscribePeopletag', array($peopletag, $profile));
91 // called if a tag gets deleted / made private
92 static function cleanup($profile_list) {
94 $subs->profile_tag_id = $profile_list->id;
97 while($subs->fetch()) {
98 $profile = Profile::staticGet('id', $subs->profile_id);
99 Event::handle('StartUnsubscribePeopletag', array($profile_list, $profile));
102 Event::handle('StartUnsubscribePeopletag', array($profile_list, $profile));
108 $result = parent::insert();
110 self::blow('profile_list:subscriber_count:%d',
111 $this->profile_tag_id);
118 $result = parent::delete();
120 self::blow('profile_list:subscriber_count:%d',
121 $this->profile_tag_id);