Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- App::uses('AppModel', 'Model');
- /**
- * Veiculo Model
- *
- * @property Contrato $Contrato
- * @property Categoria $Categoria
- * @property Cor $Cor
- * @property Combustivel $Combustivel
- * @property Versao $Versao
- * @property Veiculo $Veiculo
- * @property Anuncio $Anuncio
- * @property Carro $Carro
- * @property Moto $Moto
- * @property Veiculo $Veiculo
- * @property Visita $Visita
- */
- class Veiculo extends AppModel {
- public $actsAs = array('Containable');
- public $displayField = 'placa';
- /**
- * Validation rules
- *
- * @var array
- */
- public $validate = array(
- 'categoria_id' => array(
- 'numeric' => array(
- 'rule' => array('numeric'),
- //'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
- ),
- ),
- 'cor_id' => array(
- 'numeric' => array(
- 'rule' => array('numeric'),
- //'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
- ),
- ),
- 'combustivel_id' => array(
- 'numeric' => array(
- 'rule' => array('numeric'),
- //'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
- ),
- ),
- 'versao_id' => array(
- 'numeric' => array(
- 'rule' => array('numeric'),
- //'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
- ),
- ),
- 'antigo' => array(
- 'boolean' => array(
- 'rule' => array('boolean'),
- //'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
- /**
- * belongsTo associations
- *
- * @var array
- */
- public $belongsTo = array(
- 'Categoria' => array(
- 'className' => 'Categoria',
- 'foreignKey' => 'categoria_id',
- 'conditions' => '',
- 'fields' => '',
- 'order' => ''
- ),
- 'Cor' => array(
- 'className' => 'Cor',
- 'foreignKey' => 'cor_id',
- 'conditions' => '',
- 'fields' => '',
- 'order' => ''
- ),
- 'Combustivel' => array(
- 'className' => 'Combustivel',
- 'foreignKey' => 'combustivel_id',
- 'conditions' => '',
- 'fields' => '',
- 'order' => ''
- ),
- 'Versao' => array(
- 'className' => 'Versao',
- 'foreignKey' => 'versao_id',
- 'conditions' => '',
- 'fields' => '',
- 'order' => ''
- ),
- 'Parent' => array(
- 'className' => 'Veiculo',
- 'foreignKey' => 'veiculo_id',
- 'conditions' => '',
- 'fields' => '',
- 'order' => ''
- )
- );
- /**
- * hasMany associations
- *
- * @var array
- */
- public $hasMany = array(
- 'Anuncio' => array(
- 'className' => 'Anuncio',
- 'foreignKey' => 'foreign_key',
- 'dependent' => false,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'exclusive' => '',
- 'finderQuery' => '',
- 'counterQuery' => ''
- ),
- 'Child' => array(
- 'className' => 'Veiculo',
- 'foreignKey' => 'veiculo_id',
- 'dependent' => false,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'exclusive' => '',
- 'finderQuery' => '',
- 'counterQuery' => ''
- ),
- 'Visita' => array(
- 'className' => 'Visita',
- 'foreignKey' => 'veiculo_id',
- 'dependent' => false,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'exclusive' => '',
- 'finderQuery' => '',
- 'counterQuery' => ''
- )
- );
- public $hasOne = array(
- 'Carro' => array(
- 'className' => 'Carro',
- 'foreignKey' => 'veiculo_id',
- 'dependent' => false,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'exclusive' => '',
- 'finderQuery' => '',
- 'counterQuery' => ''
- ),
- 'Moto' => array(
- 'className' => 'Moto',
- 'foreignKey' => 'veiculo_id',
- 'dependent' => true,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'exclusive' => '',
- 'finderQuery' => '',
- 'counterQuery' => ''
- ),
- 'Nautica' => array(
- 'className' => 'Nautica',
- 'foreignKey' => 'veiculo_id',
- 'dependent' => false,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'exclusive' => '',
- 'finderQuery' => '',
- 'counterQuery' => ''
- ),
- 'Tunado' => array(
- 'className' => 'Tunado',
- 'foreignKey' => 'veiculo_id',
- 'dependent' => false,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'exclusive' => '',
- 'finderQuery' => '',
- 'counterQuery' => ''
- ),
- 'Raridade' => array(
- 'className' => 'Raridade',
- 'foreignKey' => 'veiculo_id',
- 'dependent' => false,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'exclusive' => '',
- 'finderQuery' => '',
- 'counterQuery' => ''
- ),
- 'CaminhoesOnibus' => array(
- 'className' => 'CaminhoesOnibus',
- 'foreignKey' => 'veiculo_id',
- 'dependent' => false,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'exclusive' => '',
- 'finderQuery' => '',
- 'counterQuery' => ''
- )
- );
- public $hasAndBelongsToMany = array(
- 'Opcional' => array(
- 'className' => 'Opcional',
- 'joinTable' => 'veiculos_opcionais',
- 'foreignKey' => 'veiculo_id',
- 'associationForeignKey' => 'opcional_id',
- 'unique' => true,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'finderQuery' => '',
- 'deleteQuery' => '',
- 'insertQuery' => ''
- ),
- /*'BuscaIndice' => array(
- 'className' => 'BuscaIndex',
- 'joinTable' => 'busca_indices_veiculos',
- 'foreignKey' => 'veiculo_id',
- 'associationForeignKey' => 'busca_indice_id',
- 'unique' => true,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'finderQuery' => '',
- 'deleteQuery' => '',
- 'insertQuery' => ''
- )*/
- );
- public function findLimitesAnoModelo($conditions = null){
- $limitesAnoModelo = $this->find('first',array(
- 'fields' => array(
- 'MIN(Veiculo.ano_modelo) AS inferior',
- 'MAX(Veiculo.ano_modelo) AS superior',
- ),
- 'conditions' => $conditions
- ));
- return $limitesAnoModelo[0];
- }
- public function findLimitesPreco($conditions = null){
- $limitesPreco = $this->find('first',array(
- 'fields' => array(
- 'MIN(Veiculo.preco) AS inferior',
- 'MAX(Veiculo.preco) AS superior',
- ),
- 'conditions'
- ));
- return $limitesPreco[0];
- }
- public function getBuscaRapida($model = false){
- $padraoGeral = array(
- 'categorias' => $this->Categoria->find('list',array(
- 'fields'=>array('Categoria.id','Categoria.nome'),
- 'conditions' => array('Categoria.ativo' => true, 'OR'=>array('Categoria.model' =>array('carros','motos','nautica','caminhoes_onibus'))),
- 'order' => 'nome ASC'
- )),
- 'limitesAnoModelo' => $this->findLimitesAnoModelo(),
- 'combustiveis' => $this->Combustivel->find('list',array(
- 'fields' => array('Combustivel.id','Combustivel.nome'),
- 'conditions' => array('Combustivel.ativo'=>true)
- )),
- 'cores' => $this->Cor->find('list',array(
- 'fields' => array('Cor.id','Cor.nome'),
- 'conditions' => array('Cor.ativo' => true)
- )),
- 'limitesPreco' => $this->findLimitesPreco(),
- 'limitesAnoModelo' => $this->findLimitesAnoModelo()
- );
- switch($model){
- case 'carros':
- $buscas = $this->Carro->getBuscaRapida();
- break;
- case 'caminhoes_onibus':
- $buscas = $this->CaminhoesOnibus->getBuscaRapida();
- break;
- case 'nautica':
- $buscas = $this->Nautica->getBuscaRapida();
- break;
- case 'motos':
- $buscas = $this->Moto->getBuscaRapida();
- break;
- case 'tunados':
- $buscas = $this->Tunado->getBuscaRapida();
- break;
- default:
- return $padraoGeral;
- }
- $resultado = array_merge($padraoGeral,$buscas);
- return $resultado;
- }
- }
Add Comment
Please, Sign In to add comment