public static function search($query_string, $sf_user) { if (strlen($query_string) > 3) { $c = new Criteria(); $c->add(self::NAME, '%' . $query_string . '%', Criteria::LIKE); $c->add(self::SCHOOL_YEAR_ID, SchoolYearPeer::retrieveCurrent()->getId()); if ($sf_user->isPreceptor()) { PersonalPeer::joinWithCourse($c, $sf_user->getGuardUser()->getId(), true); } elseif ($sf_user->isTeacher()) { TeacherPeer::joinWithCourses($c, $sf_user->getGuardUser()->getId()); } return self::doSelect($c); } return array(); }
/** * Event listener function that should be registered to * 'admin.build_criteria' event in order to add some * personalized criteria restrictions. * * @param sfEvent $event * @param Criteria $criteria */ static function applyRestrictions(sfEvent $event, $criteria) { $user = sfContext::getInstance()->getUser(); if ($event->getSubject() instanceof schoolyearActions) { // Restrictions for schoolyear module // $criteria->add(...); } elseif ($event->getSubject() instanceof career_subjectActions) { // Restrictions for careersubject module if ($user->getReferenceFor('career')) { $criteria->add(CareerSubjectPeer::CAREER_ID, $user->getReferenceFor('career')); CareerSubjectPeer::OrderByYearAndName($criteria); } } elseif ($event->getSubject() instanceof career_subject_optionActions) { // Restrictions for careersubject module if ($user->getReferenceFor('career')) { $criteria->add(CareerSubjectPeer::IS_OPTION, true); $criteria->add(CareerSubjectPeer::CAREER_ID, $user->getReferenceFor('career')); } } elseif ($event->getSubject() instanceof career_school_yearActions) { if ($school_year_id = $user->getReferenceFor('schoolyear')) { $criteria->add(CareerSchoolYearPeer::SCHOOL_YEAR_ID, $school_year_id); } } elseif ($event->getSubject() instanceof career_subject_school_yearActions) { if ($career_school_year_id = $user->getReferenceFor('career_school_year')) { $criteria->add(CareerSubjectSchoolYearPeer::CAREER_SCHOOL_YEAR_ID, $career_school_year_id); $criteria->add(CareerSubjectPeer::IS_OPTION, false); $criteria->addJoin(CareerSubjectPeer::ID, CareerSubjectSchoolYearPeer::CAREER_SUBJECT_ID); CareerSubjectSchoolYearPeer::sorted($criteria); } } elseif ($event->getSubject() instanceof optional_school_yearActions) { if ($career_school_year_id = $user->getReferenceFor('career_school_year')) { $criteria->add(CareerSubjectSchoolYearPeer::CAREER_SCHOOL_YEAR_ID, $career_school_year_id); $criteria->add(CareerSubjectPeer::HAS_OPTIONS, true); $criteria->addJoin(CareerSubjectPeer::ID, CareerSubjectSchoolYearPeer::CAREER_SUBJECT_ID); } } elseif ($event->getSubject() instanceof division_courseActions) { if ($division_id = $user->getReferenceFor('division')) { $criterion = $criteria->getNewCriterion(CoursePeer::DIVISION_ID, $division_id); $criterion->addOr($criteria->getNewCriterion(CoursePeer::RELATED_DIVISION_ID, $division_id)); $criteria->add($criterion); } if ($user->isPreceptor()) { self::addCoursePreceptorCriteria($criteria, $user); } if ($user->isTeacher()) { self::addCourseTeacherCriteria($criteria, $user); } $criteria->setDistinct(); } elseif ($event->getSubject() instanceof divisionActions) { DivisionPeer::sorted($criteria); if ($user->isPreceptor()) { self::addDivisionPreceptorCriteria($criteria, $user); } elseif ($user->isTeacher()) { self::addDivisionTeacherCriteria($criteria, $user); } elseif ($user->isHeadPreceptor()) { self::addDivisionHeadPersonalCriteria($criteria, $user); } } else { if ($event->getSubject() instanceof shared_studentActions) { $reference_array = sfContext::getInstance()->getUser()->getReferenceFor("shared_student"); $peer = $reference_array["peer"]; $fk = $reference_array["fk"]; if (isset($reference_array["object_id"])) { $object_id = $reference_array["object_id"]; } else { $object_ids = $reference_array["object_ids"]; } $criteria->addJoin(constant("{$peer}::STUDENT_ID"), StudentPeer::ID); $criteria->addGroupByColumn(StudentPeer::ID); if (isset($object_id)) { $criteria->add(constant("{$peer}::{$fk}"), $object_id); } else { $criteria->add(constant("{$peer}::{$fk}"), $object_ids, Criteria::IN); } $criteria->addJoin(StudentPeer::PERSON_ID, PersonPeer::ID); $criteria->add(PersonPeer::IS_ACTIVE, true); } else { if ($event->getSubject() instanceof examinationActions || $event->getSubject() instanceof manual_examinationActions) { $school_year_id = sfContext::getInstance()->getUser()->getReferenceFor("schoolyear"); $criteria->add(ExaminationPeer::SCHOOL_YEAR_ID, $school_year_id); if ($user->isTeacher()) { $criteria->addJoin(ExaminationPeer::ID, ExaminationSubjectPeer::EXAMINATION_ID); $criteria->addJoin(ExaminationSubjectPeer::ID, ExaminationSubjectTeacherPeer::EXAMINATION_SUBJECT_ID); $criteria->addJoin(ExaminationSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID); $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID); $criteria->add(PersonPeer::IS_ACTIVE, true); $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId()); } } else { if ($event->getSubject() instanceof examination_subjectActions) { $examination_id = sfContext::getInstance()->getUser()->getReferenceFor("examination"); $criteria->add(ExaminationSubjectPeer::EXAMINATION_ID, $examination_id); $criteria->addJoin(CareerSubjectSchoolYearPeer::ID, ExaminationSubjectPeer::CAREER_SUBJECT_SCHOOL_YEAR_ID); $criteria->addJoin(CareerSubjectPeer::ID, CareerSubjectSchoolYearPeer::CAREER_SUBJECT_ID); $criteria->addAscendingOrderByColumn(CareerSubjectPeer::YEAR); if ($user->isTeacher()) { $criteria->addJoin(ExaminationSubjectPeer::ID, ExaminationSubjectTeacherPeer::EXAMINATION_SUBJECT_ID); $criteria->addJoin(ExaminationSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID); $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID); $criteria->add(PersonPeer::IS_ACTIVE, true); $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId()); } } else { if ($event->getSubject() instanceof manual_examination_subjectActions) { $examination_id = sfContext::getInstance()->getUser()->getReferenceFor("manual_examination"); $criteria->add(ExaminationSubjectPeer::EXAMINATION_ID, $examination_id); if ($user->isTeacher()) { $criteria->addJoin(ExaminationSubjectPeer::ID, ExaminationSubjectTeacherPeer::EXAMINATION_SUBJECT_ID); $criteria->addJoin(ExaminationSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID); $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID); $criteria->add(PersonPeer::IS_ACTIVE, true); $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId()); } } elseif ($event->getSubject() instanceof examination_repprovedActions) { $school_year_id = sfContext::getInstance()->getUser()->getReferenceFor("schoolyear"); $criteria->add(ExaminationRepprovedPeer::SCHOOL_YEAR_ID, $school_year_id); if ($user->isTeacher()) { $criteria->addJoin(ExaminationRepprovedPeer::ID, ExaminationRepprovedSubjectPeer::EXAMINATION_REPPROVED_ID); $criteria->addJoin(ExaminationRepprovedSubjectPeer::ID, ExaminationRepprovedSubjectTeacherPeer::EXAMINATION_REPPROVED_SUBJECT_ID); $criteria->addJoin(ExaminationRepprovedSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID); $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID); $criteria->add(PersonPeer::IS_ACTIVE, true); $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId()); } } elseif ($event->getSubject() instanceof examination_repproved_subjectActions) { $examination_repproved_id = sfContext::getInstance()->getUser()->getReferenceFor("examination_repproved"); $criteria->add(ExaminationRepprovedSubjectPeer::EXAMINATION_REPPROVED_ID, $examination_repproved_id); ExaminationRepprovedSubjectPeer::sortedBySubject($criteria); if ($user->isTeacher()) { $criteria->addJoin(ExaminationRepprovedSubjectPeer::ID, ExaminationRepprovedSubjectTeacherPeer::EXAMINATION_REPPROVED_SUBJECT_ID); $criteria->addJoin(ExaminationRepprovedSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID); $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID); $criteria->add(PersonPeer::IS_ACTIVE, true); $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId()); } } else { if ($event->getSubject() instanceof courseActions) { $school_year = SchoolYearPeer::retrieveCurrent(); $criteria->add(CoursePeer::DIVISION_ID, null, Criteria::ISNULL); $criteria->add(CoursePeer::SCHOOL_YEAR_ID, $school_year->getId()); if ($user->isPreceptor()) { PersonalPeer::joinWithCourse($criteria, $user->getGuardUser()->getId()); } if ($user->isTeacher()) { $criteria->addJoin(CoursePeer::ID, CourseSubjectPeer::COURSE_ID); $criteria->addJoin(CourseSubjectPeer::ID, CourseSubjectTeacherPeer::COURSE_SUBJECT_ID); $criteria->addJoin(CourseSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID); $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID); $criteria->add(PersonPeer::IS_ACTIVE, true); $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId()); $criteria->setDistinct(); } } else { if ($event->getSubject() instanceof commissionActions) { /* $school_year = SchoolYearPeer::retrieveCurrent(); $criteria->add(CoursePeer::SCHOOL_YEAR_ID, $school_year->getId()); */ CoursePeer::sorted($criteria); $criteria->add(CoursePeer::DIVISION_ID, null, Criteria::ISNULL); $criteria->add(CoursePeer::IS_PATHWAY, false); if ($user->isPreceptor()) { PersonalPeer::joinWithCourse($criteria, $user->getGuardUser()->getId()); } elseif ($user->isTeacher()) { TeacherPeer::joinWithCourses($criteria, $user->getGuardUser()->getId(), true); } if ($user->isHeadPreceptor()) { self::addCommissionHeadPreceptorCriteria($criteria, $user); } } else { if ($event->getSubject() instanceof final_examinationActions) { $school_year_id = sfContext::getInstance()->getUser()->getReferenceFor("schoolyear"); $criteria->add(FinalExaminationPeer::SCHOOL_YEAR_ID, $school_year_id); } else { if ($event->getSubject() instanceof final_examination_subjectActions) { $final_examination_id = sfContext::getInstance()->getUser()->getReferenceFor("final_examination"); $criteria->add(FinalExaminationSubjectPeer::FINAL_EXAMINATION_ID, $final_examination_id); if ($user->isTeacher()) { $criteria->addJoin(FinalExaminationSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID); $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID); $criteria->add(PersonPeer::IS_ACTIVE, true); $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId()); } } else { if ($event->getSubject() instanceof equivalenceActions) { $student_id = sfContext::getInstance()->getUser()->getReferenceFor("student"); $criteria->add(StudentCareerSchoolYearPeer::STUDENT_ID, $student_id); } else { if ($event->getSubject() instanceof sub_orientationActions) { $orientation_id = sfContext::getInstance()->getUser()->getReferenceFor("orientation"); $criteria->add(SubOrientationPeer::ORIENTATION_ID, $orientation_id); } else { if ($event->getSubject() instanceof student_reincorporationActions) { $student_id = sfContext::getInstance()->getUser()->getReferenceFor("student"); if (is_null($student_id)) { $student_id = $user->getAttribute('student_id'); } $criteria->add(StudentReincorporationPeer::STUDENT_ID, $student_id); $criteria->addJoin(StudentReincorporationPeer::CAREER_SCHOOL_YEAR_PERIOD_ID, CareerSchoolYearPeriodPeer::ID); $criteria->addJoin(CareerSchoolYearPeriodPeer::CAREER_SCHOOL_YEAR_ID, CareerSchoolYearPeer::ID); $criteria->add(CareerSchoolYearPeer::SCHOOL_YEAR_ID, SchoolYearPeer::retrieveCurrent()->getId()); } elseif ($event->getSubject() instanceof shared_course_subjectActions) { $teacher_id = sfContext::getInstance()->getUser()->getReferenceFor("teacher"); $criteria->addJoin(CourseSubjectPeer::ID, CourseSubjectTeacherPeer::COURSE_SUBJECT_ID); $criteria->addJoin(CourseSubjectTeacherPeer::TEACHER_ID, $teacher_id); $criteria->setDistinct(); } elseif ($event->getSubject() instanceof personalActions) { $criteria->add(PersonalPeer::PERSONAL_TYPE, PersonalType::PRECEPTOR); } elseif ($event->getSubject() instanceof head_personalActions) { $criteria->add(PersonalPeer::PERSONAL_TYPE, PersonalType::HEAD_PRECEPTOR); } elseif ($event->getSubject() instanceof student_officeActions) { $criteria->add(PersonalPeer::PERSONAL_TYPE, PersonalType::STUDENTS_OFFICE); } elseif ($event->getSubject() instanceof studentActions) { if ($user->isPreceptor()) { SchoolBehaviourFactory::getInstance()->joinPreceptorWithStudents($criteria, $user->getGuardUser()->getId()); } elseif ($user->isTeacher()) { TeacherPeer::joinWithStudents($criteria, $user->getGuardUser()->getId()); } if ($user->isHeadPreceptor()) { $criteria->addJoin(DivisionStudentPeer::STUDENT_ID, StudentPeer::ID); $criteria->addJoin(DivisionStudentPeer::DIVISION_ID, DivisionPeer::ID); self::addDivisionHeadPersonalCriteria($criteria, $user); } } elseif ($event->getSubject() instanceof licenseActions) { if (!is_null(sfContext::getInstance()->getUser()->getReferenceFor("teacher"))) { $person_id = TeacherPeer::retrieveByPK(sfContext::getInstance()->getUser()->getReferenceFor("teacher"))->getPersonId(); } else { $person_id = PersonalPeer::retrieveByPK(sfContext::getInstance()->getUser()->getReferenceFor("personal"))->getPersonId(); } $criteria->add(LicensePeer::PERSON_ID, $person_id); } elseif ($event->getSubject() instanceof teacherActions) { $criteria->setDistinct(); } else { if ($event->getSubject() instanceof career_school_year_periodActions) { $career_school_year_id = sfContext::getInstance()->getUser()->getReferenceFor("career_school_year"); $criteria->add(CareerSchoolYearPeriodPeer::CAREER_SCHOOL_YEAR_ID, $career_school_year_id); } else { if ($event->getSubject() instanceof student_freeActions) { $student_id = sfContext::getInstance()->getUser()->getReferenceFor("student"); if (is_null($student_id)) { $student_id = $user->getAttribute('student_id'); } $criteria->add(StudentFreePeer::STUDENT_ID, $student_id); } else { if ($event->getSubject() instanceof course_subject_student_examinationActions) { $examination_subject_id = sfContext::getInstance()->getUser()->getReferenceFor("examination_subject"); $criteria->add(CourseSubjectStudentExaminationPeer::EXAMINATION_SUBJECT_ID, $examination_subject_id); } else { if ($event->getSubject() instanceof student_examination_repproved_subjectActions) { $examination_repproved_subject_id = sfContext::getInstance()->getUser()->getReferenceFor("examination_repproved_subject"); $criteria->add(StudentExaminationRepprovedSubjectPeer::EXAMINATION_REPPROVED_SUBJECT_ID, $examination_repproved_subject_id); } else { if ($event->getSubject() instanceof pathway_commissionActions) { $criteria->add(CoursePeer::IS_PATHWAY, true); } } } } } } } } } } } } } } } } } return $criteria; }
public function canBeEditedByPreceptorUser($preceptor_user) { $criteria = new Criteria(); PersonalPeer::joinWithCourse($criteria, $preceptor_user->getId()); return CoursePeer::doCount($criteria); }