Subversion Repositories SmartDukaan

Rev

Rev 14434 | Rev 15378 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
App::uses('AppModel', 'Model');
3
/**
4
 * Store Model
5
 *
6
 * @property Order $Order
7
 * @property StoreProduct $StoreProduct
8
 */
9
class Store extends AppModel {
10
 
11
/**
12
 * Display field
13
 *
14
 * @var string
15
 */
16
	public $displayField = 'name';
17
 
18
/**
19
 * Validation rules
20
 *
21
 * @var array
22
 */
23
	public $validate = array(
24
		'name' => array(
25
			'notEmpty' => array(
26
				'rule' => array('notEmpty'),
27
				//'message' => 'Your custom message here',
28
				//'allowEmpty' => false,
29
				//'required' => false,
30
				//'last' => false, // Stop validation after this rule
31
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
32
			),
33
		),
13558 anikendra 34
		'domain' => array(
35
			'notEmpty' => array(
36
				'rule' => array('notEmpty'),
37
				//'message' => 'Your custom message here',
38
				//'allowEmpty' => false,
39
				//'required' => false,
40
				//'last' => false, // Stop validation after this rule
41
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
42
			),
43
		),
13532 anikendra 44
		'affiliate_id' => array(
45
			'notEmpty' => array(
46
				'rule' => array('notEmpty'),
47
				//'message' => 'Your custom message here',
48
				//'allowEmpty' => false,
49
				//'required' => false,
50
				//'last' => false, // Stop validation after this rule
51
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
52
			),
53
		),
54
	);
55
 
56
	//The Associations below have been created with all possible keys, those that are not needed can be removed
57
 
58
/**
59
 * hasMany associations
60
 *
61
 * @var array
62
 */
63
	public $hasMany = array(
64
		'Order' => array(
65
			'className' => 'Order',
66
			'foreignKey' => 'store_id',
67
			'dependent' => false,
68
			'conditions' => '',
69
			'fields' => '',
70
			'order' => '',
71
			'limit' => '',
72
			'offset' => '',
73
			'exclusive' => '',
74
			'finderQuery' => '',
75
			'counterQuery' => ''
76
		),
77
		'StoreProduct' => array(
78
			'className' => 'StoreProduct',
79
			'foreignKey' => 'store_id',
80
			'dependent' => false,
81
			'conditions' => '',
82
			'fields' => '',
83
			'order' => '',
84
			'limit' => '',
85
			'offset' => '',
86
			'exclusive' => '',
87
			'finderQuery' => '',
88
			'counterQuery' => ''
89
		)
90
	);
91
 
14428 anikendra 92
	public function getByUrl($url) {
14445 anikendra 93
		$domain = $this->get_domain($url);
14428 anikendra 94
		$this->recursive = -1;
95
		return $this->findByDomain($domain);
96
	}
14445 anikendra 97
 
98
	private function get_domain($url) {
99
		$pieces = parse_url($url);
100
		$domain = isset($pieces['host']) ? $pieces['host'] : '';
101
		if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
102
			return $regs['domain'];
103
		}
104
		return false;
105
	}
13532 anikendra 106
}