示例#1
0
 public static function updatePost(Post $post)
 {
     $pdoMysql = new PdoMysql();
     $pdoMysql->conn();
     $sql = "UPDATE post_data SET ";
     $bindValues = array();
     foreach ($post->bindings as $field => $value) {
         if (!is_null($value) && $field != 'post_id' && $field != 'id') {
             if (is_a($value, 'BindingsEscape')) {
                 $sql .= "{$field}={$value->value}, ";
             } else {
                 $sql .= "{$field}=:{$field}, ";
                 $bindValues[$field] = $value;
             }
         }
     }
     $sql = substr($sql, 0, -2);
     $sql .= " WHERE id = {$post->id}";
     $rv = $pdoMysql->query($sql, $bindValues);
     if (is_a($rv, 'ErrorObject')) {
         $rv->caller = $_SERVER['SCRIPT_FILENAME'];
         return $rv;
     }
     return $pdoMysql->getNumRows();
 }
示例#2
0
 public static function setNewSubCategory($categoryName, $parentId)
 {
     $pdoMysql = new PdoMysql();
     $pdoMysql->conn();
     $categoryId = self::setNewCategory($categoryName);
     if (is_a($categoryId, 'ErrorObject')) {
         $rv->caller = $_SERVER['SCRIPT_FILENAME'];
         return $categoryId;
     }
     $sql = "INSERT INTO sub_categories\n              (`category_id`, `parent_id`) VALUES\n              (:categoryId, :parentId)";
     $bindValues = array('categoryId' => $categoryId, 'parentId' => $parentId);
     $rv = $pdoMysql->query($sql, $bindValues);
     if (is_a($rv, 'ErrorObject')) {
         $rv->caller = $_SERVER['SCRIPT_FILENAME'];
         return $rv;
     }
     return $categoryId;
 }
示例#3
0
 private static function deleteToken($token)
 {
     $pdoMysql = new PdoMysql();
     $pdoMysql->conn();
     $sql = "DELETE FROM session_tokens WHERE token='{$token}'";
     $rv = $pdoMysql->query($sql, array());
 }
示例#4
0
 public static function approveComment($commentId)
 {
     $pdoMysql = new PdoMysql();
     $pdoMysql->conn();
     $sql = "UPDATE comments SET approved = 1 WHERE id={$commentId}";
     $bindValues = array();
     $rs = $pdoMysql->query($sql, $bindValues);
     if (is_a($rs, 'ErrorObject')) {
         $rs->caller = $_SERVER['SCRIPT_FILENAME'];
         return $rs;
     }
     return $rs;
 }
示例#5
0
 public static function getFakeUser($postId = null)
 {
     $pdoMysql = new PdoMysql();
     $pdoMysql->conn();
     if (!is_null($postId)) {
         $sql = "SELECT id\n                     , user_name\n                     , user_type\n                     , email\n                     , user_pw\n                     , date_joined\n              FROM users\n              WHERE user_type = 4\n              AND id NOT IN (\n                SELECT user_id FROM comments\n                WHERE post_id = {$postId})";
     } else {
         $sql = "SELECT id\n                     , user_name\n                     , user_type\n                     , email\n                     , user_pw\n                     , date_joined\n              FROM users\n              WHERE user_type = 4";
     }
     $rv = $pdoMysql->query($sql, array());
     if (is_a($rv, 'ErrorObject')) {
         $rv->caller = $_SERVER['SCRIPT_FILENAME'];
         return $rv;
     }
     $rs = $pdoMysql->getResultsSet();
     if (count($rs) <= 0) {
         return self::getAllFakeUsers();
     }
     return self::parseResults($rs);
 }