function test_save()
 {
     //Arrange
     $description = "Buy book on learning French";
     $project_id = 1;
     $position = 1;
     $test_step = new Step($description, $project_id, $position);
     //Act
     $test_step->save();
     //Assert
     $result = Step::getAll();
     $this->assertEquals([$test_step], $result);
 }
예제 #2
0
 /**
  * Implementation for 'POST' method for Rest API
  *
  * @param  mixed $stepUid Primary key
  *
  * @return array $result Returns array within multiple records or a single record depending if
  *                       a single selection was requested passing id(s) as param
  */
 protected function post($stepUid, $proUid, $tasUid, $stepTypeObj, $stepUidObj, $stepCondition, $stepPosition, $stepMode)
 {
     try {
         $result = array();
         $obj = new Step();
         $obj->setStepUid($stepUid);
         $obj->setProUid($proUid);
         $obj->setTasUid($tasUid);
         $obj->setStepTypeObj($stepTypeObj);
         $obj->setStepUidObj($stepUidObj);
         $obj->setStepCondition($stepCondition);
         $obj->setStepPosition($stepPosition);
         $obj->setStepMode($stepMode);
         $obj->save();
     } catch (Exception $e) {
         throw new RestException(412, $e->getMessage());
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Step();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Step'])) {
         $model->attributes = $_POST['Step'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
예제 #4
0
 function test_updatePosition()
 {
     //Arrange
     $description = "Buy book on learning French";
     $project_id = 1;
     $position = 1;
     $test_step = new Step($description, $project_id, $position);
     $test_step->save();
     //Act
     $new_position = 3;
     $test_step->updatePosition($new_position);
     //Assert
     $result = $test_step->getPosition();
     $this->assertEquals($new_position, $result);
 }
예제 #5
0
 function test_getIncompleteStep()
 {
     //Arrange
     $name = "Learn to speak French";
     $motivation = "To travel";
     $due_date = "2015-10-10";
     $priority = 1;
     $test_project = new Project($name, $motivation, $due_date, $priority);
     $test_project->save();
     $description = "Buy a beret";
     $project_id = $test_project->getId();
     $position = 1;
     $test_step = new Step($description, $project_id, $position);
     $test_step->save();
     $description2 = "Eat French bread";
     $position2 = 2;
     $test_step2 = new Step($description2, $project_id, $position2);
     $test_step2->save();
     $description3 = "Watch Julia Childs";
     $position3 = 3;
     $test_step3 = new Step($description3, $project_id, $position3);
     $test_step3->save();
     //Act
     $test_step2->updateComplete(1);
     $result = Project::getAll();
     //Assert
     $this->assertEquals([$test_step, $test_step3], $result[0]->getIncompleteSteps());
 }
예제 #6
0
$coach_active_project->post('/{id}/add_step', function ($id) use($app) {
    $project = Project::find($id);
    $steps = $project->getSteps();
    // If we have a $_POST for the step description, add it now.
    if (!empty($_POST['step_description'])) {
        $step_position = 1;
        if (sizeof($steps) == 0) {
            // There are no steps yet. This step should be added at pos 1.
            $step_position = 1;
        } else {
            // If we have 3 steps, should add new one at pos 4.
            // Start counting steps from 1.
            $step_position = sizeof($steps) + 1;
        }
        $new_step = new Step($_POST['step_description'], $project->getId(), $step_position);
        $new_step->save();
    }
    return $app['twig']->render('coach/active_project/4add_step.html.twig', array('project' => $project, 'steps' => $project->getSteps()));
});
/* 5. Great. Glad you feel confident you can complete this step.
 ** Tell me when you've finished it. Wait....
 ** Let user choose if they'd like to see the next step -> /next_step
 ** or had enough for the day -> /enough
 */
$coach_active_project->get('/{id}/complete', function ($id) use($app) {
    $project = Project::find($id);
    $all_steps_count = sizeof($project->getSteps());
    if ($all_steps_count != 0) {
        $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);
예제 #7
0
 function test_deleteStep()
 {
     //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();
     $description = "Buy a beret";
     $project_id = $test_project->getId();
     $position = 1;
     $test_step = new Step($description, $project_id, $position);
     $test_step->save();
     $description2 = "Eat French bread";
     $position2 = 2;
     $test_step2 = new Step($description2, $project_id, $position2);
     $test_step2->save();
     //Act
     $test_project->deleteStep($test_step);
     $result = $test_project->getSteps();
     //Assert
     $this->assertEquals([$test_step2], $result);
 }
예제 #8
0
            $step->userGroupID = $userGroupArray[$key];
            $step->priorStepID = '';
            $step->displayOrderSequence = $seqOrderArray[$key];
            try {
                $step->save();
                $stepID = $step->primaryKey;
                //if this step has a prior step, put it in an array
                if ($priorStepArray[$key]) {
                    $stepIDPriorArray[$stepID] = $priorStepArray[$key];
                }
                $stepIDArray[$seqOrderArray[$key]] = $stepID;
            } catch (Exception $e) {
                echo $e->getMessage();
            }
        }
    }
    //now that all of the stepIDs have been set up, fix the prior step IDs
    foreach ($stepIDPriorArray as $stepID => $key) {
        if ($stepID) {
            $step = new Step(new NamedArguments(array('primaryKey' => $stepID)));
            $step->priorStepID = $stepIDArray[$key];
            try {
                $step->save();
            } catch (Exception $e) {
                echo $e->getMessage();
            }
        }
    }
} catch (Exception $e) {
    echo $e->getMessage();
}