* @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ */ class jobsActions extends sfActions { public function executeCreate(sfWebRequest $request) { if($this->getRoute() instanceof sfDoctrineRoute) { $this->job = $this->getRoute()->getObject(); } else { $this->job = false; } $this->profile = $this->getUser()->getProfile(); // Pokud vytváří inzerát admin podle jineho if(!$this->profile instanceof Profile && $this->job instanceof Job) { $this->profile = $this->job->getProfile(); } if($this->profile->isPerson()) { $this->form = new DemandJobForm(); } elseif($this->profile->isAgency()) { $this->form = new OfferJobForm(); $this->form->setDefault('city', $this->profile->getCity()); $this->form->setDefault('street', $this->profile->getStreet()); $this->form->setDefault('zip', $this->profile->getZip()); } if($this->job) { $this->form->setDefault('profile_id', $this->job->getProfileId()); $this->form->setDefault('type_id', $this->job->getTypeId()); $this->form->setDefault('category_id', $this->job->getCategoryId()); $this->form->setDefault('name', $this->job->getName()); $this->form->setDefault('text', $this->job->getText()); $this->form->setDefault('city', $this->job->getCity()); $this->form->setDefault('street', $this->job->getStreet()); $this->form->setDefault('country_id', $this->job->getCountryId()); $this->form->setDefault('style_id', $this->job->getStyleId()); $this->form->setDefault('zip', $this->job->getZip()); $this->form->setDefault('specializations_list', $this->job->getSpecializationIds()); $this->form->setDefault('regions_list', $this->job->getRegionIds()); } else { $this->form->setDefault('regions_list', array($this->profile->getRegionId())); } $this->processForms($request); $this->setTemplate('edit'); } public function executeUpdate(sfWebRequest $request) { $this->forward404Unless($this->job = $this->getRoute()->getObject()); $this->forward404Unless($this->job->isEditable()); $this->forwardUnless($this->job->hasPermissions($this->getUser()), 'sfGuardAuth', 'secure'); $this->profile = $this->job->getProfile(); if($this->job->isDemand()) { $this->form = new DemandJobForm($this->job); } elseif($this->job->isOffer()) { $this->form = new OfferJobForm($this->job); } $this->processForms($request); $this->setTemplate('edit'); } public function executeValidityUpdate(sfWebRequest $request) { $this->forward404Unless($this->job = $this->getRoute()->getObject()); $this->forward404Unless($this->job->isEditable()); $this->forwardUnless($this->job->hasPermissions($this->getUser()), 'sfGuardAuth', 'secure'); $this->form = new ValidityJobForm($this->job); if($request->isMethod('put')) { $this->form->bind($request->getParameter($this->form->getName())); // var_dump($request->getParameter($this->form->getName())); die(); if($this->form->isValid()) { $this->job = $this->form->save(); $this->getUser()->addMessage(__('Změny uloženy.')); $this->redirect($this->generateUrl('job_read', $this->job)); } } $this->setTemplate('editValidity'); } protected function processForms(sfWebRequest $request) { $profile = $this->getUser()->getProfile(); if($request->isMethod('post') || $request->isMethod('put')) { $data = $request->getParameter($this->form->getName()); if($profile instanceof Profile) { $data['profile_id'] = $profile->getId(); } if(!isset($data['specializations_list'])) { $data['specializations_list'] = array(); } $this->form->bind($data); if($this->form->isValid()) { $this->job = $this->form->save(); if($this->getActionName() == 'update') { if($this->job->getPrice() > 0) { $this->createJobInvoice($this->job, true); } $this->getUser()->addMessage('Změny uloženy.'); $this->redirect($this->generateUrl('job_read', $this->job)); } else { // $this->getMailer()->composeAndSend( // sfConfig::get('app_mail_from_address'), // $profile->getMail(), // 'Potvrzení přijetí inzerátu | '.sfConfig::get('app_title'), // $this->getComponent($this->getModuleName(), 'createJobMailBody', array('job' => $this->job)) // ); if($this->job->getPrice() > 0) { $this->createJobInvoice($this->job); } // Mail adminovi $this->getMailer()->composeAndSend( array(sfConfig::get('app_mail_from_address') => sfConfig::get('app_mail_from_name')), sfConfig::get('app_mail_to_address'), 'Vytvoření nového inzerátu | '.sfConfig::get('app_title'), $this->getPartial($this->getModuleName().'/newJobMailBody', array('job' => $this->job)) ); $this->getUser()->addMessage(__('Vytvoření inzerátu proběhlo v pořádku. Na e-mail Vám bylo odesláno potvrzení.')); $this->redirect($this->generateUrl('job_read', $this->job)); } } } } /** * Vytvoří fakturu za inzerát * * @param Job $job */ protected function createJobInvoice(Job $job, $update = false) { $profile = $job->getProfile(); $invoice = $job->createInvoice(); $stylesheet = file_get_contents(sfConfig::get('sf_web_dir').'/css/invoice.css'); $mpdf = new mPDF(); $mpdf->WriteHTML($stylesheet, 1); $mpdf->WriteHTML($this->getComponent('invoices', 'detail', array('invoice' => $invoice))); //$mpdf->Output(); //die(); $mediakit = file_get_contents(sfConfig::get('sf_web_dir').'/files/mediakit_2018.pdf'); $message = $this->getMailer() ->compose( array(sfConfig::get('app_mail_from_address') => sfConfig::get('app_mail_from_name')), array($profile->getMail()), //sfConfig::get('app_mail_to_address')), 'Objednávka inzerátu | '.sfConfig::get('app_title'), $this->getPartial($this->getModuleName().'/jobInvoiceMailBody', array('job' => $job, 'invoice' => $invoice, 'update' => $update)) )->attach(Swift_Attachment::newInstance($mpdf->Output('xa', 'S'), $invoice->getPdfName(), 'application/pdf')) ->attach(Swift_Attachment::newInstance($mediakit, 'PRÁCA v ZDRAVOTNÍCTVE_MEDIAKIT 2018.pdf', 'application/pdf')); $this->getMailer()->send($message); } public function executeRead(sfWebRequest $request) { $this->forward404Unless($this->job = $this->getRoute()->getObject()); $this->forwardUnless($this->job->isActiveAndValid() || $this->job->hasPermissions($this->getUser()), 'sfGuardAuth', 'secure'); if($this->job->isDemand() && !$this->getUser()->isAuthenticated()) { $this->forward('sfGuardAuth', 'signin'); } foreach($this->job->getRegions() as $region) { $this->getUser()->addRegionIds($region->getId()); } $this->getResponse()->setTitle($this->job->getName().' | '.sfConfig::get('app_title')); } public function executeDelete(sfWebRequest $request) { $this->forward404Unless($this->job = $this->getRoute()->getObject()); $this->forwardUnless($this->job->hasPermissions($this->getUser()), 'sfGuardAuth', 'secure'); $this->job->delete(); $this->getUser()->addMessage(__('Inzerát odstraněn.')); $this->redirect($this->generateUrl('homepage')); } public function executeProfile(sfWebRequest $request) { $this->forward404Unless($this->profile = $this->getRoute()->getObject()); $this->jobFilter = new FrontendJobProfileFormFilter($this->profile); $data = $request->getParameter($this->jobFilter->getName()); if(isset($data['regions_list'])) { $this->getUser()->addRegionIds($data['regions_list']); } $this->jobFilter->bind($data); $this->jobFilterUrl = $this->generateUrl('jobs_profile', $this->profile); $this->pager = new sfDoctrinePager('Job'); $this->pager->setMaxPerPage($request->getParameter('pagesize', sfConfig::get('app_default_pagesize'))); $this->pager->setPage($this->getRequest()->getParameter('page', 1)); $query = $this->jobFilter->getQuery(); $query->orderBy('created_at DESC'); $this->pager->setQuery($query); $this->pager->init(); $this->setTemplate('list'); } public function executeOffers(sfWebRequest $request) { $this->jobFilter = new FrontendOfferJobFormFilter(); $data = $request->getParameter($this->jobFilter->getName()); if($this->getRoute() instanceof sfDoctrineRoute && $category = $this->getRoute()->getObject()) { $data['category_id'] = $category->getId(); } if(isset($data['regions_list'])) { $this->getUser()->addRegionIds($data['regions_list']); } // if(!is_array($data)) // { // $data['country_id'] = 1; //CZ // } $this->jobFilter->bind($data); $this->jobFilterUrl = $this->generateUrl('jobs_offers'); $this->pager = new sfDoctrinePager('Job'); $this->pager->setMaxPerPage($request->getParameter('pagesize', sfConfig::get('app_default_pagesize'))); $this->pager->setPage($this->getRequest()->getParameter('page', 1)); $query = $this->jobFilter->getQuery(); $query->orderBy('style_id DESC, valid_from DESC'); $this->pager->setQuery($query); $this->pager->init(); $this->setTemplate('list'); } public function executeDemands(sfWebRequest $request) { $this->jobFilter = new FrontendDemandJobFormFilter(); $data = $request->getParameter($this->jobFilter->getName()); if($this->getRoute() instanceof sfDoctrineRoute && $category = $this->getRoute()->getObject()) { $data['category_id'] = $category->getId(); } if(isset($data['regions_list'])) { $this->getUser()->addRegionIds($data['regions_list']); } if(!is_array($data)) { $data['country_id'] = 1; //CZ } $this->jobFilter->bind($data); $this->jobFilterUrl = $this->generateUrl('jobs_offers'); $this->pager = new sfDoctrinePager('Job'); $this->pager->setMaxPerPage($request->getParameter('pagesize', sfConfig::get('app_default_pagesize'))); $this->pager->setPage($this->getRequest()->getParameter('page', 1)); $query = $this->jobFilter->getQuery(); $query->orderBy('valid_from DESC'); $this->pager->setQuery($query); $this->pager->init(); $this->setTemplate('list'); } public function executeCreateTopRequest(sfWebRequest $request) { $this->forward404Unless($this->job = $this->getRoute()->getObject()); $this->forwardUnless($this->job->hasPermissions($this->getUser()), 'sfGuardAuth', 'secure'); $this->forwardUnless($this->job->isOffer(), 'sfGuardAuth', 'secure'); $this->form = new RequestTopJobForm(); $this->form->setDefaultDates($this->job); if($request->isMethod('post')) { $data = $request->getParameter($this->form->getName()); $data['job_id'] = $this->job->getId(); $this->form->bind($data); if($this->form->isValid()) { $this->topJob = $this->form->save(); $this->getUser()->addMessage(__('Žádost o aktivování TOP inzerátu odeslána.')); $this->createTobjobInvoice($this->topJob); // Mail adminovi $this->getMailer()->composeAndSend( array(sfConfig::get('app_mail_from_address') => sfConfig::get('app_mail_from_name')), sfConfig::get('app_mail_to_address'), 'Žádost o aktivování TOP inzerátu | '.sfConfig::get('app_title'), $this->getPartial($this->getModuleName().'/newTopRequestMailBody', array('topjob' => $this->topJob)) ); $this->redirect($this->generateUrl('job_read', $this->job)); } } } /** * Vytvoří fakturu pro uživatele který žádá o TOP inzerát * * @param TopJob $topjob */ protected function createTobjobInvoice(TopJob $topjob) { $profile = $topjob->getJob()->getProfile(); $invoice = new Invoice(); $invoice->setDefaultValues(); $invoice->setSubscriber($profile); $invoice->save(); $item = new InvoiceItem(); $item->setDefaultValues(); $item->setInvoiceId($invoice->getId()); $item->setTopjobId($topjob->getId()); $item->setText('TOP inzerát na zaměstnánívezdravotnictví.cz (počet dnů)'); $item->setAmount($topjob->getDaysCount()); $item->setPriceOne(Doctrine::getTable('TopJobPrice')->getPriceOneForDays($item->getAmount())); $item->save(); // $this->getMailer()->composeAndSend( // array(sfConfig::get('app_mail_from_address') => sfConfig::get('app_mail_from_name')), // $profile->getMail(), // 'Objednání TOP inzerátu | '.sfConfig::get('app_title'), // $this->getPartial($this->getModuleName().'/topjobInvoiceMailBody', array('topjob' => $topjob, 'invoice' => $invoice)) // ); } public function executeActivate(sfWebRequest $request) { $this->forward404Unless($this->job = $this->getRoute()->getObject()); $this->forwardUnless($this->job->hasPermissions($this->getUser()), 'sfGuardAuth', 'secure'); $profile = $this->job->getProfile(); $this->forwardUnless($profile->getPrepaymentTypeId() == PrepaymentType::TYPE_DATE && $profile->isPrepaymentValid(), 'sfGuardAuth', 'secure'); $this->job->setIsActive(true); $this->job->save(); $this->getUser()->addMessage(__('Inzerát aktivován.')); $this->redirect($request->getReferer()); } public function executeDeactivate(sfWebRequest $request) { $this->forward404Unless($this->job = $this->getRoute()->getObject()); $this->forwardUnless($this->job->hasPermissions($this->getUser()), 'sfGuardAuth', 'secure'); $profile = $this->job->getProfile(); $this->forwardUnless($profile->getPrepaymentTypeId() == PrepaymentType::TYPE_DATE && $profile->isPrepaymentValid(), 'sfGuardAuth', 'secure'); $this->job->setIsActive(false); $this->job->save(); $this->getUser()->addMessage(__('Inzerát deaktivován.')); $this->redirect($request->getReferer()); } public function executeCountPriceJSON(sfWebRequest $request) { $this->forward404Unless($style = Doctrine::getTable('JobStyle')->findOneById($request->getParameter('style_id'))); $this->forward404Unless($country = Doctrine::getTable('Country')->findOneById($request->getParameter('country_id'))); $chars_count = $request->getParameter('chars_count'); $months = $request->getParameter('months'); if($request->hasParameter('profile_id')) { $profile = Doctrine::getTable('Profile')->findOneById($request->getParameter('profile_id')); } else { $profile = $this->getUser()->getProfile(); } $chars_count += mb_strlen($profile->getName()); $data = array( 'rows_count' => JobTable::getRowsCount($chars_count), 'chars_count' => $chars_count, 'price' => JobTable::getPrice($style, $country, $chars_count, $months, $profile), 'sign' => $style->getPriceRelation($country)->getCurrency(), 'prepayment_rows' => $profile->getPrepaymentRows($style), 'has_valid_prepayment_count' => ($profile->getPrepaymentTypeId() == PrepaymentType::TYPE_COUNT && $profile->isPrepaymentValid($style)), 'has_valid_prepayment_date' => ($profile->getPrepaymentTypeId() == PrepaymentType::TYPE_DATE && $profile->isPrepaymentValid()), 'has_valid_prepayment_row' => ($profile->getPrepaymentTypeId() == PrepaymentType::TYPE_DATE && $profile->isPrepaymentValid()) ); echo json_encode($data); return sfView::NONE; } }