Logo Search packages:      
Sourcecode: fet version File versions

bool Rules::removeTeacher ( const QString &  teacherName  ) 

Removes this teacher and all related activities and constraints. It returns false on failure. If successful, returns true.

!! please improve this!!!

Definition at line 434 of file rules.cpp.

References activitiesList, internalStructureComputed, removeActivity(), removeSpaceConstraint(), removeTimeConstraint(), spaceConstraintsList, ConstraintTeacherMaxDaysPerWeek::teacher, ConstraintTeacherRequiresRoom::teacherName, ConstraintActivitiesPreferredTimes::teacherName, ConstraintTeacherNotAvailable::teacherName, teachersList, and timeConstraintsList.

{
      //TODO: improve this part
      for(Activity* act=this->activitiesList.first(); act; ){
            act->removeTeacher(teacherName);
            if(act->teachersNames.count()==0){
                  this->removeActivity(act->id, act->activityGroupId);
                  act=this->activitiesList.first(); //!!! please improve this!!!
                  //(You have to be careful, there can be erased more activities here)
            }
            else
                  act=this->activitiesList.next();
      }

      for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ){
            if(ctr->type==CONSTRAINT_TEACHER_NOT_AVAILABLE){
                  ConstraintTeacherNotAvailable* crt_constraint=(ConstraintTeacherNotAvailable*)ctr;
                  if(teacherName == crt_constraint->teacherName){
                        this->removeTimeConstraint(ctr); //single constraint removal
                        ctr=this->timeConstraintsList.current();
                  }
                  else{
                        ctr=this->timeConstraintsList.next();
                  }
            }
            else
                  ctr=this->timeConstraintsList.next();
      }
      for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ){
            if(ctr->type==CONSTRAINT_TEACHER_MAX_DAYS_PER_WEEK){
                  ConstraintTeacherMaxDaysPerWeek* crt_constraint=(ConstraintTeacherMaxDaysPerWeek*)ctr;
                  if(teacherName == crt_constraint->teacher){
                        this->removeTimeConstraint(ctr); //single constraint removal
                        ctr=this->timeConstraintsList.current();
                  }
                  else{
                        ctr=this->timeConstraintsList.next();
                  }
            }
            else
                  ctr=this->timeConstraintsList.next();
      }
      for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ){
            if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){
                  ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr;
                  if(teacherName == crt_constraint->teacherName){
                        this->removeTimeConstraint(ctr); //single constraint removal
                        ctr=this->timeConstraintsList.current();
                  }
                  else{
                        ctr=this->timeConstraintsList.next();
                  }
            }
            else
                  ctr=this->timeConstraintsList.next();
      }
      
      for(SpaceConstraint* ctr=this->spaceConstraintsList.first(); ctr; ){
            if(ctr->type==CONSTRAINT_TEACHER_REQUIRES_ROOM){
                  ConstraintTeacherRequiresRoom* crt_constraint=(ConstraintTeacherRequiresRoom*)ctr;
                  if(teacherName == crt_constraint->teacherName){
                        this->removeSpaceConstraint(ctr); //single constraint removal
                        ctr=this->spaceConstraintsList.current();
                  }
                  else{
                        ctr=this->spaceConstraintsList.next();
                  }
            }
            else
                  ctr=this->spaceConstraintsList.next();
      }

      for(Teacher* tch=this->teachersList.first(); tch; tch=this->teachersList.next())
            if(tch->name==teacherName)
                  break;
      this->teachersList.remove();

      this->internalStructureComputed=false;

      return true;
}


Generated by  Doxygen 1.6.0   Back to index