<?php

class Cms_Cms_BackupController extends Pampa_Controller_Action_Cms {

  /**
   * @var Model_Backups
   */
  private $modelBackups;

  public function init() {

    $this->modelBackups = new Model_Cms_Backups();

    parent::init();
  }

  /**
   * list based on filters
   */
  public function listAction() {

    // setup the list filters
    $filters = array(
            "t" => $this->_getParam("t", 10),
            "p" => $this->_getParam("p", 1)
    );

    $this->view->filters = $filters;

    // retrieves the items list
    $this->view->items = $this->modelBackups->adminList($filters);
  }

  public function addAction() {
    $add = $this->modelBackups->add();
    if($add->error) {
      // send the error
      $this->_helper->messenger('error', $add->message);
    } else {
      // send the success
      $this->_helper->messenger('ok', 'Backup file generated');
    }
    $this->redirectTo('cms_backup', 'list');
  }

  public function deleteAction(){
    // get the file name
    $filename = $this->_getPAram("name");
    // apply backup
    $apply = $this->modelBackups->deleteFromName($filename);

    if($apply->error) {
      // send the error
      $this->_helper->messenger('error', $apply->message);
    } else {
      // send the success
      $this->_helper->messenger('ok', 'Backup deleted');
    }
    $this->redirectTo('cms_backup', 'list');
  }

}