/** * * @param <type> $post_origin_type * @param <type> $post_origin_id * @param <type> $content * @param <type> $order * @param <type> $parent the parent of the post... if this is set to zero, * then it assumes root */ public function post_create( $post_origin_type, $post_origin_id, $content, $parent = 0, $order = false, $metadata = '') { self::validate_content($content, $this->post_datatype); if (!is_numeric($parent)) { throw new DBForumException( '$parent must be numeric'); } if ($post_origin_type == null || $post_origin_type == "") { throw new DBForumException( '$post_origin_type cannot be null or empty'); } if (!is_null($post_origin_id) && !is_numeric($post_origin_id)) { throw new DBForumException( '$post_origin_id cannot be null or non numeric'); } if (!is_bool($order) && !is_numeric($order)) { throw new DBForumException( '$order must be boolean or numeric'); } if (!is_string($metadata)) { throw new DBDataTypeException( '$metadata must be a string'); } try { if ($parent != 0) { if (null == $this->db->quick_query( "SELECT ".self::POST_ID." FROM ".self::FCORE_FORUM_POST." WHERE ".self::FORUM_ID."=$this->forum_id AND ".self::POST_ID."=$parent", true)) { throw new Exception( 'parent id for the post does not exist in this thread'); } } if (is_bool($order)) { $order = $this->db->quick_query( "SELECT max(".self::POSTORDER.") FROM ".self::FCORE_FORUM_POST." WHERE ".self::POSTPARENT."=$parent AND ".self::FORUM_ID."=$this->forum_id", true); if ($order == null) { $order = 0; } else { $order = $order[0]["max(".self::POSTORDER.")"]; $order++; } } $this->db->quick_query( "INSERT INTO ".self::FCORE_FORUM_POST." SET ".self::FORUM_ID."=$this->forum_id, ".self::POSTPARENT."=$parent, ".self::ORIGIN_ID."=$post_origin_id, ".self::ORIGIN_TYPE."='$post_origin_type', ".self::POSTORDER."=$order, ".self::METADATA."='$metadata'"); $post_id = $this->db->get_last_insert(); DBDataType::CreateData( self::build_datatype_origin($this->origin_type), $post_id, $this->post_datatype, $content); $this->db->commit(); return $post_id; } catch(Exception $e) { $this->db->rollback(); throw new DBForumException($e->getMessage()); } }
/** * * @param array $data */ public function insert(array $data) { try { $this->conn->quick_query( "INSERT ".$this->config_map[self::DB_TABLE_NAME]. " SET ".$this->consume_data($data) ); $insert_id = $this->conn->get_last_insert(); $this->conn->commit(); return $insert_id; } catch(DBConnectException $e) { $this->conn->rollback(); FCore::GetLogger()->log(Logger::LEVEL_ERROR, $e->getMessage()); throw new DBFactoryException( "An Error Occurred While Attempting To Insert: ", $e); } }