<?

class watch_log extends item {

	public function get_sql() {
		return $this->sql;
	}

	public function __construct() {
		$this->set('watch_log');

		$self = $this;

		$object->add_to_watch_log = function($id, $library_item) {
			$self->_([
				'library_item_id' => $id
			]);	
			if($library_item == NULL) {
				$query = 'SELECT * FROM library WHERE id = ?';
				$library_item = $self->get_sql()->get_row($query, [$id]);
			}
			$library_item['watch_count'] = $library_item['watch_count'] + 1;
			$object->main_instance->get_library()->_([
				'id' => $library_item['id'],
				'watch_count' => $library_item['watch_count']
			]);
		};
	}

	public function load($v) {
		$query = 'SELECT library.relativepath, library.id FROM watch_log, library WHERE watch_log.library_item_id = library.id ORDER BY watch_log.rowid DESC LIMIT 1000';
		return $this->sql->get_rows($query, []);
	}
}

?>