PageRenderTime 23ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/apps/api/modules/quote/actions/actions.class.php

https://github.com/sanjuro/Meteb
PHP | 142 lines | 57 code | 30 blank | 55 comment | 5 complexity | fbaddd1a643fd28ecb8c735fc8ebbc35 MD5 | raw file
  1. <?php
  2. /**
  3. * Quote actions.
  4. *
  5. * @package meteb
  6. * @subpackage quote
  7. * @author Shadley Wentzel <shad6ster@gmail.com>
  8. * @version GIT
  9. */
  10. class quoteActions extends sfActions
  11. {
  12. /**
  13. * Executes the pre-execute session check on the API
  14. * call
  15. *
  16. * @param sfRequest $request A request object
  17. */
  18. public function preExecute()
  19. {
  20. sfConfig::set('sf_web_debug', false);
  21. }
  22. /**
  23. * Executes create quote action for the API interface
  24. * based on the client id parameter using POST
  25. *
  26. * @WSMethod(name='newQuote', webservice="soapApi")
  27. *
  28. * @param string $token Api Session token
  29. * @param newQuoteRequest $newQuote Quote Information to be used for the new license
  30. *
  31. * @return string $result
  32. *
  33. */
  34. public function executeNew(sfWebRequest $request)
  35. {
  36. $token = $request->getParameter('token');
  37. $api_token = $this->getUser()->getAttribute('api_token', '', 'user');
  38. if (empty($token) && $token != $api_token) {
  39. if($this->isSoapRequest()){
  40. $e = new SoapFault('Server', 'The user is not authenticated!');
  41. throw $e;
  42. }else{
  43. $this->response->setStatusCode('401');
  44. $feedback = 'The user is not authenticated';
  45. $this->feedback = $feedback;
  46. return $this->renderPartial('messages/error', array('feedback' => $this->feedback));
  47. }
  48. }
  49. $q = $request->getParameter('newQuote');
  50. try {
  51. /**
  52. * Create new Client object
  53. */
  54. // $client = MetebQuoteApi::createClient($request);
  55. /**
  56. * Create new associated UserProfile object
  57. */
  58. // $userProfile = MetebQuoteApi::createUserProfile($request, $client->getId(), $api_user);
  59. /**
  60. * Create new Quote object
  61. */
  62. // $quote = MetebQuoteApi::createQuote($q);
  63. $quote_calculations = MetebQuoteApi::createQuote($q);
  64. // $client = $quote->getClient();
  65. /**
  66. * Use the function
  67. */
  68. // $quote_calculations = $quote->getQuoteOutputTypes();
  69. // $quote_calculations['id'] = $quote->getId();
  70. // $quote_calculations['quote_id'] = $quote->getId();
  71. # Get Partial for PDF
  72. sfProjectConfiguration::getActive()->loadHelpers('Partial');
  73. $PDFContent = get_partial('quote/pdf', array( 'quote_calculations' => $quote_calculations, 'client' => $client, 'userprofile' => '', 'quote' => $quote) );
  74. # Generate PDF
  75. $metebPDF = new metebPDF();
  76. $metebPDF->CreateSOAPQuote($PDFContent);
  77. $metebPDF->load_html($metebPDF->HTML);
  78. // $quotePDf = $metebPDF->stream("Quotation.pdf");
  79. // $newQuoteResponseObj = new newQuoteResponse();
  80. $newQuoteResponseString = base64_encode($metebPDF->output_html());
  81. $this->result = $newQuoteResponseString;
  82. $this->response->setStatusCode('200');
  83. return $this->renderPartial('messages/message', array('message' => $this->result));
  84. }catch (Exception $e){
  85. if($this->isSoapRequest()){
  86. $e = new SoapFault('Server', $e->getMessage());
  87. throw $e;
  88. }else{
  89. $this->response->setStatusCode('401');
  90. $feedback = $e->getMessage();
  91. $this->feedback = $feedback;
  92. return $this->renderPartial('messages/error', array('feedback' => $this->feedback));
  93. }
  94. }
  95. }
  96. /**
  97. * Validate clientId
  98. *
  99. * @param string $name
  100. * @return boolean
  101. */
  102. private static function validateName($name)
  103. {
  104. $validate = new sfValidatorString(array('min_length' => 1, 'max_length' => 20 ));
  105. try{
  106. $result = $validate->clean($name);
  107. }catch (sfValidatorError $e){
  108. return false;
  109. }
  110. return true;
  111. }
  112. }