Class: AllocationCd
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- AllocationCd
- Defined in:
- model/allocation_cd.rb
Class Method Summary collapse
- .reassign_assignations(rev_id, stage, user_id_from, user_id_to, cds_id, status) ⇒ Object
- .update_assignation(rev_id, cds_id, user_id, stage, status = nil) ⇒ Object
Class Method Details
.reassign_assignations(rev_id, stage, user_id_from, user_id_to, cds_id, status) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'model/allocation_cd.rb', line 38 def self.reassign_assignations(rev_id, stage, user_id_from, user_id_to, cds_id, status) current_user_to=AllocationCd.where(:systematic_review_id=>rev_id, :user_id=>user_id_to, :stage=>stage).map(:canonical_document_id) # delete canonical from user_from # add canonical to user_to to_add=cds_id-current_user_to $db.transaction() do AllocationCd.where(:systematic_review_id=>rev_id, :user_id=>user_id_from, :stage=>stage, :canonical_document_id=>cds_id).delete to_add.each do |cd_id| AllocationCd.insert(:systematic_review_id=>rev_id, :user_id=>user_id_to, :stage=>stage, :canonical_document_id=>cd_id, :status=>status) end end result=Result.new() result.success(I18n::t("systematic_review_page.result_massive_reassignation_from_to", :original_number=>cds_id.length, :assigned_number=>to_add.length, :user_from=>user_id_from, :user_to=>user_id_to)) result end |
.update_assignation(rev_id, cds_id, user_id, stage, status = nil) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'model/allocation_cd.rb', line 69 def self.update_assignation(rev_id, cds_id, user_id,stage, status=nil) current=AllocationCd.where(:systematic_review_id=>rev_id, :user_id=>user_id, :stage=>stage).map(:canonical_document_id) to_remove=current-cds_id to_add=cds_id-current $db.transaction do AllocationCd.where(:systematic_review_id=>rev_id, :user_id=>user_id, :stage=>stage, :canonical_document_id=>to_remove).delete to_add.each do |cd_id| AllocationCd.insert(:systematic_review_id=>rev_id, :user_id=>user_id, :stage=>stage, :canonical_document_id=>cd_id, :status=>status) end end user=User[user_id] result=Result.new() result.success(I18n::t(:result_assignation_cd_to_user, :added=>to_add.length, :removed=>to_remove.length, :user_name=>user[:name])) result end |