Subversion Repositories SmartDukaan

Rev

Rev 15378 | 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
 
15767 anikendra 58
/**
59
 * hasMany associations
60
 *
61
 * @var array
62
 */
63
/*
64
	public $hasMany = array(
65
		'Order' => array(
66
			'className' => 'Order',
67
			'foreignKey' => 'store_id',
68
			'dependent' => false,
69
			'conditions' => '',
70
			'fields' => '',
71
			'order' => '',
72
			'limit' => '',
73
			'offset' => '',
74
			'exclusive' => '',
75
			'finderQuery' => '',
76
			'counterQuery' => ''
77
		),
78
		'StoreProduct' => array(
79
			'className' => 'StoreProduct',
80
			'foreignKey' => 'store_id',
81
			'dependent' => false,
82
			'conditions' => '',
83
			'fields' => '',
84
			'order' => '',
85
			'limit' => '',
86
			'offset' => '',
87
			'exclusive' => '',
88
			'finderQuery' => '',
89
			'counterQuery' => ''
90
		)
91
	);
92
*/
14428 anikendra 93
	public function getByUrl($url) {
14445 anikendra 94
		$domain = $this->get_domain($url);
14428 anikendra 95
		$this->recursive = -1;
96
		return $this->findByDomain($domain);
97
	}
14445 anikendra 98
 
99
	private function get_domain($url) {
100
		$pieces = parse_url($url);
101
		$domain = isset($pieces['host']) ? $pieces['host'] : '';
102
		if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
103
			return $regs['domain'];
104
		}
105
		return false;
106
	}
13532 anikendra 107
}