clsItemDB(); $this->tablename = GetTablePrefix()."Favorites"; $this->id_field = "FavoriteId"; $this->NoResourceId=1; if($FavoriteId) $this->LoadFromDatabase($FavoriteId); } function LoadFromDatabase($Id) { global $objSession,$Errors; if(!isset($Id)) { $Errors->AddError("error.AppError",NULL,'Internal error: LoadFromDatabase id',"",get_class($this),"LoadFromDatabase"); return false; } $sql = sprintf("SELECT * FROM ".$this->tablename." WHERE FavoriteId = '%s'",$Id); $result = $this->adodbConnection->Execute($sql); if ($result === false) { $Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"LoadFromDatabase"); return false; } $data = $result->fields; if(is_array($data)) $this->SetFromArray($data); $this->Clean(); return TRUE; } function LoadFavorite($PortalUserId,$ResourceId) { global $objSession,$Errors; $sql = "SELECT * FROM ".$this->tablename." WHERE PortalUserId='$PortalUserId' AND ResourceId=$ResourceId"; $result = $this->adodbConnection->Execute($sql); if($result === false) { $Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"LoadFromDatabase"); return FALSE; } if($result->EOF) { return FALSE; } else { $data = $result->fields; if(is_array($data)) $this->SetFromArray($data); $this->Clean(); return TRUE; } } } /* clsFavorite */ class clsFavoriteList extends clsItemCollection { var $Page; var $PerPage; function clsFavoriteList() { $this->clsItemCollection(); $this->SourceTable = GetTablePrefix()."Favorites"; $this->classname = "clsFavorite"; $this->Page=1; } function &AddFavorite($PortalUserId, $ResourceId,$ItemType) { $f = new clsFavorite; $f->Set(array("PortalUserId","ResourceId","ItemTypeId","Modified"), array($PortalUserId,$ResourceId,$ItemType,adodb_date("U"))); $f->Create(); return $f; } function DeleteFavorite($PortalUserId,$ResourceId) { $sql = "DELETE FROM ".$this->SourceTable." WHERE PortalUserId=$PortalUserId AND ResourceId=$ResourceId "; if($this->debuglevel) echo $sql; $this->adodbConnection->Execute($sql); } function GetFavoriteObject($PortalUserId,$ResourceId) { $c = new clsFavorite(); if($c->LoadFavorite($PortalUserId,$ResourceId)) { return $c; } else return FALSE; } function DeleteUser($PortalUserId) { $sql = "DELETE FROM ".$this->SourceTable." WHERE PortalUserId=$PortalUserId"; $this->adodbConnection->Execute($sql); } function DeleteItem($ResourceId) { $sql = "DELETE FROM ".$this->SourceTable." WHERE ResourceId=$ResourceId"; $this->adodbConnection->Execute($sql); } function LoadFavorites($PortalUserId,$ItemTypes=NULL) { $where = " PortalUserId=$PortalUserId"; if(strlen($ItemTypes)) { $where .= " AND ItemTypeId IN ($ItemTypes)"; } $sql = "SELECT * FROM ".$this->SourceTable." WHERE ".$where; $this->Clear(); $this->QueryItemCount=TableCount($this->SourceTable,$where,0); $this->Query_Item($sql); } function GetLimitSQL() { if($this->Page<1) $this->Page=1; if(is_numeric($this->PerPage)) { $Start = ($this->Page-1)*$this->PerPage; $limit = "LIMIT ".$Start.",".$this->PerPage; } else $limit = NULL; return $limit; } }