Commit 6259b1af3a9b3125513fa3e042f5ec6f06de969d
1 parent
c14a3e83
Exists in
master
and in
29 other branches
profile_suggestions: new rules on stoa plugin
(ActionItem3234)
Showing
2 changed files
with
49 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,35 @@ | @@ -0,0 +1,35 @@ | ||
1 | +require_dependency 'profile_suggestion' | ||
2 | + | ||
3 | +class ProfileSuggestion | ||
4 | + | ||
5 | + CATEGORIES.merge!({:common_classroom => _('Classroom in common')}) | ||
6 | + | ||
7 | + RULES += %w[ | ||
8 | + people_with_common_classroom | ||
9 | + ] | ||
10 | + | ||
11 | + def self.people_with_common_classroom(person) | ||
12 | + usp_id = person.usp_id | ||
13 | + return if usp_id.nil? | ||
14 | + person_attempts = 0 | ||
15 | + StoaPlugin::UspAlunoTurmaGrad.classrooms_from_person(usp_id).each do |classroom| | ||
16 | + person_attempts += 1 | ||
17 | + return unless person.profile_suggestions.count < N_SUGGESTIONS && person_attempts < MAX_ATTEMPTS | ||
18 | + StoaPlugin::UspAlunoTurmaGrad.find_all_by_codtur(classroom.codtur).each do |same_class| | ||
19 | + classmate = Person.find_by_usp_id(same_class.codpes) | ||
20 | + unless classmate.nil? || classmate == person || classmate.is_a_friend?(person) || person.already_request_friendship?(classmate) | ||
21 | + suggestion = person.profile_suggestions.find_or_initialize_by_suggestion_id(classmate.id) | ||
22 | + suggestion.common_classroom = 1 | ||
23 | + suggestion.save | ||
24 | + end | ||
25 | + end | ||
26 | + end | ||
27 | + end | ||
28 | + | ||
29 | + def self.people_with_common_discipline(person) | ||
30 | + person_attempts = 0 | ||
31 | + person_attempts += 1 | ||
32 | + return unless person.profile_suggestions.count < N_SUGGESTIONS && person_attempts < MAX_ATTEMPTS | ||
33 | + end | ||
34 | + | ||
35 | +end |
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +class StoaPlugin::UspAlunoTurmaGrad < ActiveRecord::Base | ||
2 | + | ||
3 | + establish_connection(:stoa) | ||
4 | + set_table_name('alunoturma_gr') | ||
5 | + | ||
6 | + def self.exists?(usp_id) | ||
7 | + StoaPlugin::UspUser.find_by_codpes(usp_id.to_i) | ||
8 | + end | ||
9 | + | ||
10 | + def self.classrooms_from_person(usp_id) | ||
11 | + StoaPlugin::UspAlunoTurmaGrad.find_all_by_codpes(usp_id) | ||
12 | + end | ||
13 | + | ||
14 | +end |