Changeset 9337
- Timestamp:
- 05/28/08 12:39:12 (5 years ago)
- Files:
-
- plugins/sfPropelSlotBehaviorPlugin/README (modified) (8 diffs)
- plugins/sfPropelSlotBehaviorPlugin/config/config.php (modified) (1 diff)
- plugins/sfPropelSlotBehaviorPlugin/data/admin generator example/_edit_slots.php (modified) (4 diffs)
- plugins/sfPropelSlotBehaviorPlugin/data/admin generator example/_template.php (added)
- plugins/sfPropelSlotBehaviorPlugin/data/admin generator example/actions.class.php (modified) (2 diffs)
- plugins/sfPropelSlotBehaviorPlugin/lib/sfPropelSlotBehavior.class.php (modified) (4 diffs)
- plugins/sfPropelSlotBehaviorPlugin/lib/sfPropelSlotTools.class.php (modified) (2 diffs)
- plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotCheckbox.class.php (modified) (1 diff)
- plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotFile.class.php (modified) (2 diffs)
- plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotInterface.class.php (modified) (3 diffs)
- plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotRichText.class.php (modified) (1 diff)
- plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotSelect.class.php (modified) (1 diff)
- plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotText.class.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfPropelSlotBehaviorPlugin/README
r9320 r9337 3 3 == Overview == 4 4 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. 5 This plugin implements a behavior that permits to manage template and slots for different models. 6 7 Slots are additional data linked to an object depends of his template. 8 9 The plugin include an interface to edit, save & retrieve the value from slots. 10 It also include tools to load templates & slots configuration. 10 11 11 12 Slots can be define for different models (like page, product, mailing, ...) 13 Slots can be multilingual. 12 14 13 15 == Installation == … … 43 45 } 44 46 45 $columns_map = array(' id' => PagePeer::ID,47 $columns_map = array('pk' => PagePeer::ID, 46 48 'template' => PagePeer::TEMPLATE); 47 49 … … 58 60 === Configuration === 59 61 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. 62 Configuration permits to define templates and slots for different models. 63 64 First, each models must be listed in "sfPropelSlot" section. 65 Each model have its own templates and slots configuration, then you must specify the section where each model slots & templates are setup. 66 Optionnaly you can define a default model. 67 68 For 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 64 72 65 73 example: … … 67 75 {{{ 68 76 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 69 87 templates: 70 88 intro_template: 71 name: "Intro page"89 title: "Intro page" 72 90 slots: [] 73 91 home_template: 74 name: "Homepage"92 title: "Homepage" 75 93 slots: [text] 76 94 page1_template: 77 name: "Page model 1"95 title: "Page model 1" 78 96 slots: [text, image, doc_file] 79 97 page2_template: 80 name: "Page model 2"98 title: "Page model 2" 81 99 slots: [column1, date, products_ads] 82 100 contact_template: 83 name: "Contact"101 title: "Contact" 84 102 slots: [text_contact, email] 85 103 slots: 86 104 text: 87 name: "Text"105 title: "Text" 88 106 type: Text 107 i18n: true 89 108 params : size=100x10 90 109 column1: 91 name: "Text - 1st column"110 title: "Text - 1st column" 92 111 type: Text 93 112 help: Don't use "CTRL+V" keystroke but "paste" icons. 94 params: rich=true tinymce_options=height:500,width:30095 113 date: 96 name: "Publication date"114 title: "Publication date" 97 115 type: Date 98 116 products_ads: 99 name: "Products"117 title: "Products" 100 118 type: Double_list 101 119 params: related_class=Products retrieve_method=doSelectPublished 102 120 doc_file: 103 name: "Documentation"121 title: "Documentation" 104 122 type: File 105 params: include_link=doc_pdf include_remove=true106 123 upload_dir: doc_pdf 107 124 help: "Download a pdf file" 108 125 email: 109 name: "E-mail address"126 title: "E-mail address" 110 127 type: Input 111 128 params: size=40 112 129 }}} 130 131 === Extends admin generator === 132 133 See example located in data directory of the plugin. 113 134 114 135 == Slot types options and params == … … 149 170 upload_dir: my_directory 150 171 }}} 172 173 include_link is equal to upload_dir by default 151 174 152 175 === Date : date field === … … 167 190 The behavior implement the following methods: 168 191 169 * getSlots() : get all slots object of theobject170 * getSlot($slot_name) : get a slot object by name171 * 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 173 196 * clearSlots() : remove all slots of the object 174 197 * hasSlots() 175 198 * 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 176 203 177 204 == Development == … … 184 211 == Todo == 185 212 186 * add tinymce_options default option in config187 213 * doSelectWithSlots method (which use a single query to retrieve objects and populate slots) 188 214 * improve existing slot interface … … 193 219 == Changelog == 194 220 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 195 227 === 2008-27-05 | 0.1.1 Alpha === 196 228 plugins/sfPropelSlotBehaviorPlugin/config/config.php
r9319 r9337 2 2 3 3 sfPropelBehavior::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 ( 6 21 'sfPropelSlotBehavior', 7 22 '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 1 6 <?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(); 8 foreach ($template_slots as $slot_name => $slot_title) 10 9 { 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 } 13 21 $fieldname="slot[$slot_name]"; 14 22 ?> … … 23 31 if(isset($slot_options['i18n']) && $slot_options['i18n']) 24 32 { 25 foreach ( sfProductCatalogTools::getLocalizations()as $culture)33 foreach ($cultures as $culture) 26 34 { 27 $slot=$ sf_product->getSlot($slot_name,$culture);35 $slot=$page->getSlot($slot_name,$culture); 28 36 if (!$slot) 29 37 { … … 32 40 $slot->setCulture($culture); 33 41 } 34 echo $culture.' : ';42 echo image_tag('/images/country_flag/'.$culture.'.gif',array('alt'=>$culture,'style'=>'margin-right:10px;')); 35 43 echo $slot_type->getSlotEditor($slot, $slot_options).'<br/>'; 36 44 } … … 38 46 else 39 47 { 40 $slot=$ sf_product->getSlot($slot_name);48 $slot=$page->getSlot($slot_name); 41 49 if (!$slot) 42 50 { plugins/sfPropelSlotBehaviorPlugin/data/admin generator example/actions.class.php
r9320 r9337 9 9 parent::savePage($obj); 10 10 $this->page=$obj; 11 $this->updateSlotFromRequest( sfPropelSlotTools::getTemplateSlots($obj->getTemplate(),'sfPage'));11 $this->updateSlotFromRequest(); 12 12 } 13 13 14 protected function updateSlotFromRequest( $template_slots)14 protected function updateSlotFromRequest() 15 15 { 16 16 $cultures=array('en','fr','es'); 17 foreach ($t emplate_slotsas $slot_name => $slot_options)17 foreach ($this->page->getTemplateSlots() as $slot_name => $slot_options) 18 18 { 19 19 if(isset($slot_options['i18n']) && $slot_options['i18n']) … … 55 55 } 56 56 } 57 }58 57 59 58 } plugins/sfPropelSlotBehaviorPlugin/lib/sfPropelSlotBehavior.class.php
r9318 r9337 3 3 class sfPropelSlotBehavior 4 4 { 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 5 28 protected function populateSlots(BaseObject $object) 6 29 { … … 115 138 } 116 139 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 */ 117 162 private static function getColumnConstant($object_class, $column) 118 163 { … … 122 167 } 123 168 169 170 /*** Peer Methods ***/ 171 124 172 public function doSelectWithSlots(BaseObject $object) 125 173 { … … 133 181 } 134 182 183 135 184 } plugins/sfPropelSlotBehaviorPlugin/lib/sfPropelSlotTools.class.php
r9319 r9337 3 3 class sfPropelSlotTools 4 4 { 5 6 public static function get Templates($modelconfig = 'sfPropelSlot')5 6 public static function getModelConfiguration($model = null, $option) 7 7 { 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 } 9 21 } 10 22 11 public static function getTemplate ($name, $modelconfig = 'sfPropelSlot')23 public static function getTemplates($model = null) 12 24 { 13 $templates =self::getTemplates($modelconfig);14 if( $templates && isset($templates[$name]))25 $templates_configuration = self::getModelConfiguration($model,'templates'); 26 if(is_array($templates_configuration)) 15 27 { 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; 19 48 } 20 49 else return false; 21 50 } 22 51 23 public static function getTemplateSlots($ name, $modelconfig = 'sfPropelSlot')52 public static function getTemplateSlots($template_name, $model = null) 24 53 { 25 $template =self::getTemplate($name,$modelconfig);54 $template_option=self::getTemplateOptions($template_name,$model); 26 55 $template_slots=array(); 27 56 28 if (isset($template ['slots']) && is_array($template['slots']))57 if (isset($template_option['slots']) && is_array($template_option['slots'])) 29 58 { 30 foreach ($template ['slots'] as $slot_name)59 foreach ($template_option['slots'] as $slot_name) 31 60 { 32 $template_slots[$slot_name]=self::getSlotOption ($slot_name,$modelconfig);61 $template_slots[$slot_name]=self::getSlotOptions($slot_name,$model); 33 62 } 34 63 } … … 36 65 } 37 66 38 39 public static function getSlotOptions($modelconfig = 'sfPropelSlot') 67 public static function getSlots($model = null) 40 68 { 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; 42 82 } 43 83 44 public static function getSlotOption ($name, $modelconfig = 'sfPropelSlot')84 public static function getSlotOptions($slot_name, $model = null) 45 85 { 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; 48 104 } 49 105 plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotCheckbox.class.php
r9318 r9337 6 6 public function getSlotEditor($slot,$slot_options=null) 7 7 { 8 $params = parent::get ControlName($slot,$slot_options);8 $params = parent::getSlotParams($slot,$slot_options); 9 9 if (!isset($params['default_value'])) $default_value=$params['default_value']; 10 10 else $default_value=null; plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotFile.class.php
r9318 r9337 6 6 public function getSlotEditor($slot,$slot_options=null) 7 7 { 8 return object_admin_input_file_tag($slot, 'getValue', $this->get Params($slot,$slot_options));8 return object_admin_input_file_tag($slot, 'getValue', $this->getSlotParams($slot,$slot_options)); 9 9 } 10 10 11 11 public function saveSlotFromRequest($slot,$request,$slot_options=null) 12 12 { 13 $params=$this->get Params($slot,$slot_options);13 $params=$this->getSlotParams($slot,$slot_options); 14 14 15 15 $control_name=$this->getControlName($slot,$slot_options); … … 37 37 } 38 38 39 public function get ControlName($slot,$slot_options=null)39 public function getSlotParams($slot,$slot_options=null) 40 40 { 41 $params = parent::getControlName($slot,$slot_options);41 $params = parent::getSlotParams($slot,$slot_options); 42 42 if (!isset($params['include_link'])) $params['include_link'] = $slot_options['upload_dir']; 43 43 if (!isset($params['include_remove'])) $params['include_remove'] = true; 44 return $params;44 return $params; 45 45 } 46 46 47 47 } plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotInterface.class.php
r9318 r9337 3 3 class sfSlotInterface 4 4 { 5 6 public function getType() 7 { 8 return substr(get_class($this),6); 9 } 10 5 11 public function getSlotValue($slot,$slot_options=null) 6 12 { … … 10 16 public function getSlotEditor($slot,$slot_options=null) 11 17 { 12 return object_input_tag($slot, 'getValue', $this->get Params($slot,$slot_options));18 return object_input_tag($slot, 'getValue', $this->getSlotParams($slot,$slot_options)); 13 19 } 14 20 … … 19 25 } 20 26 21 public function get Params($slot,$slot_options=null)27 public function getSlotParams($slot,$slot_options=null) 22 28 { 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 } 25 42 26 43 $params['control_name']=$this->getControlName($slot,$slot_options); plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotRichText.class.php
r9318 r9337 4 4 { 5 5 6 public function get ControlName($slot,$slot_options=null)6 public function getSlotParams($slot,$slot_options=null) 7 7 { 8 $params = parent::getControlName($slot,$slot_options);8 $params = parent::getSlotParams($slot,$slot_options); 9 9 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; 12 12 } 13 13 14 14 } plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotSelect.class.php
r9318 r9337 6 6 public function getSlotEditor($slot,$slot_options=null) 7 7 { 8 $params=$this->get Params($slot,$slot_options);8 $params=$this->getSlotParams($slot,$slot_options); 9 9 10 10 if (isset($params['related_class'])) plugins/sfPropelSlotBehaviorPlugin/lib/slotType/sfSlotText.class.php
r9318 r9337 11 11 public function getSlotEditor($slot,$slot_options=null) 12 12 { 13 return object_textarea_tag($slot, 'getValue', $this->get Params($slot,$slot_options));13 return object_textarea_tag($slot, 'getValue', $this->getSlotParams($slot,$slot_options)); 14 14 } 15 16 public function get ControlName($slot,$slot_options=null)15 16 public function getSlotParams($slot,$slot_options=null) 17 17 { 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; 21 21 } 22 22