<?php
/**
*
* Copyright (C) 2007 IVLOS
*
* This file is part of PDF Annotation Engine.
*
* PDF Annotation Engine is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* PDF Annotation Engine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PDF Annotation Engine. If not, see <http://www.gnu.org/licenses/>.
*
* PDF Annotation Engine was originaly made by Infi, The Netherlands.
*
* If you have any questions or suggestions, mail us at hide@address.com
*
**/
class annotation extends crud_db {
// regular methods
function get_owner_list() {
$list = array($this->owner_id => true);
if(!empty($this->reply_to)) {
$annotation = annotation::from_id($this->reply_to);
$list += $annotation->get_owner_list();
}
return $list;
}
function delete() {
$areas = $this->get_areas();
foreach($areas as $area) {
$area->delete();
}
$ratings = $this->get_ratings();
foreach($ratings as $rating) {
$rating->delete();
}
return parent::delete(__CLASS__);
}
function check_owner() {
return ($this->owner_id == user::id());
}
function owner() {
return user::from_id($this->owner_id);
}
function get_areas() {
return area::select( array( "annotation_id" => $this->id ) );
}
function add_area($array) {
$area = new area();
$fields = array('page', 'left', 'top', 'width', 'height');
foreach($fields as $field) {
$area->$field = intval($array[$field]);
}
$area->annotation_id = $this->id;
return $area->insert();
}
function add_score($score)
{
$rating = new rating();
$rating->user_id = user::id();
$rating->annotation_id = $this->id;
$rating->score = $score;
$rating->insert();
return $rating->id;
}
function add_comment_to_rating($comment)
{
$rating = new rating();
$rating->user_id = user::id();
$rating->annotation_id = $this->id;
$rating->comment = $comment;
$rating->update();
}
function get_ranking($id = '')
{
global $db;
if($id == '')
$id = $this->id;
$sql = "SELECT AVG(score) FROM rating WHERE annotation_id = ".$id;
return $db->getOne($sql);
}
function get_ranking_comment($id = '')
{
global $db;
if($id == '')
$id = $this->id;
$sql = "SELECT comment FROM rating WHERE annotation_id = ".$id;
return $db->getAll($sql);
}
function get_ratings() {
return rating::select( array( "annotation_id" => $this->id ) );
}
function has_rated($user_id)
{
$ratings = rating::select(array('user_id' => $user_id, 'annotation_id' => $this->id));
return (isset($ratings[0]))? 1: 0;
}
// inherited static methods
function from_row($row) {
return parent::from_row($row, __CLASS__);
}
function from_values($values) {
return parent::from_values($values, __CLASS__);
}
function array_from_id($id) {
return parent::array_from_id($id, __CLASS__);
}
function from_id($id) {
return parent::from_id($id, __CLASS__);
}
function select($filter=array()) {
return parent::select($filter, __CLASS__);
}
function assoc_list($field, $filter=array()) {
return parent::assoc_list($field, $filter, __CLASS__);
}
// inherited regular methods
function update() {
return parent::update(__CLASS__);
}
function insert() {
return parent::insert(__CLASS__);
}
}