Logo Search packages:      
Sourcecode: fet version File versions

bool Rules::modifyTeacher ( const QString &  initialTeacherName,
const QString &  finalTeacherName 
)

Modifies (renames) this teacher and takes care of all related activities and constraints. Returns true on success, false on failure (if not found)

Definition at line 516 of file rules.cpp.

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

{
      assert(this->searchTeacher(finalTeacherName)==-1);
      assert(this->searchTeacher(initialTeacherName)>=0);

      //TODO: improve this part
      for(Activity* act=this->activitiesList.first(); act; act=this->activitiesList.next())
            act->renameTeacher(initialTeacherName, finalTeacherName);

      for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ctr=this->timeConstraintsList.next()){
            if(ctr->type==CONSTRAINT_TEACHER_NOT_AVAILABLE){
                  ConstraintTeacherNotAvailable* crt_constraint=(ConstraintTeacherNotAvailable*)ctr;
                  if(initialTeacherName == crt_constraint->teacherName)
                        crt_constraint->teacherName=finalTeacherName;
            }
      }

      for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ctr=this->timeConstraintsList.next()){
            if(ctr->type==CONSTRAINT_TEACHER_MAX_DAYS_PER_WEEK){
                  ConstraintTeacherMaxDaysPerWeek* crt_constraint=(ConstraintTeacherMaxDaysPerWeek*)ctr;
                  if(initialTeacherName == crt_constraint->teacher)
                        crt_constraint->teacher=finalTeacherName;
            }
      }
      
      for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ctr=this->timeConstraintsList.next()){
            if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){
                  ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr;
                  if(initialTeacherName == crt_constraint->teacherName)
                        crt_constraint->teacherName=finalTeacherName;
            }
      }
      
      for(SpaceConstraint* ctr=this->spaceConstraintsList.first(); ctr; ctr=this->spaceConstraintsList.next()){
            if(ctr->type==CONSTRAINT_TEACHER_REQUIRES_ROOM){
                  ConstraintTeacherRequiresRoom* crt_constraint=(ConstraintTeacherRequiresRoom*)ctr;
                  if(initialTeacherName == crt_constraint->teacherName)
                        crt_constraint->teacherName=finalTeacherName;
            }
      }

      int t=0;
      for(Teacher* tch=this->teachersList.first(); tch; tch=this->teachersList.next())
            if(tch->name==initialTeacherName){
                  tch->name=finalTeacherName;
                  t++;
            }
      assert(t<=1);

      this->internalStructureComputed=false;

      if(t==0)
            return false;
      else
            return true;
}


Generated by  Doxygen 1.6.0   Back to index