addOptions(array( new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'admin'), new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'), )); $this->namespace = ''; $this->name = 'testSolver'; $this->briefDescription = 'Jednorazově vyřeší testy podle predchozích řešení (OLD/NEW_VLNA_ID)'; $this->detailedDescription = 'Jednorazově vyřeší testy podle predchozích řešení (OLD/NEW_VLNA_ID)'; } const OLD_VLNA_ID = 8; const NEW_VLNA_ID = 34; // const OLD_VLNA_ID = 6; // const NEW_VLNA_ID = 33; 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(); $fake_date = '2010-08-31 16:11:12'; $uchazeci = Doctrine::getTable('Uchazec')->createQuery() ->addWhere('vlna_id = ?', self::NEW_VLNA_ID) ->execute(); foreach($uchazeci as $uchazec) { $bodu_celkem = 0; $bodu_ziskanych = 0; $old_uchazec = Doctrine::getTable('Uchazec')->createQuery('u') ->addWhere('u.vlna_id = ?', self::OLD_VLNA_ID) ->addWhere('u.email = ?', $uchazec->getEmail()) ->fetchOne(); foreach($uchazec->getUchazec_text() as $text) { $text->delete(); } foreach($old_uchazec->getUchazec_text() as $old_text) { $text = new Uchazec_text(); $text->setUchazecId($uchazec->getId()); $text->setCviceniId($old_text->getCviceniId()); $text->setOtazkaId($old_text->getOtazkaId()); $text->setDatumVytvoreni($fake_date); $text->setDatumZodpovezeni($fake_date); $text->setDatumPosledniZmeny($fake_date); $text->setZadani($old_text->getZadani()); $text->setOdpoved($old_text->getOdpoved()); $text->setSpravne($old_text->getSpravne()); $text->setPocetZodpovezeni($old_text->getPocetZodpovezeni()); $text->setSpravneGramatika($old_text->getSpravneGramatika()); $text->setSpatneGramatika($old_text->getSpatneGramatika()); //if($old_text->getCviceniId() == 12) if($old_text->getCviceniId() == 80) { $text->setBoduNaOtazku(0.5); } else { $text->setBoduNaOtazku($old_text->getBoduNaOtazku()); } $bodu_celkem += $text->getBoduNaOtazku(); if($text->getSpravne()) { $bodu_ziskanych += $text->getBoduNaOtazku(); } $text->save(); $this->logSection('Uchazec_text', 'uloženo id='.$text->getId()); } $uchazec->setPracovnikId($old_uchazec->getPracovnikId()); $uchazec->setZakaznikId($old_uchazec->getZakaznikId()); if(strlen($old_uchazec->getDatumStartu())) { $uchazec->setDatumStartu($fake_date); $uchazec->setDatumPrihlaseni($fake_date); $uchazec->setDatumUkonceni($fake_date); $uchazec->setUspesnost(($bodu_ziskanych == 0) ? 0 : round(($bodu_ziskanych / $bodu_celkem) * 100)); } else { $uchazec->setDatumStartu(null); $uchazec->setDatumPrihlaseni(null); $uchazec->setDatumUkonceni(null); $uchazec->setUspesnost(null); } $uchazec->save(); $this->logSection('Uchazec', 'uloženo id='.$uchazec->getId()); } } }