Skip to content

Instantly share code, notes, and snippets.

@igorw
Created February 8, 2010 19:12
Show Gist options
  • Select an option

  • Save igorw/298475 to your computer and use it in GitHub Desktop.

Select an option

Save igorw/298475 to your computer and use it in GitHub Desktop.
<?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