BasicRelationsMain.php
Current file: /home/magister/git/yii-example/example/protected/models/BasicRelationsMain.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
100.00% 1 / 1
100.00% 10 / 10 CRAP
100.00% 40 / 40
BasicRelationsMain
100.00% 1 / 1
100.00% 10 / 10 13
100.00% 40 / 40
 model($className=__CLASS__)
100.00% 1 / 1 1
100.00% 1 / 1
 tableName()
100.00% 1 / 1 1
100.00% 1 / 1
 rules()
100.00% 1 / 1 1
100.00% 7 / 7
 relations()
100.00% 1 / 1 1
100.00% 5 / 5
 many_many_map ()
100.00% 1 / 1 1
100.00% 3 / 3
 attributeLabels()
100.00% 1 / 1 1
100.00% 4 / 4
 search()
100.00% 1 / 1 1
100.00% 7 / 7
 validBelongsToID ($attribute, $params)
100.00% 1 / 1 4
100.00% 9 / 9
 getMagic_Attribute_Many_Many_Selected ()
100.00% 1 / 1 1
100.00% 1 / 1
 setMagic_Attribute_Many_Many_Selected ($selected_list)
100.00% 1 / 1 1
100.00% 2 / 2


       1                 : <?php                                                                                                                                                                                       
       2                 :                                                                                                                                                                                             
       3                 : /**                                                                                                                                                                                         
       4                 :  * This is the model class for table "tbl_basic_relations_main".                                                                                                                            
       5                 :  *                                                                                                                                                                                          
       6                 :  * The followings are the available columns in table 'tbl_basic_relations_main':                                                                                                            
       7                 :  * @property integer $id                                                                                                                                                                    
       8                 :  * @property integer $column_belongs_to_id                                                                                                                                                  
       9                 :  * @property string $column_main_content                                                                                                                                                    
      10                 :  */                                                                                                                                                                                         
      11                 : class BasicRelationsMain extends RelationsActiveRecord {                                                                                                                                    
      12                 :     /**                                                                                                                                                                                     
      13                 :      * Returns the static model of the specified AR class.                                                                                                                                  
      14                 :      * @return BasicRelationsMain the static model class                                                                                                                                    
      15                 :      */                                                                                                                                                                                     
      16                 :     public static function model($className=__CLASS__) {                                                                                                                                    
      17               3 :         return parent::model($className);                                                                                                                                                   
      18                 :     }                                                                                                                                                                                       
      19                 :                                                                                                                                                                                             
      20                 :     /**                                                                                                                                                                                     
      21                 :      * @return string the associated database table name                                                                                                                                    
      22                 :      */                                                                                                                                                                                     
      23                 :     public function tableName() {                                                                                                                                                           
      24               8 :         return 'tbl_basic_relations_main';                                                                                                                                                  
      25                 :     }                                                                                                                                                                                       
      26                 :                                                                                                                                                                                             
      27                 :     /**                                                                                                                                                                                     
      28                 :      * @return array validation rules for model attributes.                                                                                                                                 
      29                 :      */                                                                                                                                                                                     
      30                 :     public function rules() {                                                                                                                                                               
      31                 :         return array(                                                                                                                                                                       
      32               7 :             array ('column_belongs_to_id, column_main_content', 'required'),                                                                                                                
      33               7 :             array ('column_belongs_to_id', 'numerical', 'integerOnly' => true),                                                                                                             
      34               7 :             array ('column_belongs_to_id', 'validBelongsToID'), // Custom validator to check for the presence of the specified ID                                                           
      35               7 :             array ('column_main_content', 'length', 'max' => 255),                                                                                                                          
      36               7 :             array ('magic_attribute_many_many_selected', 'safe'),                                                                                                                           
      37               7 :             array ('id, column_belongs_to_id, column_main_content', 'safe', 'on' => 'search'),                                                                                              
      38               7 :         );                                                                                                                                                                                  
      39                 :     }                                                                                                                                                                                       
      40                 :                                                                                                                                                                                             
      41                 :     /**                                                                                                                                                                                     
      42                 :      * @return array relational rules.                                                                                                                                                      
      43                 :      */                                                                                                                                                                                     
      44                 :     public function relations() {                                                                                                                                                           
      45                 :         return array(                                                                                                                                                                       
      46               4 :             'relation_belongs_to' => array (self::BELONGS_TO, 'BasicRelationsBelongsTo', 'column_belongs_to_id'),                                                                           
      47               4 :             'relation_has_one' => array (self::HAS_ONE, 'BasicRelationsHasOne', 'column_main_id'),                                                                                          
      48               4 :             'relation_has_many' => array (self::HAS_MANY, 'BasicRelationsHasMany', 'column_main_id'),                                                                                       
      49               4 :             'relation_many_many' => array (self::MANY_MANY, 'BasicRelationsManyMany', 'tbl_basic_relations_pivot(column_main_id, column_many_many_id)'),                                    
      50               4 :         );                                                                                                                                                                                  
      51                 :     }                                                                                                                                                                                       
      52                 :                                                                                                                                                                                             
      53                 :     /**                                                                                                                                                                                     
      54                 :      * Returns an array of the many to many relation and the name of the pivot class and/or                                                                                                 
      55                 :      */                                                                                                                                                                                     
      56                 :     public function many_many_map () {                                                                                                                                                      
      57                 :         return array (                                                                                                                                                                      
      58                 :             'relation_many_many' => array (                                                                                                                                                 
      59               2 :                 'class' => 'BasicRelationsPivot',                                                                                                                                           
      60                 :                 'attribute' => 'magic_attribute_many_many_selected'                                                                                                                         
      61               2 :             ),                                                                                                                                                                              
      62               2 :         );                                                                                                                                                                                  
      63                 :     }                                                                                                                                                                                       
      64                 :                                                                                                                                                                                             
      65                 :     /**                                                                                                                                                                                     
      66                 :      * @return array customized attribute labels (name=>label)                                                                                                                              
      67                 :      */                                                                                                                                                                                     
      68                 :     public function attributeLabels() {                                                                                                                                                     
      69                 :         return array(                                                                                                                                                                       
      70               6 :             'id' => 'ID',                                                                                                                                                                   
      71               6 :             'column_belongs_to_id' => 'Column Belongs To ID',                                                                                                                               
      72               6 :             'column_main_content' => 'Column Main Content',                                                                                                                                 
      73               6 :         );                                                                                                                                                                                  
      74                 :     }                                                                                                                                                                                       
      75                 :                                                                                                                                                                                             
      76                 :     /**                                                                                                                                                                                     
      77                 :      * Retrieves a list of models based on the current search/filter conditions.                                                                                                            
      78                 :      * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.                                                                      
      79                 :      */                                                                                                                                                                                     
      80                 :     public function search() {                                                                                                                                                              
      81               1 :         $criteria=new CDbCriteria;                                                                                                                                                          
      82                 :                                                                                                                                                                                             
      83               1 :         $criteria->compare('id',$this->id);                                                                                                                                                 
      84               1 :         $criteria->compare('column_belongs_to_id',$this->column_belongs_to_id);                                                                                                             
      85               1 :         $criteria->compare('column_main_content',$this->column_main_content,true);                                                                                                          
      86                 :                                                                                                                                                                                             
      87               1 :         return new CActiveDataProvider('BasicRelationsMain', array(                                                                                                                         
      88               1 :             'criteria'=>$criteria,                                                                                                                                                          
      89               1 :         ));                                                                                                                                                                                 
      90                 :     }                                                                                                                                                                                       
      91                 :                                                                                                                                                                                             
      92                 :     /*************                                                                                                                                                                          
      93                 :      * Validators                                                                                                                                                                           
      94                 :      *************/                                                                                                                                                                         
      95                 :                                                                                                                                                                                             
      96                 :     /**                                                                                                                                                                                     
      97                 :      * Validator for the column_belongs_to_id. It verifies that the specified                                                                                                               
      98                 :      * id exists in the tbl_basic_relations_belongs_to table.                                                                                                                               
      99                 :      */                                                                                                                                                                                     
     100                 :     public function validBelongsToID ($attribute, $params) {                                                                                                                                
     101                 :         // If an error is already present for this attribute, skip the check.                                                                                                               
     102               6 :         if (isset ($this->errors) && isset ($this->errors[$attribute]))                                                                                                                     
     103               6 :             return;                                                                                                                                                                         
     104                 :         $t_params=array (                                                                                                                                                                   
     105               4 :             '{attribute}' => $this->getAttributeLabel($attribute),                                                                                                                          
     106               4 :             '{attribute_value}' => $this->$attribute,                                                                                                                                       
     107               4 :             '{basic_relations_belongs_to_table}' => BasicRelationsBelongsTo::tableName(),                                                                                                   
     108               4 :         );                                                                                                                                                                                  
     109               4 :         if (!BasicRelationsBelongsTo::model()->idPresent ($this->$attribute))                                                                                                               
     110               4 :             $this->addError ($attribute, Yii::t ('basic_relations', 'The {attribute} of \'{attribute_value}\' does not exist in the {basic_relations_belongs_to_table} table.', $t_params));
     111               4 :     }                                                                                                                                                                                       
     112                 :                                                                                                                                                                                             
     113                 :     /*******************                                                                                                                                                                    
     114                 :      * Magic Attributes                                                                                                                                                                     
     115                 :      *******************/                                                                                                                                                                   
     116                 :                                                                                                                                                                                             
     117                 :     /**                                                                                                                                                                                     
     118                 :      *                                                                                                                                                                                       
     119                 :      */                                                                                                                                                                                     
     120                 :     public function getMagic_Attribute_Many_Many_Selected () {                                                                                                                              
     121               2 :         return $this->magicRelationManyManySelectedRead ('relation_many_many');                                                                                                             
     122                 :     }                                                                                                                                                                                       
     123                 :                                                                                                                                                                                             
     124                 :     /**                                                                                                                                                                                     
     125                 :      *                                                                                                                                                                                       
     126                 :      */                                                                                                                                                                                     
     127                 :     public function setMagic_Attribute_Many_Many_Selected ($selected_list) {                                                                                                                
     128               2 :         $this->magicRelationManyManySelectedWrite ('relation_many_many', $selected_list);                                                                                                   
     129               2 :     }                                                                                                                                                                                       
     130                 : }                                                                                                                                                                                           

Generated by PHP_CodeCoverage 1.1.2 using PHP 5.4.4-14+deb7u2 and PHPUnit 3.6.10 at Wed Aug 14 22:01:23 CDT 2013.