Flexible sidebar database design - php

In my system I have a flexible layout, where you can place your sidebar left or right (or both). You can add multiple sidebars and then choose which one you want to use for your page, and on which location.
What is the best way to store the items in a sidebar, while maintaining the ability to edit the item configuration per sidebar?
The items consist of a php class in which the config options are passed through to a template file.
My origional thought was to implement some sort of shortcode functionality and add a shortcode to a sidebar_item entry in the database, but this way it wouldn't really be configurable.

If I understand you correctly, you have:
a user, who can place a sidebar where he wants to,
a sidebar, that can contain some elements,
items, that can belong to each sidebar to each user,
files to handle items of different types.
and every user has his own sidebar with his own content.
I can propose tables:
users in which users are defined by some id,
sidebars in which you say which user it belongs to, and if it is left or right,
item_types where you say which template and/or configuration files should be used,
items in what type it is (from item_types), so you know which template to use, then in which sidebar (from sidebars) it is, maybe what position it is (first, second, ...).
You should create relations between:
sidebars and users on user id so selecting user you could know which sidebar(s) he owns,
items and sidebars on sidebar id, so knowing sidebar you know which items are in it,
item_types and items on item type so you know how to handle it,
Perhaps, in items you can also store configuration variables that you could pass to template.

Related

Wordpress custom menu for each user?

I was wondering, is it possible to give a registered user to create his own menu based on his chosen categories for the website on WordPress? Let's say he chooses which menu items he wants to see & only sees those menu's when logged in.
This is not a built-in feature, but yes, this would be possible on a custom WordPress site (i.e. WordPress.org, not WordPress.com), and there are a lot of different ways you could structure it.
It would not be trivial to implement, however.
My initial approach would be to have an actual WordPress menu hold all possible items, and then store user preferences as to which of the items are shown or hidden. On their user profile edit page, you could output the menu items as a checkbox list, and then store their selection as a user option. On the rest of the site, when you output the menu, you'd first pull that user option, then output the menu items manually one at a time if they have the option for that item checked.
There are of course other ways, but they would be similarly complex -- well beyond copying and pasting a code snippet, or me typing up a solution for you here.

list all products and link each category grid with category box in opencart

I want to load all categories grids on one page and want all products to be available on scroll down. currently I need to click on each category and the page refreshes for each category. This is the site I am working on(ahmad.esy.es). I want this type of functionality upon clicking the category(http://www.just-eat.co.uk/restaurants-hertsplaice-en11/menu#2254). kindly suggest me what changes should I make in view files (product.tpl, category.tpl) or controller files(product.php, category.php). how can I load all the grids of categories in one page
I didn't look at the site you have posted above - if you cannot describe your issue by words or by submitting a code or image it should be improved.
From what I understand you just want an infinite scroll to display all the products you have in your eshop. It is not mentioned whether you want to preserve the default functionality (category tree with products attached to certain categories) or whether you want only this one listing - basically it does not matter - so I will describe in short how to add such new functionality.
The model
you do not need to touch any model - you can reuse the method ModelCatalogProduct::getProducts()
this will give you the possibility to sort or filter the products except you will have to omit the filter_category_id to load all the products
The controller
feel free to create a new controller (e.g. ControllerProductInfinite) or just to reuse one of the already existing - either ControllerProductCategory or ControllerProductProduct
all you need is basically the same as in ControllerProductCategory::index() except adding filter_category_id into a array passed when calling ModelCatalogProduct::getProducts() and a new template for rendering
The template
create a new template that will meet your expectations and infinite scroll requirements
stick to any infinite scroll plugin/implementation you like (may Google be with you)

MySQL Organisation Strategy for Multi-user with 100% customization

My question today is how should I organize my MySQL Table to get a 100% customized menu for my different users...
Let me explain: I will have a large menu tree (like windows) that will display Categories & Items for the user. I want the user to be able to delete, add or Modify anything like: Category name, Delete category, Add item, Change item name and Delete Item.
BUT: I want to offer my different clients a starting "Base" menu with common Items and Categories when they register, but when a user modifies the category (ex: change name or delete it), I don't want his changes to interfere with the other user's Menu..
So, how should I organize my DB to handle this: at this moment, I have 2 Tables: T_categories(with parent info to structure for the tree menu) & T_items (with category_id) but I realize that I don't really know how I will be handling my queries to enable "delete or rename" for Categories and Items... Should I make unlimited tables like this??
T_user1_categories & T_user1_items
T_user2_categories & T_user2_items
and so on, but if I have 1000 users it'll not be cool =/
At this time I can only(i think) create customized items with ex: privateview_id (user id)
Also, if I build something that, when I rename a category, it create a new category with a privateview_ID, all the items that were already in it will lose their position
I'm using PHP and MySQL
If you have an idea, i will be happy to hear it!!
Thank-you!
Raphael
A menu bar is a hierarchical thing. I suggest you "build" that things using a hierarchical meta data like XML.
You can store your users, categories and items in respective tables and also create a menus table to store the menus users created.
You ill still be able to do relations between users, menus, categories and items creating relational tables.
Also a user can just move a item from a category for another, not changing your usersXcategories or usersXitems relations but just changing the XML.
I cannot say more without knowing more details but your requirements.
Well, finally i've come to conclusion that the best way will be to create a table for every users... I've read that some people have MySql databases with over 1000+ tables without any problem and going the other way would be a lot of trouble. Also, I don't plan on having 1000+ users because that custom menu is part of a "paying" option. Thank-you for your answer jean

Active state for static categories menu

I'm working on a store with a small amount of categories and for the purpose of tayloring the drop down menu li's with bg images and descriptions, I want to markup the top.phtml manually.
After searching high and low I'm posting here to know if anyone can point me in the right direction for adding active class to the current category/parent category?
Much obliged,
Peter
There are a couple options here.
#1, You can let the menu render itself and then do string finds and replaces to mark it up better.
#2, You can compare the requested url to category url fragments to determine which ones are active.
I've used a combination of the two to create menus with CMS pages and certain categories with different CSS classes etc.

How to place multiple content types on a Drupal page?

I've created a new content type called Homepage, which has a number of fields. The fields are node references to the Single Image Promo content type. Single Promo Box has fields for title, text and image. The idea is that I can create multiple copies of a Single Promo Box, each with different field values. I then want to place a few of them on the homepage.
So I can place a specific Single Image Promo on the homepage fine now. But what template file do I need to create to style the way Single Image Promo is shown when it's a node reference on the homepage?
Thanks,
Maria
It sounds like you are over complicating things.
If you want to create some different boxes on your homepage, using node reference is not the right way to go about this. There are some few different ways to do what you want, the easiest i probably to create a block view of the node you want to display. When you turn a node into a block, you get the ability to place it in any of your theme's defined regions.
You could also just create a view and from there get the different Single Image Promo you want without using node reference at all. Views has a lot of different filters, which will enable to you create a view that always displays the right nodes. This solution wont work well, if you want to place the nodes in different regions though.
To answer your question, when nodes are being displayed, they will by default be rendered with the node.tpl.php template file. To make specific templates for each of your node types, you can create a new template named node-nodetype.tpl.php, where nodetype is what you called the node type when you created it.
node-nodetype.tpl.php can work to a certain degree, but in that file you are styling the entire page, with the content type's fields delivered wholesale to the tpl via a single $content variable. Maybe it is enough for you, but if you need finer grained control:
You can edit and style the individual content type's fields with the Content Template (contemplate) module. It provides access to all of a content type's fields within the $content variable (which is delivered wholesale to the node-nodetype.tpl.php. The contemplate is php, so you can add logic and conditional formatting for the node-reference fields (usually clearly labeled in the contemplate).
And don't overlook the simple solution of the content type's 'display fields' tab (next to manage fields tab), where you can control some field outputs right out of the gate.

Categories