public function configure() { $student_id = $this->getOption('student_id'); $this->student = StudentPeer::retrieveByPK($student_id); $this->career_school_year_id = $this->getOption('career_school_year_id'); $this->course_subject_id = $this->getOption('course_subject_id'); $this->division_id = $this->getOption('division_id'); $sf_formatter_attendance_week = new sfWidgetFormSchemaFormatterAttendanceWeek($this->getWidgetSchema()); $this->getWidgetSchema()->addFormFormatter("AttendanceWeek", $sf_formatter_attendance_week); $this->getWidgetSchema()->setFormFormatterName('AttendanceWeek'); $day = $this->getOption('day'); $this->widgetSchema->setNameFormat('attendance_' . $student_id . '][%s]'); #student $this->setWidget("student_id", new sfWidgetFormInputHidden()); $this->setValidator("student_id", new sfValidatorPropelChoice(array("model" => "Student", "required" => true))); $this->setWidget("student", new mtWidgetFormPlain(array('object' => $this->student))); for ($i = 0; $i <= 6; $i++) { $day_i = date('Y-m-d', strtotime($day . '-' . $i . 'day a go')); $student_attendance = StudentAttendancePeer::retrieveOrCreateByDateAndStudent($day_i, $this->student, $this->getOption('course_subject_id')); if ($student_attendance) { $this->setDefault("value_" . $i, $student_attendance->getAbsenceTypeId()); } $this->setWidget("value_" . $i, $this->getAttendanceWidget()); $this->getWidget("value_" . $i, $this->getAttendanceWidget())->setAttribute('class', 'attendance_week_input'); $this->setValidator("value_" . $i, $this->getAttendanceValidator()); } $this->setDefault("student_id", $student_id); $this->disableCSRFProtection(); $this->course_subject = CourseSubjectPeer::retrieveByPK($this->course_subject_id); $period = CareerSchoolYearPeriodPeer::retrieveByPK($this->course_subject->getCourse()->getCurrentPeriod()); $this->setWidget('period', new mtWidgetFormPartial(array('module' => 'student_attendance', 'partial' => 'totalAbsences', 'form' => $this, 'parameters' => array('career_school_year_id' => $this->career_school_year_id, 'period' => $period, 'course_subject_id' => $this->course_subject_id, 'student' => $this->student)))); $this->getWidgetSchema()->moveField('period', sfWidgetFormSchema::LAST); }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); $c = new Criteria(); foreach (StudentAttendancePeer::doSelect($c) as $student_attendance) { $c1 = new Criteria(); $c1->add(StudentAttendancePeer::ID, $student_attendance->getId(), Criteria::NOT_EQUAL); $c1->add(StudentAttendancePeer::STUDENT_ID, $student_attendance->getStudentId()); $c1->add(StudentAttendancePeer::DAY, $student_attendance->getDay(), Criteria::EQUAL); foreach (StudentAttendancePeer::doSelect($c1) as $delete) { $delete->delete(); } } // add your code here }
public function save() { $con = Propel::getConnection(); try { $con->beginTransaction(); foreach ($this->students as $student) { $student_attendance = StudentAttendancePeer::retrieveOrCreate($student, $this->course_subject_id, $this->day, $this->career_school_year_id); $name = 'student_attendance_' . $student->getId() . '_' . $this->day; $this->setStudentAttendanceValue($name, $student_attendance); $student_attendance->save($con); } $con->commit(); } catch (PropelExeption $e) { $con->rollBack(); throw $e; } }
public function configure() { $student_id = $this->getOption('student_id'); $this->student = StudentPeer::retrieveByPK($student_id); $this->career_school_year_id = $this->getOption('career_school_year_id'); $this->course_subject_id = $this->getOption('course_subject_id'); $this->division_id = $this->getOption('division_id'); $sf_formatter_attendance_week = new sfWidgetFormSchemaFormatterAttendanceWeek($this->getWidgetSchema()); $this->getWidgetSchema()->addFormFormatter("AttendanceWeek", $sf_formatter_attendance_week); $this->getWidgetSchema()->setFormFormatterName('AttendanceWeek'); $day = $this->getOption('day'); $this->widgetSchema->setNameFormat('attendance_' . $student_id . '][%s]'); #student $this->setWidget("student_id", new sfWidgetFormInputHidden()); $this->setValidator("student_id", new sfValidatorPropelChoice(array("model" => "Student", "required" => true))); $this->setWidget("student", new mtWidgetFormPlain(array('object' => $this->student))); $sf_user = sfContext::getInstance()->getUser(); if ($sf_user->isPreceptor()) { $limit = SchoolBehaviourFactory::getInstance()->getDaysForMultipleAttendanceForm(); } else { $limit = BaseSchoolBehaviour::DAYS_FOR_MULTIPLE_ATTENDANCE_FORM; } for ($i = 0; $i <= $limit; $i++) { $day_i = date('Y-m-d', strtotime($day . '-' . $i . 'day ago')); $student_attendance = StudentAttendancePeer::retrieveOrCreateByDateAndStudent($day_i, $this->student, $this->getOption('course_subject_id')); if ($student_attendance) { $this->setDefault("value_" . $i, $student_attendance->getAbsenceTypeId()); } $this->setWidget("value_" . $i, $this->getAttendanceWidget()); #$this->getWidget('value_'.$i)->setLabel($day_i); $this->setValidator("value_" . $i, $this->getAttendanceValidator()); } #sumarle 7 dias al dia antes de mandarlo a la funcion // $total_absenses = $this->student->getAmountStudentAttendanceUntilDay( strtotime($day . '+ 7 day a go')); // $this->setWidget("total", new mtWidgetFormPartial(array('module'=>'student_attendance','partial'=>'total_absens','form'=>$this,'parameters'=>array('total'=>$total_absenses )) )); $this->setDefault("student_id", $student_id); $this->disableCSRFProtection(); $this->setWidget('period', new mtWidgetFormPartial(array('module' => 'student_attendance', 'partial' => 'totalAbsences', 'form' => $this, 'parameters' => array('career_school_year_id' => $this->career_school_year_id, 'course_subject_id' => null, 'student' => $this->student, 'day' => $day)))); $this->getWidgetSchema()->moveField('period', sfWidgetFormSchema::LAST); }
public function save($con = null) { $con = is_null($con) ? Propel::getConnection() : $con; parent::save($con); $values = $this->getValues(); $justification_type_id = $values['justification_type_id']; $observation = $values['observation']; $document = $values['document']; unset($values['justification_type_id'], $values['observation'], $values['document'], $values['id']); $con->beginTransaction(); try { foreach ($values as $value) { $student_attendance = StudentAttendancePeer::retrieveByPK($value); $student_attendance->setStudentAttendanceJustification($this->getObject()); #$student_attendance->updateAbsence($con); no va mas $student_attendance->save($con); } $con->commit(); } catch (PropelException $e) { throw $e; $con->rollBack(); } }
public function executeJustificate(sfWebRequest $request) { sfContext::getInstance()->getConfiguration()->loadHelpers(array('I18N')); $id = $request->getParameter('id'); if ($id != '') { $this->student_attendance = StudentAttendancePeer::retrieveByPK($request->getParameter('id')); $this->student_attendances = array($this->student_attendance->getId()); $this->student_attendance_justification = $this->student_attendance->getStudentAttendanceJustificationOrCreate(); } else { $this->student_attendance_justification = new StudentAttendanceJustification(); $this->student_attendances = $request->getParameter('ids'); } if (StudentAttendancePeer::areAllFromSameStudent($this->student_attendances)) { $this->form = new StudentAttendanceJustificationForm($this->student_attendance_justification); $this->form->setStudentAttendances($this->student_attendances); } else { $this->getUser()->setFlash('error', __('Cant do multiple justification with diferent students')); $this->forward('attendance_justification', 'index'); } }
public function getAbsencesReport($career_school_year_id, $student_id) { $c = new Criteria(); $c->add(StudentAttendancePeer::STUDENT_ID, $student_id); $c->add(StudentAttendancePeer::CAREER_SCHOOL_YEAR_ID, $career_school_year_id); $c->add(StudentAttendancePeer::VALUE, 0, Criteria::NOT_EQUAL); $c->addAscendingOrderByColumn(StudentAttendancePeer::DAY); return $student_attendances = StudentAttendancePeer::doSelect($c); }
public function canBeDeleted(PropelPDO $con = null) { $criteria = new Criteria(); $criteria->add(StudentAttendancePeer::ABSENCE_TYPE_ID, $this->getId()); return !StudentAttendancePeer::doCount($criteria); }
public function save() { $con = Propel::getConnection(); try { $con->beginTransaction(); foreach ($this->students as $student) { foreach ($this->days as $day => $day_i) { $student_attendance = StudentAttendancePeer::retrieveOrCreate($student, $this->course_subject_id, $day_i, $this->career_school_year_id); if (!$this->getValue('day_disabled_' . $day)) { $name = 'student_attendance_' . $student->getId() . '_' . $day; $this->setStudentAttendanceValue($name, $student_attendance); $student_attendance->save($con); } elseif (!$student_attendance->isNew()) { $student_attendance->delete($con); } } } $con->commit(); } catch (PropelExeption $e) { $con->rollBack(); throw $e; } }
/** * This method returns the absences depending of arguments: * * IF period_id is null, then returns all the absences. * IF course_subject_id is null then returns the absences per day. * IF include_justificated is null, then excludes the absences justificated. * * @param type $career_school_year_id * @param type $student_id * @param type $period_id * @param type $course_subject_id * @param type $include_justificated * * @return StudentAttendance array */ public function getAbsences($career_school_year_id, $student_id, $period = null, $course_subject_id = null, $exclude_justificated = true) { $c = new Criteria(); $c->add(StudentAttendancePeer::STUDENT_ID, $student_id); $c->add(StudentAttendancePeer::CAREER_SCHOOL_YEAR_ID, $career_school_year_id); if ($course_subject_id instanceof CourseSubject) { $c->add(StudentAttendancePeer::COURSE_SUBJECT_ID, $course_subject_id->getId()); } else { $c->add(StudentAttendancePeer::COURSE_SUBJECT_ID, $course_subject_id); } $c->add(StudentAttendancePeer::VALUE, 0, Criteria::NOT_EQUAL); if (!is_null($period)) { $criterion = $c->getNewCriterion(StudentAttendancePeer::DAY, $period->getStartAt(), Criteria::GREATER_EQUAL); $criterion->addAnd($c->getNewCriterion(StudentAttendancePeer::DAY, $period->getEndAt(), Criteria::LESS_EQUAL)); $c->add($criterion); } return $student_attendances = StudentAttendancePeer::doSelect($c); }
?> <?php $period = CareerSchoolYearPeriodPeer::retrieveByDay($day, $division->getCourseType()); ?> <?php $clasz = is_null($period) ? '' : $student->getFreeClass($period, $course_subject, CareerSchoolYearPeer::retrieveByPk($career_school_year_id), $division); ?> <?php } ?> <?php } ?> <?php $student_attendance = StudentAttendancePeer::retrieveByDateAndStudent(date('Y-m-d', $day), $student, $course_subject_id, $career_school_year_id); ?> <?php if ($student_attendance) { ?> <?php $total = $total + $student_attendance->getValue(); ?> <?php if ($student_attendance->getStudentAttendanceJustification()) { $total_justificated = $total_justificated + $student_attendance->getValue(); } ?> <td class="<?php
public function hasAttendanceForDate($date) { $c = new Criteria(); $c->add(StudentAttendancePeer::COURSE_SUBJECT_ID, $this->getId()); $c->add(StudentAttendancePeer::DAY, $date); return StudentAttendancePeer::doCount($c) > 0; }
public function hasJustificatedAbsencePerSubjectAndDay($career_school_year, $day, $course_subject_id) { $c = new Criteria(); $c->add(StudentAttendancePeer::CAREER_SCHOOL_YEAR_ID, $career_school_year->getId()); $c->add(StudentAttendancePeer::STUDENT_ID, $this->getId()); $c->add(StudentAttendancePeer::COURSE_SUBJECT_ID, $course_subject_id); $c->add(StudentAttendancePeer::STUDENT_ATTENDANCE_JUSTIFICATION_ID, null, Criteria::ISNOTNULL); $c->add(StudentAttendancePeer::VALUE, 0, Criteria::GREATER_THAN); $c->add(StudentAttendancePeer::DAY, $day, Criteria::EQUAL); return StudentAttendancePeer::doSelectOne($c); }
if ($student_attendance && $student_attendance->getStudentAttendanceJustification()) { ?> <?php echo link_to(image_tag('sanction.png'), 'attendance_justification/show?id=' . $student_attendance->getStudentAttendanceJustificationId()); ?> <?php } ?> </td> <?php } ?> <?php $student_attendance = StudentAttendancePeer::retrieveByDateAndStudent($day, $student, $course_subject_id); ?> <td class="<?php $student_attendance ? $student_attendance->getStudentAttendanceJustification() and print 'attendance_justificated' : ''; ?> "> <?php echo $form['student_' . $student->getId()]->renderError(); ?> <?php echo $form['student_' . $student->getId()]->render(); ?> <?php echo $form['student_' . $student->getId() . '_attendance_id']->render(); ?> <?php
public function getTotalAbsences() { $c = new Criteria(); $c->add(StudentAttendancePeer::STUDENT_ID, $this->getStudentId()); $c->add(StudentAttendancePeer::COURSE_SUBJECT_ID, $this->getCourseSubjectId()); $c->add(StudentAttendancePeer::STUDENT_ATTENDANCE_JUSTIFICATION_ID, null, Criteria::ISNULL); $student_attendances = StudentAttendancePeer::doSelect($c); $total = 0; foreach ($student_attendances as $student_attendance) { $total += $student_attendance->getAbsenceType() ? $student_attendance->getAbsenceType()->getValue() : $student_attendance->getValue(); } //$total = $this->roundAbsences($total); return $total; }