Browse Source

Self load for future

Vova Tkach 5 years ago
parent
commit
a071fa330a

+ 4 - 2
engine/fetdata/blog.go

@@ -32,9 +32,9 @@ type Blog struct {
 	bufferCats map[string][]*BlogCategory
 }
 
-func (this *Blog) load() {
+func (this *Blog) load() *Blog {
 	if this == nil {
-		return
+		return this
 	}
 	sql_nums := `
 		SELECT
@@ -276,6 +276,8 @@ func (this *Blog) load() {
 			Current: this.postsCurrPage >= this.postsMaxPage,
 		}
 	}
+
+	return this
 }
 
 func (this *Blog) Category() *BlogCategory {

+ 5 - 1
engine/fetdata/blog_category.go

@@ -13,6 +13,10 @@ type BlogCategory struct {
 	user *User
 }
 
+func (this *BlogCategory) load() *BlogCategory {
+	return this
+}
+
 func (this *BlogCategory) Id() int {
 	if this == nil {
 		return 0
@@ -28,7 +32,7 @@ func (this *BlogCategory) User() *User {
 		return this.user
 	}
 	this.user = &User{wrap: this.wrap}
-	this.user.load(this.object.A_user)
+	this.user.loadById(this.object.A_user)
 	return this.user
 }
 

+ 5 - 1
engine/fetdata/blog_post.go

@@ -15,6 +15,10 @@ type BlogPost struct {
 	user *User
 }
 
+func (this *BlogPost) load() *BlogPost {
+	return this
+}
+
 func (this *BlogPost) Id() int {
 	if this == nil {
 		return 0
@@ -30,7 +34,7 @@ func (this *BlogPost) User() *User {
 		return this.user
 	}
 	this.user = &User{wrap: this.wrap}
-	this.user.load(this.object.A_user)
+	this.user.loadById(this.object.A_user)
 	return this.user
 }
 

+ 5 - 1
engine/fetdata/currency.go

@@ -10,7 +10,11 @@ type Currency struct {
 	object *utils.MySql_shop_currency
 }
 
-func (this *Currency) load(id int) {
+func (this *Currency) load() *Currency {
+	return this
+}
+
+func (this *Currency) loadById(id int) {
 	if this == nil {
 		return
 	}

+ 3 - 3
engine/fetdata/fetdata.go

@@ -28,12 +28,12 @@ func New(wrap *wrapper.Wrapper, drow interface{}, is404 bool) *FERData {
 	} else if wrap.CurrModule == "blog" {
 		if len(wrap.UrlArgs) == 3 && wrap.UrlArgs[0] == "blog" && wrap.UrlArgs[1] == "category" && wrap.UrlArgs[2] != "" {
 			if o, ok := drow.(*utils.MySql_blog_category); ok {
-				d_Blog = &Blog{wrap: wrap, category: &BlogCategory{wrap: wrap, object: o}}
+				d_Blog = &Blog{wrap: wrap, category: (&BlogCategory{wrap: wrap, object: o}).load()}
 				d_Blog.load()
 			}
 		} else if len(wrap.UrlArgs) == 2 && wrap.UrlArgs[0] == "blog" && wrap.UrlArgs[1] != "" {
 			if o, ok := drow.(*utils.MySql_blog_post); ok {
-				d_Blog = &Blog{wrap: wrap, post: &BlogPost{wrap: wrap, object: o}}
+				d_Blog = &Blog{wrap: wrap, post: (&BlogPost{wrap: wrap, object: o}).load()}
 			}
 		} else {
 			d_Blog = &Blog{wrap: wrap}
@@ -42,7 +42,7 @@ func New(wrap *wrapper.Wrapper, drow interface{}, is404 bool) *FERData {
 	} else if wrap.CurrModule == "shop" {
 		if len(wrap.UrlArgs) == 3 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] == "category" && wrap.UrlArgs[2] != "" {
 			if o, ok := drow.(*utils.MySql_shop_category); ok {
-				d_Shop = &Shop{wrap: wrap, category: &ShopCategory{wrap: wrap, object: o}}
+				d_Shop = &Shop{wrap: wrap, category: (&ShopCategory{wrap: wrap, object: o}).load()}
 				d_Shop.load()
 			}
 		} else if len(wrap.UrlArgs) == 2 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] != "" {

+ 5 - 1
engine/fetdata/index.go

@@ -15,6 +15,10 @@ type Page struct {
 	user *User
 }
 
+func (this *Page) load() *Page {
+	return this
+}
+
 func (this *Page) Id() int {
 	if this == nil {
 		return 0
@@ -30,7 +34,7 @@ func (this *Page) User() *User {
 		return this.user
 	}
 	this.user = &User{wrap: this.wrap}
-	this.user.load(this.object.A_user)
+	this.user.loadById(this.object.A_user)
 	return this.user
 }
 

+ 4 - 2
engine/fetdata/shop.go

@@ -32,9 +32,9 @@ type Shop struct {
 	bufferCats map[string][]*ShopCategory
 }
 
-func (this *Shop) load() {
+func (this *Shop) load() *Shop {
 	if this == nil {
-		return
+		return this
 	}
 	sql_nums := `
 		SELECT
@@ -368,6 +368,8 @@ func (this *Shop) load() {
 			Current: this.productsCurrPage >= this.productsMaxPage,
 		}
 	}
+
+	return this
 }
 
 func (this *Shop) Category() *ShopCategory {

+ 6 - 2
engine/fetdata/shop_category.go

@@ -13,7 +13,11 @@ type ShopCategory struct {
 	user *User
 }
 
-func (this *ShopCategory) load(id int) {
+func (this *ShopCategory) load() *ShopCategory {
+	return this
+}
+
+func (this *ShopCategory) loadById(id int) {
 	if this == nil {
 		return
 	}
@@ -63,7 +67,7 @@ func (this *ShopCategory) User() *User {
 		return this.user
 	}
 	this.user = &User{wrap: this.wrap}
-	this.user.load(this.object.A_user)
+	this.user.loadById(this.object.A_user)
 	return this.user
 }
 

+ 3 - 3
engine/fetdata/shop_product.go

@@ -65,7 +65,7 @@ func (this *ShopProduct) User() *User {
 		return this.user
 	}
 	this.user = &User{wrap: this.wrap}
-	this.user.load(this.object.A_user)
+	this.user.loadById(this.object.A_user)
 	return this.user
 }
 
@@ -77,7 +77,7 @@ func (this *ShopProduct) Currency() *Currency {
 		return this.currency
 	}
 	this.currency = &Currency{wrap: this.wrap}
-	this.currency.load(this.object.A_currency)
+	this.currency.loadById(this.object.A_currency)
 	return this.currency
 }
 
@@ -131,7 +131,7 @@ func (this *ShopProduct) Category() *ShopCategory {
 		return this.category
 	}
 	this.category = &ShopCategory{wrap: this.wrap}
-	this.category.load(this.object.A_category)
+	this.category.loadById(this.object.A_category)
 	return this.category
 }
 

+ 4 - 0
engine/fetdata/shop_product_image.go

@@ -10,6 +10,10 @@ type ShopProductImage struct {
 	object *utils.MySql_shop_product_image
 }
 
+func (this *ShopProductImage) load() *ShopProductImage {
+	return this
+}
+
 func (this *ShopProductImage) ProductId() int {
 	if this == nil {
 		return 0

+ 5 - 1
engine/fetdata/user.go

@@ -10,7 +10,11 @@ type User struct {
 	object *utils.MySql_user
 }
 
-func (this *User) load(id int) {
+func (this *User) load() *User {
+	return this
+}
+
+func (this *User) loadById(id int) {
 	if this == nil {
 		return
 	}