[eluser]walrus_lt[/eluser]
Hello, i developed my own forum model, with functions that creates, inserts new topics, categories, forums, messages and so on. I dont know whatever i made it "as best as it can be". So i want to please you to share suggestions what i need to edit to improve my class and usage of it. My forum model class is:
Code:
<?php
class Forum_Model extends Model
{
var $category;
var $forum;
var $topic;
var $message;
var $forum_id;
var $topic_id;
function Forum_Model()
{
parent::Model();
$this -> category = & new _Category;
$this -> forum = & new _Forum;
$this -> topic = & new _Topic;
$this -> message = & new _Message;
}
function get_categories()
{
$this -> db -> select('category_id AS id, category_name AS name')
-> from('forum_categories')
-> order_by('category_order', 'ASC')
-> get();
}
function get_forums()
{
$this -> db -> select('forum_id AS id, forum_name AS name, forum_topics AS topics, forum_messages AS messages')
-> from('forum_forums')
-> where('forum_category', $this->category)
-> order_by('forum_order', 'asc')
-> get();
}
function get_topics()
{
$this -> db -> select('topic_id AS id, topic_name AS name, topic_author AS author, topic_messages AS messages')
-> from('forum_topics')
-> where('forum_id', $this->forum_id)
-> order_by('forum_last_message', 'asc')
-> get();
}
function get_messages()
{
$this -> db -> select('message_id AS id, message_title AS title, message_text AS text, message_author AS author, message_timestamp AS timestamp')
-> from('forum_messages')
-> where('topic_id', $this->topic_id)
-> order_by('message_id', 'asc')
-> get();
}
function create_category()
{
$this -> db -> insert('forum_categories', $this -> category);
}
function create_forum()
{
$this -> db -> insert('forum_forums', $this -> forum);
}
function post_topic()
{
$this -> db -> insert('forum_topics', $this -> topic);
}
function post_mesage()
{
$this -> db -> insert('forum_messages', $this -> message);
}
}
class _Category
{
var $category_order;
var $category_name;
}
class _Forum
{
var $forum_category;
var $forum_name;
var $forum_order;
}
class _Topic
{
var $forum_id;
var $topic_title;
var $topic_author;
}
class _Message
{
var $topic_id;
var $message_title;
var $message_text;
var $message_author;
}
?>
Usage of it is (With create_category() example):
Code:
<?php
class Forum extends Controller
{
function Forum()
{
parent::Controller();
$this->load->model('forum_model');
}
/** ** ** ** ** ** ** **
* Index Page
** ** ** ** ** ** ** **/
function index()
{
$this -> forum_model -> category -> category_order = 0;
$this -> forum_model -> category -> category_name = 'Gera Kategorija';
$this -> forum_model -> create_category();
}
}
?>
I would apprecate any help from anyone, i want make it best