Kohana_Model_Collection_Promo_Code::available()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php defined('SYSPATH') OR die('No direct script access.');
2
3
/**
4
 * @package    openbuildings\promotions
5
 * @author     Ivan Kerin <[email protected]>
6
 * @copyright  (c) 2013 OpenBuildings Ltd.
7
 * @license    http://spdx.org/licenses/BSD-3-Clause
8
 */
9
class Kohana_Model_Collection_Promo_Code extends Jam_Query_Builder_Collection {
10
11 1
	public function not_expired($current_time = NULL)
12
	{
13
		return $this
14 1
			->where_open()
15 1
				->where('expires_at', '=', NULL)
16 1
				->or_where('expires_at', '>=', date('Y-m-d H:i:s', $current_time ?: time()))
17 1
			->where_close();
18
	}
19
20 1
	public function available()
21
	{
22
		return $this
23 1
			->join('purchases', 'LEFT')
24 1
			->where_open()
25 1
				->where('allow_multiple', '=', TRUE)
26 1
				->or_where('purchase.id', '=', NULL)
27 1
			->where_close();
28
	}
29
30 1
	public function available_for_purchase(Model_Purchase $purchase)
31
	{
32
		return $this
33 1
			->join('purchases', 'LEFT')
34 1
			->where_open()
35 1
				->where('allow_multiple', '=', TRUE)
36 1
				->or_where('purchase.id', '=', NULL)
37 1
				->or_where('purchase.id', '=', $purchase->id())
38 1
			->where_close();
39
	}
40
}
41