예제 #1
0
 public function executeAdd(sfWebRequest $request)
 {
     if ($request->isMethod('post')) {
         $name = $request->getParameter('reports')['name'];
         if (!$name) {
             $this->forwardToSecureAction();
         }
         if (!in_array($name, array_keys(Reports::getGlobalReports($this->getUser())))) {
             $this->info_message = $this->getI18N()->__("You are not allowed to print this kind of report.");
             return $this->renderPartial("info_msg", array("info_message" => $this->info_message));
         }
         $default_vals = array();
         foreach ($request->getRequestParameters() as $rp_key => $rp_value) {
             if (strpos($rp_key, 'default_vals[') !== false && strpos($rp_key, ']') !== false && strpos($rp_key, ']') - strpos($rp_key, '[') > 1) {
                 $default_vals[substr($rp_key, strpos($rp_key, '[') + 1, strpos($rp_key, ']') - strpos($rp_key, '[') - 1)] = $rp_value;
             }
         }
         $this->setWidgetsOptions($name);
         $this->form = new ReportsForm(null, array('fields' => $this->widgets, 'name' => $name, 'model_name' => $request->getParameter('catalogue', 'taxonomy'), 'with_js' => $request->getParameter('with_js', false), 'default_vals' => $default_vals, 'current_user' => $this->getUser()));
         $this->form->bind($request->getParameter($this->form->getName()));
         if ($this->form->isValid()) {
             if (isset($request->getParameter('reports')['loan_id']) && count(Doctrine::getTable('Loans')->getPrintableLoans(array($request->getParameter('reports')['loan_id']), $this->getUser())) == 0) {
                 $this->info_message = $this->getI18n()->__("You don't have the necessary credentials to print this loan");
             } else {
                 $this->info_message = $this->getI18n()->__("Your report has been saved. It will be availlable tomorrow");
                 $report = new Reports();
                 $report->fromArray(array('name' => $name, 'user_ref' => $this->getUser()->getId(), 'lang' => $this->getUser()->getCulture(), 'format' => $request->getParameter('reports')['format'], 'comment' => $request->getParameter('reports')['comment']));
                 $report->setParameters($request->getParameter('reports'));
                 // Save the report whatever it's a fast or a non fast one
                 $report->save();
                 //if it's a fast report, it can be downloaded directly
                 if (Reports::getIsFast($name)) {
                     $response = $this->processDownload($report);
                     if ($response != 0) {
                         $message = json_encode($this->getPartial("info_msg", array("info_message" => $this->info_message)));
                         return $this->renderText('{ "report_url" : "' . $this->generateUrl("default", array("module" => "report", "action" => "downloadFile", "id" => $response), TRUE) . '", "message": ' . $message . ' }');
                     }
                 }
             }
             return $this->renderPartial("info_msg", array("info_message" => $this->info_message));
         }
         $val = $this->renderPartial("report_form", array('form' => $this->form, 'fields' => $this->widgets, 'fields_options' => $this->widgets_options, 'fields_at_second_line' => $this->widgets_second_line_count, 'model_name' => $request->getParameter('catalogue', 'taxonomy'), 'fast' => Reports::getIsFast($name), 'with_js' => $request->getParameter('with_js', false), 'default_vals' => $default_vals));
         return $val;
     }
 }
예제 #2
0
<?php

include dirname(__FILE__) . '/../../bootstrap/Doctrine.php';
$t = new lime_test(4, new lime_output_color());
$u = Doctrine::getTable('Users')->getUserByPassword("root", "evil");
$reports = Doctrine::getTable('Reports')->getTaskReports();
$t->is(count($reports), 0, '"0" Tasks report available');
$report = new Reports();
$report->setParameters(array('name' => 'annual_stat_collection', 'collection_ref' => 1, 'date_from' => '01-01-2000', 'date_to' => '31-12-2012'));
$report->setUserRef($u->getId());
$report->setName('annual_stat_collection');
$report->setLang('en');
$report->setFormat('pdf');
$report->save();
$reports = Doctrine::getTable('Reports')->getTaskReports();
$t->is(count($reports), 1, '"1" Task report available');
$reports = Doctrine::getTable('Reports')->getUserReport($u->getId());
$t->is(count($reports), 1, '"1" report available for user "' . $u->getGivenName() . '"');
foreach ($reports as $report) {
    $t->is($report->getParameters()->count(), 3, '"3" parameters (collection_ref,date_from,date_to) set for "' . $report->getName() . '"');
}