<?php
// $Id: nivelamento_respostas.php,v 1.2 2007/03/17 03:12:34 marcellobrandao Exp $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
// <http://www.xoops.org/> //
// ------------------------------------------------------------------------ //
// This program 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. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program 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 this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
include_once XOOPS_ROOT_PATH."/class/xoopsobject.php";
/**
* nivelamento_respostas class.
* $this class is responsible for providing data access mechanisms to the data source
* of XOOPS user class objects.
*/
class nivelamento_respostas extends XoopsObject
{
var $db;
// constructor
function nivelamento_respostas ($id=null)
{
$this->db =& Database::getInstance();
$this->initVar("cod_resposta",XOBJ_DTYPE_INT,null,false,10);
$this->initVar("cod_pergunta",XOBJ_DTYPE_INT,null,false,10);
$this->initVar("titulo",XOBJ_DTYPE_TXTBOX, null, false);
$this->initVar("iscerta",XOBJ_DTYPE_INT,null,false,10);
$this->initVar("data_criacao",XOBJ_DTYPE_TXTBOX,null,false);
$this->initVar("data_update",XOBJ_DTYPE_TXTBOX,null,false);
$this->initVar("uid_elaboradores",XOBJ_DTYPE_TXTBOX, null, false);
$this->initVar("isativa",XOBJ_DTYPE_INT,null,false,10);
if ( !empty($id) ) {
if ( is_array($id) ) {
$this->assignVars($id);
} else {
$this->load(intval($id));
}
} else {
$this->setNew();
}
}
function load($id)
{
$sql = 'SELECT * FROM '.$this->db->prefix("nivelamento_respostas").' WHERE cod_resposta='.$id;
$myrow = $this->db->fetchArray($this->db->query($sql));
$this->assignVars($myrow);
if (!$myrow) {
$this->setNew();
}
}
function getAllnivelamento_respostass($criteria=array(), $asobject=false, $sort="cod_resposta", $order="ASC", $limit=0, $start=0)
{
$db =& Database::getInstance();
$ret = array();
$where_query = "";
if ( is_array($criteria) && count($criteria) > 0 ) {
$where_query = " WHERE";
foreach ( $criteria as $c ) {
$where_query .= " $c AND";
}
$where_query = substr($where_query, 0, -4);
} elseif ( !is_array($criteria) && $criteria) {
$where_query = " WHERE ".$criteria;
}
if ( !$asobject ) {
$sql = "SELECT cod_resposta FROM ".$db->prefix("nivelamento_respostas")."$where_query ORDER BY $sort $order";
$result = $db->query($sql,$limit,$start);
while ( $myrow = $db->fetchArray($result) ) {
$ret[] = $myrow['nivelamento_respostas_id'];
}
} else {
$sql = "SELECT * FROM ".$db->prefix("nivelamento_respostas")."$where_query ORDER BY $sort $order";
$result = $db->query($sql,$limit,$start);
while ( $myrow = $db->fetchArray($result) ) {
$ret[] = new nivelamento_respostas ($myrow);
}
}
return $ret;
}
}
// -------------------------------------------------------------------------
// ------------------nivelamento_respostas user handler class -------------------
// -------------------------------------------------------------------------
/**
* nivelamento_respostashandler class.
* This class provides simple mecanisme for nivelamento_respostas object
*/
class Xoopsnivelamento_respostasHandler extends XoopsObjectHandler
{
/**
* create a new nivelamento_respostas
*
* @param bool $isNew flag the new objects as "new"?
* @return object nivelamento_respostas
*/
function &create($isNew = true) {
$nivelamento_respostas = new nivelamento_respostas();
if ($isNew) {
$nivelamento_respostas->setNew();
}
//hack consertando
else {
$nivelamento_respostas->unsetNew();
}
//fim do hack para consertar
return $nivelamento_respostas;
}
/**
* retrieve a nivelamento_respostas
*
* @param int $id of the nivelamento_respostas
* @return mixed reference to the {@link nivelamento_respostas} object, FALSE if failed
*/
function &get($id) {
$sql = 'SELECT * FROM '.$this->db->prefix('nivelamento_respostas').' WHERE cod_resposta='.$id;
if (!$result = $this->db->query($sql)) {
return false;
}
$numrows = $this->db->getRowsNum($result);
if ($numrows == 1) {
$nivelamento_respostas = new nivelamento_respostas();
$nivelamento_respostas->assignVars($this->db->fetchArray($result));
return $nivelamento_respostas;
}
return false;
}
/**
* insert a new nivelamento_respostas in the database
*
* @param object $nivelamento_respostas reference to the {@link nivelamento_respostas} object
* @param bool $force
* @return bool FALSE if failed, TRUE if already present and unchanged or successful
*/
function insert(&$nivelamento_respostas, $force = false) {
Global $xoopsConfig;
if (get_class($nivelamento_respostas) != 'nivelamento_respostas') {
return false;
}
if (!$nivelamento_respostas->isDirty()) {
return true;
}
if (!$nivelamento_respostas->cleanVars()) {
return false;
}
foreach ($nivelamento_respostas->cleanVars as $k => $v) {
${$k} = $v;
}
$now = "date_add(now(), interval ".$xoopsConfig['server_TZ']." hour)";
if ($nivelamento_respostas->isNew()) {
// ajout/modification d'un nivelamento_respostas
$nivelamento_respostas = new nivelamento_respostas();
$format = "INSERT INTO %s (cod_resposta, cod_pergunta, titulo, iscerta, data_criacao, data_update, uid_elaboradores, isativa)";
$format .= "VALUES (%u, %u, %s, %u, %s, %s, %s, %u)";
$sql = sprintf($format ,
$this->db->prefix('nivelamento_respostas'),
$cod_resposta
,$cod_pergunta
,$this->db->quoteString($titulo)
,$iscerta
,$now
,$now
,$this->db->quoteString($uid_elaboradores)
,$isativa
);
$force = true;
} else {
$format = "UPDATE %s SET ";
$format .="cod_resposta=%u, cod_pergunta=%u, titulo=%s, iscerta=%u, data_criacao=%s, data_update=%s, uid_elaboradores=%s, isativa=%u";
$format .=" WHERE cod_resposta = %u";
$sql = sprintf($format, $this->db->prefix('nivelamento_respostas'),
$cod_resposta
,$cod_pergunta
,$this->db->quoteString($titulo)
,$iscerta
,$now
,$now
,$this->db->quoteString($uid_elaboradores)
,$isativa
, $cod_resposta);
}
if (false != $force) {
$result = $this->db->queryF($sql);
} else {
$result = $this->db->query($sql);
}
if (!$result) {
return false;
}
if (empty($cod_resposta)) {
$cod_resposta = $this->db->getInsertId();
}
$nivelamento_respostas->assignVar('cod_resposta', $cod_resposta);
return true;
}
/**
* delete a nivelamento_respostas from the database
*
* @param object $nivelamento_respostas reference to the nivelamento_respostas to delete
* @param bool $force
* @return bool FALSE if failed.
*/
function delete(&$nivelamento_respostas, $force = false)
{
if (get_class($nivelamento_respostas) != 'nivelamento_respostas') {
return false;
}
$sql = sprintf("DELETE FROM %s WHERE cod_resposta = %u", $this->db->prefix("nivelamento_respostas"), $nivelamento_respostas->getVar('cod_resposta'));
if (false != $force) {
$result = $this->db->queryF($sql);
} else {
$result = $this->db->query($sql);
}
if (!$result) {
return false;
}
return true;
}
/**
* retrieve nivelamento_respostass from the database
*
* @param object $criteria {@link CriteriaElement} conditions to be met
* @param bool $id_as_key use the UID as key for the array?
* @return array array of {@link nivelamento_respostas} objects
*/
function &getObjects($criteria = null, $id_as_key = false)
{
$ret = array();
$limit = $start = 0;
$sql = 'SELECT * FROM '.$this->db->prefix('nivelamento_respostas');
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
$sql .= ' '.$criteria->renderWhere();
if ($criteria->getSort() != '') {
$sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
}
$limit = $criteria->getLimit();
$start = $criteria->getStart();
}
$result = $this->db->query($sql, $limit, $start);
if (!$result) {
return $ret;
}
while ($myrow = $this->db->fetchArray($result)) {
$nivelamento_respostas = new nivelamento_respostas();
$nivelamento_respostas->assignVars($myrow);
if (!$id_as_key) {
$ret[] =& $nivelamento_respostas;
} else {
$ret[$myrow['cod_resposta']] =& $nivelamento_respostas;
}
unset($nivelamento_respostas);
}
return $ret;
}
/**
* count nivelamento_respostass matching a condition
*
* @param object $criteria {@link CriteriaElement} to match
* @return int count of nivelamento_respostass
*/
function getCount($criteria = null)
{
$sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('nivelamento_respostas');
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
$sql .= ' '.$criteria->renderWhere();
}
$result = $this->db->query($sql);
if (!$result) {
return 0;
}
list($count) = $this->db->fetchRow($result);
return $count;
}
/**
* delete nivelamento_respostass matching a set of conditions
*
* @param object $criteria {@link CriteriaElement}
* @return bool FALSE if deletion failed
*/
function deleteAll($criteria = null)
{
$sql = 'DELETE FROM '.$this->db->prefix('nivelamento_respostas');
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
$sql .= ' '.$criteria->renderWhere();
}
if (!$result = $this->db->query($sql)) {
return false;
}
return true;
}
}
?>