Skip to content

Commit

Permalink
Merge pull request #551 from alaashafaee/C3_Saeed_164_Course_Sign_Up_2.6
Browse files Browse the repository at this point in the history
Pull Request: C3_Saeed_164_Course_Sign_Up_2.6
  • Loading branch information
ahmedhagii committed May 16, 2014
2 parents fffba8f + 1442a28 commit a5626aa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions tutor/app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def sign_up
student = Student.find(current_student.id)
if student.courses.find_by_id(@course.id) == nil
student.courses << @course
@course.topics.each do |topic|
progress = TrackProgression.create(level: 0, topic_id: topic.id)
student.progressions << progress
end
else
@status = "7"
end
Expand Down
7 changes: 4 additions & 3 deletions tutor/app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,23 @@ def index
# create_topic_form
# Returns:
# flash[:notice]: A message indicating the success or failure of the creation
# Author: Ahmed Akram
# Author: Ahmed Akram + Mohamed Saeed
def create
@new_topic = Topic.new
@new_topic.title = topic_params[:title]
@new_topic.description = topic_params[:description]
bool = @new_topic.save
if bool == true
if bool == true
flash[:notice] = "Topic successfully created"
@course = Course.find(course_params[:course_id])
@course.topics << @new_topic
redirect_to :action => 'index'
Topic.update_track_progression @new_topic
else
if @new_topic.errors.any?
flash[:notice] = @new_topic.errors.full_messages.first
end
render :action => 'new'
render :action => 'new'
end
end

Expand Down
16 changes: 16 additions & 0 deletions tutor/app/models/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,20 @@ def self.search(params)
end
end
end

# [Course Sign-Up - Story 2.6]
# Update the the progress of all students for a topic in a
# specfic course
# Parameters:
# Topic: the topic in which the progress of students should be updated
# Returns: none
# Author: Mohamed Saeed
def self.update_track_progression topic
course = Course.find_by_id(topic.course_id)
course.students.each do |student|
progress = TrackProgression.create(level: 0, topic_id: topic.id)
student.progressions << progress
end
end

end

0 comments on commit a5626aa

Please sign in to comment.