Development

Changeset 19816

You must first sign up to be able to contribute.

Changeset 19816

Show
Ignore:
Timestamp:
07/02/09 09:52:05 (9 months ago)
Author:
gimler
Message:

csDoctrineActAsAttachablePlugin[1.3]: fix plugin

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/csDoctrineActAsAttachablePlugin/branches/1.3/lib/template/Attachable.php

    r19666 r19816  
    1212{ 
    1313  protected $_options = array('types' => array(), 
    14                              'attachableModels' => array()); 
     14                              'attachableModels' => array()); 
    1515 
    1616  /** 
     
    3939   * @return Doctrine_Query 
    4040   */ 
    41  public function getAttachmentsQuery() 
    42 
    43    $object = $this->getInvoker(); 
    44  
    45    return Doctrine::getTable('Attachment') 
     41  public function getAttachmentsQuery() 
     42 
     43    $object = $this->getInvoker(); 
     44 
     45    return Doctrine::getTable('Attachment') 
    4646      ->createQuery() 
    47      ->addWhere('Attachment.object_class = ?', get_class($object)) 
    48      ->addWhere('Attachment.object_id = ?', $object->getId()); 
    49 
     47      ->addWhere('Attachment.object_class = ?', get_class($object)) 
     48      ->addWhere('Attachment.object_id = ?', $object->getId()); 
     49 
    5050 
    5151  /** 
     
    5454   * @return Doctrine_Collection|false 
    5555   */ 
    56    public function getAttachments() 
    57 
    58    $object = $this->getInvoker(); 
    59  
    60    return $object->getAttachmentsQuery()->execute(); 
    61 
     56  public function getAttachments() 
     57 
     58    $object = $this->getInvoker(); 
     59 
     60    return $object->getAttachmentsQuery()->execute(); 
     61 
    6262 
    6363  /** 
     
    7070   * @see addAttachment 
    7171   */ 
    72  public function setAttachments($attachments) 
    73 
    74    foreach ($attachments as $attachment)  
    75    
    76      $this->addAttachment($attachment); 
    77    
     72  public function setAttachments($attachments) 
     73 
     74    foreach ($attachments as $attachment)  
     75   
     76      $this->addAttachment($attachment); 
     77   
    7878  } 
    7979 
     
    8383   * @return boolean 
    8484   */ 
    85  public function hasAttachments() 
    86 
    87    return ($this->getAttachments()->count() > 0); 
    88 
     85  public function hasAttachments() 
     86 
     87    return ($this->getAttachments()->count() > 0); 
     88 
    8989 
    9090  /** 
     
    9393   * @return boolean 
    9494   */ 
    95  public function hasAttachmentsOfType($type) 
    96 
    97    return ($this->getAttachmentsByType($type)->count() > 0); 
    98 
     95  public function hasAttachmentsOfType($type) 
     96 
     97    return ($this->getAttachmentsByType($type)->count() > 0); 
     98 
    9999 
    100100  /** 
     
    105105   * @return void 
    106106   */ 
    107  public function addAttachment(Attachment $attachment) 
    108 
    109    $object = $this->getInvoker(); 
    110  
    111    $attachment->setObjectClass(get_class($object)); 
    112    if(!$object['id']) 
    113    
    114      $object->save(); 
    115    
    116    $attachment->setObjectId($object->getId()); 
    117    $attachment->save();  
    118 
    119  
    120  /** 
     107  public function addAttachment(Attachment $attachment) 
     108 
     109    $object = $this->getInvoker(); 
     110 
     111    $attachment->setObjectClass(get_class($object)); 
     112    if(!$object['id']) 
     113   
     114      $object->save(); 
     115   
     116    $attachment->setObjectId($object->getId()); 
     117    $attachment->save();   
     118 
     119 
     120  /** 
    121121   * get record attachments of specific type 
    122122   * 
     
    125125   * @return Doctrine_Collection 
    126126   */ 
    127  public function getAttachmentsByType($type) 
    128 
    129    if(in_array($type, $this->_options['types'])) 
    130    
    131      return Doctrine::getTable('Attachment') 
     127  public function getAttachmentsByType($type) 
     128 
     129    if(in_array($type, $this->_options['types'])) 
     130   
     131      return Doctrine::getTable('Attachment') 
    132132        ->createQuery() 
    133133        ->where('object_class = ?', get_class($this->getInvoker())) 
     
    135135        ->andWhere('type = ?', strtolower($type)) 
    136136        ->execute(); 
    137    }       
    138    $table = strtolower($type) == 'other' ? 'Attachment' : sfInflector::classify($type.'_attachment'); 
    139  
    140    return new Doctrine_Collection($table); 
    141 
     137    }      
     138    $table = strtolower($type) == 'other' ? 'Attachment' : sfInflector::classify($type.'_attachment'); 
     139 
     140    return new Doctrine_Collection($table); 
     141 
    142142 
    143143  /** 
     
    148148   * @see getAttachableConfig() 
    149149   */ 
    150  public function getSupportedAttachmentTypes() 
    151 
    152    return $this->getAttachableConfig('types'); 
    153 
     150  public function getSupportedAttachmentTypes() 
     151 
     152    return $this->getAttachableConfig('types'); 
     153 
    154154 
    155155  /** 
     
    160160   * @return mixed 
    161161   */ 
    162  public function getAttachableConfig($index = null) 
    163 
    164    if($index) 
    165    
    166      return $this->_options[$index]; 
    167    
    168    return $this->_options; 
    169 
     162  public function getAttachableConfig($index = null) 
     163 
     164    if($index) 
     165   
     166      return $this->_options[$index]; 
     167   
     168    return $this->_options; 
     169 
    170170 
    171171  /** 
     
    176176   * @see getAttachmentsByType() 
    177177   */ 
    178  public function getVideoAttachments() 
    179 
    180    return $this->getAttachmentsByType('Video'); 
    181 
     178  public function getVideoAttachments() 
     179 
     180    return $this->getAttachmentsByType('Video'); 
     181 
    182182 
    183183  /** 
     
    188188   * @see getAttachmentsByType() 
    189189   */ 
    190  public function getImageAttachments() 
    191 
    192    return $this->getAttachmentsByType('Image'); 
    193 
     190  public function getImageAttachments() 
     191 
     192    return $this->getAttachmentsByType('Image'); 
     193 
    194194 
    195195  /** 
     
    200200   * @see getAttachmentsByType() 
    201201   */ 
    202  public function getDocumentAttachments() 
    203 
    204    return $this->getAttachmentsByType('Document'); 
     202  public function getDocumentAttachments() 
     203 
     204    return $this->getAttachmentsByType('Document'); 
    205205  } 
    206206 
     
    212212   * @see getAttachmentsByType() 
    213213   */ 
    214  public function getOtherAttachments() 
    215 
    216    return $this->getAttachmentsByType('Other'); 
    217 
     214  public function getOtherAttachments() 
     215 
     216    return $this->getAttachmentsByType('Other'); 
     217 
    218218 
    219219  /** 
     
    224224   * @see getAttachmentsByType() 
    225225   */ 
    226   public function getModelAttachments() 
    227   { 
    228     return $this->getAttachmentsByType('Model'); 
    229   } 
    230  
    231   //This method doesn't work for some reason! 
    232   public function __call($method, $arguments) 
    233   { 
    234     foreach ($this->_options['types'] as $type) 
    235     { 
    236       if(sfInflector::camelize('get_'.$type.'_attachments') == $method) 
    237       { 
    238         return $this->getAttachmentsByType($type); 
    239       } 
    240     } 
    241  
    242     parent::__call($method, $arguments); 
    243   } 
     226  public function getModelAttachments() 
     227  { 
     228    return $this->getAttachmentsByType('Model'); 
     229  } 
    244230} 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.