06.27 php saved
davemo
Tags add more
 
Note
web_page.php model
  1. <?php
  2. class WebPage extends AppModel {
  3.  
  4.     const IS_ACTIVE = 1;
  5.     const IS_NOT_ACTIVE = 0;
  6.  
  7.     var $name = 'WebPage';
  8.     var $actsAs = array('Containable');
  9.    
  10.     var $validate = array(
  11.         'title' => array(
  12.             'validLength' => array(
  13.                 'rule' => array('between', 3, 25),
  14.                 'message' => 'Your title must be between 3 and 30 characters.'
  15.             ),
  16.             'invalidChars' => array(
  17.                 'rule' => array('validTitleChars'),
  18.                 'message' => 'Your title can not contain any of the following characters:  @ . : ; / \\ % _ '
  19.             ),
  20.             'isUnique' => array(
  21.                 'rule' => array('uniqueInSection'),
  22.                 'message' => 'This title has already been used within this section.'
  23.             )
  24.         ),
  25.         'section_id' => array(
  26.             'rule' => array('range', 0, 7))
  27.     );
  28.    
  29.     function validTitleChars( $data )  {
  30.         $valid = true;
  31.         //  QUOTATIONS!?
  32.         $badChars = array( '@', '.', ':', ';', '/', '\\', '%', '_' );
  33.         $title = strtolower( $this->data['WebPage']['title'] );
  34.         $i = count( $badChars );
  35.        
  36.         while( $valid && $i )
  37.             $valid = ( strpos( $title, $badChars[ $i-- - 1 ] ) === false );
  38.        
  39.         return( $valid );
  40.     }
  41.    
  42.     function uniqueInSection($data) {
  43.         $unique = false;
  44.         $parent_id = $this->data['WebPage']['parent_id'];
  45.         $title = $this->data['WebPage']['title'];
  46.        
  47.         if( ! ( $this->find( "WebPage.parent_id = $parent_id and WebPage.title like '$title'" ) ) )
  48.         {
  49.             $unique = true;
  50.         }
  51.        
  52.         return $unique;
  53.     }
  54.  
  55.     //The Associations below have been created with all possible keys, those that are not needed can be removed
  56.     var $belongsTo = array(
  57.             'Parent' => array('className' => 'WebPage',
  58.                                 'foreignKey' => 'parent_id',
  59.                                 'conditions' => '',
  60.                                 'fields' => '',
  61.                                 'order' => ''
  62.             ),
  63.             'User' => array('className' => 'User',
  64.                                 'foreignKey' => 'user_id',
  65.                                 'conditions' => '',
  66.                                 'fields' => '',
  67.                                 'order' => ''
  68.             ),
  69.             'WebPageType' => array('className' => 'WebPageType',
  70.                                 'foreignKey' => 'web_page_type_id',
  71.                                 'conditions' => '',
  72.                                 'fields' => '',
  73.                                 'order' => ''
  74.             ),
  75.             'Team' => array('className' => 'Team',
  76.                                 'foreignKey' => 'team_id',
  77.                                 'conditions' => '',
  78.                                 'fields' => '',
  79.                                 'order' => ''
  80.             ),
  81.             'Site' => array('className' => 'Site',
  82.                                 'foreignKey' => 'site_id',
  83.                                 'conditions' => '',
  84.                                 'fields' => '',
  85.                                 'order' => ''
  86.             )
  87.     );
  88.  
  89.     var $hasMany = array(
  90. /*      'Resource' => array('className' => 'Resource',
  91.                                 'foreignKey' => 'resource_id',
  92.                                 'dependent' => false,
  93.                                 'conditions' => '',
  94.                                 'fields' => '',
  95.                                 'order' => '',
  96.                                 'limit' => '',
  97.                                 'offset' => '',
  98.                                 'exclusive' => '',
  99.                                 'finderQuery' => '',
  100.                                 'counterQuery' => ''
  101.             ),*/
  102.             'Child' => array('className' => 'WebPage',
  103.                                 'foreignKey' => 'parent_id',
  104.                                 'dependent' => false,
  105.                                 'conditions' => '',
  106.                                 'fields' => '',
  107.                                 'order' => '',
  108.                                 'limit' => '',
  109.                                 'offset' => '',
  110.                                 'exclusive' => '',
  111.                                 'finderQuery' => '',
  112.                                 'counterQuery' => ''
  113.             )
  114.     );
  115.    
  116.     var $hasAndBelongsToMany = array( 'Resource' );
  117.    
  118.    
  119.    
  120.    
  121.  
  122. }
  123. ?>
Parsed in 0.253 seconds, using GeSHi 1.0.7.14

Modify this Paste