コード例 #1
0
ファイル: Habit.php プロジェクト: kevintokheim/lifecoach
 static function find($search_id)
 {
     $found_habit = null;
     $habits = Habit::getAll();
     foreach ($habits as $habit) {
         $habit_id = $habit->getId();
         if ($habit_id == $search_id) {
             $found_habit = $habit;
         }
     }
     return $found_habit;
 }
コード例 #2
0
ファイル: HabitTest.php プロジェクト: ashlinaronin/lifecoach
 function testDelete()
 {
     $name = "Meditate";
     $motivation = "Clarity";
     $interval_days = 3;
     $id = 4;
     $completed = False;
     $test_habit = new Habit($name, $motivation, $interval_days, $completed, $id);
     $test_habit->save();
     $name2 = "Go running";
     $motivation2 = "Fitness";
     $interval_days2 = 35;
     $id2 = 5;
     $completed2 = False;
     $test_habit2 = new Habit($name2, $motivation2, $interval_days2, $completed2, $id2);
     $test_habit2->save();
     $test_habit->delete();
     $this->assertEquals([$test_habit2], Habit::getAll());
 }
コード例 #3
0
ファイル: habit.php プロジェクト: r-hills/live_test
<?php

$habit = $app['controllers_factory'];
$habit->get('/current_habits', function () use($app) {
    $count = 0;
    return $app['twig']->render('habit/current_habits.html.twig', array('habits' => Habit::getAll()));
});
$habit->get('/habits/{id}', function ($id) use($app) {
    $habit = Habit::find($id);
    return $app['twig']->render('habit/habit_edit.html.twig', array('habit' => $habit));
});
$habit->patch('/habits/{id}', function ($id) use($app) {
    $habit = Habit::find($id);
    $name = $_POST['name'];
    $motivation = $_POST['motivation'];
    $interval_days = $_POST['interval_days'];
    $habit->updateName($name);
    $habit->updateMotivation($motivation);
    $habit->updateIntervalDays($interval_days);
    return $app['twig']->render('habit/habit_edit.html.twig', array('habit' => $habit));
});
$habit->delete('/habits/{id}', function ($id) use($app) {
    $habit = Habit::find($id);
    $habit->delete();
    return $app['twig']->render('habit/current_habits.html.twig', array('habits' => Habit::getAll()));
});
// Place all urls in this file at /habit/*
$app->mount('/habit', $habit);
コード例 #4
0
<?php

$coach_active_habit = $app['controllers_factory'];
$coach_active_habit->get('/progress/{id}', function ($id) use($app) {
    $habit = Habit::find($id);
    $days_complete = $habit->getDaysCompleted($habit->getId());
    return $app['twig']->render('coach/active_habit/1progress.html.twig', array('habit' => $habit, 'days' => $days_complete));
});
$coach_active_habit->post('/success/{id}', function ($id) use($app) {
    $habit = Habit::find($id);
    $habit->completeOnDayId($habit->getId());
    $days_complete = $habit->getDaysCompleted($habit->getId());
    return $app['twig']->render('coach/active_habit/2success.html.twig', array('habit' => $habit, 'days' => $days_complete));
});
$coach_active_habit->get('/fail/{id}', function ($id) use($app) {
    $habit = Habit::find($id);
    $motivation = $habit->getMotivation();
    $days_complete = $habit->getDaysCompleted($habit->getId());
    return $app['twig']->render('coach/active_habit/3failure.html.twig', array('habit' => $habit, 'motivation' => $motivation, 'days' => $days_complete));
});
// Place all urls in this file at /coach/active_habit/*
$app->mount('/coach/active_habit', $coach_active_habit);
コード例 #5
0
ファイル: HabitTest.php プロジェクト: r-hills/live_test
 function testGetActiveHabitCount2()
 {
     $name = "Meditate";
     $motivation = "Clarity";
     $interval_days = 5;
     $completed = False;
     $test_habit = new Habit($name, $motivation, $interval_days, $completed);
     $test_habit->save();
     $name2 = "Go running";
     $motivation2 = "Fitness";
     $interval_days2 = 35;
     $id2 = 5;
     $completed2 = False;
     $test_habit2 = new Habit($name2, $motivation2, $interval_days2, $completed2, $id2);
     $test_habit2->save();
     $result = Habit::getActiveHabitCount();
     $this->assertEquals(2, $result);
 }
コード例 #6
0
ファイル: Habit.php プロジェクト: r-hills/live_test
 function getDaysCompleted($habit_id)
 {
     $this_habit = Habit::find($habit_id);
     $days = $GLOBALS['DB']->query("SELECT day_id FROM daily_completed WHERE complete_today = true AND habit_id = {$habit_id};");
     $count = 0;
     foreach ($days as $day) {
         $count++;
     }
     return $count;
 }