<?php
class Pampa_Controller_Action_Conteudo extends Pampa_Controller_Action {

  public function init(){
    parent::init();
  }

  /**
   * return a error information with a message
   * @param String $message the error message
   * @param Boolean $file if the transaction had a file
   */
  protected function message($message = '', $type){
    // check for messages
    if(!empty($message)){
      // add the message
      $this->_helper->messenger($type, $message);
    }
    
  }
  /**
   * return a error information with a message
   * @param String $message the error message
   * @param Boolean $file if the transaction had a file
   */
  protected function sendError($message = '', $file = FALSE){
    // check for messages
    if(!empty($message)){
      // add the message
      $this->_helper->messenger('error', $message);
    }
    // setup the params array
    $params = array(
      "e" => TRUE,
      "m" => $message
    );
    $this->sendReturn($params, $file);
  }

  /**
   * return a success info
   * @param String $message The success message
   * @param String $redirect URL to redirect
   * @param Boolean $file if the transaction had a file
   */
  protected function sendSuccess($message = '', $redirect = '', $file = FALSE){
    // check for messages
    if(!empty($message)){
      // add the message
      $this->_helper->messenger('ok', $message);
    }
    // setup the params array
    $params = array(
      "e" => FALSE,
      "r" => $redirect,
      "m" => $message
    );
    $this->sendReturn($params, $file);
  }

  /**
   * send the info
   * @param Array $params the json info
   * @param Boolean $file
   */
  protected function sendReturn($params = array(), $file = FALSE){
    // check for file
    if($file){
      // change layout
      $this->_helper->Layout->setLayout('clean');
      // send params to view
      $this->view->params = $params;
      // render custom view
      $this->render('cms/return', NULL, TRUE);
    } else {
      // just return the json data
      $this->renderJson($params);
    }
  }
}