post_phobic Posted April 8, 2009 Share Posted April 8, 2009 I have in mind an application that would allow users to change the display of their content. For example, users could have a page that has a blocks of data A, B and C and Format=n. I want to allow them to switch the format of this data to one of various formats that are stored in a database based on the Format Field. So Format=1 may look like this: |---------||---------| | A || B | ----------- ---------- ---------------------- | C | ---------------------- (Three divs, A and B are floated with width =50%, C has width = 100%) and Format=2 may look like: ---------------------- | A | ---------------------- ---------------------- | C | ---------------------- ---------------------- | B | ---------------------- (Three divs, all with width = 100%) The reason I would like the formats to be stored in the database is that there may be a large number of new formats added on a regular basis. I had in mind the format to be controlled by a Format Table that specifies the order and css class to be applied to each block of data. Users can completely change their layout with a simple switch of the format_id. Currently, I have a table for the content that is similar to this: tbl_content: contentid | block_data_A | block_data_B | block_data_C | format_id And a table for the presentation that looks like: tbl_format: format_id | block | block_order | block_class A row in tbl_content would correspond to multiple rows in tbl_format format_id | block | block_order | block_class 1 | A | 1 | xyz 1 | B | 2 | xyz 1 | C | 3 | xyz So my content table is flat while my presentation table is relatively un-flat. To achieve the display I want, I am looping through the format data (which is sorted asc by the block_order). If the block == A then I create a div with tbl_content.block_data_A as the content and tbl_format.block_class as the css class and so on. I have noticed some disadvantages to this method but have also thought of disadvantages to unflattening my content table (or on the other hand, flattening my format table). Its one of those situations where I can't make up my mind as to what the sweet spot would be when considering ease of development and long term maintenance. My question is how sane do you think this approach is? What is the best way to model a scenario where you want to multiple versions of presentation data in a database? Quote Link to comment Share on other sites More sharing options...
dbo Posted April 10, 2009 Share Posted April 10, 2009 If your data elements (A, B, C) are well defined and are always going to exist, why not just store a reference to a stylesheet (theme) that would create the desired layout. Alternatively if you're using a templating system of some sort you could store a reference to the desired template. If either of the above don't work for you, can you perhaps explain more as to why you want to store layout logic/presentation in a data model of sorts? Quote Link to comment Share on other sites More sharing options...
post_phobic Posted April 11, 2009 Author Share Posted April 11, 2009 A reference to a stylesheet sounds like a good idea, but I would not have as much control over the order of my objects (lets say I wanted my objects to display as C, B, A rather than A, B, C). Maybe I am wrong here? I am using SMARTY templates, but I don't want to maintain lots of HTML/ template code. Lets say I want to add object D to my list of objects - that would require me to go back and add code for D in all of my template files. I think storing a reference to a stylesheet/theme or template file make sense if you only have a couple templates to switch between. My entire thought process behind this is that I expect there to be many templates and that it should be easy to add new ones quickly. If my presentation meta data is stored in a table then to add new page layouts all I would have to do is copy an existing format and make small changes to the ordering and classes; format_id | block | block_order | block_class 1 | A | 1 | xyz 1 | B | 2 | xyz 1 | C | 3 | xyz For example, use some php/sql functions to copy format_id 1, make some small changes to the order and classes and then insert: 2 | C | 1 | css_class2 2 | B | 2 | xyz 2 | A | 3 | css_class3_withFloatRight No HTML necessary and if I need to make any changes - lets say add the text 'something fancy' between the first and second object when it displays to the user I only have to do this in one place - my one front end HTML/template, rather than having to update dozens of template files. Also, I think the total amount of HTML I will have to maintain will be much less, since most of it will be created on the page load as I loop through the presentation array. Additionally, a UI could be created that easily puts together new presentation formats without requiring one to write error prone html code. I might very well have the wrong idea about this or there might be an easier way that all the pros use, which is why I wanted to share what I was doing before I became too committed... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.