/** * Create Application query. * */ protected function createQuery($array, $search) { $this->objects = ApplicationQuery::create()->orderByCreatedAt('desc'); if (isset($array['StudentId']) && $array['StudentId'] !== "") { $this->objects->where("application.student_id = " . $array['StudentId']); } if (isset($array['SubjectId']) && $array['SubjectId'] !== "") { $this->objects->where("application.subject_id = " . $array['SubjectId']); } if (isset($array['ProfessorId']) && $array['ProfessorId'] !== "") { $this->objects->join('Application.Student'); $this->objects->join('Student.Course'); $this->objects->join('Course.Engagement'); $this->objects->where('Engagement.subject_id = Application.subject_id'); $this->objects->where('Engagement.school_year_id = Application.school_year_id'); $this->objects->where('Engagement.ProfessorId = ?', $array['ProfessorId']); } if (\Auth::user()->getStatus() == 'professor') { $this->objects->join('Application.Student'); $this->objects->join('Student.Course'); $this->objects->join('Course.Engagement'); $this->objects->where('Engagement.subject_id = Application.subject_id'); $this->objects->where('Engagement.school_year_id = Application.school_year_id'); $professor_id = \Auth::user()->getProfessorId(); $this->objects->where('Engagement.ProfessorId = ?', $professor_id); } else { if (\Auth::user()->getStatus() == 'student') { $student_id = \Auth::user()->getStudentId(); $this->objects->where('Application.student_id = ?', $student_id); } } if (isset($array['PeriodId']) && $array['PeriodId'] !== "") { $this->objects->where("application.period_id = " . $array['PeriodId']); } if (isset($array['SchoolYearId']) && $array['SchoolYearId'] !== "") { $this->objects->where("application.school_year_id = " . $array['SchoolYearId']); } //if(isset($array['OralExamInvitationId']) && $array['OralExamInvitationId'] !== "") $this->objects->where("application.oral_exam_invitation_id = ".$array['OralExamInvitationId']); if (isset($array['ApplicationDateFrom']) && $array['ApplicationDateFrom'] !== "") { $this->objects->where("application.application_date >= '" . $array['ApplicationDateFrom'] . "'"); } if (isset($array['ApplicationDateTo']) && $array['ApplicationDateTo'] !== "") { $this->objects->where("application.application_date >= '" . $array['ApplicationDateTo'] . "'"); } if (isset($array['ExamDateFrom']) && $array['ExamDateFrom'] !== "") { $this->objects->where("application.exam_date >= '" . $array['ExamDateFrom'] . "'"); } if (isset($array['ExamDateTo']) && $array['ExamDateTo'] !== "") { $this->objects->where("application.exam_date >= '" . $array['ExamDateTo'] . "'"); } if (isset($array['ExamScore']) && $array['ExamScore'] !== "") { $this->objects->where("application.exam_score = " . $array['ExamScore']); } if ($search) { session(['application_filter' => $array]); } }
/** * Create Application query. * */ protected function createQuery($array, $search) { $this->objects = ApplicationQuery::create()->withColumn('COUNT(*)', 'ApplicationsNumber')->withColumn('case when Application.exam_score > 5 then count(*) end', 'SuccessRate')->select(['Subject.Name', 'SchoolYear.Year', 'Course.Name', 'Course.Id', 'SubjectId', 'SchoolYearId', 'ApplicationsNumber', 'SuccessRate'])->useSubjectQuery()->groupByName()->endUse()->useStudentQuery()->useCourseQuery()->groupByName()->endUse()->endUse()->useSchoolYearQuery()->groupByYear()->orderByYear('desc')->endUse()->useSubjectQuery()->orderByName()->endUse(); if (isset($array['SubjectId']) && $array['SubjectId'] !== "") { $this->objects->where("application.subject_id = ?", $array['SubjectId']); } if (isset($array['CourseId']) && $array['CourseId'] !== "") { $this->objects->useStudentQuery()->where("Student.course_id = ?", $array['CourseId'])->endUse(); } if (isset($array['SchoolYearId']) && $array['SchoolYearId'] !== "") { $this->objects->where("application.school_year_id = ?", $array['SchoolYearId']); } if ($search) { session(['application_by_subject_filter' => $array]); } }
public function getApplications($subject_id, $school_year_id, $course_id) { $subject = SubjectQuery::create()->findPk($subject_id); $course = CourseQuery::create()->findPk($course_id); $schoolYear = SchoolYearQuery::create()->findPk($school_year_id); $applications = ApplicationQuery::create()->where('Application.subject_id = ?', $subject_id)->where('Application.school_year_id = ?', $school_year_id)->join('Application.Student')->join('Application.Period')->where('Student.course_id = ?', $course_id)->select(['Student.FirstName', 'Student.LastName', 'Student.CourseId', 'Period.Name', 'ApplicationDate', 'ExamDate', 'ExamTime', 'ExamScore'])->find(); //dd($applications); $applications_arr = []; $cnt = 0; foreach ($applications as $key => $application) { $professor = $this->getProfessorName($subject_id, $application['Student.CourseId'], $school_year_id); $applications_arr[$professor][$cnt]['student'] = $application['Student.FirstName'] . ' ' . $application['Student.LastName']; $applications_arr[$professor][$cnt]['period'] = $application['Period.Name']; $applications_arr[$professor][$cnt]['application_date'] = $application['ApplicationDate']; $applications_arr[$professor][$cnt]['exam_datetime'] = $application['ExamDate'] . " " . $application['ExamTime']; $applications_arr[$professor][$cnt]['exam_score'] = isset($application['ExamScore']) && $application['ExamScore'] != 0 ? $application['ExamScore'] : ''; $cnt++; } $result['data'] = $applications_arr; $result['course'] = $course->__toString(); $result['subject'] = $subject->__toString(); $result['school_year'] = $schoolYear->__toString(); return $result; }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @throws LogicException if no primary key is defined * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = ChildApplicationQuery::create(); $criteria->add(ApplicationTableMap::COL_ID, $this->id); return $criteria; }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Student is new, it will return * an empty collection; or if this Student has previously * been saved, it will retrieve related Applications from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Student. * * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return ObjectCollection|ChildApplication[] List of ChildApplication objects */ public function getApplicationsJoinSchoolYear(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildApplicationQuery::create(null, $criteria); $query->joinWith('SchoolYear', $joinBehavior); return $this->getApplications($query, $con); }
/** * Get the associated ChildApplication object * * @param ConnectionInterface $con Optional Connection object. * @return ChildApplication The associated ChildApplication object. * @throws PropelException */ public function getApplication(ConnectionInterface $con = null) { if ($this->aApplication === null && $this->application_id !== null) { $this->aApplication = ChildApplicationQuery::create()->findPk($this->application_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aApplication->addApplicationRequests($this); */ } return $this->aApplication; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $application = ApplicationQuery::create()->findPK($id); $application->delete(); flash()->success("DELETED"); session(['attribute' => \Lang::get('general.APPLICATION')]); return redirect($this->main_page); }
private function allowedToApply($student_id, $subject, $period_id, $school_year_id) { $applications = ApplicationQuery::create()->where("Application.student_id = ?", $student_id)->where("Application.subject_id = ?", $subject->getId())->where("Application.school_year_id = ?", $school_year_id)->find(); if (count($applications) == 3) { return "Izgubili ste pravo da polažete ispit iz predmeta " . $subject->getName(); } foreach ($applications as $application) { if ($application->getPeriodId() == $period_id) { return "Vec ste prijavili ispit iz predmeta " . $subject->getName(); } if ($application->getExamScore() > 5) { return "Vec ste polozili ispit iz predmeta " . $subject->getName(); } } return null; }
private function getNewApplications($professor_id) { $date = date('Y-m-d H:i:s'); $period = PeriodSchoolYearQuery::create()->where('PeriodSchoolYear.date_start <= ?', $date)->where('PeriodSchoolYear.date_end >= ?', $date)->findOne(); if (is_null($period)) { return ['stats_arr' => [], 'courses' => [], 'period_year' => '']; } $applications = ApplicationQuery::create()->where('Application.period_id = ?', $period->getPeriodId())->where('Application.school_year_id = ?', $period->getSchoolYearId()); $applications->useStudentQuery()->useCourseQuery()->orderById()->endUse()->endUse(); if (!is_null($professor_id)) { $applications->join('Application.Student'); $applications->join('Student.Course'); $applications->join('Course.Engagement'); $applications->where('Engagement.subject_id = Application.subject_id'); $applications->where('Engagement.school_year_id = Application.school_year_id'); $applications->where('Engagement.professor_id = ?', $professor_id); } else { $study_programs_arr = $this->getSubjectYears(); } if (count($applications) == 0) { return ['stats_arr' => [], 'courses' => [], 'period_year' => '']; } $period_year = $period->getPeriod()->__toString() . ", " . $period->getSchoolYear()->__toString(); $courses_arr = []; $application_stats_arr = []; foreach ($applications as $application) { $course = $application->getStudent()->getCourse()->__toString(); if (!isset($courses_arr[$course])) { $courses_arr[$course] = $course; } if (!is_null($professor_id)) { $subject = $application->getSubject()->__toString(); if (!isset($application_stats_arr[$course][$subject])) { $application_stats_arr[$course][$subject]['prijavljeno'] = 0; } $application_stats_arr[$course][$subject]['xkey'] = $subject; $application_stats_arr[$course][$subject]['prijavljeno']++; } else { $course_id = $application->getStudent()->getCourseId(); $subject_id = $application->getSubjectId(); $year = $study_programs_arr[$subject_id][$course_id] . ". godina"; if (!isset($application_stats_arr[$course][$year])) { $application_stats_arr[$course][$year]['prijavljeno'] = 0; } $application_stats_arr[$course][$year]['xkey'] = $year; $application_stats_arr[$course][$year]['prijavljeno']++; } } $stats_arr = []; foreach ($application_stats_arr as $course => $array) { foreach ($array as $arr) { $stats_arr[$course][] = $arr; } } $courses = array_values($courses_arr); $result['courses'] = $courses; $result['stats_arr'] = $stats_arr; $result['period_year'] = $period_year; return $result; }
/** * Performs an INSERT on the database, given a Application or Criteria object. * * @param mixed $criteria Criteria or Application object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(ApplicationTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from Application object } if ($criteria->containsKey(ApplicationTableMap::COL_ID) && $criteria->keyContainsValue(ApplicationTableMap::COL_ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . ApplicationTableMap::COL_ID . ')'); } // Set the correct dbName $query = ApplicationQuery::create()->mergeWith($criteria); // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) return $con->transaction(function () use($con, $query) { return $query->doInsert($con); }); }