views:

184

answers:

1

I'm creating a simple tag system that allows me to link a tag to almost everything in my application. In order to facilitate this, I created a table called "objects", referenced by my model "Object".

I've got three models setup at the moment:

  • Tag (with TagObject defined as a dependentTable)
  • Object (with TagObject defined as a dependedTable)
  • TagObject (with both Tag and Object defined in the referenceMap)

I already created some simple methods like fetchTagById() and fetchTagByName() in my Tag model, but now I want to create a method that gets my tags and their respective occurences in the objects table, in order to create a simple tag cloud.

Structure-wise, what is the best location to create this method (using findDependentRowset())?

I somehow feel it is not very good practise to store this in my Tag model, but storing it in my TagObject model seems awkward too, and might overcomplicate things.

Any advice would be greatly appreciated.

Thanks in advance.

+1  A: 

If the method retrieves the tags, then it should be in the tag model. If it retrieves objects, it should be in the object model. Since you are retrieving tags and their occurrences, it should be in the tag model.

I would call the model Tags not Tag, since Tag is a Row in Tags and in the ZF the model is usually a DataGateway to a table. Same with objects.

$tags = new Tags();
$cloud = $tags -> getWithObjectOccurrences();

On another note, I would never name a class "object" or "objects" as it is too generic (objects are a basic language construct). Consider finding a more descriptive name for it.

Eran Galperin