public function delete() { if (!$this->loaded()) { throw new Exception('Cannot delete user because model is not loaded.'); } $materials = ORM::factory('material')->where('teacher_id', '=', $this->id)->find_all(); foreach ($materials as $material) { $material->delete(); } parent::delete(); }
public function delete($id = null) { //delete all comments foreach ($this->comments->find_all() as $comment) { $comment->delete(); } //delete all photos foreach ($this->photos->find_all() as $photo) { $photo->delete(); } //delete avatar if ($this->avatar->loaded()) { $this->avatar->delete(); } //delete all logs that refer to this user $logInfos = ORM::factory("Game_LogInfo")->or_where_open()->where("name", "=", "user")->or_where("name", "=", "user_id")->or_where_close()->where("data", "=", $this->id)->find_all(); foreach ($logInfos as $logInfo) { $logInfo->_eventLog->delete(); } //delete the user in gamification DB $site = Helper_Game::getSite(); $gUser = $site->getUser($this->id); $gUser->delete(); parent::delete($id); }
/** * Overrides the default delete behaviour * Removes all the data associated with the user from * the system. This data includes buckets, rivers, tags, * collaborations, subscriptions and auth tokens */ public function delete() { // Does this user have an account space? $account = ORM::factory('account')->where('user_id', '=', $this->id)->find(); if ($account->loaded()) { // Delete buckets - droplets, subscriptions and collaborations $buckets = ORM::factory('bucket')->where('account_id', '=', $account->id)->find_all(); foreach ($buckets as $bucket) { $bucket->delete(); } // Delete rivers - droplets, subscriptions and collaborations $rivers = ORM::factory('river')->where('account_id', '=', $account->id)->find_all(); foreach ($rivers as $river) { $river->delete(); } // User created tags DB::delete('account_droplet_tags')->where('account_id', '=', $account->id)->execute(); // User created places DB::delete('account_droplet_places')->where('account_id', '=', $account->id)->execute(); // User created links DB::delete('account_droplet_links')->where('account_id', '=', $account->id)->execute(); // User created media DB::delete('account_droplet_media')->where('account_id', '=', $account->id)->execute(); } // Remove follows and list of followers DB::delete('user_followers')->where('user_id', '=', $this->id)->or_where('follower_id', '=', $this->id)->execute(); // Accounts associated with the user DB::delete('accounts')->where('user_id', '=', $this->id)->execute(); // User tokens DB::delete('user_tokens')->where('user_id', '=', $this->id)->execute(); // Purge the logs - where the user has initiated an action // or an action has been performed on them DB::delete('user_actions')->where('user_id', '=', $this->id)->or_where('action_to_id', '=', $this->id)->execute(); // Default parent::delete(); }
public function delete() { foreach ($this->tokens->find_all() as $token) { $token->delete(); } foreach ($this->roles->find_all() as $role) { $this->remove('roles', $role->id); } $pages = $this->pages->find_all(); if ((bool) $pages->count()) { foreach ($pages as $page) { $page->delete(); } } $oauths = $this->oauths->find_all(); if ((bool) $oauths->count()) { foreach ($oauths as $oauth) { $oauth->delete(); } } $challenge = ORM::factory('User_Challenge')->where('user_id', '=', $this->id)->find(); if ($challenge->loaded()) { $challenge->delete(); } return parent::delete(); }