public static function retrieveByPKs($pks, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(); $criteria->add(Cur13GradePeer::ID, $pks, Criteria::IN); $objs = Cur13GradePeer::doSelect($criteria, $con); } return $objs; }
/** * getGrades function * function to get grades of each students * Have to set students and termSpecs before call this function * @return array */ public function getGrades() { $grades = array(); foreach ($this->getStudents() as $student) { $termSpecId = array(); $grades[$student->getId()] = array(); foreach ($this->getTermSpecs() as $termSpec) { $termSpecId[] = $termSpec->getId(); $grades[$student->getId()][$termSpec->getId()] = false; } $c = new Criteria(); $c->add(Cur13GradePeer::CUR13_TERM_SPEC_ID, $termSpecId, Criteria::IN); $c->add(Cur13GradePeer::STUDENT_ACCAL_ID, $student->getId(), Criteria::EQUAL); $c->addDescendingOrderByColumn(Cur13GradePeer::GRADE); $nilai = Cur13GradePeer::doSelect($c); foreach ($nilai as $n) { $grades[$student->getId()][$n->getCur13TermSpecId()] = $n; } } $this->grades = $grades; return $this->grades; }
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = Cur13GradePeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setStudentAccalId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setCur13TermSpecId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setGrade($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setRemark($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setGradeScale($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setTotalValue($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setAvgValue($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setCreatedAt($arr[$keys[8]]); } }
public function executeSaveElse() { $course_schedule = CourseSchedulePeer::retrieveByPk($this->getRequestParameter('course_id')); $this->forward404Unless($course_schedule); $this->course_schedule = $course_schedule; $cur13_term_id = $this->getRequestParameter('cur13_term_id'); $cur13_term = Cur13TermPeer::retrieveByPK($cur13_term_id); $this->forward404Unless($cur13_term); $this->cur13_term = $cur13_term; if ($cur13_term->getCur13KiId() == ScoreRule::THREE) { $ct = new Criteria(); $ct->add(GradeConversionPeer::TYPE_CONVERSION, ScoreRule::ONE); } else { $ct = new Criteria(); $ct->add(GradeConversionPeer::TYPE_CONVERSION, ScoreRule::TWO); } $grade_convs = GradeConversionPeer::doSelect($ct); $scores = $this->getRequestParameter('score'); foreach ($scores as $k => $score) { if ($score != null) { ## Simpan if ($score != '-') { $ids = split('_', $k); ## $ids[0] = Student Accal Id ## $ids[1] = Cur13 Term Spec Id $cr = new Criteria(); $cr->add(Cur13GradePeer::STUDENT_ACCAL_ID, $ids[0]); $cr->add(Cur13GradePeer::CUR13_TERM_SPEC_ID, $ids[1]); $g = Cur13GradePeer::doSelectOne($cr); if ($g == null) { $g = new Cur13Grade(); } $g->setStudentAccalId($ids[0]); $g->setCur13TermSpecId($ids[1]); $g->setGradeScale($score); $g->save(); $crm = new Criteria(); $crm->add(Cur13TermSpecPeer::CUR13_TERM_ID, $cur13_term->getId()); $crm->addJoin(Cur13GradePeer::CUR13_TERM_SPEC_ID, Cur13TermSpecPeer::ID); $crm->add(Cur13GradePeer::STUDENT_ACCAL_ID, $ids[0]); #$crm->addDescendingOrderByColumn(Cur13GradePeer::GRADE_SCALE); #$crm->setLimit(1); #$modus = Cur13GradePeer::doSelectOne($crm); $alls = Cur13GradePeer::doSelect($crm); $total = 0; $count = 0; foreach ($alls as $all) { $total += $all->getGradeScale(); $count += 1; } $avg = number_format($total / $count, 2); $avg_scale = number_format($avg / 100 * 4, 2); #$avg = $modus->getGradeScale(); $remark = ''; foreach ($grade_convs as $gc) { if ($avg_scale >= $gc->getMinScale() && $avg_scale <= $gc->getMaxScale()) { $remark = $gc->getName(); } } $cri = new Criteria(); $cri->add(Cur13GradeTermPeer::STUDENT_ACCAL_ID, $ids[0]); $cri->add(Cur13GradeTermPeer::CUR13_TERM_ID, $cur13_term->getId()); $gi = Cur13GradeTermPeer::doSelectOne($cri); if ($gi == null) { $gi = new Cur13GradeTerm(); } $gi->setStudentAccalId($ids[0]); $gi->setCur13TermId($cur13_term->getId()); $gi->setGrade($avg); $gi->setGradeScale($avg_scale); $gi->setRemark($remark); $gi->save(); ## Delete } else { $cr = new Criteria(); $cr->add(Cur13GradePeer::STUDENT_ACCAL_ID, $ids[0]); $cr->add(Cur13GradePeer::CUR13_TERM_SPEC_ID, $ids[1]); $g = Cur13GradePeer::doSelectOne($cr); if ($g != null) { $g->delete(); } } } } if ($cur13_term->getCur13KiId() == ScoreRule::THREE) { return $this->redirect('course_sd/listScoreKi3?course_id=' . $course_schedule->getId() . '&cur13_ki_id=' . $cur13_term->getCur13KiId() . '&cur13_term_id=' . $cur13_term->getId()); } else { return $this->redirect('course_sd/listScoreKi4?course_id=' . $course_schedule->getId() . '&cur13_ki_id=' . $cur13_term->getCur13KiId() . '&cur13_term_id=' . $cur13_term->getId()); } }
public function getCur13GradesJoinStudentAccal($criteria = null, $con = null) { include_once 'lib/model/om/BaseCur13GradePeer.php'; if ($criteria === null) { $criteria = new Criteria(); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collCur13Grades === null) { if ($this->isNew()) { $this->collCur13Grades = array(); } else { $criteria->add(Cur13GradePeer::CUR13_TERM_SPEC_ID, $this->getId()); $this->collCur13Grades = Cur13GradePeer::doSelectJoinStudentAccal($criteria, $con); } } else { $criteria->add(Cur13GradePeer::CUR13_TERM_SPEC_ID, $this->getId()); if (!isset($this->lastCur13GradeCriteria) || !$this->lastCur13GradeCriteria->equals($criteria)) { $this->collCur13Grades = Cur13GradePeer::doSelectJoinStudentAccal($criteria, $con); } } $this->lastCur13GradeCriteria = $criteria; return $this->collCur13Grades; }