@ -157,8 +157,17 @@ class ExerciseController < ApplicationController
else
else
none_shixun_ids = ShixunSchool . where ( " school_id != #{ User . current . user_extensions . try ( :school_id ) } " ) . pluck ( :shixun_id )
none_shixun_ids = ShixunSchool . where ( " school_id != #{ User . current . user_extensions . try ( :school_id ) } " ) . pluck ( :shixun_id )
end
end
@shixuns = Shixun . where ( " status = 2 and challenges_count = 1 and id not in ( #{ none_shixun_ids . join ( " , " ) } ) " ) .
where ( " name like ? " , " % #{ search } % " ) . select { | shixun | shixun . challenges . where ( :st = > 1 ) . count == 0 }
if search . blank?
@shixuns = Shixun . where ( " shixuns.status = 2 and challenges_count = 1 and shixuns.id not in ( #{ none_shixun_ids . join ( " , " ) } ) " ) .
select { | shixun | shixun . challenges . where ( :st = > 1 ) . count == 0 }
else
@shixuns = Shixun . joins ( challenges : :challenge_tags ) . where ( " shixuns.status = 2 and challenges_count = 1 and shixuns.id not in ( #{ none_shixun_ids . join ( " , " ) } ) " ) .
where ( " shixuns.name like ? or challenge_tags.name like ? " , " % #{ search } % " , " % #{ search } % " ) . select { | shixun | shixun . challenges . where ( :st = > 1 ) . count == 0 }
end
@limit = 10
@limit = 10
@total_pages = ( @shixuns . count / 10 . 0 ) . ceil
@total_pages = ( @shixuns . count / 10 . 0 ) . ceil
@shixuns = paginateHelper @shixuns , @limit
@shixuns = paginateHelper @shixuns , @limit