Development

Changeset 18560

You must first sign up to be able to contribute.

Changeset 18560

Show
Ignore:
Timestamp:
05/22/09 22:26:20 (4 years ago)
Author:
Mickael.Kurmann
Message:

ajout des tests unitaires des base
ajout de l'option de rounding
ajout de l'option d'utilisateur
mise à jour du readme
mise à jour du schema

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfDoctrineActAsRattablePlugin/trunk/README

    r18417 r18560  
    8888The plugin implements the following methods to the object: 
    8989 
    90  * getRatingsDetails() 
    91  * getAvgRatings() 
     90 * getRates() 
     91 * getRating() 
    9292 * addRate(RategObject $rateObject) 
    9393 * removeRatings() 
  • plugins/sfDoctrineActAsRattablePlugin/trunk/config/doctrine/schema.yml

    r18389 r18560  
    1 rating: 
    2   columns: 
    3     rate:         integer 
    4     model_class:  string(255) 
    5     model_id:     integer 
    6     rated_by:     integer 
  • plugins/sfDoctrineActAsRattablePlugin/trunk/lib/Rattable.class.php

    r18417 r18560  
    77class Doctrine_Rattable extends Doctrine_Record_Generator 
    88{ 
    9     protected $_options = array( 
     9  protected $_options = array( 
    1010                            'className'     => '%CLASS%Rate', 
    11                             'fields'        => array()
     11                            'tableName'     => false
    1212                            'generateFiles' => false, 
    1313                            'table'         => false, 
     
    1515                            'children'      => array(), 
    1616                            'options'       => array(), 
    17                             'criterias'     => 'rate'
     17                            'criterias'     => array('rate')
    1818                            'max_rate'      => 5, 
     19                            'rounding_rate' => 1, 
    1920                            'with_comment'  => true, 
    20     ); 
     21                            'user'          => array('class' => 'sfGuardUser', 
     22                                                     'type'  => 'integer', 
     23                                                     'size'  => 4), 
     24  ); 
     25 
    2126 
    2227    /** 
     
    2631     * @return void 
    2732     */ 
    28     public function __construct($options) 
    29    
    30         $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options); 
    31    
     33  public function __construct($options) 
     34 
     35    $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options); 
     36 
    3237 
    33     public function buildRelation() 
    34    
    35         $this->buildForeignRelation('Rate'); 
    36         $this->buildLocalRelation(); 
    37    
     38  public function buildRelation() 
     39 
     40    $this->buildForeignRelation('Rate'); 
     41    $this->buildLocalRelation(); 
     42 
    3843 
    3944    /** 
     
    4348     * @return void 
    4449     */ 
    45     public function setTableDefinition() 
     50  public function setTableDefinition() 
     51  { 
     52    if(is_int($this->_options['rounding_rate'])) 
    4653    { 
    47         $options = array('className' => $this->_options['className']); 
     54      $type = 'integer'; 
     55      $length = 4; 
     56    } 
     57    else 
     58    { 
     59      $type = 'float'; 
     60      $length = null; 
     61    } 
    4862 
    49         if(is_int($this->_options['rounding_rate'])) 
    50         { 
    51             $type = 'integer'; 
    52             $length = 4; 
    53         } 
    54         else 
    55         { 
    56             $type = 'float'; 
    57             $length = null; 
    58         } 
     63    $options['range'] = array(1 => $this->_options['max_rate']); 
    5964 
    60         $options['range'] = array(0 => $this->_options['max_rate']); 
     65    foreach ($this->_options['criterias'] as $fieldName) 
     66    { 
     67      $this->hasColumn($fieldName, $type, $length, $options); 
     68    } 
     69    unset($options['range']); 
    6170 
    62         foreach ($this->_options['criterias'] as $fieldName
    63        
    64             $this->hasColumn($fieldName, $type, $length, $options); 
    65        
     71    if($this->_options['with_comment']
     72   
     73      $this->hasColumn('comment', 'string', 4000, $options); 
     74   
    6675 
     76    if($this->_options['user']) 
     77    { 
     78      $user = $this->_options['user']; 
     79      $this->hasColumn(Doctrine_Inflector::tableize($user['class']) . '_id', $user['type'], $user['size'], array('primary' => true)); 
     80    } 
     81    else 
     82    { 
     83      $this->hasColumn(Doctrine_Inflector::tableize($this->_options['table']->getComponentName()) . '_id', 'integer', null, array('primary' => true)); 
     84      $this->hasColumn('id', 'integer', null, array('primary' => true, 'autoincrement' => true)); 
     85    } 
     86  } 
    6787 
    68         $options = $this->_options['options']; 
     88  public function buildLocalRelation() 
     89  { 
     90    // relation to the main object 
     91    $options['foreign'] = $this->_options['table']->getIdentifier(); 
     92    $options['local'] = ($this->_options['user']) ? 'id' : Doctrine_Inflector::tableize($this->_options['table']->getComponentName()) . '_id'; 
     93    $options['type'] = Doctrine_Relation::ONE; 
     94    $options['onDelete'] = 'CASCADE'; 
     95    $options['onUpdate'] = 'CASCADE'; 
     96    $this->_table->getRelationParser()->bind($this->_options['table']->getComponentName(), $options); 
    6997 
    70         if($this->_options['with_comment']) 
    71         { 
    72             $this->hasColumn('comment', 'string', 4000, $options); 
    73         } 
     98    // relation to the user 
     99    if($this->_options['user']) 
     100    { 
     101      $user = $this->_options['user']; 
    74102 
     103      $table = Doctrine::getTable($user['class']); 
     104      $options['foreign'] = $table->getIdentifier(); 
     105      $options['local'] = Doctrine_Inflector::tableize($user['class']) . '_id'; 
     106      $options['type'] = Doctrine_Relation::ONE; 
    75107 
    76 //        // Rewrite any relations to our original table 
    77 //        $originalName = $this->_options['table']->getClassnameToReturn(); 
    78 //        $relations = $this->_options['table']->getRelationParser()->getPendingRelations(); 
    79 //        foreach($relations as $table => $relation) { 
    80 //            if ($table != $this->_table->getTableName() ) { 
    81 //                // check that the localColumn is part of the moved col 
    82 //                if (isset($relation['local']) && in_array($relation['local'], $this->_options['fields'])) { 
    83 //                    // found one, let's rewrite it 
    84 //                    $this->_options['table']->getRelationParser()->unsetPendingRelations($table); 
    85 // 
    86 //                    // and bind the rewritten one 
    87 //                    $this->_table->getRelationParser()->bind($table, $relation); 
    88 // 
    89 //                    // now try to get the reverse relation, to rewrite it 
    90 //                    $rp = Doctrine::getTable($table)->getRelationParser(); 
    91 //                    $others = $rp->getPendingRelation($originalName); 
    92 //                    if (isset($others)) { 
    93 //                        $others['class'] = $this->_table->getClassnameToReturn(); 
    94 //                        $others['alias'] = $this->_table->getClassnameToReturn(); 
    95 //                        $rp->unsetPendingRelations($originalName); 
    96 //                        $rp->bind($this->_table->getClassnameToReturn() ,$others); 
    97 //                    } 
    98 //                } 
    99 //            } 
    100 //        } 
     108      $this->_table->getRelationParser()->bind($table->getComponentName() . ' as User', $options); 
    101109    } 
     110  } 
    102111} 
  • plugins/sfDoctrineActAsRattablePlugin/trunk/lib/RattableTemplate.class.php

    r18417 r18560  
    11<?php 
    2   
     2 
    33class Rattable extends Doctrine_Template 
    44{ 
     
    66     * __construct 
    77     * 
    8      * @param string $array  
     8     * @param string $array 
    99     * @return void 
    1010     */ 
    11     public function __construct(array $options = array()) 
    12    
    13      parent::__construct($options); 
    14         $this->_plugin = new Doctrine_Rattable($this->_options); 
    15    
     11  public function __construct(array $options = array()) 
     12 
     13    parent::__construct($options); 
     14    $this->_plugin = new Doctrine_Rattable($this->_options); 
     15 
    1616 
    1717    /** 
     
    2020     * @return void 
    2121     */ 
    22     public function setUp() 
    23    
    24         $this->_plugin->initialize($this->_table);  
    25    
     22  public function setUp() 
     23 
     24    $this->_plugin->initialize($this->_table); 
     25 
    2626 
    2727    /** 
     
    3030     * @return void 
    3131     */ 
    32     public function getRattable() 
    33     { 
    34         return $this->_plugin; 
    35     } 
     32  public function getRattable() 
     33  { 
     34    return $this->_plugin; 
     35  } 
     36 
     37  public function getRates() 
     38  { 
     39    return array(); 
     40  } 
     41 
     42  public function getRating() 
     43  { 
     44    return array(); 
     45  } 
     46 
     47  public function getRateCount() 
     48  { 
     49    return 0; 
     50  } 
     51 
     52  public function addRate() 
     53  { 
     54    return true; 
     55  } 
     56 
     57  public function removeRatings() 
     58  { 
     59    return false; 
     60  } 
    3661}