Development

Changeset 9337

You must first sign up to be able to contribute.

Changeset 9337

Show
Ignore:
Timestamp:
05/28/08 12:39:12 (5 years ago)
Author:
Sylvio
Message:

sfPropelSlotBehaviorPlugin : releasing version 0.1.2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelSlotBehaviorPlugin/README

    r9320 r9337  
    33== Overview == 
    44 
    5 This plugin implements a behavior that permits to add slots to a propel object. 
    6  
    7 Slots are additional fields for a model. These fields linked to an object depends of his template. 
    8  
    9 The plugin include an interface to edit, save & retrieve the value. It also include tools to load templates & slots configuration. 
     5This plugin implements a behavior that permits to manage template and slots for different models. 
     6 
     7Slots are additional data linked to an object depends of his template. 
     8 
     9The plugin include an interface to edit, save & retrieve the value from slots. 
     10It also include tools to load templates & slots configuration. 
    1011 
    1112Slots can be define for different models (like page, product, mailing, ...) 
     13Slots can be multilingual. 
    1214 
    1315== Installation == 
     
    4345      } 
    4446 
    45       $columns_map = array('id'       => PagePeer::ID, 
     47      $columns_map = array('pk'       => PagePeer::ID, 
    4648                           'template' => PagePeer::TEMPLATE); 
    4749  
     
    5860=== Configuration === 
    5961 
    60 Configuration permits to define templates and slots. 
    61  
    62 By default, templates & slots section are under "sfPropelSlot" in your app.yml file. 
    63 But this can be setup into your code (to have slots for different model) and you can have different templates & slots description for different models. 
     62Configuration permits to define templates and slots for different models. 
     63 
     64First, each models must be listed in "sfPropelSlot" section. 
     65Each model have its own templates and slots configuration, then you must specify the section where each model slots & templates are setup. 
     66Optionnaly you can define a default model. 
     67 
     68For each model configuration: 
     69 * You can define default slot options by slot type 
     70 * you have to list available templates for the model, each template must have a title and optionally slots 
     71 * you must define all slots used by templates, each slots must have a title and a type and optionally options and parameters 
    6472 
    6573example:  
     
    6775{{{ 
    6876  sfPropelSlot: 
     77    default_model: Page 
     78    models: 
     79      Page: myCMS 
     80       
     81  myCMS: 
     82    default_slot_options: 
     83      RichText: 
     84        params: tinymce_options=height:250,width:600,language:"en",theme:"advanced",theme_advanced_disable:"flash,image,paste",plugins:"contextmenu,paste",theme_advanced_buttons1_add:"hr",theme_advanced_buttons3:"cut,copy,pastetext,pasteword,separator,formatselect,fontsizeselect,forecolor" 
     85      File: 
     86        params: include_remove=true 
    6987    templates: 
    7088      intro_template: 
    71         name: "Intro page" 
     89        title: "Intro page" 
    7290        slots: [] 
    7391      home_template: 
    74         name: "Homepage" 
     92        title: "Homepage" 
    7593        slots: [text] 
    7694      page1_template:  
    77         name: "Page model 1" 
     95        title: "Page model 1" 
    7896        slots: [text, image, doc_file] 
    7997      page2_template:  
    80         name: "Page model 2" 
     98        title: "Page model 2" 
    8199        slots: [column1, date, products_ads] 
    82100      contact_template:  
    83         name: "Contact" 
     101        title: "Contact" 
    84102        slots: [text_contact, email] 
    85103    slots: 
    86104      text: 
    87         name: "Text" 
     105        title: "Text" 
    88106        type: Text 
     107        i18n: true 
    89108        params : size=100x10 
    90109      column1: 
    91         name: "Text - 1st column" 
     110        title: "Text - 1st column" 
    92111        type: Text 
    93112        help: Don't use "CTRL+V" keystroke but "paste" icons. 
    94         params: rich=true tinymce_options=height:500,width:300 
    95113      date: 
    96         name: "Publication date" 
     114        title: "Publication date" 
    97115        type: Date 
    98116      products_ads: 
    99         name: "Products" 
     117        title: "Products" 
    100118        type: Double_list 
    101119        params: related_class=Products retrieve_method=doSelectPublished 
    102120      doc_file: 
    103         name: "Documentation" 
     121        title: "Documentation" 
    104122        type: File 
    105         params: include_link=doc_pdf include_remove=true 
    106123        upload_dir: doc_pdf 
    107124        help: "Download a pdf file" 
    108125      email: 
    109         name: "E-mail address" 
     126        title: "E-mail address" 
    110127        type: Input 
    111128        params: size=40 
    112129}}} 
     130 
     131=== Extends admin generator === 
     132 
     133See example located in data directory of the plugin. 
    113134 
    114135== Slot types options and params == 
     
    149170  upload_dir: my_directory 
    150171}}} 
     172 
     173include_link is equal to upload_dir by default 
    151174 
    152175=== Date : date field === 
     
    167190The behavior implement the following methods: 
    168191 
    169  * getSlots() : get all slots object of the object 
    170  * getSlot($slot_name) : get a slot object by name 
    171  * getSlotValue($slot_name) : get a slot value by name 
    172  * removeSlot(slot_name) : remove a slot by name 
     192 * getSlots() : return all slots object used by object 
     193 * getSlot($slot_name) : return a slot object by name from the object 
     194 * getSlotValue($slot_name) : get a slot value by name from the object 
     195 * removeSlot(slot_name) : remove a slot by name from the object 
    173196 * clearSlots() : remove all slots of the object 
    174197 * hasSlots() 
    175198 * hasSlot($slot_name) 
     199 * getTemplate : return object's template 
     200 * getTemplateOptions : return options of template used by object 
     201 * getTemplateSlots : return options for each slots of the template used by object 
     202 * setTemplate($template_name) : set the template of the object   
    176203 
    177204== Development == 
     
    184211== Todo == 
    185212 
    186  * add tinymce_options default option in config 
    187213 * doSelectWithSlots method (which use a single query to retrieve objects and populate slots) 
    188214 * improve existing slot interface 
     
    193219== Changelog == 
    194220 
     221=== 2008-28-05 | 0.1.2 Alpha === 
     222 
     223 * sylvio: refactor a lot of things 
     224 * sylvio: improve configuration 
     225 * sylvio: fix major bugs 
     226 
    195227=== 2008-27-05 | 0.1.1 Alpha === 
    196228 
  • plugins/sfPropelSlotBehaviorPlugin/config/config.php

    r9319 r9337  
    22 
    33sfPropelBehavior::registerMethods('sfPropelSlotBehavior', array ( 
    4  
    5 array ( 
     4  array ( 
     5    'sfPropelSlotBehavior', 
     6    'getTemplate' 
     7  ), 
     8  array ( 
     9    'sfPropelSlotBehavior', 
     10    'getTemplateOptions' 
     11  ), 
     12  array ( 
     13    'sfPropelSlotBehavior', 
     14    'getTemplateSlots' 
     15  ), 
     16  array ( 
     17    'sfPropelSlotBehavior', 
     18    'setTemplate' 
     19  ), 
     20  array ( 
    621    'sfPropelSlotBehavior', 
    722    'getSlots' 
  • plugins/sfPropelSlotBehaviorPlugin/data/admin generator example/_edit_slots.php

    r9320 r9337  
     1<?php $cultures=array('en','fr','es'); ?> 
     2<fieldset id="sf_fieldset_slots" class=""> 
     3<?php $template_option=$page->getTemplateOptions(); ?> 
     4<h2><?php $template_option['title']; ?></h2> 
     5 
    16<?php 
    2 $template=sfPropelSlotTools::getTemplate($sf_product->getTemplate(),'sfPage'); 
    3 $slots=sfPropelSlotTools::getTemplateSlots($sf_product->getTemplate(),'sfPage'); 
    4 ?> 
    5 <fieldset id="sf_fieldset_slots" class=""> 
    6 <h2><?php echo __('Page slots').' : '.$template['title']; ?></h2> 
    7  
    8 <?php  
    9 foreach ($slots as $slot_name => $slot_options) 
     7$template_slots=$page->getTemplateSlots(); 
     8foreach ($template_slots as $slot_name => $slot_title) 
    109{ 
    11   $slot_type_class = 'sfSlot'.$slot_options['type']; 
    12   $slot_type = new $slot_type_class(); 
     10  $slot_options=sfPropelSlotTools::getSlotOptions($slot_name); 
     11   
     12  if($slot_options['type']) 
     13  { 
     14    $slot_type_class = 'sfSlot'.$slot_options['type']; 
     15    $slot_type = new $slot_type_class(); 
     16  } 
     17  else 
     18  { 
     19    throw new sfException("Type of slot $slot_name is not defined"); 
     20  } 
    1321  $fieldname="slot[$slot_name]"; 
    1422  ?> 
     
    2331      if(isset($slot_options['i18n']) && $slot_options['i18n']) 
    2432      { 
    25         foreach (sfProductCatalogTools::getLocalizations() as $culture) 
     33        foreach ($cultures as $culture) 
    2634        { 
    27           $slot=$sf_product->getSlot($slot_name,$culture); 
     35          $slot=$page->getSlot($slot_name,$culture); 
    2836          if (!$slot) 
    2937          { 
     
    3240            $slot->setCulture($culture); 
    3341          } 
    34           echo $culture.' : '
     42          echo image_tag('/images/country_flag/'.$culture.'.gif',array('alt'=>$culture,'style'=>'margin-right:10px;'))
    3543          echo $slot_type->getSlotEditor($slot, $slot_options).'<br/>'; 
    3644        } 
     
    3846      else 
    3947      { 
    40         $slot=$sf_product->getSlot($slot_name); 
     48        $slot=$page->getSlot($slot_name); 
    4149        if (!$slot) 
    4250        { 
  • plugins/sfPropelSlotBehaviorPlugin/data/admin generator example/actions.class.php

    r9320 r9337  
    99    parent::savePage($obj); 
    1010    $this->page=$obj; 
    11     $this->updateSlotFromRequest(sfPropelSlotTools::getTemplateSlots($obj->getTemplate(),'sfPage')); 
     11    $this->updateSlotFromRequest(); 
    1212  } 
    1313 
    14   protected function updateSlotFromRequest($template_slots
     14  protected function updateSlotFromRequest(
    1515  { 
    1616    $cultures=array('en','fr','es'); 
    17     foreach ($template_slots as $slot_name => $slot_options) 
     17    foreach ($this->page->getTemplateSlots() as $slot_name => $slot_options) 
    1818    { 
    1919      if(isset($slot_options['i18n']) && $slot_options['i18n']) 
     
    5555      } 
    5656    } 
    57   } 
    5857 
    5958} 
  • plugins/sfPropelSlotBehaviorPlugin/lib/sfPropelSlotBehavior.class.php

    r9318 r9337  
    33class sfPropelSlotBehavior 
    44{ 
     5 
     6  public function getTemplate(BaseObject $object) 
     7  { 
     8    $getter = self::forgeMethodName($object, 'get', 'template');  
     9    return $object->$getter(); 
     10  } 
     11 
     12  public function getTemplateOptions(BaseObject $object) 
     13  { 
     14    return sfPropelSlotTools::getTemplateOptions($object->getTemplate(),get_class($object)); 
     15  } 
     16 
     17  public function getTemplateSlots(BaseObject $object) 
     18  { 
     19    return sfPropelSlotTools::getTemplateSlots($object->getTemplate(),get_class($object)); 
     20  } 
     21   
     22  public function setTemplate(BaseObject $object, $value) 
     23  { 
     24    $setter = self::forgeMethodName($object, 'set', 'template');  
     25    return $object->$setter($value); 
     26  } 
     27   
    528  protected function populateSlots(BaseObject $object) 
    629  { 
     
    115138  } 
    116139 
     140  /** 
     141   * Returns getter / setter name for requested column. 
     142   *  
     143   * @param     BaseObject    $node 
     144   * @param     string        $prefix     Usually 'get' or 'set' 
     145   * @param     string        $column     left|right|parent|scope 
     146   */ 
     147  private static function forgeMethodName(BaseObject $object, $prefix, $column) 
     148  { 
     149    $method_name = sprintf('%s%s', $prefix, $object->getPeer()->translateFieldName(self::getColumnConstant(get_class($object), $column), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME)); 
     150    return $method_name; 
     151  }  
     152   
     153  /** 
     154   * Returns the appropriate column name. 
     155   *  
     156   * @param   string   $node_class               Propel model class 
     157   * @param   string   $column                   "generic" column name (either parent, left, right, scope) 
     158   * @param   bool     $skip_table_name_prefix   Removes table name from column name if true (defaults to false) 
     159   *  
     160   * @return  string   Column's name 
     161   */  
    117162  private static function getColumnConstant($object_class, $column) 
    118163  { 
     
    122167  } 
    123168   
     169   
     170  /*** Peer Methods ***/ 
     171   
    124172  public function doSelectWithSlots(BaseObject $object) 
    125173  { 
     
    133181  } 
    134182 
     183   
    135184} 
  • plugins/sfPropelSlotBehaviorPlugin/lib/sfPropelSlotTools.class.php

    r9319 r9337  
    33class sfPropelSlotTools 
    44{ 
    5  
    6   public static function getTemplates($modelconfig = 'sfPropelSlot'
     5   
     6  public static function getModelConfiguration($model = null, $option
    77  { 
    8     return sfConfig::get('app_'.$modelconfig.'_templates',array()); 
     8    if($model===null) $model=sfConfig::get('app_sfPropelSlot_default_model',false); 
     9     
     10    $sfPropelSlotModels=sfConfig::get('app_sfPropelSlot_models',array()); 
     11    if($model && isset($sfPropelSlotModels[$model])) 
     12    { 
     13      $model_config=sfConfig::get('app_'.$sfPropelSlotModels[$model].'_'.$option,array()); 
     14      if($model_config) return $model_config; 
     15      else return null; 
     16    } 
     17    else 
     18    { 
     19      throw new sfException ("Model: $model has no configuration"); 
     20    } 
    921  } 
    1022   
    11   public static function getTemplate($name, $modelconfig = 'sfPropelSlot'
     23  public static function getTemplates($model = null
    1224  { 
    13     $templates=self::getTemplates($modelconfig); 
    14     if($templates && isset($templates[$name])) 
     25    $templates_configuration = self::getModelConfiguration($model,'templates'); 
     26    if(is_array($templates_configuration)) 
    1527    { 
    16       $template= $templates[$name]; 
    17       $template['name']=$name; 
    18       return $template; 
     28      $templates=array(); 
     29      foreach ($templates_configuration as $template_name => $template_option) 
     30      { 
     31        if(isset($template_option['title'])) $templates[$template_name]=$template_option['title']; 
     32        elseif(isset($template_option['name'])) $templates[$template_name]=$template_option['name']; 
     33        else $templates[$template_name]=$template_name; 
     34      } 
     35      return $templates; 
     36    } 
     37    return false; 
     38  } 
     39   
     40  public static function getTemplateOptions($template_name, $model = null) 
     41  { 
     42    $templates_option = self::getModelConfiguration($model,'templates'); 
     43    if($templates_option && isset($templates_option[$template_name])) 
     44    { 
     45      $template_option= $templates_option[$template_name]; 
     46      $template_option['name']=$template_name; 
     47      return $template_option; 
    1948    } 
    2049    else return false; 
    2150  } 
    2251 
    23   public static function getTemplateSlots($name, $modelconfig = 'sfPropelSlot'
     52  public static function getTemplateSlots($template_name, $model = null
    2453  { 
    25     $template=self::getTemplate($name,$modelconfig); 
     54    $template_option=self::getTemplateOptions($template_name,$model); 
    2655    $template_slots=array(); 
    2756     
    28     if (isset($template['slots']) && is_array($template['slots'])) 
     57    if (isset($template_option['slots']) && is_array($template_option['slots'])) 
    2958    { 
    30     foreach ($template['slots'] as $slot_name) 
     59    foreach ($template_option['slots'] as $slot_name) 
    3160      { 
    32        $template_slots[$slot_name]=self::getSlotOption($slot_name,$modelconfig); 
     61       $template_slots[$slot_name]=self::getSlotOptions($slot_name,$model); 
    3362      } 
    3463    } 
     
    3665  } 
    3766   
    38    
    39   public static function getSlotOptions($modelconfig = 'sfPropelSlot') 
     67  public static function getSlots($model = null) 
    4068  { 
    41     return sfConfig::get('app_'.$modelconfig.'_slots',array()); 
     69    $slots_configuration = self::getModelConfiguration($model,'slots'); 
     70    if(is_array($slots_configuration)) 
     71    { 
     72      $slots=array(); 
     73      foreach ($slots_configuration as $slot_name => $slot_option) 
     74      { 
     75        if(isset($slot_option['title'])) $slots[$slot_name]=$slot_option['title']; 
     76        elseif(isset($slot_option['name'])) $slots[$slot_name]=$slot_option['name']; 
     77        else $slots[$slot_name]=$slot_name; 
     78      } 
     79      return $slots; 
     80    } 
     81    return false; 
    4282  } 
    4383   
    44   public static function getSlotOption($name, $modelconfig = 'sfPropelSlot'
     84  public static function getSlotOptions($slot_name, $model = null
    4585  { 
    46     $slots = self::getSlotOptions($modelconfig); 
    47     return isset($slots[$name]) ? $slots[$name] : null; 
     86    $slots = self::getModelConfiguration($model,'slots'); 
     87    if($slots && isset($slots[$slot_name])) 
     88    { 
     89      $slot_options=array(); 
     90      //get default options 
     91      if($default_options_array=sfConfig::get('app_sfPropelSlot_default_slot_options',array())) 
     92      { 
     93        if(isset($default_options_array[$slot_options['type']])) $slot_options=$default_options_array[$slot_options['type']]; 
     94      } 
     95       
     96      foreach($slots[$slot_name] as $option_name => $option_value) 
     97      { 
     98        $slot_options[$option_name]=$option_value; 
     99      } 
     100      $slot_options['name']=$slot_name; 
     101      return $slot_options; 
     102    } 
     103    else return false; 
    48104  } 
    49105 
  • plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotCheckbox.class.php

    r9318 r9337  
    66  public function getSlotEditor($slot,$slot_options=null) 
    77  { 
    8     $params = parent::getControlName($slot,$slot_options); 
     8    $params = parent::getSlotParams($slot,$slot_options); 
    99    if (!isset($params['default_value'])) $default_value=$params['default_value']; 
    1010    else $default_value=null; 
  • plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotFile.class.php

    r9318 r9337  
    66  public function getSlotEditor($slot,$slot_options=null) 
    77  { 
    8     return object_admin_input_file_tag($slot, 'getValue', $this->getParams($slot,$slot_options)); 
     8    return object_admin_input_file_tag($slot, 'getValue', $this->getSlotParams($slot,$slot_options)); 
    99  } 
    1010 
    1111  public function saveSlotFromRequest($slot,$request,$slot_options=null) 
    1212  { 
    13     $params=$this->getParams($slot,$slot_options); 
     13    $params=$this->getSlotParams($slot,$slot_options); 
    1414 
    1515    $control_name=$this->getControlName($slot,$slot_options); 
     
    3737  } 
    3838 
    39   public function getControlName($slot,$slot_options=null) 
     39  public function getSlotParams($slot,$slot_options=null) 
    4040  { 
    41   $params = parent::getControlName($slot,$slot_options); 
     41    $params = parent::getSlotParams($slot,$slot_options); 
    4242    if (!isset($params['include_link'])) $params['include_link'] = $slot_options['upload_dir']; 
    4343    if (!isset($params['include_remove'])) $params['include_remove'] = true; 
    44   return $params; 
     44    return $params; 
    4545  } 
    46  
     46   
    4747} 
  • plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotInterface.class.php

    r9318 r9337  
    33class sfSlotInterface 
    44{ 
     5   
     6  public function getType() 
     7  { 
     8    return substr(get_class($this),6); 
     9  } 
     10   
    511  public function getSlotValue($slot,$slot_options=null) 
    612  { 
     
    1016  public function getSlotEditor($slot,$slot_options=null) 
    1117  { 
    12     return object_input_tag($slot, 'getValue', $this->getParams($slot,$slot_options)); 
     18    return object_input_tag($slot, 'getValue', $this->getSlotParams($slot,$slot_options)); 
    1319  } 
    1420 
     
    1925  } 
    2026 
    21   public function getParams($slot,$slot_options=null) 
     27  public function getSlotParams($slot,$slot_options=null) 
    2228  { 
    23     if (!isset($slot_options['params']) || !$slot_options['params']) $params = array (); 
    24     else $params = is_array($slot_options['params']) ? $slot_options['params'] : sfToolkit::stringToArray($slot_options['params']); 
     29    if($default_options_array=sfConfig::get('app_sfPropelSlot_default_slot_options',array())) 
     30    { 
     31      if(isset($default_options_array[$this->getType()])) $default_options=$default_options_array[$this->getType()]; 
     32      else $default_options=array(); 
     33      if (isset($default_options['params']) && $default_options['params']) $params = is_array($default_options['params']) ? $default_options['params'] : sfToolkit::stringToArray($default_options['params']); 
     34    } 
     35    if (!isset($slot_options['params']) || !$slot_options['params']) $slot_params = array (); 
     36    else $slot_params = is_array($slot_options['params']) ? $slot_options['params'] : sfToolkit::stringToArray($slot_options['params']); 
     37 
     38    foreach($slot_params as $param_name => $param_value) 
     39    { 
     40      $params[$param_name]=$slot_params[$param_name]; 
     41    } 
    2542 
    2643    $params['control_name']=$this->getControlName($slot,$slot_options); 
  • plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotRichText.class.php

    r9318 r9337  
    44{ 
    55 
    6   public function getControlName($slot,$slot_options=null) 
     6  public function getSlotParams($slot,$slot_options=null) 
    77  { 
    8   $params = parent::getControlName($slot,$slot_options); 
     8    $params = parent::getSlotParams($slot,$slot_options); 
    99    if (!isset($params['rich'])) $params['rich'] = true; 
    10     if (!isset($params['tinymce_options'])) $params['tinymce_options']='params: rich=true tinymce_options=height:250,width:600,language:"fr",theme:"advanced",theme_advanced_disable:"flash,image,paste",plugins:"contextmenu,paste",theme_advanced_buttons1_add:"hr",theme_advanced_buttons3:"cut,copy,pastetext,pasteword,separator,formatselect,fontsizeselect,forecolor"'; 
    11   return $params; 
     10    //if (!isset($params['tinymce_options'])) $params['tinymce_options']='height:250,width:600,language:"fr",theme:"advanced",theme_advanced_disable:"flash,image,paste",plugins:"contextmenu,paste",theme_advanced_buttons1_add:"hr",theme_advanced_buttons3:"cut,copy,pastetext,pasteword,separator,formatselect,fontsizeselect,forecolor"'; 
     11    return $params; 
    1212  } 
    13  
     13   
    1414} 
  • plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotSelect.class.php

    r9318 r9337  
    66  public function getSlotEditor($slot,$slot_options=null) 
    77  {  
    8     $params=$this->getParams($slot,$slot_options); 
     8    $params=$this->getSlotParams($slot,$slot_options); 
    99     
    1010    if (isset($params['related_class'])) 
  • plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotText.class.php

    r9318 r9337  
    1111  public function getSlotEditor($slot,$slot_options=null) 
    1212  { 
    13     return object_textarea_tag($slot, 'getValue', $this->getParams($slot,$slot_options)); 
     13    return object_textarea_tag($slot, 'getValue', $this->getSlotParams($slot,$slot_options)); 
    1414  } 
    15    
    16   public function getControlName($slot,$slot_options=null) 
     15 
     16  public function getSlotParams($slot,$slot_options=null) 
    1717  { 
    18   $params = parent::getControlName($slot,$slot_options); 
    19   if (!isset($params['size'])) $params['size'] = '80x10'; 
    20   return $params; 
     18    $params = parent::getSlotParams($slot,$slot_options); 
     19    if (!isset($params['size'])) $params['size'] = '80x10'; 
     20    return $params; 
    2121  } 
    2222