/** * Returns the con * @return resource */ function getConnection() { if (is_null($this->con)) { $this->con = Controller::getInstance()->getContext()->getDatabaseConnection('default'); } return $this->con; }
/** * Write a Message to the db table. * @param Message * * @throws <b>LoggingException</b> if no Layout is set or the file * cannot be written. * * @return void */ public function write($message) { if (($layout = $this->getLayout()) === null) { throw new LoggingException('No Layout set'); } $str = sprintf("%s\n", $this->getLayout()->format($message)); /* @var $code_error_form CodeErrorForm */ $code_error_form = Controller::getInstance()->getContext()->getController()->getForm("Error", "CodeError"); /* @var $code_error_model CodeErrorModel */ $code_error_model = Controller::getInstance()->getContext()->getController()->getModel("Error", "CodeError"); $code_error_form->setMessage($message); $code_error_form->setWebApplicationId($this->getWebApplicationId()); $code_error_model->performInsert($code_error_form); }
/** * Retrieve the current application context. * * @return Context A Context instance. */ public function getContext() { return Controller::getInstance()->getContext(); }
/** * Returns the databaseManager * @return DatabaseManager */ function getDatabaseManager() { if (is_null(self::$databaseManager)) { self::$databaseManager = Controller::getInstance()->getContext()->getDatabaseManager(); } return self::$databaseManager; }
/** * Returns the prepared statement with the values replaced. The statement will be * escaped for any string that was passed in. The internal string is not modified * during this process, so it can be used again and again with different values. * @return string */ function getPreparedStatement($con = null) { $retVal = $this->statement; foreach ($this->values as $name => $value) { if ($value['type'] == self::TYPE_BARE_STRING) { $retVal = str_replace("<<" . $name . ">>", $value['value'], $retVal); } else { if ($value['type'] == self::TYPE_UNESCAPED_STRING) { $retVal = str_replace("<<" . $name . ">>", $value['value'], $retVal); } else { if ($value['type'] == self::TYPE_ARRAY) { $retVal = str_replace("<<" . $name . ">>", "'" . implode("','", $value['value']) . "'", $retVal); } else { if (strpos($retVal, "<<" . $name . ">>") !== false) { $retVal = str_replace("<<" . $name . ">>", ":" . $name, $retVal); } else { unset($this->values[$name]); } } } } } /* @var $dbh PDOStatement */ if (is_null($con)) { $con = Controller::getInstance()->getContext()->getDatabaseConnection('default'); } if (is_null($con)) { LoggerManager::error(__METHOD__ . " :: " . var_export($con, true)); throw new \Exception('Cannot instantiate PDO object with query: ' . $retVal); } $dbh = $con->prepare($retVal); foreach ($this->values as $name => $value) { if ($value['type'] == self::TYPE_FLOAT) { $dbh->bindValue(":" . $name, $value["value"], \PDO::PARAM_INT); } else { if ($value['type'] == self::TYPE_INTEGER) { $dbh->bindValue(":" . $name, $value["value"], \PDO::PARAM_INT); } else { if ($value['type'] == self::TYPE_LONG) { $dbh->bindValue(":" . $name, $value["value"], \PDO::PARAM_INT); } else { if ($value['type'] == self::TYPE_DATE) { $dbh->bindValue(":" . $name, $value["value"], \PDO::PARAM_STR); } else { if ($value['type'] == self::TYPE_TIMESTAMP) { $dbh->bindValue(":" . $name, $value["value"], \PDO::PARAM_STR); } else { if ($value['type'] == self::TYPE_TIME) { $dbh->bindValue(":" . $name, $value["value"], \PDO::PARAM_STR); } else { if ($value['type'] == self::TYPE_NULL) { $dbh->bindValue(":" . $name, $value["value"], \PDO::PARAM_NULL); } else { if ($value['type'] == self::TYPE_BOOLEAN) { $dbh->bindValue(":" . $name, $value["value"], \PDO::PARAM_BOOL); } else { if ($value['type'] == self::TYPE_BARE_STRING) { continue; } else { if ($value['type'] == self::TYPE_UNESCAPED_STRING) { continue; } else { if ($value['type'] == self::TYPE_ARRAY) { continue; } else { if ($value['type'] == self::TYPE_BINARY_STRING) { $dbh->bindValue(":" . $name, $value["value"], \PDO::PARAM_STR); } else { $dbh->bindValue(":" . $name, $value["value"], \PDO::PARAM_STR); } } } } } } } } } } } } } return $dbh; }
/** * Retrieves the Errors object. * @return Errors */ function getErrors() { return Controller::getInstance()->getContext()->getErrors(); }
/** * Retrieve an attribute. * * @param string An attribute name. * @param mixed The name of the module of the form you'd like returned OR the actual value you'd like returned if the parameter does not exist * @param string The name of the form you'd like returned * * @return mixed An attribute value, if the attribute exists, otherwise * null. */ public function &getAttribute($name, $default = null, $default2 = null) { $retval = $default; if (isset($this->attributes[$name])) { $retval = $this->attributes[$name]; } elseif (!is_null($default2)) { $retval = Controller::getInstance()->getContext()->getController()->getForm($default, $default2); } return $retval; }
/** * Returns the collection based on this class * @param string $db_host * @param string $db_name * @param string $collection * @return MongoCollection */ public function getCollection($db_name = null, $collection = null) { if (is_null($collection)) { if ($this->getCollectionName() == '') { throw new \Exception('You have not set the collection name for ' . get_class($this)); } $collection = $this->getCollectionName(); } if (is_null($db_name)) { $db_name = $this->getDbName(); } if (trim($collection) == '') { // Use the default database name according to the connection $collection = Controller::getInstance()->getContext()->getDatabaseManager()->getDatabase($db_name)->getParameter('database'); } return $this->getConnection($db_name)->{$collection}; }