Development

Changeset 25085

You must first sign up to be able to contribute.

Changeset 25085

Show
Ignore:
Timestamp:
12/08/09 16:51:37 (3 years ago)
Author:
Mickael.Kurmann
Message:

renamed files (serializable is already used somewhere)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/pplActAsSerializablePlugin/trunk/lib/pplSerializable.class.php

    r25069 r25085  
    55 * 
    66 */ 
    7 class Doctrine_Serializable extends Doctrine_Record_Generator 
     7class Doctrine_pplSerializable extends Doctrine_Record_Generator 
    88{ 
    99  protected $_options = array( 
    10       'className'     => 'Serial', 
    11       'tableName'     => false, 
    12       'generateFiles' => false, 
    13       'table'         => false, 
    14       'pluginTable'   => false, 
    15       'children'      => array(), 
    16       'options'       => array(), 
    17       'parameter'     => 'year', 
    18       'format'        => '0000', 
     10      'className'      => 'pplSerial', 
     11      'tableName'      => false, 
     12      'generateFiles'  => false, 
     13      'table'          => false, 
     14      'pluginTable'    => false, 
     15      'children'       => array(), 
     16      'options'        => array(), 
     17      'format'         => '0000', 
    1918  ); 
    2019 
     
    3332  public function buildRelation() 
    3433  { 
    35     $this->buildForeignRelation('Serial'); 
    36     $this->buildLocalRelation(); 
     34    $this->buildForeignRelation('pplSerial'); 
     35    //$this->buildLocalRelation(); 
    3736  } 
    3837 
     
    4544  public function setTableDefinition() 
    4645  { 
    47     $this->_options['parameter'] = ($this->_options['parameter'] != 'year') ? 'custom' :  $this->_options['parameter']; 
    48  
    49     if($this->_options['format']) 
    50     { 
    51  
    52     } 
    53  
    5446    $this->hasColumn('id', 'integer', 4, array( 
    5547        'unsigned' => true, 
     
    5850    )); 
    5951 
    60     $this->hasColumn('related_model', 'string(100)'); 
    61     $this->hasColumn('parameter', 'string(100)'); 
     52    $this->hasColumn('model_class', 'string', 100); 
     53    $this->hasColumn('ppl_year', 'string', 2); 
     54    $this->hasColumn('serial', 'integer', 4, array('unsigned' => true)); 
    6255 
    63     $this->hasColumn('serial', 'integer', 4, array('unsigned' => true)); 
     56    $this->index('model_class_parameter', array( 
     57        'fields' => array('model_class', 'ppl_year'), 
     58        'type' => 'unique', 
     59    )); 
    6460  } 
    6561 
    66   public function buildLocalRelation() 
    67   { 
    68     // relation to the main object 
    69     $options['foreign'] = $this->_options['table']->getIdentifier(); 
    70     $options['local'] = $this->getSerialObjectFk(); 
    71     $options['type'] = Doctrine_Relation::ONE; 
    72     $options['onDelete'] = 'CASCADE'; 
    73     $options['onUpdate'] = 'CASCADE'; 
    74     $this->_table->getRelationParser()->bind($this->_options['table']->getComponentName(), $options); 
    75   } 
    76  
    77   public function getSerialObjectFk() 
    78   { 
    79     return Doctrine_Inflector::tableize($this->_options['table']->getComponentName()) . '_id'; 
    80   } 
    8162} 
  • plugins/pplActAsSerializablePlugin/trunk/lib/pplSerializableListener.class.php

    r25041 r25085  
    11<?php 
    22 
    3 class SerializableListener extends Doctrine_Record_Listener 
     3class pplSerializableListener extends Doctrine_Record_Listener 
    44{ 
    5   /** 
    6    * Instance of Doctrine_Auditlog 
    7    * 
    8    * @var Doctrine_AuditLog 
    9    */ 
    10   protected $_serializable; 
     5  public function preInsert(Doctrine_Event $event) 
     6  { 
     7    $invoker = $event->getInvoker(); 
     8    $class_name = $invoker->getSerializable()->getOption('className'); 
    119 
     10    $c = new $class_name; 
     11    $c->merge(array( 
     12        'model_class' => get_class($invoker), 
     13        'ppl_year'    => $invoker->getCurrentYear(), 
     14        'serial'      => $invoker->getNext(), 
     15    )); 
    1216 
    13   public function __construct(Doctrine_Serializable $serializable) 
    14   { 
    15     $this->_serializable = $serializable; 
    16   } 
    17  
    18   public function preSave(Doctrine_Event $event) 
    19   { 
    20  
     17    $c->save(); 
    2118  } 
    2219} 
  • plugins/pplActAsSerializablePlugin/trunk/lib/pplSerializableTemplate.class.php

    r25068 r25085  
    11<?php 
    22 
    3 class Serializable extends Doctrine_Template 
     3class pplSerializable extends Doctrine_Template 
    44{ 
    55    /** 
     
    99     * @return void 
    1010     */ 
    11   public function __construct(array $options = array()) 
    12  
    13     parent::__construct($options); 
    14     $this->_plugin = new Doctrine_Serializable($this->_options); 
    15  
     11    public function __construct(array $options = array()) 
     12   
     13        parent::__construct($options); 
     14        $this->_plugin = new Doctrine_pplSerializable($this->_options); 
     15   
    1616 
    17   /** 
    18    * Initialize the Rattable plugin for the template 
    19    
    20    * @return void 
    21    */ 
    22   public function setUp() 
    23  
    24     $this->_plugin->initialize($this->_table); 
    25     $this->addListener(new sfDoctrineRecordListener()); 
    26  
     17    /** 
     18     * Initialize the Rattable plugin for the template 
     19    
     20     * @return void 
     21     */ 
     22    public function setUp() 
     23   
     24        $this->_plugin->initialize($this->_table); 
     25        $this->addListener(new pplSerializableListener()); 
     26   
    2727 
    28   /** 
    29    * Get the plugin instance for the Rattable template 
    30    
    31    * @return void 
    32    */ 
    33   public function getSerializable() 
    34  
    35     return $this->_plugin; 
    36  
     28    /** 
     29     * Get the plugin instance for the Rattable template 
     30    
     31     * @return Doctrine_Serializable 
     32     */ 
     33    public function getSerializable() 
     34   
     35        return $this->_plugin; 
     36   
    3737 
    38   /** 
    39    * 
    40    * @return int formated serial 
    41    */ 
    42   public function getSerial() 
    43   { 
    44      
    45   } 
     38    /** 
     39     * 
     40     * @return string formated serial 
     41     */ 
     42    public function getFormatedSerial() 
     43    { 
     44        $nb = new sfNumberFormat(); 
     45        return $nb->format($this->getNext(), $this->getFormat()); 
     46    } 
    4647 
    47   protected function getNext() 
    48   { 
    49      
    50   } 
     48    /** 
     49     * @return int next serial 
     50     */ 
     51    public function getNext() 
     52    { 
     53        if($this->getInvoker()->exists()) 
     54        { 
     55            throw new Exception('You can only get Serial on new objects'); 
     56        } 
    5157 
     58        return $this->getSerial()+1; 
     59    } 
    5260 
    53   protected function resetNeeded() 
    54   { 
    55      
    56   } 
     61    public function getSerial() 
     62    { 
     63        $model_class = get_class($this->getInvoker()); 
     64        $year = $this->getCurrentYear(); 
     65 
     66        return Doctrine_Query::create() 
     67                ->select('ps.serial') 
     68                ->from('pplSerial ps') 
     69                ->where('ps.model_class = ? AND ps.ppl_year = ?', array($model_class, $year)) 
     70                ->limit(1) 
     71                ->execute(array(), Doctrine::HYDRATE_SINGLE_SCALAR); 
     72    } 
     73 
     74    public function getCurrentYear() 
     75    { 
     76        return date('y', time()); 
     77    } 
     78 
     79    public function getYear() 
     80    { 
     81        $model_class = get_class($this->getInvoker()); 
     82 
     83        return Doctrine_Query::create() 
     84                ->select('MAX(ppl_year)') 
     85                ->from('pplSerial ps') 
     86                ->where('ps.model_class = ?', array($model_class)) 
     87                ->limit(1) 
     88                ->execute(array(), Doctrine::HYDRATE_SINGLE_SCALAR); 
     89    } 
     90 
     91    /** 
     92     * @return boolean 
     93     */ 
     94    public function resetNeeded() 
     95    { 
     96        return $this->getYear() < $this->getCurrentYear(); 
     97    } 
     98 
     99    protected function getFormat() 
     100    { 
     101        return $this->getSerializable()->getOption('format'); 
     102    } 
    57103 
    58104}