Guest User

Untitled

a guest
Aug 13th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.86 KB | None | 0 0
  1. <?php
  2. App::uses('AppModel', 'Model');
  3. /**
  4.  * Guestbook Model
  5.  *
  6.  * @property Comments $comments
  7.  */
  8. class Guestbook extends AppModel {
  9.  
  10. /**
  11.  * Display field
  12.  *
  13.  * @var string
  14.  */
  15.   public $displayField = 'name';
  16.  
  17. /**
  18.  * Validation rules
  19.  *
  20.  * @var array
  21.  */
  22.   public $validate = array(
  23.     'name' => array(
  24.       'notempty' => array(
  25.         'rule' => array('notempty'),
  26.         'message' => 'Veuillez saisir votre nom',
  27.         //'allowEmpty' => false,
  28.         //'required' => false,
  29.         //'last' => false, // Stop validation after this rule
  30.         //'on' => 'create', // Limit validation to 'create' or 'update' operations
  31.       ),
  32.     ),
  33.     'slug' => array(
  34.     ),
  35.     'content' => array(
  36.       'notempty' => array(
  37.         'rule' => array('notempty'),
  38.         'message' => 'Vous devez saisir un message',
  39.         //'allowEmpty' => false,
  40.         //'required' => false,
  41.         //'last' => false, // Stop validation after this rule
  42.         //'on' => 'create', // Limit validation to 'create' or 'update' operations
  43.       ),
  44.     ),
  45.     'email' => array(
  46.       'email' => array(
  47.         'rule' => array('email'),
  48.         'message' => 'Veuillez saisir un email valide',
  49.         'allowEmpty' => true,
  50.         //'required' => false,
  51.         //'last' => false, // Stop validation after this rule
  52.         //'on' => 'create', // Limit validation to 'create' or 'update' operations
  53.       ),
  54.     ),
  55.     'created' => array(
  56.       'datetime' => array(
  57.         'rule' => array('datetime'),
  58.         //'message' => 'Your custom message here',
  59.         //'allowEmpty' => false,
  60.         //'required' => false,
  61.         //'last' => false, // Stop validation after this rule
  62.         //'on' => 'create', // Limit validation to 'create' or 'update' operations
  63.       ),
  64.     ),
  65.     'online' => array(
  66.       'boolean' => array(
  67.         'rule' => array('boolean'),
  68.         //'message' => 'Your custom message here',
  69.         //'allowEmpty' => false,
  70.         //'required' => false,
  71.         //'last' => false, // Stop validation after this rule
  72.         //'on' => 'create', // Limit validation to 'create' or 'update' operations
  73.       ),
  74.     ),
  75.     'clientip' => array(
  76.       'ip' => array(
  77.         'rule' => array('ip'),
  78.         //'message' => 'Your custom message here',
  79.         'allowEmpty' => true,
  80.         'required' => false,
  81.         //'last' => false, // Stop validation after this rule
  82.         //'on' => 'create', // Limit validation to 'create' or 'update' operations
  83.       ),
  84.     ),
  85.   );
  86.  
  87.   //The Associations below have been created with all possible keys, those that are not needed can be removed
  88.  
  89. /**
  90.  * hasMany associations
  91.  *
  92.  * @var array
  93.  */
  94.   public $hasMany = array(
  95.     'Comments' => array(
  96.       'className' => 'Comments',
  97.       'foreignKey' => 'guestbook_id',
  98.       'dependent' => false,
  99.       'conditions' => '',
  100.       'fields' => '',
  101.       'order' => '',
  102.       'limit' => '',
  103.       'offset' => '',
  104.       'exclusive' => '',
  105.       'finderQuery' => '',
  106.       'counterQuery' => ''
  107.     )
  108.   );
  109.  
  110.   public function afterFind($data,$primary = bool){
  111.         foreach($data as $k=>$d){
  112.             if(isset($d['Guestbook']['slug']) && isset($d['Guestbook']['id'])){
  113.                 $d['Guestbook']['link'] = array(
  114.                     'controller'    => 'guestbooks',
  115.                     'action'        => 'show',
  116.                     'id'            => $d['Guestbook']['id'],
  117.                     'slug'          => $d['Guestbook']['slug']
  118.                 );
  119.             }
  120.             $data[$k] = $d;
  121.         }
  122.         return $data;
  123.     }
  124.  
  125.   public function beforeSave($options = array()){
  126.         if(empty($this->data['Guestbook']['slug']) && !empty($this->data['Guestbook']['name']))
  127.             $this->data['Guestbook']['slug'] = strtolower(Inflector::slug($this->data['Guestbook']['name'],'-'));
  128.         return true;
  129.     }
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment