1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CakePHPify : CakePHP Plugin for Shopify API Authentication |
4
|
|
|
* Copyright (c) Multidimension.al (http://multidimension.al) |
5
|
|
|
* Github : https://github.com/multidimension-al/cakephpify |
6
|
|
|
* |
7
|
|
|
* Licensed under The MIT License |
8
|
|
|
* For full copyright and license information, please see the LICENSE file |
9
|
|
|
* Redistributions of files must retain the above copyright notice. |
10
|
|
|
* |
11
|
|
|
* @copyright (c) Multidimension.al (http://multidimension.al) |
12
|
|
|
* @link https://github.com/multidimension-al/cakephpify CakePHPify Github |
13
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Multidimensional\Shopify\Model\Table; |
17
|
|
|
|
18
|
|
|
use Cake\ORM\Query; |
19
|
|
|
use Cake\ORM\RulesChecker; |
20
|
|
|
use Cake\ORM\Table; |
21
|
|
|
use Cake\Validation\Validator; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* AccessTokens Model |
25
|
|
|
* |
26
|
|
|
* @method \Shopify\Model\Entity\AccessToken get($primaryKey, $options = []) |
27
|
|
|
* @method \Shopify\Model\Entity\AccessToken newEntity($data = null, array $options = []) |
28
|
|
|
* @method \Shopify\Model\Entity\AccessToken[] newEntities(array $data, array $options = []) |
29
|
|
|
* @method \Shopify\Model\Entity\AccessToken|bool save(\Cake\Datasource\EntityInterface $entity, $options = []) |
30
|
|
|
* @method \Shopify\Model\Entity\AccessToken patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) |
31
|
|
|
* @method \Shopify\Model\Entity\AccessToken[] patchEntities($entities, array $data, array $options = []) |
32
|
|
|
* @method \Shopify\Model\Entity\AccessToken findOrCreate($search, callable $callback = null) |
33
|
|
|
*/ |
34
|
|
|
class AccessTokensTable extends Table { |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Initialize method |
38
|
|
|
* |
39
|
|
|
* @param array $config The configuration for the Table. |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
30 |
|
public function initialize(array $config) { |
43
|
30 |
|
parent::initialize($config); |
44
|
|
|
|
45
|
|
|
//$this->table('access_tokens'); |
46
|
30 |
|
$this->displayField('token'); |
47
|
|
|
//$this->primaryKey('id'); |
48
|
|
|
|
49
|
30 |
|
$this->belongsTo('Shops', [ |
50
|
30 |
|
'className' => 'Multidimensional/Shopify.Shops']); |
51
|
30 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Default validation rules. |
55
|
|
|
* |
56
|
|
|
* @param \Cake\Validation\Validator $validator Validator instance. |
57
|
|
|
* @return \Cake\Validation\Validator |
58
|
|
|
*/ |
59
|
|
|
public function validationDefault(Validator $validator) { |
60
|
|
|
$validator |
61
|
|
|
->integer('id') |
62
|
|
|
->allowEmpty('id', 'create'); |
63
|
|
|
|
64
|
|
|
$validator |
65
|
|
|
->requirePresence('api_key', 'create') |
66
|
|
|
->notEmpty('api_key'); |
67
|
|
|
|
68
|
|
|
$validator |
69
|
|
|
->requirePresence('shop_id', 'create') |
70
|
|
|
->notEmpty('shop_id'); |
71
|
|
|
|
72
|
|
|
$validator |
73
|
|
|
->requirePresence('token', 'create') |
74
|
|
|
->notEmpty('token') |
75
|
|
|
->add('token', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']); |
76
|
|
|
|
77
|
|
|
$validator |
78
|
|
|
->dateTime('created_at') |
79
|
|
|
->requirePresence('created_at', 'create') |
80
|
|
|
->notEmpty('created_at'); |
81
|
|
|
|
82
|
|
|
$validator |
83
|
|
|
->dateTime('updated_at') |
84
|
|
|
->requirePresence('updated_at', 'create') |
85
|
|
|
->notEmpty('updated_at'); |
86
|
|
|
|
87
|
|
|
$validator |
88
|
|
|
->dateTime('expired_at') |
89
|
|
|
->allowEmpty('expired_at'); |
90
|
|
|
|
91
|
|
|
return $validator; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Returns a rules checker object that will be used for validating |
96
|
|
|
* application integrity. |
97
|
|
|
* |
98
|
|
|
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. |
99
|
|
|
* @return \Cake\ORM\RulesChecker |
100
|
|
|
*/ |
101
|
|
|
public function buildRules(RulesChecker $rules) { |
102
|
|
|
$rules->add($rules->isUnique(['token'])); |
103
|
|
|
|
104
|
|
|
return $rules; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|