private function getLicense(sfForm $form)
 {
     $post = $form->getValues();
     $license = $this->getEmployeeService()->getEmployeeLicences($post['emp_number'], $post['code']);
     $isAllowed = FALSE;
     if (!$license instanceof EmployeeLicense) {
         if ($this->licensePermissions->canCreate()) {
             $license = new EmployeeLicense();
             $isAllowed = TRUE;
         }
     } else {
         if ($this->licensePermissions->canUpdate()) {
             $isAllowed = TRUE;
         }
     }
     if ($isAllowed) {
         $license->empNumber = $post['emp_number'];
         $license->licenseId = $post['code'];
         $license->licenseNo = $post['license_no'];
         $license->licenseIssuedDate = $post['date'];
         $license->licenseExpiryDate = $post['renewal_date'];
         return $license;
     } else {
         return NULL;
     }
 }
 private function getEducation(sfForm $form)
 {
     $post = $form->getValues();
     $isAllowed = FALSE;
     if (!empty($post['id'])) {
         if ($this->educationPermissions->canUpdate()) {
             $education = $this->getEmployeeService()->getEducation($post['id']);
             $isAllowed = TRUE;
         }
     }
     if (!$education instanceof EmployeeEducation) {
         if ($this->educationPermissions->canCreate()) {
             $education = new EmployeeEducation();
             $isAllowed = TRUE;
         }
     }
     if ($isAllowed) {
         $education->empNumber = $post['emp_number'];
         $education->educationId = $post['code'];
         $education->institute = $post['institute'];
         $education->major = $post['major'];
         $education->year = $post['year'];
         $education->score = $post['gpa'];
         $education->startDate = $post['start_date'];
         $education->endDate = $post['end_date'];
     }
     return $education;
 }
 private function getLanguage(sfForm $form)
 {
     $post = $form->getValues();
     $language = $this->getEmployeeService()->getEmployeeLanguages($post['emp_number'], $post['code'], $post['lang_type']);
     $isAllowed = FALSE;
     if (!$language instanceof EmployeeLanguage) {
         if ($this->languagePermissions->canCreate()) {
             $language = new EmployeeLanguage();
             $isAllowed = TRUE;
         }
     } else {
         if ($this->languagePermissions->canUpdate()) {
             $isAllowed = TRUE;
         } else {
             $this->getUser()->setFlash('warning', __("You don't have update permission"));
         }
     }
     if ($isAllowed) {
         $language->empNumber = $post['emp_number'];
         $language->langId = $post['code'];
         $language->fluency = $post['lang_type'];
         $language->competency = $post['competency'];
         $language->comments = $post['comments'];
         return $language;
     } else {
         return NULL;
     }
 }
 protected function processCommentForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $comment = $form->save();
         //save cookie with user info
         $user_info = $form->getValues();
         unset($user_info['id'], $user_info['article_id'], $user_info['message']);
         $this->getUser()->setAttribute('zs_commenter_info', $user_info);
         $this->redirect($this->generateUrl('zs_blog_article', $comment->getArticle()) . '#comment-' . $comment->getId());
     }
 }
 private function getSkill(sfForm $form)
 {
     $post = $form->getValues();
     $skill = $this->getEmployeeService()->getEmployeeSkills($post['emp_number'], $post['code']);
     if (!$skill instanceof EmployeeSkill) {
         $skill = new EmployeeSkill();
     }
     $skill->emp_number = $post['emp_number'];
     $skill->skillId = $post['code'];
     $skill->years_of_exp = $post['years_of_exp'];
     $skill->comments = $post['comments'];
     return $skill;
 }
 private function getLanguage(sfForm $form)
 {
     $post = $form->getValues();
     $language = $this->getEmployeeService()->getLanguage($post['emp_number'], $post['code'], $post['lang_type']);
     if (!$language instanceof EmployeeLanguage) {
         $language = new EmployeeLanguage();
     }
     $language->empNumber = $post['emp_number'];
     $language->langId = $post['code'];
     $language->fluency = $post['lang_type'];
     $language->competency = $post['competency'];
     $language->comments = $post['comments'];
     return $language;
 }
 private function getLicense(sfForm $form)
 {
     $post = $form->getValues();
     $license = $this->getEmployeeService()->getLicense($post['emp_number'], $post['code']);
     if (!$license instanceof EmployeeLicense) {
         $license = new EmployeeLicense();
     }
     $license->empNumber = $post['emp_number'];
     $license->licenseId = $post['code'];
     $license->licenseNo = $post['license_no'];
     $license->licenseIssuedDate = $post['date'];
     $license->licenseExpiryDate = $post['renewal_date'];
     return $license;
 }
 private function getWorkExperience(sfForm $form)
 {
     $post = $form->getValues();
     $workExperience = $this->getEmployeeService()->getEmployeeWorkExperienceRecords($post['emp_number'], $post['seqno']);
     if (!$workExperience instanceof EmpWorkExperience) {
         $workExperience = new EmpWorkExperience();
     }
     $workExperience->emp_number = $post['emp_number'];
     $workExperience->seqno = $post['seqno'];
     $workExperience->employer = $post['employer'];
     $workExperience->jobtitle = $post['jobtitle'];
     $workExperience->from_date = $post['from_date'];
     $workExperience->to_date = $post['to_date'];
     $workExperience->comments = $post['comments'];
     return $workExperience;
 }
Exemplo n.º 9
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';
         try {
             $values = $form->getValues();
             if ($form->getObject()->hasAlreadyMedailleWithParameters($values['visiteur_id'], $values['medaille_id'])) {
                 $message = sprintf("The medal %s is unique for this visitor %s", $values['medaille_id'], $values['visiteur_id']);
                 $this->getUser()->setFlash('error', $message);
                 return sfView::SUCCESS;
             }
             $visiteur_medaille = $form->save();
         } catch (Doctrine_Validator_Exception $e) {
             $errorStack = $form->getObject()->getErrorStack();
             $message = get_class($form->getObject()) . ' has ' . count($errorStack) . " field" . (count($errorStack) > 1 ? 's' : null) . " with validation errors: ";
             foreach ($errorStack as $field => $errors) {
                 $message .= "{$field} (" . implode(", ", $errors) . "), ";
             }
             $message = trim($message, ', ');
             $this->getUser()->setFlash('error', $message);
             return sfView::SUCCESS;
         }
         $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $visiteur_medaille)));
         if ($request->hasParameter('_save_and_add')) {
             $this->getUser()->setFlash('notice', $notice . ' You can add another one below.');
             $this->redirect('@visiteur_medaille_new');
         } else {
             $this->getUser()->setFlash('notice', $notice);
             $route = 'visiteur_medaille';
             $action = $form->getObject()->isNew() ? 'new' : 'edit';
             $redirection = strtolower($this->configuration->getValue($action . '.redirection'));
             if (isset($redirection) && 'list' !== $redirection) {
                 $route .= '_' . $redirection;
             }
             $url = array('sf_route' => $route);
             if (isset($redirection) && 'list' !== $redirection) {
                 $url['sf_subject'] = $visiteur_medaille;
             }
             $this->redirect($url);
         }
     } else {
         $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
     }
 }
 private function getEducation(sfForm $form)
 {
     $post = $form->getValues();
     if (!empty($post['id'])) {
         $education = $this->getEmployeeService()->getEducation($post['id']);
     }
     if (!$education instanceof EmployeeEducation) {
         $education = new EmployeeEducation();
     }
     $education->empNumber = $post['emp_number'];
     $education->educationId = $post['code'];
     $education->institute = $post['institute'];
     $education->major = $post['major'];
     $education->year = $post['year'];
     $education->score = $post['gpa'];
     $education->startDate = $post['start_date'];
     $education->endDate = $post['end_date'];
     return $education;
 }
Exemplo n.º 11
0
 protected function processMembershipForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $auth_key = $this->getUser()->getApiAuthKey();
         if ($form->getValue('id')) {
             // Update existing item.
             $values = $form->getValues();
             $id = $form->getValue('id');
             $membership = $form->getObject();
             $membership_array = $membership->toArray();
             foreach ($membership_array as $key => $value) {
                 if (array_key_exists($key, $values) && $values[$key] == $membership_array[$key]) {
                     unset($values[$key]);
                 }
             }
             if (array_key_exists('display_membership', $values)) {
                 $values['display_membership'] = (bool) $values['display_membership'] ? 1 : 0;
             }
             if (count($values)) {
                 $result = Api::getInstance()->setUser($auth_key)->put('subredditmembership/' . $id, $values);
                 $success = $this->checkHttpCode($result, 'put', 'subredditmembership/' . $id, json_encode($values));
                 if ($success) {
                     $this->getUser()->setFlash('notice', 'Membership was edited successfully.');
                 }
             }
         }
         $this->redirect('subreddit/membership?id=' . $id);
     }
 }
Exemplo n.º 12
0
 /**
  * 
  * @param sfWebRequest $request
  * @param sfForm $form
  * @param Room $room
  * @return <bool> false if preview action
  */
 protected function processTopicForm(sfWebRequest $request, sfForm $form, Room $room, User $user)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         if ($this->getRequestParameter('submitAct')) {
             $values = $form->getValues();
             // topic saving
             $topic = new Topic();
             $topic->setTitle($values['title']);
             $topic->setIdRoom($room->getId());
             $topic->setIdUser($user->getId());
             $topic->save();
             // post saving
             $post = new Post();
             $post->setContent($values['post']['content']);
             $post->setIdTopic($topic->getId());
             $post->setIdUser($user->getId());
             $post->save();
             $this->redirect('room_topic_show', $topic);
         } else {
             if ($this->getRequestParameter('prevSubmitAct')) {
                 return;
             } else {
                 return false;
             }
         }
     }
 }
 /**
  * Process general forms
  *
  * @param sfWebRequest $request  Request object
  * @param sfForm       $form     Form object
  */
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $form_values = $form->getValues();
         // Reset session variable
         $this->getVoucherManager()->resetSessionVoucher();
         // Add data to session
         $this->getVoucherManager()->setSessionVoucherArray($form_values);
         $this->getUser()->setFlash('notice', 'Voucher has been ' . ($request->getParameter('action') == 'update' ? 'updated' : 'created'));
         $this->updateUserSession();
         // Redirect to referer page
         $referer = $this->getReferer($request);
         if ($referer) {
             $this->cleanReferer();
             $this->redirect($referer);
         }
         // No referer, go to edit voucher
         $this->redirect('rt_shop_voucher_edit');
     }
     $this->getUser()->setFlash('default_error', true, false);
 }
 private function _setLeapYearLeavePeriodDetails(sfForm $form)
 {
     $post = $form->getValues();
     if ($post['cmbStartMonth'] == 2 && $post['cmbStartDate'] == 29) {
         $nonLeapYearLeavePeriodStartDate = $post['cmbStartMonthForNonLeapYears'];
         $nonLeapYearLeavePeriodStartDate .= '-';
         $nonLeapYearLeavePeriodStartDate .= $post['cmbStartDateForNonLeapYears'];
         ParameterService::setParameter('nonLeapYearLeavePeriodStartDate', $nonLeapYearLeavePeriodStartDate);
         ParameterService::setParameter('isLeavePeriodStartOnFeb29th', 'Yes');
         ParameterService::setParameter('leavePeriodStartDate', '');
     } else {
         $leavePeriodStartDate = $post['cmbStartMonth'];
         $leavePeriodStartDate .= '-';
         $leavePeriodStartDate .= $post['cmbStartDate'];
         ParameterService::setParameter('leavePeriodStartDate', $leavePeriodStartDate);
         ParameterService::setParameter('nonLeapYearLeavePeriodStartDate', '');
         ParameterService::setParameter('isLeavePeriodStartOnFeb29th', 'No');
     }
 }
Exemplo n.º 15
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         try {
             $dataArray = $form->getValues();
             if ($form->getObject()->isNew()) {
                 $user_id = $this->getUser()->getGuardUser()->getId();
                 $folioData = Doctrine::getTable('Folio')->findOneBy('user_id', $user_id);
                 $clientData = Doctrine::getTable('Client')->findOneBy('id', $dataArray['client_id']);
                 $basePath = sfConfig::get('app_enviroment_basepath');
                 $javaWebPath = $basePath . '/java/SifactJava/dist/';
                 $webBasePath = $basePath . '/web/';
                 $cfdUserBasePath = $webBasePath . 'cfdiData/' . $user_id . '/';
                 //              if($dataArray['status'] == 'Active'){
                 /*
                  * Se verifica que el directorio de facturas exista, si no lo crea
                  */
                 if (!is_dir($cfdUserBasePath)) {
                     mkdir($cfdUserBasePath, 0777);
                     mkdir($cfdUserBasePath . 'out/', 0777);
                 }
                 $userData = $this->getUser()->getGuardUser()->getProfile();
                 $invoiceData['Emisor']['rfc'] = $userData->getRfc();
                 $invoiceData['Emisor']['nombre'] = $userData->getIssuingCompany();
                 $invoiceData['Emisor']['calle'] = $userData->getStreet();
                 $invoiceData['Emisor']['noExterior'] = $userData->getExtNumber();
                 $invoiceData['Emisor']['noInterior'] = $userData->getIntNumber();
                 $invoiceData['Emisor']['colonia'] = $userData->getCity();
                 $invoiceData['Emisor']['codigoPostal'] = $userData->getPostalCode();
                 $invoiceData['Emisor']['municipio'] = $userData->getMunicipality();
                 $invoiceData['Emisor']['estado'] = $userData->getState();
                 $invoiceData['Emisor']['pais'] = $userData->getCountry();
                 $invoiceData['Emisor']['RegimenFiscal'] = $userData->getFiscalRegime();
                 $invoiceData['version'] = sfConfig::get('app_sat_version');
                 $invoiceData['serie'] = $folioData['series'];
                 $invoiceData['folio'] = $folioData['start'];
                 $invoiceData['noAprobacion'] = $folioData['num_approval'];
                 $invoiceData['anoAprobacion'] = $folioData['year_approval'];
                 ####
                 $invoiceData['fecha'] = $this->isoDate(date("Y-m-d h:i:s"));
                 $invoiceData['formaDePago'] = $dataArray['means_payment'];
                 //$dataArray['tipoDePago']; // VALORES: EFECTIVO. TRANSFERENCIA ELECTRONICA, TARJETA DE CREDITO, DEPOSITO BANCARIO, DINEROMAIL
                 $invoiceData['subTotal'] = number_format($dataArray['subtotal'], 6, '.', '');
                 // FORMATEADO A DOS DIGITOS
                 $invoiceData['tipoDeComprobante'] = 'ingreso';
                 // ingreso,egreso,traslado
                 $invoiceData['metodoDePago'] = $dataArray['method_payment'];
                 $invoiceData['idSistema'] = 1;
                 $invoiceData['idbanco'] = $dataArray['idbanco'];
                 $invoiceData['comentario'] = $dataArray['comment'];
                 $invoiceData['descuento'] = number_format($dataArray['discount'] * $dataArray['subtotal'] / 100, 6, '.', '');
                 $invoiceData['NumCtaPago'] = $dataArray['comment'];
                 $preTotal = $dataArray['subtotal'] - $invoiceData['descuento'];
                 $invoiceData['iva'] = number_format($preTotal * 0.16, 6, '.', '');
                 // FORMATEADO A DOS DIGITOS
                 $invoiceData['total'] = number_format($preTotal + $invoiceData['iva'], 6, '.', '');
                 // DATOS DEL CLIENTE
                 $invoiceData['Receptor']['rfc'] = $clientData['rfc'];
                 $invoiceData['Receptor']['nombre'] = $clientData['issuing_company'];
                 $invoiceData['Receptor']['calle'] = $clientData['street'];
                 $invoiceData['Receptor']['noExterior'] = $clientData['ext_number'];
                 $invoiceData['Receptor']['noInterior'] = $clientData['int_number'];
                 $invoiceData['Receptor']['colonia'] = $clientData['city'];
                 $invoiceData['Receptor']['municipio'] = $clientData['municipality'];
                 $invoiceData['Receptor']['estado'] = $clientData['state'];
                 $invoiceData['Receptor']['pais'] = $clientData['country'];
                 $invoiceData['Receptor']['codigoPostal'] = $clientData['postal_code'];
                 $invoiceData['Receptor']['telefono1'] = $clientData['phone1'];
                 $invoiceData['Receptor']['telefono2'] = $clientData['phone2'];
                 ## Conceptos
                 for ($i = 0; $i <= $dataArray['count']; $i++) {
                     // CONCEPTOS
                     $concept = Doctrine::getTable('Concept')->find($dataArray["Concepts{$i}"]['concept_id']);
                     $invoiceData['Conceptos'][$i]['cantidad'] = $dataArray["Concepts{$i}"]['quantity'];
                     $invoiceData['Conceptos'][$i]['idconcepto'] = $dataArray["Concepts{$i}"]['concept_id'];
                     $invoiceData['Conceptos'][$i]['descripcion'] = $concept->getDescription();
                     $invoiceData['Conceptos'][$i]['unidad'] = $concept->getMeasuringUnit();
                     $invoiceData['Conceptos'][$i]['valorUnitario'] = number_format($dataArray["Concepts{$i}"]['price'], 6, '.', '');
                     $invoiceData['Conceptos'][$i]['descuento'] = $dataArray["Concepts{$i}"]['discount'];
                     $invoiceData['Conceptos'][$i]['importe'] = number_format($dataArray["Concepts{$i}"]['total'], 6, '.', '');
                 }
                 $invoiceM = new InvoiceManage($invoiceData);
                 $invoiceData['cadenaOriginal'] = $invoiceM->generateOriginalString();
                 //                $file='dabc820821n34.cer.pem';      // Ruta al archivo de Llave publica
                 $userCer = $this->getUser()->getGuardUser()->getFiles()->getFileCer();
                 $userKey = $this->getUser()->getGuardUser()->getFiles()->getFileKey();
                 $userPass = $this->getUser()->getGuardUser()->getFiles()->getCerPass();
                 $command = 'openssl x509 -inform DER -outform PEM -in ' . $webBasePath . $userCer . ' -pubkey > ' . $webBasePath . $userCer . '.pem';
                 system($command);
                 $file = $webBasePath . $userCer . ".pem";
                 $datos = file($file);
                 $certificado = "";
                 $carga = false;
                 for ($i = 0; $i < sizeof($datos); $i++) {
                     if (strstr($datos[$i], "END CERTIFICATE")) {
                         $carga = false;
                     }
                     if ($carga) {
                         $certificado .= trim($datos[$i]);
                     }
                     if (strstr($datos[$i], "BEGIN CERTIFICATE")) {
                         $carga = true;
                     }
                 }
                 $invoiceData['certificado'] = $certificado;
                 $xml = $invoiceM->generateInvoiceXML($invoiceData);
                 //                 print_r($invoiceData);
                 //                 echo $xml;
                 //                 exit();
                 //              }
             }
             $userCFDFile = 'cfd_' . $user_id . '-' . $invoiceData['folio'] . '.xml';
             $resource = fopen($webBasePath . 'tmp/' . $userCFDFile, "w+");
             fwrite($resource, $xml);
             /**
              * 
              * Firma el CFD a partir del documento generado 
              */
             $command = 'java -jar "' . $javaWebPath . 'SifactJava.jar" ' . $webBasePath . 'tmp/' . $userCFDFile . ' ' . $webBasePath . $userKey . ' ' . $userPass . ' ' . $webBasePath . $userCer . ' ' . $cfdUserBasePath . $userCFDFile;
             $this->logMessage('edicom -  Java Commmand' . $command, 'info');
             //	 echo $command;
             //	 exit();
             system($command);
             fclose($resource);
             unlink($webBasePath . 'tmp/' . $userCFDFile);
             /**
              * Firma el cfd a trav�s de Edicom
              */
             $command = "./EdicomSign.sh -i " . $cfdUserBasePath . " -o " . $cfdUserBasePath . "/out";
             //	 echo $command;
             //	 exit();
             // Hace el guardado d ela factura
             try {
                 exec($command, $result);
                 $this->logMessage('edicom - SSH Command ' . $command . ' RESULTADO - ' . implode("---", $result), 'info');
             } catch (Exception $e) {
                 echo 'Caught exception: ', $e->getMessage(), "\n";
             }
             $cfdEdicomFile = $cfdUserBasePath . 'out/SIGN_' . $userCFDFile;
             if (file_exists($cfdEdicomFile)) {
                 $datos = file($cfdEdicomFile);
                 $xmlFile = implode("", $datos);
                 $xmlArr = simplexml_load_string($xmlFile);
                 $invoiceData['sello'] = $xmlArr['sello']->__toString();
                 $invoice = $form->save();
                 $invoice->setXml(urlencode($xmlFile));
                 $invoice->setFolio($invoiceData['folio']);
                 $invoice->setArr(urlencode(serialize($invoiceData)));
                 $invoice->save();
                 $tmp = Doctrine::getTable('Folio')->updateFolio();
                 $dataSAT = $this->getSATData(urldecode($xmlFile));
                 $cfdEmailData = array('to' => $clientData['email'], 'cc' => $this->getUser()->getGuardUser()->getProfile()->getEmail(), 'clientData' => $clientData, 'cfdPath' => $cfdEdicomFile, 'htmlPath' => $webBasePath . 'tmp/HTMLInvoice.html', 'htmlData' => array('invoiceData' => $invoiceData, 'xmlData' => $xmlArr, 'dataSAT' => $dataSAT, 'discount' => $invoice->getDiscount()));
                 $this->sendCFDEmail($cfdEmailData);
                 $this->getUser()->setFlash('notice', 'La factura se ha creado de manera satisfactoria.');
                 unlink($cfdUserBasePath . $userCFDFile);
             } else {
                 $this->getUser()->setFlash('error', 'No se ha creado la factura, ERROR: ' . implode("---", $result));
             }
             $this->redirect('@invoice');
             //print_r($form->getValues());
             //exit();
         } catch (Doctrine_Validator_Exception $e) {
             $errorStack = $form->getObject()->getErrorStack();
             $message = get_class($form->getObject()) . ' has ' . count($errorStack) . " field" . (count($errorStack) > 1 ? 's' : null) . " with validation errors: ";
             foreach ($errorStack as $field => $errors) {
                 $message .= "{$field} (" . implode(", ", $errors) . "), ";
             }
             $message = trim($message, ', ');
             $this->getUser()->setFlash('error', $message);
             return sfView::SUCCESS;
         }
         $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $invoice)));
         if ($request->hasParameter('_save_and_add')) {
             $this->getUser()->setFlash('notice', $notice . ' You can add another one below.');
             $this->redirect('@invoice_new');
         } else {
             $this->getUser()->setFlash('notice', $notice);
             $this->redirect(array('sf_route' => 'invoice_edit', 'sf_subject' => $invoice));
         }
     } else {
         $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
     }
 }
Exemplo n.º 16
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()));
     if ($form->isValid()) {
         if ($form->getObject()->isNew()) {
             $this->saveLastCreated($form->getValues());
             $this->getUser()->setFlash('notice', 'The item was created successfully.');
         } else {
             $this->getUser()->setFlash('notice', 'The item was updated successfully.');
         }
         if ($request->hasParameter('_save_and_close')) {
             $form->getObject()->setIsClosed(true);
         }
         if ($request->hasParameter('_save_and_close_batch')) {
             $form->close_issues = true;
         }
         $issue = $form->save();
         if ($request->hasParameter('_save_and_add')) {
             $this->redirect('@issues_new');
         } else {
             if ($request->hasParameter('_save_batch') || $request->hasParameter('_save_and_close_batch')) {
                 $this->getUser()->setFlash('notice', 'The items were updated successfully.');
                 $this->redirect('@issues');
             } else {
                 $this->redirect('@issues_show?id=' . $issue['id']);
             }
         }
     } else {
         $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.');
     }
 }
Exemplo n.º 17
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->getValue('recipient_id') == $this->getUser()->getApiUserId()) {
         $this->getUser()->setFlash('error', 'You cannot sent messages to yourself.');
         $this->redirect('message');
     }
     if ($form->isValid() && $this->getUser()->getApiUserId()) {
         $auth_key = $this->getUser()->getApiAuthKey();
         if ($form->getValue('id')) {
             // Update existing item.
             $values = $form->getObject()->getModified();
             $message = $form->getObject();
             unset($values['id']);
             $id = $form->getValue('id');
             $result = Api::getInstance()->setUser($auth_key)->put('message/' . $id, $values);
             $success = $this->checkHttpCode($result, 'put', 'message/' . $id, json_encode($values));
             if ($success) {
                 $this->getUser()->setFlash('notice', 'Message was edited successfully.');
             }
             $test_message = ApiDoctrine::createObject('Message', $result['body']);
             $message = $test_message ? $test_message : $message;
         } else {
             // Create new item
             $values = $form->getValues();
             $message = $form->getObject();
             foreach ($values as $key => $value) {
                 if (is_null($value)) {
                     unset($values[$key]);
                 }
             }
             if (!array_key_exists('sender_id', $values)) {
                 $values['sender_id'] = $this->getUser()->getApiUserId();
             }
             $result = Api::getInstance()->setUser($auth_key)->post('message', $values);
             $success = $this->checkHttpCode($result, 'post', 'message', json_encode($values));
             if ($success) {
                 $this->getUser()->setFlash('notice', 'Message was sent successfully.');
             }
         }
         if (!$this->getUser()->getApiUserId()) {
             $this->getUser()->setFlash('error', 'You are not logged in!');
         }
         $this->redirect('message');
     }
 }