Subversion Repositories SmartDukaan

Rev

Rev 14445 | 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
 
14428 anikendra 58
	public function getByUrl($url) {
14445 anikendra 59
		$domain = $this->get_domain($url);
14428 anikendra 60
		$this->recursive = -1;
61
		return $this->findByDomain($domain);
62
	}
14445 anikendra 63
 
64
	private function get_domain($url) {
65
		$pieces = parse_url($url);
66
		$domain = isset($pieces['host']) ? $pieces['host'] : '';
67
		if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
68
			return $regs['domain'];
69
		}
70
		return false;
71
	}
13532 anikendra 72
}