Example #1
0
    /**
     *
     * @param <type> $post_id
     * @param <type> $new_content
     * @param <type> $new_parent
     * @param <type> $new_order
     * @return <type> 
     */
    public function post_update(
            $post_id,
            $new_content = false,
            $new_parent = false,
            $new_order  = false,
            $metadata   = false)
    {
        if (!is_numeric($post_id))
        {
            throw new DBForumException(
                    '$post_id must be numeric');
        }
        if (!is_bool($new_parent) && !is_numeric($new_parent))
        {
            throw new DBForumException(
                    '$new_parent must be numeric or boolean');
        }
        if (!is_bool($new_order) && !is_numeric($new_order))
        {
            throw new DBForumException(
                    '$new_order must be numeric or boolean');
        }
        if (!is_bool($new_content))
        {
            self::validate_content($new_content, $this->post_datatype);
        }
        if (!is_bool($metadata) && !is_string($metadata))
        {
            throw new DBDataTypeException(
                    '$metadata must be a string');
        }
        if (is_bool($new_content) && 
            is_bool($new_parent) &&
            is_bool($new_order) &&
            is_bool($metadata))
        {
            return;
        }
        try
        {
            if (!is_bool($new_parent) || !is_bool($new_order) || !is_bool($metadata))
            {
                if (is_bool($new_order) && !is_bool($new_parent))
                {
                    $new_order = $this->db->quick_query(
                            "SELECT max(".self::POSTORDER.") FROM ".self::FCORE_FORUM_POST." WHERE
                                ".self::POSTPARENT."=$new_parent AND
                                ".self::FORUM_ID."=$this->forum_id", true);
                    if ($new_order == null)
                    {
                        $new_order = 0;
                    }
                    else
                    {
                        $new_order = $new_order[0]["max(".self::POSTORDER.")"];
                        $new_order++;
                    }
                }
                $set = "";
                if (!is_bool($new_parent))
                {
                    if ($new_parent != 0)
                    {
                        $count = $this->db->quick_query(
                                "SELECT COUNT(*) FROM ".self::FCORE_FORUM_POST." WHERE
                                    ".self::FORUM_ID."=$this->forum_id &&
                                    ".self::POST_ID."=$new_parent",
                                true);
                        $count = $count[0]["COUNT(*)"];
                        if ($count == 0)
                        {
                            throw new Exception(
                                    "the parent id does not exist in this forum");
                        }
                    }
                    $set .= self::POSTPARENT."=$new_parent";
                    if (!is_bool($new_order) || !is_bool($metadata))
                    {
                        $set .= ",";
                    }
                }
                if (!is_bool($new_order))
                {
                    $set .= self::POSTORDER."=$new_order";
                    if (!is_bool($metadata))
                    {
                        $set .= ",";
                    }
                }
                if (!is_bool($metadata))
                {
                    $set .= self::METADATA."='$metadata'";
                }

                $this->db->quick_query(
                        "UPDATE ".self::FCORE_FORUM_POST." SET
                            $set
                            WHERE
                            ".self::POST_ID."=$post_id AND
                            ".self::FORUM_ID."=$this->forum_id");
                $this->db->commit();
            }
            if (is_string($new_content))
            {
                DBDataType::UpdateContentFromOrigin(
                        $new_content,
                        self::build_datatype_origin($this->origin_type),
                        $post_id);
            }
        }
        catch(Exception $e)
        {
            $this->db->rollback();
            throw new DBForumException($e->getMessage());
        }
    }
Example #2
0
 /**
  * 
  */
 public function delete_all()
 {
     try
     {
         $this->conn->quick_query(
                 "DELETE FROM ".$this->config_map[self::DB_TABLE_NAME]
                 );
         $this->conn->commit();
     }
     catch(DBConnectException $e)
     {
         $this->conn->rollback();
         FCore::GetLogger()->log(Logger::LEVEL_ERROR, $e->getMessage());
         throw new DBFactoryException(
                 "An Error Occurred While Attempting To Delete: ", $e);
     }
 }