1
|
|
|
<?php defined('SYSPATH') OR die('No direct script access.'); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package openbuildings\promotions |
5
|
|
|
* @author Ivan Kerin <[email protected]> |
6
|
|
|
* @author Yasen Yanev <[email protected]> |
7
|
|
|
* @copyright (c) 2013 OpenBuildings Ltd. |
8
|
|
|
* @license http://spdx.org/licenses/BSD-3-Clause |
9
|
|
|
*/ |
10
|
|
|
class Kohana_Model_Promo_Code extends Jam_Model { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @codeCoverageIgnore |
14
|
|
|
*/ |
15
|
|
|
public static function initialize(Jam_Meta $meta) |
16
|
|
|
{ |
17
|
|
|
$meta |
18
|
|
|
->name_key('code') |
19
|
|
|
->unique_key(function($key){ |
|
|
|
|
20
|
|
|
return is_string($key) ? 'code' : 'id'; |
21
|
|
|
}) |
22
|
|
|
->behaviors(array( |
23
|
|
|
'tokenable' => Jam::behavior('tokenable', array( |
24
|
|
|
'field' => 'code', |
25
|
|
|
'uppercase' => TRUE, |
26
|
|
|
)), |
27
|
|
|
)) |
28
|
|
|
->associations(array( |
29
|
|
|
'purchases' => Jam::association('hasmany', array('inverse_of' => 'promo_code', 'foreign_model' => 'purchase')), |
30
|
|
|
'promotion' => Jam::association('belongsto', array('inverse_of' => 'promo_codes')) |
31
|
|
|
)) |
32
|
|
|
->fields(array( |
33
|
|
|
'id' => Jam::field('primary'), |
34
|
|
|
'origin' => Jam::field('string'), |
35
|
|
|
'allow_multiple' => Jam::field('boolean'), |
36
|
|
|
'created_at' => Jam::field('timestamp', array('auto_now_create' => TRUE, 'format' => 'Y-m-d H:i:s')), |
37
|
|
|
'expires_at' => Jam::field('timestamp', array('format' => 'Y-m-d H:i:s')) |
38
|
|
|
)) |
39
|
|
|
->validator('promotion', 'origin', array('present' => TRUE)); |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
public function validate_purchase(Model_Purchase $purchase) |
43
|
|
|
{ |
44
|
1 |
|
$this->get_insist('promotion')->validate_purchase($purchase); |
45
|
1 |
|
} |
46
|
|
|
|
47
|
4 |
|
public function is_expired() |
48
|
|
|
{ |
49
|
4 |
|
return (bool) $this->expires_at AND strtotime($this->expires_at) < time(); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: