function executeList() { $page = isset($this->page) ? $this->page : 1; $this->show_petition = false; $this->show_subscriber = true; $this->show_status = false; $this->show_email = false; $this->download_filter = null; $this->action = ''; $this->route = null; $this->route_params = array(); $data_owner_id = null; if (isset($this->campaign)) { $query = PetitionSigningTable::getInstance()->query(array(PetitionSigningTable::CAMPAIGN => $this->campaign, PetitionSigningTable::ORDER => PetitionSigningTable::ORDER_DESC)); $this->form = new SigningsDownloadForm(array(), array(PetitionSigningTable::CAMPAIGN => $this->campaign, PetitionSigningTable::ORDER => PetitionSigningTable::ORDER_DESC, SigningsDownloadForm::OPTION_QUERY => $query->copy(), SigningsDownloadForm::OPTION_IS_DATA_OWNER => $this->getGuardUser()->isDataOwnerOfCampaign($this->campaign))); $this->form->bindSelf('c' . $this->campaign->getId()); $this->route = 'data_campaign_pager'; $this->route_params = array('id' => $this->campaign->getId()); $this->show_petition = true; $data_owner_id = $this->campaign->getDataOwnerId(); } elseif (isset($this->petition)) { $query = PetitionSigningTable::getInstance()->query(array(PetitionSigningTable::PETITION => $this->petition, PetitionSigningTable::ORDER => PetitionSigningTable::ORDER_DESC)); $this->form = new SigningsDownloadForm(array(), array(PetitionSigningTable::PETITION => $this->petition, PetitionSigningTable::ORDER => PetitionSigningTable::ORDER_DESC, SigningsDownloadForm::OPTION_QUERY => $query->copy(), SigningsDownloadForm::OPTION_IS_DATA_OWNER => $this->getGuardUser()->isDataOwnerOfCampaign($this->petition->getCampaign()))); $this->form->bindSelf('p' . $this->petition->getId()); $this->route = 'data_petition_pager'; $this->route_params = array('id' => $this->petition->getId()); $data_owner_id = $this->petition->getCampaign()->getDataOwnerId(); } elseif (isset($this->widget)) { // this is for widget owners only $query = PetitionSigningTable::getInstance()->query(array(PetitionSigningTable::WIDGET => $this->widget, PetitionSigningTable::USER => $this->getGuardUser(), PetitionSigningTable::ORDER => PetitionSigningTable::ORDER_DESC)); $this->form = new SigningsDownloadForm(array(), array(PetitionSigningTable::WIDGET => $this->widget, PetitionSigningTable::USER => $this->getGuardUser(), PetitionSigningTable::ORDER => PetitionSigningTable::ORDER_DESC, SigningsDownloadForm::OPTION_QUERY => $query->copy(), SigningsDownloadForm::OPTION_IS_DATA_OWNER => true)); $this->form->bindSelf('w' . $this->widget->getId()); $this->route = 'data_widget_pager'; $this->route_params = array('id' => $this->widget->getId()); $data_owner_id = $this->widget->getCampaign()->getDataOwnerId(); } $this->can_delete = $this->getUser()->getUserId() == $data_owner_id; $this->signings = new policatPager($query, $page, $this->route, $this->route_params, true, 20, $this->form); if ($this->form->isValid()) { $this->count = $this->form->getCount(); $this->pages = UtilExport::pages($this->count); $this->pending = $this->form->getPending(); $this->download_filter = array($this->form->getName() => $this->form->getValues()); $this->show_subscriber = !$this->form->getSubscriber(); $this->show_email = $this->form->getSubscriber(); } }
public function executePrepare(sfWebRequest $request) { $download = DownloadTable::getInstance()->find((int) $request->getParameter('id')); /* @var $download Download */ if (!$download || $download->getUserId() != $this->getGuardUser()->getId()) { return $this->renderJson(array('status' => 'fail')); } // buildQuery checks for permissions $query = $this->buildQuery($download->getType(), $download->getIdForType(), json_decode($download->getFilter(), true)); if (!$query instanceof Doctrine_Query) { return $this->renderJson(array('status' => 'fail')); } $page = (int) $request->getParameter('page', 0); if ($page != $download->getPagesProcessed()) { if ($page < 0) { if ($download->getPagesProcessed() != $download->getPages()) { return $this->renderText('error'); } header('Content-Description: File Transfer'); header('Content-Type: application/csv'); header('Content-Disposition: attachment; filename="' . $download->getDownloadFilename() . '"'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); $out = fopen($download->getFilepath(), 'r'); fpassthru($out); fclose($out); flush(); exit; } return $this->renderJson(array('status' => 'fail')); } UtilExport::writeCsv($download->getFilepath(), $query, $download->getSubscriber(), $page); $download->setPagesProcessed($page + 1); $download->save(); return $this->renderJson(array('status' => 'ok')); }