[eluser]Hyra[/eluser]
Hey hey,
I've got a quick question to the "best practice" of arranging my model/library cluster. Or at least some opinions, hopefully.
In short:
I'm re-arranging the code for ArtInvolved.com (currently 100% CI ignited)
Lenghtier:
I'm struggling a bit with the way I want to implement the "Browsing functionality". An Artwork has a lot of data to it. The actual artworkdata such as Location of the image and title, but it has a lot of additional data underneath it: Comments, Statistics, ArtistData, etc.
Now, currently I've got one model (Artwork_Mdl) which pretty much handles, well, everything.
It contains methods like:
Code:
get_comments(); // To retrieve the array of comments
get_stats(); // Views, Rewards, Was it featured, etc.
find_by($what, $dir); // Part of the method collection to browse
This, obviously, gets a bit
bloated, and contains a lot of methods that query other tables (user table, log table, etc.) to retrieve the additional info.
While this works OK i was wondering if I should maybe split the model up into a few little models that query the other tables specifically, and, for the sake of usability, have a library that the controller can call, which in turn asks questions to the different models.
A little braindump, for the purpose of "how to display the Latest Additions':
- I create a library "browser"
- This "browser" can be called from the controller with: $this->browser->latest_additions();
- The library invokes an Artwork_Mdl, which returns the basic data such as the ID, title, artistID and the location of the image for the X latest addtions.
This is simple enough. Now, same for a specific artwork:
- The library invokes Artwork_Mdl and requests the data for a specific ArtworkID
- The library invokes the Comment_Mdl and gets all the comments for it
- The library invokes a Stats_Mdl and gets the statistics
- Etc.
Now, adding a new comment ..
- Library has a function "add_comment"
- Library invokes the Comment_Mdl and stores the new comment
As you can see this can get very messy too. In fact, the browser library becomes the Artwork_Mdl the current version uses, but acts as an intermediate, therefore increasing code rather than trimming it down.
I do apologize for the incoherent rambling. It's just that it's unclear to me what approach I should go for, therefore can't really explain
Any help/suggestions/thoughts will be highly appreciated!