Esempio n. 1
0
 /**
  * Entire Answer data will be returned
  * in request
  *
  * @return object $this
  */
 protected function setOutput()
 {
     /*$d = __METHOD__.' '.__LINE__;
       exit($d);*/
     $a = $this->Answer->getArrayCopy();
     /**
      * @todo maybe use special template
      * for 'app' instead of default template?
      *
      */
     $a['edit_delete'] = ' <span class="ico del ajax" title="Delete">delete</span>  <span class="ico edit ajax" title="Edit">edit</span>';
     $a['html'] = \tplAnswer::parse($a);
     d('before sending out $a: ' . print_r($a, 1));
     $this->Output->setData($a);
     return $this;
 }
Esempio n. 2
0
 /**
  * Process submitted Answer
  *
  * @return void
  */
 protected function process()
 {
     $formVals = $this->Form->getSubmittedValues();
     d('formVals: ' . print_r($formVals, 1));
     $oAdapter = new AnswerParser($this->Registry);
     try {
         $Answer = $oAdapter->parse(new SubmittedAnswerWWW($this->Registry, $formVals));
         d('cp created new answer: ' . \print_r($Answer->getArrayCopy(), 1));
         d('ans id: ' . $Answer->getResourceId());
         /**
          * In case of ajax we need to send out a
          * parsed html block with one answer
          * under the 'answer' key
          *
          * In case of non-ajax redirect back to question page,
          * hopefully the new answer will show up there too
          */
         if (Request::isAjax()) {
             $aAnswer = $Answer->getArrayCopy();
             /**
              * Add edit and delete tools because
              * Viewer already owns this comment and is
              * allowed to edit or delete it right away.
              * Javascript that usually dynamically adds these tools
              * is not going to be fired, so these tools
              * must already be included in the returned html
              *
              */
             $aAnswer['edit_delete'] = ' <span class="ico del ajax" title="@@Delete@@">@@delete@@</span>  <span class="ico edit ajax" title="@@Edit@@">@@edit@@</span>';
             $a = array('answer' => \tplAnswer::parse($aAnswer));
             d('before sending out $a: ' . print_r($a, 1));
             Responder::sendJSON($a);
         } else {
             Responder::redirectToPage($this->Question->getUrl());
         }
     } catch (\Lampcms\AnswerParserException $e) {
         d('Got AnswerParserException ' . $e->getMessage());
         /**
          * The setFormError in Form sends our json in
          * case of Ajax request, so we don't have to
          * worry about it here
          */
         $this->Form->setFormError($e->getMessage());
         $this->showFormWithErrors();
     }
 }