예제 #1
0
파일: View.php 프로젝트: asymptix/framework
 public function __construct($tpl)
 {
     if (!empty($tpl)) {
         if (is_string($tpl)) {
             $this->_tpl = $tpl;
         } elseif (Tools::isInstanceOf($tpl, new Route())) {
             $this->_route = $tpl;
             $this->_tpl = $this->_route->controller . "/" . $this->_route->controller . "_" . $this->_route->action;
         } else {
             throw new \Exception("Invalid view template");
         }
     } else {
         throw new \Exception("Empty view template");
     }
 }
예제 #2
0
파일: User.php 프로젝트: asymptix/framework
 /**
  * Checks if user is logged in.
  *
  * @global User $_USER Current user object.
  *
  * @return boolean
  */
 public static function checkLoggedIn()
 {
     global $_USER;
     if (Tools::isInstanceOf($_USER, new User())) {
         return true;
     }
     return false;
 }
예제 #3
0
 /**
  * Generates SQL formatted condition string.
  *
  * @param mixed $queryCondition List of DBQueryCondition objects or object
  *           itself.
  * @param string $operator Initial logical OR or AND operator.
  *
  * @return string SQL query condition string.
  */
 public static function getSQLCondition($queryCondition, $operator = "")
 {
     $operator = strtoupper(trim($operator));
     if ($operator === "OR" || $operator === "AND") {
         if (is_array($queryCondition)) {
             if ($operator === "AND") {
                 $cond = " (1";
             } else {
                 $cond = " (0";
             }
             foreach ($queryCondition as $operation => $conditions) {
                 $cond .= " " . $operator . self::getSQLCondition($conditions, $operation);
             }
             $cond .= ")";
             return $cond;
         }
     } else {
         if (is_array($queryCondition)) {
             foreach ($queryCondition as $operation => $conditions) {
                 return trim(str_replace(["(1 AND ", "(0 OR "], "(", self::getSQLCondition($conditions, $operation)));
             }
         } elseif (Tools::isInstanceOf($queryCondition, "\\Asymptix\\db\\DBQueryCondition")) {
             return " " . $queryCondition->sqlCondition;
         }
         return "";
     }
 }
예제 #4
0
파일: DBCore.php 프로젝트: pomed/Framework
 /**
  * Execute DB SQL queries using Prepared Statements.
  *
  * @param mixed $query SQL query template string or DBPreparedQuery object
  *           if single parameter.
  * @param string $types Types string (ex: "isdb").
  * @param array $params Parameters in the same order like types string.
  *
  * @return mixed Statement object or FALSE if an error occurred.
  */
 private static function doQuery($query, $types = "", $params = array())
 {
     if (!Tools::isInstanceOf($query, new DBPreparedQuery())) {
         $dbQuery = new DBPreparedQuery($query, $types, $params);
     } else {
         $dbQuery = $query;
     }
     $stmt = self::connection()->prepare($dbQuery->query);
     self::checkDbError(self::connection());
     if ($dbQuery->isBindable()) {
         if ($dbQuery->isValid()) {
             self::bindParameters($stmt, $dbQuery->types, $dbQuery->params);
         } else {
             throw new DBCoreException("Number of types is not equal parameters number or types string is invalid");
         }
     }
     $stmt->execute();
     self::checkDbError($stmt);
     return $stmt;
 }
예제 #5
0
 /**
  * Executes SQL query with single record and value result and return this value.
  *
  * @param mixed $query SQL query template string or DBPreparedQuery object
  *           if single parameter.
  * @param string $types Types string (ex: "isdb").
  * @param array $params Parameters in the same order like types string.
  *
  * @return mixed
  * @throws DBCoreException If no one or more than one records selected.
  */
 public static function selectSingleValue($query, $types = "", $params = [])
 {
     if (!Tools::isInstanceOf($query, new DBPreparedQuery())) {
         $dbQuery = new DBPreparedQuery($query, $types, $params);
     } else {
         $dbQuery = $query;
     }
     $stmt = $dbQuery->go();
     if ($stmt !== false) {
         $value = null;
         $numRows = $stmt->num_rows;
         if ($numRows === 1) {
             $stmt->bind_result($value);
             $stmt->fetch();
         }
         $stmt->close();
         if ($numRows !== 1) {
             throw new DBCoreException("No one or more than one records selected.");
         }
         return $value;
     }
     return null;
 }