/** * Override delete method * Delete topic itself and all it's comments, ratings, and view counter */ public function delete() { $tid = $this->id; // delete view counter Counter::where("[entityId] = ? AND [entityTypeId] = ?", [$tid, Topic::ENTITY_TYPE])->delete(); Rating::where("[entityId] = ? AND [entityType] = ?", [$tid, Topic::ENTITY_TYPE])->delete(); RatingStatistic::where("[entityId] = ? AND [entityType] = ?", [$tid, Topic::ENTITY_TYPE])->delete(); Comment::where("[topicId] = ?", $tid)->delete(); parent::delete(); }
/** * Delete plus-rating data */ public function delete() { if (isset($this->entityType) && isset($this->entityId)) { Rating::where("[entityId] = ? AND [entityType] = ?", [$this->entityId, $this->entityType])->delete(); RatingStatistic::where("[entityId] = ? AND [entityType] = ?", [$this->entityId, $this->entityType])->delete(); } }
public static function deleteGroup(Group $group) { Rating::where("[entityId] = ? AND [entityType] = ?", [$group->id, Group::ENTITY_TYPE])->delete(); RatingStatistic::where("[entityId] = ? AND [entityType] = ?", [$group->id, Group::ENTITY_TYPE])->delete(); Counter::where("[entityId] = ? AND [entityTypeId] = ?", [$group->id, Group::ENTITY_TYPE])->delete(); $topics = Topic::find("groupId", $group->id)->all(); foreach ($topics as $topic) { $topic->delete(); } GroupUser::where("[groupId] = ?", $group->id)->delete(); $group->delete(); }