Last active
December 24, 2015 14:28
-
-
Save hugofabricio/6812344 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* TaskModel | |
* | |
*/ | |
define('UPLOAD_DIR', WWW_ROOT . 'img/tasks/'); | |
App::uses('AppModel', 'Model'); | |
App::uses('AttachmentBehavior', 'Uploader.Model/Behavior'); | |
class Task extends AppModel { | |
/** | |
* Nome | |
*/ | |
public $name = 'Task'; | |
/** | |
* Plugins | |
*/ | |
public $actsAs = array( | |
'Uploader.Attachment' => array( | |
'image' => array( | |
'uploadDir' => UPLOAD_DIR, | |
'nameCallback' => 'getName', | |
'overwrite' => true, | |
'transforms' => array( | |
array( | |
'method' => 'exif', | |
'self' => true | |
), | |
'image_small' => array( | |
'method' => AttachmentBehavior::CROP, | |
'nameCallback' => 'getName', | |
'append' => '-small', | |
'overwrite' => true, | |
'width' => 100, | |
'height' => 100 | |
) | |
) | |
) | |
), | |
'Uploader.FileValidation' => array( | |
'image' => array( | |
'extension' => array('gif', 'jpg', 'png', 'jpeg') | |
) | |
) | |
); | |
/** | |
* Gera slug do campo name | |
*/ | |
public function getName($name) { | |
return $this->formatName($this->data[$this->alias]['name']); | |
} | |
/** | |
* Validações | |
*/ | |
public $validate = array( | |
'name' => array( | |
'required' => array( | |
'rule' => array('notEmpty'), | |
'message' => 'Campo obrigatório.' | |
) | |
), | |
'deadline' => array( | |
'required' => array( | |
'rule' => array('notEmpty'), | |
'message' => 'Campo obrigatório.' | |
) | |
), | |
'details' => array( | |
'required' => array( | |
'rule' => array('notEmpty'), | |
'message' => 'Campo obrigatório.' | |
) | |
), | |
'is_active' => array( | |
'boolean' => array( | |
'rule' => array('boolean'), | |
'message' => 'Campo obrigatório.' | |
) | |
) | |
); | |
/** | |
* Métodos carregados antes de salvar | |
*/ | |
public function beforeSave($options = array()) { | |
// Seta a data | |
$this->data[$this->alias]['deadline'] = $this->dateFormat($this->data[$this->alias]['deadline']); | |
// Seta o slug | |
$this->data[$this->alias]['slug'] = $this->getName(); | |
parent::beforeSave($options); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment