public function testCRUD() { //CREATE Test $newProject = new Project(); $projectName = 'This is a Test'; $newProject->setAttributes(array('name' => $projectName, 'description' => 'This project is for test purpose only', 'start_date' => '2010-11-15 15:00:00', 'end_date' => '2010-12-06 00:00:00', 'update_user_id' => 1, 'category' => 2, 'status' => 1, 'owner' => 1)); $this->assertTrue($newProject->save(false)); //READ Test $readProject = Project::model()->findByPk($newProject->id); $this->assertTrue($readProject instanceof Project); $this->assertEquals($projectName, $readProject->name); //UPDATE Test $updateProjectName = 'Updated Name2'; $newProject->name = $updateProjectName; $this->AssertTrue($newProject->save(false)); $updatedProject = Project::model()->findByPk($newProject->id); $this->assertTrue($updatedProject instanceof Project); $this->assertNotEquals($projectName, $updatedProject->name); //DELETE Test $deletedProjectId = $newProject->id; $newProject->delete(); $deletedProject = Project::model()->findByPk($newProject->id); $this->assertEquals(Null, $deletedProject); //GetUserVote Test $project = Project::model()->findByPk(18); $this->assertTrue($project->getUserVote(7) == true); //Vote Test $this->assertTrue($project->vote(1, 1) == 1); }
function delete_projects() { $projects = $this->get_projects(); foreach ($projects as $project) { $this_project = new Project($project['id']); $this_project->delete(); } }
/** * Delete a project * @route DELETE project/$id/$token (rewritten by codeigniter route) * @param type $id * @param type $token */ public function project_delete($id, $token) { $token_entry = new Token(); $token_entry->get_by_valid_token($token)->get(); $response = new stdClass(); if ($token_entry->exists() && $token_entry->user->get()->is_admin) { $projects = new Project(); $projects->get_by_id($id); $projects->delete(); $response->status = TRUE; $this->response($response); } else { $response->status = FALSE; $response->error = 'Token not found, not an admin or session expired'; $this->response($response); } }
/** * Delete project * * @param void * @return null */ function delete() { if ($this->request->isApiCall() && !$this->request->isSubmitted()) { $this->httpError(HTTP_ERR_BAD_REQUEST, null, true, $this->request->isApiCall()); } // if if ($this->active_project->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND, null, true, $this->request->isApiCall()); } // if if (!$this->active_project->canDelete($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN, null, true, $this->request->isApiCall()); } // if if ($this->request->isSubmitted()) { $delete = $this->active_project->delete(); if ($delete && !is_error($delete)) { if ($this->request->isApiCall()) { $this->httpOk(); } else { flash_success("Project ':name' has been deleted", array('name' => $this->active_project->getName())); $this->redirectTo('projects'); } // if } else { if ($this->request->isApiCall()) { $this->serveData($delete); } else { flash_error("Failed to delete ':name' project", array('name' => $this->active_project->getName())); $this->redirectTo('projects'); } // if } // if } else { $this->httpError(HTTP_ERR_BAD_REQUEST, null, true, $this->request->isApiCall()); } // if }
/** * Delete a project and it's children * * @param Project $project * @return void */ public static function delete_project($project) { $id = $project->id; $project->delete(); /* Delete all children from the project */ Project\Issue::where('project_id', '=', $id)->delete(); Project\Issue\Comment::where('project_id', '=', $id)->delete(); Project\User::where('project_id', '=', $id)->delete(); User\Activity::where('parent_id', '=', $id)->delete(); }
} Session::checkLoginUser(); $project = new Project(); if (isset($_POST["add"])) { $project->check(-1, CREATE, $_POST); $newID = $project->add($_POST); Event::log($newID, "project", 4, "maintain", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])); if ($_SESSION['glpibackcreated']) { Html::redirect($project->getFormURL() . "?id=" . $newID); } else { Html::back(); } } else { if (isset($_POST["delete"])) { $project->check($_POST["id"], DELETE); $project->delete($_POST); Event::log($_POST["id"], "project", 4, "maintain", sprintf(__('%s deletes an item'), $_SESSION["glpiname"])); $project->redirectToList(); } else { if (isset($_POST["restore"])) { $project->check($_POST["id"], DELETE); $project->restore($_POST); Event::log($_POST["id"], "project", 4, "maintain", sprintf(__('%s restores an item'), $_SESSION["glpiname"])); $project->redirectToList(); } else { if (isset($_POST["purge"])) { $project->check($_POST["id"], PURGE); $project->delete($_POST, 1); Event::log($_POST["id"], "project", 4, "maintain", sprintf(__('%s purges an item'), $_SESSION["glpiname"])); $project->redirectToList(); } else {
function test_delete() { //Arrange $name = "Build a shed"; $motivation = "have storage"; $due_date = "2015-09-09"; $priority = 1; $test_project = new Project($name, $motivation, $due_date, $priority); $test_project->save(); $name2 = "Learn French"; $motivation2 = "To travel"; $test_project2 = new Project($name2, $motivation2, $due_date, $priority); $test_project2->save(); //Act $test_project->delete(); $result = Project::getAll(); //Assert $this->assertEquals([$test_project2], $result); }
if ($object->id > 0) { $object->fetch_thirdparty(); } /* * Actions */ // Cancel if (GETPOST("cancel") && ! empty($backtopage)) { if (GETPOST("comefromclone")==1) { $result=$object->delete($user); if ($result > 0) { Header("Location: index.php"); exit; } else { dol_syslog($object->error,LOG_DEBUG); $mesg='<div class="error">'.$langs->trans("CantRemoveProject").'</div>'; } } header("Location: ".$backtopage); exit; }
/** * testProjectDelete * * @param int $id Id of project * @return void * * @depends testProjectClose * The depends says test is run only if previous is ok */ public function testProjectDelete($id) { global $conf, $user, $langs, $db; $conf = $this->savconf; $user = $this->savuser; $langs = $this->savlangs; $db = $this->savdb; $localobject = new Project($this->savdb); $result = $localobject->fetch($id); $result = $localobject->delete($user); print __METHOD__ . " id=" . $id . " result=" . $result . "\n"; $this->assertLessThan($result, 0); return $result; }
include "layouts/forms/project.html"; break; case "changeStatus": case "delete": if ($action == "changeStatus") { /* Change status*/ $sMsg1 = $objProject->changeStatus($id, $_GET["status"]); if ($sMsg1 == 1) { $sMsg = $objMessages->changestatusIndication($moduleLabel); } else { $sMsg = $objMessages->errorIndication($moduleLabel, $action); } } else { if ($action == "delete") { /* Delete record */ $sMsg1 = $objProject->delete($id); if ($sMsg1 == 1) { $sMsg = $objMessages->addupdatesucessIndication($moduleLabel, $action); } else { $sMsg = $objMessages->errorIndication($moduleLabel, $action); } } } default: /* List the customers */ $count = $objProject->getProjectCount(); if ($count > 0) { $projectList = $objProject->getProjectList(); } include "layouts/project.html"; }
if (GETPOST('action') == 'confirm_reopen' && GETPOST('confirm') == 'yes') { $project = new Project($db); $project->fetch(GETPOST("id")); $result = $project->setValid($user); if ($result <= 0) { $mesg='<div class="error">'.$project->error.'</div>'; } } if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->projet->supprimer) { $project = new Project($db); $project->fetch(GETPOST("id")); $result=$project->delete($user); if ($result > 0) { Header("Location: index.php"); exit; } else { dol_syslog($project->error,LOG_DEBUG); $mesg='<div class="error">'.$langs->trans("CantRemoveProject").'</div>'; } } /* * View
/** * Delete personal project * It doesnt delete the project If more than one user have this project as personal project. * @param void * @return null */ function deletePersonalProject() { $usersWithThatProject = count(Users::GetByPersonalProject($this->getPersonalProjectId())); if ($this->personal_project && $usersWithThatProject == 1) { $this->personal_project->delete(); } // if }
** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with Open Source ACH. If not, see <http://www.gnu.org/licenses/>. //////////////////////////////////////////////////////////////////////////////// */ include "code/includes.php"; $id = $_REQUEST['id']; $part = $_REQUEST['part']; $active_project = new Project(); $active_project->populateFromID($id); $can_delete = FALSE; // User must be owner and they must get to this page via the Delete link on the project page. include "parts/includes.php"; if ($active_user->id == $active_project->user_id && substr($_SERVER['HTTP_REFERER'], 0, strlen("{$base_URL}/project/")) == "{$base_URL}/project/") { $can_delete = TRUE; $active_project->delete(); } ?> <html> <head> <title>Deleting...</title> <script language="JavaScript"> <?php if ($can_delete) { ?> alert("Project deleted."); <?php } else { ?>
<?php # delete_task.php # 1. logic Auth::kickout('login'); $project = new Project(); $project->load(['slug' => Route::param('slug')]); $project->delete(); # 2. views URL::redirect('/home');
/** * @param $id * * @return mixed|void */ public function delete($id) { $this->project = $this->project->find($id); $this->project->delete(); }
/** * Remove the specified resource from storage. * DELETE /projects/{id} * * @param Project $project * @return Response */ public function destroy(Project $project) { $project->delete(); return Redirect::route('projects.index')->with('message', 'Project deleted.'); }
/** * @param string $get_array * @return string * @throws ProjectDeleteException * @throws ProjectSecurityAccessDeniedException; * @throws ProjectIDMissingException */ public static function delete_handler($get_array) { global $user; if ($get_array) { $_GET = unserialize($get_array); } if ($_GET['project_id']) { $project = new Project($_GET['project_id']); if ($project->get_deleted() == true) { if ($user->is_admin() == true) { if ($project->delete() == true) { return "1"; } else { throw new ProjectDeleteException(); } } else { throw new ProjectSecurityAccessDeniedException(); } } else { $project_security = new ProjectSecurity($_GET['project_id']); if ($project_security->is_access(6, false) == true) { if ($project->mark_as_deleted() == true) { return "1"; } else { throw new ProjectDeleteException(); } } else { throw new ProjectSecurityAccessDeniedException(); } } } else { throw new ProjectIDMissingException(); } }
/** * The function that decides what to do and which page to view. * * @param $getvars an associative array, representing the GET variables * from the URL * @return void */ function controlHandler($getvars) { global $dao, $global; include_once $global['approot'] . 'inc/lib_location.inc'; //first authorize the user $ac = new AccessController($getvars); if (!$ac->isAuthorized()) { return; } // temporary, to support older 'action' instead of 'vm_action' $vm_action = $getvars['vm_action'] ? $getvars['vm_action'] : $getvars['action']; switch ($vm_action) { case 'display_single': $p = new Project($getvars['proj_id']); $this->displayProject($p); break; case 'display_add': $this->addProject(); break; case 'display_edit': $this->addProject(new Project($getvars['proj_id'])); break; case 'display_closure_edit': if ($dao->isSiteManagerForProject($_SESSION['user_id'], $getvars['proj_id'])) { if (!empty($_POST)) { $dao->saveClosureReport($getvars['proj_id'], $_POST); $this->displayConfirmation(_('Changes Saved.')); echo '<script type="text/javascript">'; echo 'setTimeout(\'location.href="?mod=vm&act=project&vm_action=display_closure_report&proj_id=' . $getvars['proj_id'] . '"\',1500);'; echo '</script>'; } else { $this->editClosure($getvars['proj_id']); } } break; case 'display_closure_report': $this->viewClosure($getvars['proj_id']); break; case 'display_closure_reports': $this->listClosureReports(); $this->showPagingNavigation("index.php?mod=vm&act=project&vm_action=display_closure_reports"); break; case 'process_add': $p = new Project($getvars['proj_id']); $p->info['name'] = $getvars['name']; $p->info['description'] = $getvars['description']; $p->info['start_date'] = $getvars['start_date']; $p->info['end_date'] = $getvars['end_date']; $p->info['mgr_id'] = $getvars['manager']; $p->info['locations'] = array(); shn_get_parents(shn_location_get_form_submit_loc(), $p->info['locations']); if ($this->validateAddForm($getvars)) { $p->save(); $this->displayConfirmation(_('Changes Saved.')); $this->displayProject($p); } else { $this->addProject(); } break; case 'process_delete': $p = new Project(); $p->delete($getvars['proj_id']); View::View(); $this->displayConfirmation('The requested Project was deleted.'); $this->listProjects(); $this->showPagingNavigation("index.php?mod=vm&act=project&vm_action=default"); break; case 'display_confirm_delete': View::View(); $this->confirmDelete($getvars['proj_id']); break; case 'display_select_project': View::View(); if ($dao->isSiteManager($_SESSION['user_id']) && !$ac->dataAccessIsAuthorized(array('vm_proj_vol' => 'ru'), false)) { $projects = $dao->listProjects($_SESSION['user_id'], true); } else { $projects = $dao->listProjects(); } $this->displaySelectProjectForAssignmentForm($projects); break; case 'display_assign': View::View(); if ($getvars['proj_id'] == '') { add_error(SHN_ERR_VM_NO_PROJECT); //if the user is just a site manager who got here due to overriding access control, only display his projects, otherwise display all if ($dao->isSiteManager($_SESSION['user_id']) && !$ac->dataAccessIsAuthorized(array('vm_vol_position' => 'ru'), false)) { $projects = $dao->listProjects($_SESSION['user_id'], true); } else { $projects = $dao->listProjects(); } $this->displaySelectProjectForAssignmentForm($projects); } else { if ($this->validateAssignForm($getvars)) { $p_uuid = $this->getAssigningVolId($getvars); $dao->assignVolunteerToPosition($p_uuid, $getvars['pos_id_' . $p_uuid]); add_confirmation(_('Volunteer has been successfully assigned')); } $p = new Project($getvars['proj_id']); $this->assignVol($getvars['proj_id'], $p->positions); } break; case 'process_remove_from_project': $dao->deleteFromProject($getvars['p_uuid'], $getvars['proj_id']); $p = new Project($getvars['proj_id']); $this->displayProject($p); break; case 'display_my_list': $this->listProjects($_SESSION['user_id']); $this->showPagingNavigation("index.php?mod=vm&act=project&vm_action=display_my_list"); break; case 'display_coming_list': echo _('The items listed below are projects that will start from today or after today.'); echo '<div align="right"><a href="?mod=vm&act=project">' . _('View all projects') . '</a></div>'; $this->listComingProjects(); $this->showPagingNavigation("index.php?mod=vm&act=project&vm_action=display_coming_list"); break; case 'process_add_position': if ($getvars['pos_id'] != null) { $p = new Position($getvars['pos_id']); } else { $p = new Position(); } $p->proj_id = $getvars['proj_id']; $p->ptype_id = $getvars['ptype_id']; $p->description = $getvars['description']; $p->title = $getvars['title']; $p->numSlots = $getvars['numSlots']; $p->payrate = $getvars['payrate']; if ($this->validateAddPosition($getvars)) { $dao->savePosition($p); //$this->displayConfirmation("Position assignment has been added to {$p->position_title}"); $this->controlHandler(array('vm_action' => 'display_single', 'proj_id' => $p->proj_id)); } else { $this->addPosition($p); } break; case 'add_position': //this case only displays the form to add/edit a position if ($getvars['pos_id']) { $p = new Position($getvars['pos_id']); } else { $p = new Position(); } if (isset($getvars['proj_id'])) { $p->proj_id = $getvars['proj_id']; } $this->addPosition($p); break; case 'remove_position': $dao->removePosition($getvars['pos_id']); $this->controlHandler(array('vm_action' => 'display_single', 'proj_id' => $getvars['proj_id'])); break; default: echo '<div align="right"><a href="?mod=vm&act=project&vm_action=display_coming_list">' . _('View coming projects') . '</a></div>'; $this->listProjects(); $this->showPagingNavigation("index.php?mod=vm&act=project&vm_action=default"); break; } }