Browse Source

Continued e3f6fd8a350b218c9d0f35f4f32a6792e613e9ca

Dmitry Yu Okunev 5 years ago
parent
commit
fb1914f93d
3 changed files with 38 additions and 0 deletions
  1. 8 0
      formular.go
  2. 26 0
      person.go
  3. 4 0
      unit.go

+ 8 - 0
formular.go

@@ -85,6 +85,10 @@ func (f *Formular) PrepareUnit() *Formular {
 	return f
 }
 
+func (f Formular) IsUnitReady() bool {
+	return f.unitReady
+}
+
 func (f Formular) GetUnit() Unit {
 	if !f.unitReady {
 		panic("formular is not ready for method GetUnit: it's required to call PrepareUnit method, first")
@@ -103,6 +107,10 @@ func (f *Formular) PreparePerson() *Formular {
 	return f
 }
 
+func (f Formular) IsPersonReady() bool {
+	return f.personReady
+}
+
 func (f Formular) GetPerson() Person {
 	if !f.personReady {
 		panic("formular is not ready for method GetPerson: it's required to call PreparePerson method, first")

+ 26 - 0
person.go

@@ -90,6 +90,10 @@ func (person *Person) PrepareFormulars() *Person {
 	return person
 }
 
+func (person Person) IsFormularsReady() bool {
+	return person.formularsReady
+}
+
 func (person Person) GetFormulars() Formulars {
 	if !person.formularsReady {
 		panic("person is not ready for method GetFormulars: it's required to call PrepareFormulars method, first")
@@ -101,3 +105,25 @@ func (person Person) GetFormularsPtr() *Formulars {
 	return &person.formulars
 }
 
+func (people People) PrepareFormulars() People {
+	ids := people.GetEmpGUIDs()
+
+	formulars, err := FormularSQL.Select("EmpGUID IN (?)", ids)
+	if err != nil && err != sql.ErrNoRows {
+		panic(err)
+	}
+
+	personMap := People(people).ToMap()
+
+	for _, formular := range formulars {
+		(*personMap[formular.EmpGUID]).formulars = append((*personMap[formular.EmpGUID]).formulars, formular)
+	}
+
+	for idx, _ := range people {
+		people[idx].formularsReady = true
+	}
+
+	return people
+}
+
+

+ 4 - 0
unit.go

@@ -176,6 +176,10 @@ func (u Unit) GetFormularsPtr() *Formulars {
 	return &u.formulars
 }
 
+func (u Unit) IsFormularsReady() bool {
+	return u.formularsReady
+}
+
 func (u Unit) GetFormulars() Formulars {
 	if !u.formularsReady {
 		panic("unit is not ready for method GetFormulars: it's required to call PrepareFormulars method, first")