Beispiel #1
0
 public function addNgTestApplSched(NgTestApplSched $l)
 {
     $this->collNgTestApplScheds[] = $l;
     $l->setNgTestSchedule($this);
 }
Beispiel #2
0
 public function executeSavePayment()
 {
     #$user_id = $this->getContext()->getUser()->getAttribute('user_id', null, 'bo');
     $i18n = new sfI18N();
     $i18n->initialize($this->getContext());
     $i18n->setCulture($this->getUser()->getCulture());
     $action_i18n = $i18n->globalMessageFormat->format('save as new');
     $action_type = $this->getRequestParameter('action_type');
     /**        
             $year = $this->getRequestParameter('year');
             $month = $this->getRequestParameter('month');
             
             $department = DepartmentPeer::retrieveByPK($this->getRequestParameter('department_id'));
             $dept_code = $department->getNumCode().'-';
             
             $code_appl = 'REG';
             $stu_code = ParamsPeer::retrieveByCode('applicant_code');
     
             $sc = $stu_code->getValue();
             $sc = explode('$', $sc);
             array_shift($sc);
             $code_len = 0;
             $code = '';
             foreach ($sc as $k => $v) {
                 $v = explode('#', $v);
                 if ($v[0] == 'app') {
                     $code_len += $v[1];
                     $code .= str_pad($code_appl, $v[1], '0', STR_PAD_LEFT);
                 } elseif ($v[0] == 'dept') {
                     $code .= str_pad($dept_code, $v[1], '0', STR_PAD_LEFT);
                     $code_len += $v[1];
                 } elseif ($v[0] == 'year') {
                     if (strlen($year) <= $v[1]) {
                         $code .= str_pad($year, $v[1], '0', STR_PAD_LEFT);
                     } else {
                         $code .= substr($year, strlen($year) - $v[1]);
                     }
                     $code_len += $v[1];
                 } elseif ($v[0] == 'month') {
                     if (strlen($month) <= $v[1]) {
                         $code .= str_pad($month, $v[1], '0', STR_PAD_LEFT);
                     } else {
                         $code .= substr($month, strlen($month) - $v[1]);
                     }
                     $code_len += $v[1];
                 } elseif ($v[0] == 'seq') {
                     $c = new Criteria();
                     $c->add(NgTestApplicantPeer::CODE, $code . '%', Criteria::LIKE);
                     $c->addDescendingOrderByColumn(NgTestApplicantPeer::CODE);
                     $c->setLimit(1);
                     $last_applicant = NgTestApplicantPeer::doSelectOne($c);
                     if ($last_applicant) {
                         $lap = $last_applicant->getCode();
                         $lap = substr_replace($lap, '', 0, $code_len);
                         $lap = substr($lap, 0, $v[1]);
                         $lap++;
                         $code .= str_pad($lap, $v[1], '0', STR_PAD_LEFT);
                     } else {
                         $code .= str_pad(1, $v[1], '0', STR_PAD_LEFT);
                         break;
                     }
                 }
                 $sc[$k] = $v;
             }
             **/
     $newCode = $this->pmbTools->generateApplicantCode(NgStatusApplicant::CONFIRMED, $this->getRequestParameter('department_id'));
     if ($action_type == $action_i18n || !$this->getRequestParameter('id')) {
         $ng_test_applicant = new NgTestApplicant();
     } else {
         $ng_test_applicant = NgTestApplicantPeer::retrieveByPk($this->getRequestParameter('id'));
         $this->forward404Unless($ng_test_applicant);
     }
     $ng_test_applicant->setCode($newCode);
     $ng_test_applicant->setNgStatusApplicantId(NgStatusApplicant::CONFIRMED);
     $ng_test_applicant->save();
     $c = new Criteria();
     $c->add(NgRegTestPeriodPeer::NG_REG_PERIOD_ID, $ng_test_applicant->getNgRegTestPeriod()->getNgRegPeriodId());
     $nrtps = NgRegTestPeriodPeer::doSelect($c);
     foreach ($nrtps as $nrtp) {
         $cw = new Criteria();
         $cw->add(NgTestSchedulePeer::NG_REG_TEST_PERIOD_ID, $nrtp->getId());
         $cw->addAscendingorderByColumn(NgTestSchedulePeer::ID);
         $scheds = NgTestSchedulePeer::doSelect($cw);
         $s1 = array();
         foreach ($scheds as $s) {
             $s1[$s->getNgRegTestPeriodId()][] = array('ng_reg_test_period_id' => $s->getNgRegTestPeriodId(), 'used' => $s->countNgTestApplScheds(), 'capacity' => $s->getCapacity(), 'sched' => $s);
         }
         foreach ($s1 as $s) {
             $c = new Criteria();
             $c->add(NgTestSchedulePeer::NG_REG_TEST_PERIOD_ID, $nrtp->getId());
             $c->addJoin(TestApplSchedPeer::TEST_SCHEDULE_ID, TestSchedulePeer::ID);
             $c->add(NgTestApplSchedPeer::NG_TEST_APPLICANT_ID, $ng_test_applicant->getId());
             $tas = NgTestApplSchedPeer::doSelectOne($c);
             if ($tas == null) {
                 $i = 0;
                 while ($s[$i]) {
                     $sched = $s[$i];
                     if ($sched['used'] < $sched['capacity']) {
                         $tas = new NgTestApplSched();
                         $tas->setNgTestApplicant($ng_test_applicant);
                         $tas->setNgTestSchedule($sched['sched']);
                         $tas->save();
                         break;
                     }
                     $i++;
                 }
             }
         }
     }
     return $this->redirect('ng_test_applicant/list');
 }