Subversion Repositories SmartDukaan

Rev

Rev 14445 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
App::uses('AppModel', 'Model');
/**
 * Store Model
 *
 * @property Order $Order
 * @property StoreProduct $StoreProduct
 */
class Store extends AppModel {

/**
 * Display field
 *
 * @var string
 */
        public $displayField = 'name';

/**
 * Validation rules
 *
 * @var array
 */
        public $validate = array(
                'name' => array(
                        'notEmpty' => array(
                                'rule' => array('notEmpty'),
                                //'message' => 'Your custom message here',
                                //'allowEmpty' => false,
                                //'required' => false,
                                //'last' => false, // Stop validation after this rule
                                //'on' => 'create', // Limit validation to 'create' or 'update' operations
                        ),
                ),
                'domain' => array(
                        'notEmpty' => array(
                                'rule' => array('notEmpty'),
                                //'message' => 'Your custom message here',
                                //'allowEmpty' => false,
                                //'required' => false,
                                //'last' => false, // Stop validation after this rule
                                //'on' => 'create', // Limit validation to 'create' or 'update' operations
                        ),
                ),
                'affiliate_id' => array(
                        'notEmpty' => array(
                                'rule' => array('notEmpty'),
                                //'message' => 'Your custom message here',
                                //'allowEmpty' => false,
                                //'required' => false,
                                //'last' => false, // Stop validation after this rule
                                //'on' => 'create', // Limit validation to 'create' or 'update' operations
                        ),
                ),
        );

        //The Associations below have been created with all possible keys, those that are not needed can be removed

        public function getByUrl($url) {
                $domain = $this->get_domain($url);
                $this->recursive = -1;
                return $this->findByDomain($domain);
        }

        private function get_domain($url) {
                $pieces = parse_url($url);
                $domain = isset($pieces['host']) ? $pieces['host'] : '';
                if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
                        return $regs['domain'];
                }
                return false;
        }
}