static function setTags($tagger, $tagged, $newtags) { $newtags = array_unique($newtags); $oldtags = Profile_tag::getTags($tagger, $tagged); # Delete stuff that's old that not in new $to_delete = array_diff($oldtags, $newtags); # Insert stuff that's in new and not in old $to_insert = array_diff($newtags, $oldtags); $profile_tag = new Profile_tag(); $profile_tag->tagger = $tagger; $profile_tag->tagged = $tagged; $profile_tag->query('BEGIN'); foreach ($to_delete as $deltag) { $profile_tag->tag = $deltag; $result = $profile_tag->delete(); if (!$result) { common_log_db_error($profile_tag, 'DELETE', __FILE__); return false; } } foreach ($to_insert as $instag) { $profile_tag->tag = $instag; $result = $profile_tag->insert(); if (!$result) { common_log_db_error($profile_tag, 'INSERT', __FILE__); return false; } } $profile_tag->query('COMMIT'); return true; }
static function cleanup($profile_list) { $ptag = new Profile_tag(); $ptag->tagger = $profile_list->tagger; $ptag->tag = $profile_list->tag; $ptag->find(); while ($ptag->fetch()) { if (Event::handle('StartUntagProfile', array($ptag))) { $orig = clone $ptag; $result = $ptag->delete(); if (!$result) { common_log_db_error($this, 'DELETE', __FILE__); } Event::handle('EndUntagProfile', array($orig)); } } }
function _deleteTags() { $tag = new Profile_tag(); $tag->tagger = $this->id; $tag->delete(); }