Пример #1
0
 public static function fromArray($data)
 {
     $settings = new RoleSettings();
     foreach ($data as $key => $value) {
         if (property_exists(get_class($settings), $key)) {
             if (is_array($value)) {
                 if ($key == "transactions") {
                     $settings->{$key} = Transactions::fromArray($value);
                 }
                 if ($key == "reports") {
                     $settings->{$key} = Reports::fromArray($value);
                 }
                 if ($key == "help") {
                     $settings->{$key} = Help::fromArray($value);
                 }
                 if ($key == "mobileVTAccess") {
                     $settings->{$key} = MobileVTAcces::fromArray($value);
                 }
                 if ($key == "admin") {
                     $settings->{$key} = Admin::fromArray($value);
                 }
                 if ($key == "customer") {
                     $settings->{$key} = Customers::fromArray($value);
                 }
                 if ($key == "webPosAccess") {
                     $settings->{$key} = WebPosAccess::fromArray($value);
                 }
             } else {
                 $settings->{$key} = $value;
             }
         }
     }
     return $settings;
 }
Пример #2
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;
     }
 }