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 = 'import'; $this->name = 'fei-uchazeci'; $this->briefDescription = ''; $this->detailedDescription = 'Jednorázový import uchazecu pro FEI'; } 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(); $this->reemails(); die('done'); $filename = $this->configuration->getRootDir().DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'import'.DIRECTORY_SEPARATOR.'FEI_uchazeci.csv'; if (($handle = fopen($filename, "r")) !== false) { $test = Doctrine::getTable('Test')->findOneById(52); $filesize = filesize($filename); while (($row = fgetcsv($handle, $filesize, ";")) !== false) { $jmeno = $this->getJmenoUchazece($row); $email = $this->getEmailUchazece($row); if(in_array($email, array('jana.duchanova@fei.com', 'romana.kuklova@fei.com', 'stanislav.antos@fei.com', 'radka.kopeckova@fei.com', 'pavel.rychtecky@fei.com', 'jiri.heroudek@fei.com'))) { continue; } $pracovnik = Doctrine::getTable('Pracovnik')->createQuery() ->addWhere('jmeno = ? AND prijmeni = ? AND zakaznik_id = ?', array($row[2], $row[1], 6)) //FEI ->fetchOne(); $uchazec = new Uchazec(); $uchazec->setZakaznikId(6); //FEI $uchazec->setPersonalistaId(8); //NOvotny $uchazec->setTestZakaznikId(70); $uchazec->setVlnaId(50); $uchazec->setOdeslaniEmailu(true); $uchazec->setJmeno($jmeno); $uchazec->setEmail($email); $uchazec->setTestNazev($test->getNazevTestu()); $uchazec->setTestCas($test->getCas()); $uchazec->setTestInstrukce($test->getInstrukce()); $uchazec->setTestKriteria($test->getKriteria()); if($pracovnik) { $uchazec->setPracovnikId($pracovnik->getId()); } $uchazec->save(); uchazecActions::createTest($test->getId(), $uchazec); $this->logSection('uchazec+', $uchazec->getEmail()); } fclose($handle); } $this->log('Done'); } protected function reemails() { $uchazeci = Doctrine::getTable('Uchazec')->createQuery() ->addWhere('id >= ?', 5932) ->execute(); foreach($uchazeci as $uchazec) { $uchazec->setEmail(str_replace('@fei.cz', '@fei.com', $uchazec->getEmail())); $uchazec->save(); $this->logSection('uchazec+', $uchazec->getEmail()); } } protected function getJmenoUchazece($row) { return $row[2].' '.$row[1]; } protected function getEmailUchazece($row) { return Doctrine_Inflector::urlize($row[2]).'.'.Doctrine_Inflector::urlize($row[1]).'@fei.cz'; } }