Skip to content

Commit

Permalink
Dev Fixed issue where vendorspecific SQL was used.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Oct 14, 2013
1 parent cf1a19d commit b598e38
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions application/models/Token.php
Expand Up @@ -137,17 +137,19 @@ public function rules()

public function scopes()
{
return array(
'incomplete' => array(
'condition' => 'completed = "N"'
),
'usable' => array(
'condition' => 'usesleft > 0 AND COALESCE(validuntil, NOW()) >= NOW() AND COALESCE(validfrom, NOW()) <= NOW()'
),
'editable' => array(
'condition' => 'COALESCE(validuntil, NOW()) >= NOW() AND COALESCE(validfrom, NOW()) <= NOW()'
$now = date('Y-m-d H:i:s');

return array(
'incomplete' => array(
'condition' => 'completed = "N"'
),
array(
'condition' => "COALESCE(validuntil, '$now') >= '$now' AND COALESCE(validfrom, '$now') <= '$now'"
),
array(
'condition' => "usesleft > 0 AND COALESCE(validuntil, '$now') >= '$now' AND COALESCE(validfrom, '$now') <= '$now'"
)
);
);
}
public function summary()
{
Expand All @@ -167,7 +169,6 @@ public function tableName()
{
return '{{tokens_' . $this->id . '}}';
}

}

?>

1 comment on commit b598e38

@c-schmitz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elegant enough ;)

Please sign in to comment.