Skip to content

Commit

Permalink
fix many interpretor errors #35
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuNls committed Nov 23, 2015
1 parent 0873072 commit a656397
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions application/models/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,14 @@ public function cronCheck($time = null) {
$this->userWithWatchWithoutMeasure($time, $emailsWatchSent);
$this->userWithOneCompleteMeasureAndOneWatch($time, $emailsUserSent);
$this->checkAccuracy($time, $emailsMeasureSent);
$this->checkAccuracyOneWeek($time, $emailsMeasureSent);
$this->startANewMeasure($time, $emailsWatchSent);
// $this->checkAccuracyOneWeek($time, $emailsMeasureSent);
// $this->startANewMeasure($time, $emailsWatchSent);

return array(
'users' => $emailsUserSent,
'watches' => $emailsWatchSent,
'measures' => $emailsMeasureSent
);
}

private function sendMandrillEmail($subject, $content, $recipientName,
Expand Down Expand Up @@ -105,8 +110,8 @@ private function sendAtString($scheduleTime) {
}

private function whereNotAlreadySentUser($emailType) {
return $this->where('(select count(1) from email_user where user.userId '.
'= email_user.userId and emailType = '.$emailType.')', 0);
return '(select count(1) from email_user where user.userId '.
'= email_user.userId and emailType = '.$emailType.') = ';
}

private function whereNotAlreadySentWatch($emailType) {
Expand All @@ -122,7 +127,7 @@ private function whereNotAlreadySentMeasure($emailType) {
private function addEmailToQueue($queue, $userId, $emailType, $time) {
array_push($queue,
array(
'userId' => $user->userId,
'userId' => $userId,
'sendTime' => $time,
'emailType' => $emailType,
)
Expand All @@ -134,7 +139,7 @@ private function inactiveUser($time, $queuedEmail) {
->user
->select()
->where('lastLogin <=', $time-$this->day*100)
->whereNotAlreadySentUser($this->COMEBACK)
->where($this->whereNotAlreadySentUser($this->COMEBACK), 0, false)
->find_all();

if ($inactiveUsers !== FALSE) {
Expand Down Expand Up @@ -162,17 +167,17 @@ private function userWithoutWatch($time, $queuedEmail) {

$userWithoutWatch = $this
->user
->select('user.name, firstname, email')
->where('(select count(1) from watch where user.userId = watch.userId)', 0)
->whereNotAlreadySentUser($this->ADD_FIRST_WATCH)
->select('user.userId, user.name, firstname, email')
->where('(select count(1) from watch where user.userId = watch.userId) =', 0)
->where($this->whereNotAlreadySentUser($this->ADD_FIRST_WATCH), 0, false)
->where('lastLogin <=', $time-$this->day)
->find_all();

if ($userWithoutWatch !== FALSE) {
foreach ($userWithoutWatch as $user) {
$this->sendMandrillEmail(
'Let’s add a watch and start measuring! ⌚',
$this->load->view('email/add-first-watch-email', $user, true),
$this->load->view('email/add-first-watch', $user, true),
$user->name.' '.$user->firstname,
$user->email,
'add_first_watch_email',
Expand All @@ -194,9 +199,9 @@ private function userWithWatchWithoutMeasure($time, $queuedEmail) {
->watch
->select('user.name, user.firstname, email')
->join('user', 'watch.userId = user.userId')
->where('select count(1) from measure where watch.watchId = measure.watchId', 0)
->where('(select count(1) from measure where watch.watchId = measure.watchId) = ', 0)
->where('creationDate <=', $time-$this->day)
->whereNotAlreadySentWatch($this->START_FIRST_MEASURE)
->where($this->whereNotAlreadySentUser($this->START_FIRST_MEASURE), 0, false)
->find_all();

if ($userWithWatchWithoutMeasure !== FALSE) {
Expand Down Expand Up @@ -229,14 +234,14 @@ private function userWithOneCompleteMeasureAndOneWatch($time, $queuedEmail) {

$userWithOneCompleteMeasureAndOneWatch = $this
->user
->select('user.name, firstname, email')
->where('(select count(1) from watch where user.userId = watch.userId)', 1)
->select('user.userId, user.name, firstname, email')
->where('(select count(1) from watch where user.userId = watch.userId) = ', 1)
->where('(select count(1) from measure
join watch on measure.watchId = watch.watchId
where user.userId = watch.userId
and measure.status = 2
and measure.accuracyUserTime <= '.$twoDays.')')
->whereNotAlreadySentUser($this->ADD_SECOND_WATCH)
and measure.statusId = 2
and measure.accuracyUserTime) <= ', $twoDays)
->where($this->whereNotAlreadySentUser($this->ADD_SECOND_WATCH), 0, false)
->find_all();

if ($userWithOneCompleteMeasureAndOneWatch !== FALSE) {
Expand Down Expand Up @@ -265,20 +270,27 @@ private function userWithOneCompleteMeasureAndOneWatch($time, $queuedEmail) {
private function checkAccuracy($time, $queuedEmail) {
$measureWithoutAccuracy = $this
->measure
->select('user.name, user.firstname, email')
->select('user.userId, user.name, user.firstname, email')
->join('watch', 'watch.watchId = measure.watchId')
->join('user', 'watch.userId = user.userId')
->where('statusId', 1)
->where('measureReferenceTime <=', $time-$this->day)
->whereNotAlreadySentMeasure($this->CHECK_ACCURACY)
->where($this->whereNotAlreadySentUser($this->CHECK_ACCURACY), 0, false)
->as_array()
->find_all();

if ($measureWithoutAccuracy !== FALSE) {

if(!is_array($measureWithoutAccuracy)){
$measureWithoutAccuracy = array($measureWithoutAccuracy);
}

$this->__->groupBy($measureWithoutAccuracy, 'email');

foreach ($measureWithoutAccuracy as $user) {

$user = (object) $user;

$this->sendMandrillEmail(
'Let’s check your watch accuracy! ⌚',
$this->load->view('email/remind-check-accuracy', $user, true),
Expand All @@ -301,7 +313,7 @@ private function checkAccuracy($time, $queuedEmail) {
private function checkAccuracyOneWeek($time, $queuedEmail) {
$measureWithoutAccuracy = $this
->measure
->select('user.name, user.firstname, email')
->select('user.userId, user.name, user.firstname, email')
->join('watch', 'watch.watchId = measure.watchId')
->join('user', 'watch.userId = user.userId')
->where('statusId', 1)
Expand Down Expand Up @@ -337,7 +349,7 @@ private function checkAccuracyOneWeek($time, $queuedEmail) {
private function startANewMeasure($time, $queuedEmail) {
$userWithWatchWithoutMeasure = $this
->measure
->select('user.name, user.firstname, email')
->select('user.userId, user.name, user.firstname, email')
->join('watch', 'watch.watchId = measure.watchId')
->join('user', 'watch.userId = user.userId')
->where('statusId', 2)
Expand Down

0 comments on commit a656397

Please sign in to comment.