$incomplete_steps_count = sizeof($project->getIncompleteSteps()); $complete_steps_count = $all_steps_count - $incomplete_steps_count; $progress_percent = (int) ($complete_steps_count / $all_steps_count * 100); } else { // If there are no steps, then progress percent is definitely 0. $progress_percent = 0; } // get next step should work here return $app['twig']->render('coach/active_project/5complete.html.twig', array('project' => $project, 'step' => $project->getNextStep(), 'progress_percent' => $progress_percent)); }); // Duplicate for post, sent here if user checks that they have finished step // on get page $coach_active_project->post('/{id}/complete', function ($id) use($app) { $project = Project::find($id); // Pass step id to here through hidden form input $step = Step::find($_POST['step_id']); if (!empty($_POST['complete']) && $_POST['complete'] == 'true') { $step->updateComplete(1); } else { $step->updateComplete(0); } // get percent complete on this project $all_steps_count = sizeof($project->getSteps()); $incomplete_steps_count = sizeof($project->getIncompleteSteps()); $complete_steps_count = $all_steps_count - $incomplete_steps_count; $progress_percent = (int) ($complete_steps_count / $all_steps_count * 100); // If finishing this step completes the project, then update complete in project // and re-direct on twig page to project complete page. //if length of project get incomplete steps = 0 then update complete true if ($incomplete_steps_count == 0) { $project->updateComplete(1);
function test_find() { //Arrange $description = "Buy book on learning French"; $project_id = 1; $position = 1; $test_step = new Step($description, $project_id, $position); $test_step->save(); $description2 = "Buy French bread"; $project_id2 = 1; $position2 = 2; $test_step2 = new Step($description2, $project_id2, $position2); $test_step2->save(); //Act $result = Step::find($test_step2->getId()); //Assert $this->assertEquals($test_step2, $result); }
/* 6. Add due date from previous page. ** Give user option to edit the project as they have entered it. */ $coach_new_project->post('/{id}/update', function ($id) use($app) { $project = Project::find($id); $project->updateDueDate($_POST['due_date']); return $app['twig']->render('coach/new_project/6update.html.twig', array('project' => $project, 'steps' => $project->getSteps())); }); // Get route to update step positions from JS values // Disable for now b/c update button goes to finished // $coach_new_project->get('/{id}/update', function($id) use ($app) { // $project = Project::find($id); // // return $app['twig']->render('coach/new_project/6update.html.twig', array( // 'project' => $project, // 'steps' => $project->getSteps() // )); // }); /* 7. If anything was edited, update it here. ** Display congratulations, redirect to dashboard. */ $coach_new_project->get('/{id}/finished', function ($id) use($app) { $project = Project::find($id); // logic to do updating here // Get updated step position values from JS foreach ($_GET as $step_id => $new_position) { $step = Step::find($step_id); $step->updatePosition($new_position); } return $app['twig']->render('coach/new_project/7finished.html.twig', array('project' => $project, 'steps' => $project->getSteps())); }); // Place all urls in this file at /coach/new_project/* $app->mount('/coach/new_project', $coach_new_project);