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
0.00% 0 / 1
76.47% 13 / 17 CRAP
91.80% 56 / 61
BasicRelationsMain
0.00% 0 / 1
76.47% 13 / 17 24.32
91.80% 56 / 61
 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
 pivots()
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_Belongs_To_List ()
100.00% 1 / 1 4
100.00% 10 / 10
 getMagic_Attribute_Belongs_To_Content ()
100.00% 1 / 1 2
100.00% 3 / 3
 getMagic_Attribute_Has_One ()
100.00% 1 / 1 1
100.00% 1 / 1
 setMagic_Attribute_Has_One ($value)
100.00% 1 / 1 1
100.00% 2 / 2
 validMagic_Attribute_Has_One ($attribute, $params)
100.00% 1 / 1 1
100.00% 2 / 2
 getMagic_Attribute_Has_Many ()
0.00% 0 / 1 2
0.00% 0 / 1
 setMagic_Attribute_Has_Many (array $value_array)
0.00% 0 / 1 2
0.00% 0 / 2
 getMagic_Attribute_Many_Many ()
0.00% 0 / 1 2
0.00% 0 / 1
 setMagic_Attribute_Many_Many ()
0.00% 0 / 1 2
0.00% 0 / 1


       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 BasicRelationsModel {                                                                                                                                      
      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               5 :         return parent::model($className);                                                                                                                                                   
      18                 :     }                                                                                                                                                                                       
      19                 :                                                                                                                                                                                             
      20                 :     /**                                                                                                                                                                                     
      21                 :      * @return string the associated database table name                                                                                                                                    
      22                 :      */                                                                                                                                                                                     
      23                 :     public function tableName() {                                                                                                                                                           
      24              10 :         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               6 :             array ('column_belongs_to_id, column_main_content', 'required'),                                                                                                                
      33               6 :             array ('column_belongs_to_id', 'numerical', 'integerOnly' => true),                                                                                                             
      34               6 :             array ('column_belongs_to_id', 'validBelongsToID'), // Custom validator to check for the presence of the specified ID                                                           
      35               6 :             array ('column_main_content', 'length', 'max' => 255),                                                                                                                          
      36                 : //            array ('magic_attribute_has_one', 'required'),                                                                                                                                
      37               6 :             array ('magic_attribute_has_one', 'validMagic_Attribute_Has_One'),                                                                                                              
      38               6 :             array ('id, column_belongs_to_id, column_main_content', 'safe', 'on' => 'search'),                                                                                              
      39               6 :         );                                                                                                                                                                                  
      40                 :     }                                                                                                                                                                                       
      41                 :                                                                                                                                                                                             
      42                 :     /**                                                                                                                                                                                     
      43                 :      * @return array relational rules.                                                                                                                                                      
      44                 :      */                                                                                                                                                                                     
      45                 :     public function relations() {                                                                                                                                                           
      46                 :         return array(                                                                                                                                                                       
      47               6 :             'relation_belongs_to' => array (self::BELONGS_TO, 'BasicRelationsBelongsTo', 'column_belongs_to_id'),                                                                           
      48               6 :             'relation_has_one' => array (self::HAS_ONE, 'BasicRelationsHasOne', 'column_main_id'),                                                                                          
      49               6 :             'relation_has_many' => array (self::HAS_MANY, 'BasicRelationsHasMany', 'column_main_id'),                                                                                       
      50               6 :             'relation_many_manys' => array (self::MANY_MANY, 'BasicRelationsManyMany', 'tbl_basic_relations_pivot(column_main_id, column_many_many_id)'),                                   
      51               6 :         );                                                                                                                                                                                  
      52                 :     }                                                                                                                                                                                       
      53                 :                                                                                                                                                                                             
      54                 :     /**                                                                                                                                                                                     
      55                 :      * Returns an array of the many to many relation and the name of the pivot class.                                                                                                       
      56                 :      */                                                                                                                                                                                     
      57                 :     public function pivots() {                                                                                                                                                              
      58                 :         return array (                                                                                                                                                                      
      59               1 :             'relation_many_many' => 'BasicRelationsPivot',                                                                                                                                  
      60               1 :         );                                                                                                                                                                                  
      61               3 :     }                                                                                                                                                                                       
      62               3 :                                                                                                                                                                                             
      63                 :     /**                                                                                                                                                                                     
      64                 :      * @return array customized attribute labels (name=>label)                                                                                                                              
      65                 :      */                                                                                                                                                                                     
      66                 :     public function attributeLabels() {                                                                                                                                                     
      67                 :         return array(                                                                                                                                                                       
      68               5 :             'id' => 'ID',                                                                                                                                                                   
      69               5 :             'column_belongs_to_id' => 'Column Belongs To ID',                                                                                                                               
      70               5 :             'column_main_content' => 'Column Main Content',                                                                                                                                 
      71               5 :         );                                                                                                                                                                                  
      72                 :     }                                                                                                                                                                                       
      73                 :                                                                                                                                                                                             
      74                 :     /**                                                                                                                                                                                     
      75                 :      * Retrieves a list of models based on the current search/filter conditions.                                                                                                            
      76                 :      * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.                                                                      
      77                 :      */                                                                                                                                                                                     
      78                 :     public function search() {                                                                                                                                                              
      79               1 :         $criteria=new CDbCriteria;                                                                                                                                                          
      80                 :                                                                                                                                                                                             
      81               1 :         $criteria->compare('id',$this->id);                                                                                                                                                 
      82               1 :         $criteria->compare('column_belongs_to_id',$this->column_belongs_to_id);                                                                                                             
      83               1 :         $criteria->compare('column_main_content',$this->column_main_content,true);                                                                                                          
      84                 :                                                                                                                                                                                             
      85               1 :         return new CActiveDataProvider('BasicRelationsMain', array(                                                                                                                         
      86               1 :             'criteria'=>$criteria,                                                                                                                                                          
      87               1 :         ));                                                                                                                                                                                 
      88                 :     }                                                                                                                                                                                       
      89                 :                                                                                                                                                                                             
      90                 :     /*************                                                                                                                                                                          
      91                 :      * Validators                                                                                                                                                                           
      92                 :      *************/                                                                                                                                                                         
      93                 :                                                                                                                                                                                             
      94                 :     /**                                                                                                                                                                                     
      95                 :      * Validator for the column_belongs_to_id. It verifies that the specified                                                                                                               
      96                 :      * id exists in the tbl_basic_relations_belongs_to table.                                                                                                                               
      97                 :      */                                                                                                                                                                                     
      98                 :     public function validBelongsToID ($attribute, $params) {                                                                                                                                
      99                 :         // If an error is already present for this attribute, skip the check.                                                                                                               
     100               5 :         if (isset ($this->errors) && isset ($this->errors[$attribute]))                                                                                                                     
     101               5 :             return;                                                                                                                                                                         
     102                 :         $t_params=array (                                                                                                                                                                   
     103               3 :             '{attribute}' => $this->getAttributeLabel($attribute),                                                                                                                          
     104               3 :             '{attribute_value}' => $this->$attribute,                                                                                                                                       
     105               3 :             '{basic_relations_belongs_to_table}' => BasicRelationsBelongsTo::tableName(),                                                                                                   
     106               3 :         );                                                                                                                                                                                  
     107               3 :         if (!BasicRelationsBelongsTo::model()->idPresent ($this->$attribute))                                                                                                               
     108               3 :             $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));
     109               3 :     }                                                                                                                                                                                       
     110                 :                                                                                                                                                                                             
     111                 :     /*******************                                                                                                                                                                    
     112                 :      * Magic Attributes                                                                                                                                                                     
     113                 :      *******************/                                                                                                                                                                   
     114                 :                                                                                                                                                                                             
     115                 :     public function getMagic_Attribute_Belongs_To_List () {                                                                                                                                 
     116               1 :         if (isset ($this->_magic_attributes['belongs_to_list']))                                                                                                                            
     117               1 :             return $this->_magic_attributes['belongs_to_list'];                                                                                                                             
     118               1 :         $belongs_to_entries=BasicRelationsBelongsTo::model()->findAll ();                                                                                                                   
     119               1 :         if (empty ($belongs_to_entries))                                                                                                                                                    
     120               1 :             return array();                                                                                                                                                                 
     121               1 :         $belongs_to_list=array();                                                                                                                                                           
     122               1 :         foreach ($belongs_to_entries as $belongs_to) {                                                                                                                                      
     123               1 :             $belongs_to_list[$belongs_to->id]=$belongs_to->column_belongs_to_content;                                                                                                       
     124               1 :         }                                                                                                                                                                                   
     125               1 :         return $this->_magic_attributes['belongs_to_list']=$belongs_to_list;                                                                                                                
     126                 :     }                                                                                                                                                                                       
     127                 :                                                                                                                                                                                             
     128                 :     public function getMagic_Attribute_Belongs_To_Content () {                                                                                                                              
     129               1 :         if (empty ($this->relation_belongs_to))                                                                                                                                             
     130               1 :             return null;                                                                                                                                                                    
     131               1 :         return $this->relation_belongs_to->column_belongs_to_content;                                                                                                                       
     132                 :     }                                                                                                                                                                                       
     133                 :                                                                                                                                                                                             
     134                 :     public function getMagic_Attribute_Has_One () {                                                                                                                                         
     135               1 :         return $this->magicRelationHasOneRead ('relation_has_one','column_has_one_content');                                                                                                
     136                 :     }                                                                                                                                                                                       
     137                 :                                                                                                                                                                                             
     138                 :     public function setMagic_Attribute_Has_One ($value) {                                                                                                                                   
     139               3 :         $this->magicRelationHasOneWrite ('relation_has_one', 'column_has_one_content', $value);                                                                                             
     140               3 :     }                                                                                                                                                                                       
     141                 :                                                                                                                                                                                             
     142                 :     public function validMagic_Attribute_Has_One ($attribute, $params) {                                                                                                                    
     143               5 :         $this->magicRelationHasOneValidate ('relation_has_one', 'column_has_one_content', 'magic_attribute_has_one', $params);                                                              
     144               5 :     }                                                                                                                                                                                       
     145                 :                                                                                                                                                                                             
     146                 :     public function getMagic_Attribute_Has_Many () {                                                                                                                                        
     147               0 :         return $this->magicRelationHasManyRead ('relation_has_many');                                                                                                                       
     148                 :     }                                                                                                                                                                                       
     149                 :                                                                                                                                                                                             
     150                 :     public function setMagic_Attribute_Has_Many (array $value_array) {                                                                                                                      
     151               0 :         $this->magicRelationHasManyWrite ('relation_has_many', $value_array);                                                                                                               
     152               0 :     }                                                                                                                                                                                       
     153                 :                                                                                                                                                                                             
     154                 :     public function getMagic_Attribute_Many_Many () {                                                                                                                                       
     155               0 :     }                                                                                                                                                                                       
     156                 :                                                                                                                                                                                             
     157                 :     public function setMagic_Attribute_Many_Many () {                                                                                                                                       
     158               0 :     }                                                                                                                                                                                       
     159                 :                                                                                                                                                                                             
     160                 : }                                                                                                                                                                                           

Generated by PHP_CodeCoverage 1.1.2 using PHP 5.4.4-14+deb7u2 and PHPUnit 3.6.10 at Tue Aug 13 16:58:12 CDT 2013.