public function GET() { // throw new RESTMethodNotImplementedException ('Pesquisa', 'GET'); $questoes = Application::getConf('questoes'); $result = array(); //@todo Pegar total de registros $db = Database::getDatabase(); $total = $db->query('select count(*) from pesquisa')->fetchColumn(); foreach ($questoes as $questao) { $numero = $questao->questao; $tabela = 'count_' . $questao->questao; $tipo = $questao->tipo; $descricao = $questao->descricao; $st = $db->query("select * from {$tabela}"); if ($tipo == 'int') { $result[] = (object) array("questao" => $numero, "descricao" => $descricao, "respostas" => (array) $st->fetch(PDO::FETCH_ASSOC)); } else { $rows = array(); while ($row = $st->fetch(PDO::FETCH_ASSOC)) { $rows[] = (object) array("escolha" => $row[$numero], "Total" => $row['Total']); } $result[] = (object) array("questao" => $numero, "descricao" => $descricao, "respostas" => $rows); } } $this->setResult(array('status' => 'OK', 'content' => (object) array('votos' => $total, 'respostas' => $result))); }
public function __construct() { $security = Application::getConf('security'); if ($security === FALSE) { throw new RESTObjectException('System error'); } $this->secrets = $security->secrets; }
public function __construct() { $database = Application::getConf('database'); $dbname = $database->database; $host = $database->host; $port = $database->port; parent::__construct("mysql:dbname={$dbname};" . "host={$host};" . "port={$port};", $database->user, $database->password); }
/** * Configuration constructor. * @param Application $app */ public function __construct(Application $app) { $this->path = str_replace(DIRECTORY_SEPARATOR, '/', realpath(dirname(__FILE__) . '/..')); $this->path_root_postfix = '/webroot'; $this->path_root = $this->setPathRoot(); $this->path_url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . (strlen($this->path_root) ? "/" . $this->getPathRoot() : ''); $this->path_sys_template = '/Template/base.twig'; $this->path_user_template = '/App/views/'; $this->path_library = $this->path . '/ArtLibs/'; $this->path_template = $this->getPathSysTemplate(); $this->path_static = $this->getPathUrl() . '/Template/static/'; $this->db_host = 'localhost'; $this->db_name = 'artcms'; $this->db_user = '******'; $this->db_pass = ''; $this->development_mode = false; $this->user_var = array('project_name' => 'ArtWeb'); $this->app = $app; $this->conf = $app->getConf(); }
public function POST() { throw new RESTMethodNotImplementedException('Device', 'POST'); $fim = Application::getConf('votacao')->fim; $agora = time; if ($agora > $fim) { throw new RESTObjectException('Votações encerradas', $agora); } $sk = new SecureKeyAuth(); $sd = new SecureDeviceHash(); $sk->checkAuth(); $sd->checkAuth(); $params = $this->getPostParams(); $db = Database::getDatabase(); if ($db->select('device_votou_momo', "iddevice = {$params['iddevice']}")->fetch()) { throw new RESTObjectException('Você já votou para momo'); } try { $db->beginTransaction(); $flag = false; //inserir registro votado $flag = $db->exec("INSERT INTO device_votou_momo (iddevice) VALUES ({$params['iddevice']})") ? TRUE : FALSE; //inserir registro if ($flag) { $flag = $db->exec("INSERT INTO votos_momo (idmomo) VALUES ({$params['idmomo']})") ? TRUE : FALSE; } if ($flag) { $db->commit(); } else { $db->rollBack(); throw new RESTObjectException('Database insert fail'); } $this->GET(); } catch (PDOException $ex) { $db->rollBack(); throw new RESTObjectException('Database insert fail'); } }