Top menu



Wascou.org / Blogs / Maxime THOMAS / About a class heritage system




About a class heritage system

Main concept

A year ago, I was working on a project where we were confronted to a certain problematic. We had a lot of classes which really looked like each other and had the same schema of class. So, when we had to modify a class because an attribute was missing or not in the right datatype, we have been obliged to modify all classes and it's very very long when you've got a lot of content types. We were thinking at a solution : creating a class wich willl be a parent class for all the other classes. For exemple, your customer is selling furniture products via the webshop and here is a detail of how this solution could be applied :

  • You create a class Furniture Product with those very generic attributes : Name, Description and so on.
  • Actually, you have three types of furniture products, Table, Cupboard, Settee. In the normal way, you will have to create three different classes with common generic attributes and specific attributes. There, you will just create a class with the specific attributes, and choose via a list of classes from wich one you would like to inherit.
  • After that, when you are editing and publishing content, the content schema is based on the merge of the parent class attributes and the specific class attributes.

Implementation

To realize that, here's what I was thinking about :

  • Modify the SQL schema of the ezcontentclass table to add a integer attribute called parentclass_id.
  • Modify the kernel/classes/ezcontentclass.php file to add parentclass_id to the definition of the object.
  • Modify the kernel/classes/ezcontentclass_attribute.php file to process all the attributes, main class and parent class attributes, when we use a function.
  • Modify the design/admin/templates/class/edit.tpl file to add the list of classes who can be parent.
  • Modify the kernel/class/edit.php file to save the information.

Comments