/** * Forward the user to a specified url * * @param string $url The URL to forward to * @param integer $code[optional] HTTP status code * @param integer $method[optional] 2 for meta redirect instead of header */ public function forward($url, $code = 200) { if (Caspar::getRequest()->isAjaxCall() || Caspar::getRequest()->getRequestedFormat() == 'json') { $this->getResponse()->ajaxResponseText($code, Caspar::getMessageAndClear('forward')); } \caspar\core\Logging::log("Forwarding to url {$url}"); \caspar\core\Logging::log('Triggering header redirect function'); $this->getResponse()->headerRedirect($url, $code); }
/** * Returns the current row * * @return Row */ public function getCurrentRow() { if ($this->int_ptr == 0 && Core::isDebugLoggingEnabled()) { \caspar\core\Logging::log('This is not a valid row'); } if (isset($this->rows[$this->int_ptr - 1])) { return $this->rows[$this->int_ptr - 1]; } return null; }
/** * Performs a query, then returns a resultset * * @param string $action[optional] The crud action performed (select, insert, update, delete, create, alter) * * @return Resultset */ public function performQuery() { try { $values = $this->getCriteria() instanceof Criteria ? $this->getCriteria()->getValues() : array(); if (Core::isDebugMode()) { if (Core::isDebugLoggingEnabled()) { \caspar\core\Logging::log('executing PDO query (' . Core::getSQLCount() . ') - ' . ($this->getCriteria() instanceof Criteria ? $this->getCriteria()->action : 'unknown'), 'B2DB'); } $pretime = Core::getDebugTime(); } for ($i = 0; $i < sizeof($values); $i++) { $value = $values[$i]['value']; $type = $values[$i]['type']; switch ($type) { case 'boolean': $pdotype = \PDO::PARAM_BOOL; break; case 'integer': $pdotype = \PDO::PARAM_INT; break; case 'blob': $pdotype = \PDO::PARAM_LOB; break; default: $pdotype = \PDO::PARAM_STR; } $this->statement->bindValue($i + 1, $value, $pdotype); } $res = $this->statement->execute(); if (!$res) { $error = $this->statement->errorInfo(); if (Core::isDebugMode()) { Core::sqlHit($this, $pretime); } throw new Exception($error[2], $this->printSQL()); } if (Core::isDebugLoggingEnabled()) { \caspar\core\Logging::log('done', 'B2DB'); } if ($this->getCriteria() instanceof Criteria && $this->getCriteria()->action == 'insert') { if (Core::getDBtype() == 'mysql') { $this->insert_id = Core::getDBLink()->lastInsertId(); } elseif (Core::getDBtype() == 'pgsql') { $this->insert_id = Core::getDBLink()->lastInsertId(Core::getTablePrefix() . $this->getCriteria()->getTable()->getB2DBName() . '_id_seq'); if (Core::isDebugLoggingEnabled()) { \caspar\core\Logging::log('sequence: ' . Core::getTablePrefix() . $this->getCriteria()->getTable()->getB2DBName() . '_id_seq', 'b2db'); \caspar\core\Logging::log('id is: ' . $this->insert_id, 'b2db'); } } } $retval = new Resultset($this); if (Core::isDebugMode()) { Core::sqlHit($this, $pretime); } if (!$this->getCriteria() || $this->getCriteria()->action != 'select') { $this->statement->closeCursor(); } return $retval; } catch (\Exception $e) { throw $e; } }
/** * Performs a query, then returns a resultset * * @param string $action[optional] The crud action performed (select, insert, update, delete, create, alter) * * @return Resultset */ public function performQuery() { try { $values = $this->getCriteria() instanceof Criteria ? $this->getCriteria()->getValues() : array(); if (Core::isDebugMode()) { if (Core::isDebugLoggingEnabled()) { \caspar\core\Logging::log('executing PDO query (' . Core::getSQLCount() . ') - ' . ($this->getCriteria() instanceof Criteria ? $this->getCriteria()->action : 'unknown'), 'B2DB'); } $pretime = Core::getDebugTime(); } $res = $this->statement->execute($values); if (!$res) { $error = $this->statement->errorInfo(); if (Core::isDebugMode()) { Core::sqlHit($this, $pretime); } throw new Exception($error[2], $this->printSQL()); } if (Core::isDebugLoggingEnabled()) { \caspar\core\Logging::log('done', 'B2DB'); } if ($this->getCriteria() instanceof Criteria && $this->getCriteria()->action == 'insert') { if (Core::getDBtype() == 'mysql') { $this->insert_id = Core::getDBLink()->lastInsertId(); } elseif (Core::getDBtype() == 'pgsql') { $this->insert_id = Core::getDBLink()->lastInsertId(Core::getTablePrefix() . $this->getCriteria()->getTable()->getB2DBName() . '_id_seq'); if (Core::isDebugLoggingEnabled()) { \caspar\core\Logging::log('sequence: ' . Core::getTablePrefix() . $this->getCriteria()->getTable()->getB2DBName() . '_id_seq', 'b2db'); \caspar\core\Logging::log('id is: ' . $this->insert_id, 'b2db'); } } } $retval = new Resultset($this); if (Core::isDebugMode()) { Core::sqlHit($this, $pretime); } if (!$this->getCriteria() || $this->getCriteria()->action != 'select') { $this->statement->closeCursor(); } return $retval; } catch (\Exception $e) { throw $e; } }