Skip to content

Commit

Permalink
Event#loadOrCreate needs to search for entry/exit pairs too
Browse files Browse the repository at this point in the history
  • Loading branch information
jwheare committed Mar 11, 2012
1 parent 3ef145a commit 487fce6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/model/event.class.php
Expand Up @@ -25,7 +25,27 @@ protected function afterLoad() {
public function isExit () {
return $this->action == 'Exit';
}
public function isEntry () {
return $this->action == 'Entry';
}
public function isJourney () {
return $this->action == 'Journey';
}
public function loadOrCreate() {
if ($this->load()) {
// Exact date and action match
return false;
}
if ($this->end_date) {
// Search for Entry and Exit pairs
$e = new self();
$keys = array('creation_date', 'action');
if ($e->totalBy($keys, array($this->creation_date, 'Entry'))
&& $e->totalBy($keys, array($this->end_date, 'Exit'))) {
return false;
}
}
$this->insert();
return true;
}
}

0 comments on commit 487fce6

Please sign in to comment.