Exemple #1
0
func scanUser(row *sql.Rows) (schema.User, error) {
	u := schema.User{Person: schema.Person{}}
	var last pq.NullTime
	var r string
	err := row.Scan(
		&u.Person.Firstname,
		&u.Person.Lastname,
		&u.Person.Email,
		&u.Person.Tel,
		&r,
		&last,
	)
	u.Role = schema.Role(r)
	u.LastVisit = nullableTime(last)
	return u, err
}
Exemple #2
0
func (s *Store) DefenseSession(room, id string) (schema.DefenseSession, error) {
	st := s.stmt(defenseSession)
	rows, err := st.Query(room, id)
	if err != nil {
		return schema.DefenseSession{}, err
	}
	defer rows.Close()
	if !rows.Next() {
		return schema.DefenseSession{}, schema.ErrUnknownDefense
	}
	session, err := scanDefenseSession(rows)
	if err != nil {
		return session, err
	}
	//jury
	st = s.stmt(selectJury)
	rows2, err := st.Query(room, id)
	if err != nil {
		return session, err
	}
	defer rows2.Close()
	for rows2.Next() {
		var last pq.NullTime
		u := schema.User{Person: schema.Person{}}
		var role string
		err := rows2.Scan(&u.Person.Firstname,
			&u.Person.Lastname,
			&u.Person.Tel,
			&u.Person.Email,
			&role,
			&last)
		u.Role = schema.Role(role)
		u.LastVisit = nullableTime(last)
		if err != nil {
			return session, err
		}
		session.Juries = append(session.Juries, u)
	}
	//students
	st = s.stmt(selectStudentInDefenseSession)
	rows3, err := st.Query(room, id)
	if err != nil {
		return session, err
	}
	defer rows3.Close()
	for rows3.Next() {

		var student string
		var grade sql.NullInt64
		def := schema.Defense{}
		err = rows3.Scan(&student, &grade, &def.Public, &def.Local, &def.Time)

		if err != nil {
			return session, err
		}
		ints, err := s.Internship(student)
		if err != nil {
			return session, err
		}
		if grade.Valid {
			def.Grade = int(grade.Int64)
		}
		def.Student = ints.Convention.Student
		def.Company = ints.Convention.Company
		session.Defenses = append(session.Defenses, def)
	}
	return session, err
}
Exemple #3
0
//ReportIdleAccount send a mail to the user to remind him to connect
func (n *Notifier) ReportIdleAccount(u schema.User) {
	err := n.mailer.Send(u.Person, "idle_account.txt", u)
	logger.Log("event", "cron", "send an idle account reminder for "+u.Fullname(), err)
}
Exemple #4
0
//TutorNewsLetter send to a tutor a mail about the missing reports or reviews
func (n *Notifier) TutorNewsLetter(tut schema.User, lates []schema.StudentReports) {
	now := time.Now()
	var statuses []studentStatus
	reports := 0
	reviews := 0
	for _, stu := range lates {
		s := studentStatus{Student: stu.Student.User, Status: make([]string, 0)}
		for _, r := range stu.Reports {
			//missing deadlines
			if r.Delivery == nil {
				s.Status = append(s.Status, r.Kind+" deadline passed; was "+r.Deadline.Format(config.DateLayout))
				reports++
			}
			//missing reviews
			if r.Deadline.Before(now) && r.Reviewed == nil {
				deadline := r.Deadline.Add(n.reviewDuration[r.Kind])
				s.Status = append(s.Status, r.Kind+" waiting for review (deadline: "+deadline.Format(config.DateLayout)+")")
				reviews++
			}
		}
		statuses = append(statuses, s)
	}
	//Safety belt
	if reviews == 0 && reports == 0 {
		return
	}
	buf := fmt.Sprintf("send the weekly report to '%s' with %d warning(s): %d late reports, %d pending reviews", tut.Fullname(), len(statuses), reports, reviews)
	err := n.mailer.Send(tut.Person, "tutor_newsletter.txt", statuses)
	logger.Log("event", "cron", buf, err)
}