public function remove() { if (!$this->exists()) { return false; } // Remove all of the user's surveys foreach ($this->surveys as $surveyID) { $survey = new Survey($surveyID); $survey->remove(); } // And the container which references them Redis::del("User:{$this->id}:surveys"); // And the username-userid reference Redis::set("User:username:{$this->username}"); parent::remove(); }
public function delete($id) { $survey = new Survey($id); if (!$survey->exists()) { $this->message = "Survey not found"; $this->status = 404; return; } if ($survey->ownerID != Session::$user['id']) { $this->message = "Unauthorized"; $this->status = 403; return; } $survey->remove(); $this->message = "Survey removed"; $this->status = 204; }
function showRemoveSurveyRes() { /* update last page */ $_SESSION['LASTPAGE'] = 'sysadmin.surveys'; $displaySysAdmin = new DisplaySysAdmin(); $suid = getFromSessionParams('suid'); if ($suid != '') { //remove $survey = new Survey($suid); /* remove sections */ $sections = $survey->getSections(); foreach ($sections as $section) { $section->remove(); /* remove variables */ $variables = $survey->getVariableDescriptives($section->getSeid()); foreach ($variables as $variable) { $variable->remove(); } } /* remove types */ $types = $survey->getTypes(); foreach ($types as $type) { $type->remove(); } /* remove types */ $groups = $survey->getGroups(); foreach ($groups as $group) { $group->remove(); } /* remove versions */ $versions = $survey->getVersions(); foreach ($versions as $version) { $version->remove(); } /* remove survey */ $survey->remove(); /* update users */ $users = new Users(); $users = $users->getUsers(); foreach ($users as $u) { $u->removeSurvey($suid); $u->saveChanges(); } /* return result */ return $displaySysAdmin->showSurveys($displaySysAdmin->displaySuccess(Language::messageSurveyRemoved($survey->getName()))); } else { return $displaySysAdmin->showSurveys(); } }