[eluser]TheFuzzy0ne[/eluser]
Hi everyone. I've spent weeks on this, and I'm still not convinced I have it right. I've practically designed a whole forum already, and then get pissed off and end up doing a rewrite. I'd be interested to see how everyone else would do this. I've opted to use objects rather than a model. I'd appreciate any pointers - something I could change, a method I should add, a different structure etc...
Here's the prototype, I think it's fairly self-explanatory, and obviously there will be more methods added eventually.
Code:
<?php
class Forum {
var $id,
$title,
$description,
$lft,
$rgt;
function Forum() {}
function set_id() {} # Setting the id will reinitialize the object.
function get_id() {}
function set_title() {}
function get_title() {}
function set_description() {}
function get_description() {}
function set_lft() {} # Setting the lft will reinitialize the object.
function get_lft() {}
function set_rgt() {} # Setting the rgt will reinitialize the object.
function get_rgt() {}
function delete($forum_id=NULL) {} # Deletes this forum, and any forums/posts under it.
function save() {} # Inserts/updates the database appropriately
function _reset() {} # Resets the object.
function move_up() {} # Moves the forum up one place within the confines of the parent forum.
function move_down() {} # Moves the forum down one place within the confines of the parent forum.
function get_posts($page_num) {} # retreives the posts from the forum
function get_post($post_id) {} # Get's a single post from the database
function add_post($post_obj) {} # Adds a post
function mark_post_read($post_id, $user_id) {}
function mark_forum_read($forum_id, $user_id) {}
function delete_post($post_id) {} # Deletes a post
function delete_all_posts($forum_id) {} # Deletes all posts under the specified forum
function move_post($post_id, $forum_id) {} # Moves a post
}
class Forum_Post {
var $id,
$user_id,
$date,
$subject,
$body;
function Forum_post() {}
function set_id($id) {} # Reinitialises the object.
function get_id() {}
function set_user_id($user_id) {}
function get_user_id() {}
function set_subject($subject) {}
function get_subject() {}
function set_body($body) {}
function get_body() {}
function set_date($date) {}
function get_date() {}
function _reset() {} # Resets the object
}
Although I use objects all the time, I don't think I use them the way I should, but I'd like to, which is why I want to try to start off on the right foot. When I say "how I should", I mean that I only ever seem to need a single object of any one type instantiated at anyone time (like a model, or library).