Created
February 8, 2010 19:12
-
-
Save igorw/298475 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class activity_box { | |
| private $items = array(); | |
| private $user_id; | |
| private $exists = true; | |
| public function __construct($user_id) { | |
| $this->user_id = (int) $user_id; | |
| $result = registry::$db->query('SELECT object FROM activity_box WHERE user_id = ' . $this->user_id; | |
| $this->items = unserialize(registry::$db->fetch_field('object', $result); | |
| if (!$this->items) { | |
| $this->items = array(); | |
| $this->exists = false; | |
| } | |
| } | |
| public function add(activity_item $item) { | |
| $this->items[] = $item; | |
| } | |
| public function get_items() { | |
| // do some sorting of items first (usort)... | |
| return $items; | |
| } | |
| public function save() { | |
| if ($this->exists) { | |
| registry::$db->sql_query('UPDATE activity_box SET object = \'' . registry::$db->escape(serialize($this->items)) . '\' WHERE user_id = ' . $this->user_id; | |
| } else { | |
| registry::$db->sql_query('INSERT INTO activity_box (user_id, object) VALUES (' . $this->user_id . ', \'' . registry::$db->escape(serialize($this->items)) . '\''; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment