Skip to content

Commit

Permalink
Change to controller were forgotten in previous commit #58
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuNls committed Jan 29, 2016
1 parent b7625d5 commit d78f96e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 54 deletions.
56 changes: 20 additions & 36 deletions application/controllers/Measures.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,15 @@ public function new_measure() {

$this->event->add(MEASURE_LOAD);

array_push($this->_headerData['javaScripts'], "watch.animation",
"time",
"input.time.logic"
);

$this->_headerData['headerClass'] = 'blue';
$this->load->view('header', $this->_headerData);

$this->load->view('measure/new-measure', $this->_bodyData);
$this->load->view('measure/audio.php');

$this->load->view('footer');
}
Expand Down Expand Up @@ -239,14 +243,16 @@ public function get_accuracy() {
$this->event->add(ACCURACY_LOAD);

$this->_headerData['headerClass'] = 'blue';
array_push($this->_headerData['javaScripts'], "watch.animation");
array_push($this->_headerData['javaScripts'], "watch.animation",
"time",
"input.time.logic"
);
$this->load->view('header', $this->_headerData);

$this->_bodyData['selectedWatch'] = $this->watch->getWatch($this->input->post('watchId'));
$this->_bodyData['measureId'] = $this->input->post('measureId');

$this->load->view('measure/get-accuracy', $this->_bodyData);
$this->load->view('measure/audio.php');

$this->load->view('footer');

Expand All @@ -255,15 +261,6 @@ public function get_accuracy() {
}
}

/**
* getReferenceTime. Set the server time to the user session.
*
* This must to be call by the user before accuracyMeasure or baseMeasure
*/
function getReferenceTime() {
$this->session->set_userdata('referenceTime', time());
}

/**
* Save the base measure (1/2)
*
Expand All @@ -278,21 +275,14 @@ function getReferenceTime() {
*/
function baseMeasure() {

if ($this->expectsPost(array('watchId', 'userTimezone', 'userTime'))) {

$result = array();

$watchId = $this->input->post('watchId');

//Construct user time
$referenceTime = $this->session->userdata('referenceTime');
$userTimezone = $this->input->post('userTimezone');
$tempUserTime = preg_split('/:/', $this->input->post('userTime'));
$userTime = mktime($tempUserTime[0], $tempUserTime[1],
$tempUserTime[2], date("n"), date("j"), date("Y"));
if ($this->expectsPost(array('watchId', 'referenceTimestamp', 'userTimestamp'))) {

//Add the base measure
if ($this->measure->addBaseMesure($watchId, $referenceTime, $userTime)) {
if ($this->measure->addBaseMesure(
$this->watchId,
$this->referenceTimestamp/1000,
$this->userTimestamp/1000)
) {

$result['success'] = true;

Expand All @@ -311,8 +301,6 @@ function baseMeasure() {
* TODO: When this becomes doable from many endpoints (web, mobile, ...)
* I'll to move it to the model.
*
* FIXME: userTimezone parameter isn't used. Should it ?
*
* @param POST String measureId
* @param POST String userTimezone
* @param POST String userTime
Expand All @@ -321,18 +309,14 @@ function baseMeasure() {
*/
function accuracyMeasure() {

if ($this->expectsPost(array('measureId', 'userTimezone', 'userTime'))) {

//Construct the user time
$referenceTime = $this->session->userdata('referenceTime');
$userTimezone = $this->input->post('userTimezone');
$tempUserTime = preg_split('/:/', $this->input->post('userTime'));
$userTime = mktime($tempUserTime[0], $tempUserTime[1], $tempUserTime[2],
date("n"), date("j"), date("Y"));
if ($this->expectsPost(array('measureId', 'referenceTimestamp', 'userTimestamp'))) {

//Add the watch measure
$watchMeasure = $this->measure->addAccuracyMesure(
$this->input->post('measureId'), $referenceTime, $userTime);
$this->measureId,
$this->referenceTimestamp,
$this->userTimestamp
);

// If the computed accuracy makes sense, we return success
if (is_numeric($watchMeasure->accuracy)) {
Expand Down
24 changes: 6 additions & 18 deletions application/tests/controllers/Measures_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function test_newWatch(){

public function test_newMeasure(){
$output = $this->request('GET', ['Measures', 'new_measure']);
$this->assertContains('<h1>New measure</h1>', $output);
$this->assertContains('<h1>New measure', $output);
}

public function test_getAccuracyFail(){
Expand All @@ -135,17 +135,7 @@ public function test_getAccuracy(){
]
);

$this->assertContains('<h1 id="mainTitle">Check the accuracy</h1>', $output);
}

public function test_getReferenceTime() {
$CI = &get_instance();
$CI->load->model('User');
$CI->load->library('Session');

$output = $this->request('GET', ['Measures', 'getReferenceTime']);

$this->assertEquals($CI->session->userdata('referenceTime'), time());
$this->assertContains('<h1 id="mainTitle">Check the accuracy', $output);
}

public function test_baseMesure() {
Expand All @@ -171,8 +161,8 @@ public function test_baseMesure() {
['Measures', 'baseMeasure'],
[
'watchId' => self::$watchId,
'userTime' => '10:13:12',
'userTimezone' => '5'
'referenceTimestamp' => microtime(),
'userTimestamp' => microtime()
]
);

Expand All @@ -186,15 +176,13 @@ public function test_accuracyMeasure() {

$measure = $CI->Measure->find_by('watchId', self::$watchId);

$CI->session->set_userdata('referenceTime', time());

$output = $this->request(
'POST',
['Measures', 'accuracyMeasure'],
[
'measureId' => $measure->id,
'userTime' => '10:16:12',
'userTimezone' => '5'
'referenceTimestamp' => microtime(),
'userTimestamp' => microtime()
]
);

Expand Down

0 comments on commit d78f96e

Please sign in to comment.