| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version $ Id; blocks-backups.php 21-03-2012 03:22:10 Ahmed Said $ |
| 4 |
*/ |
| 5 |
|
| 6 |
// Disallow direct access. |
| 7 |
defined('ABSPATH') or die("Access denied"); |
| 8 |
|
| 9 |
// import dependencies. |
| 10 |
cssJSToolbox::import('framework:mvc:controller-ajax.inc.php'); |
| 11 |
|
| 12 |
/** |
| 13 |
* |
| 14 |
* |
| 15 |
* @author Ahmed Said |
| 16 |
* @version 6 |
| 17 |
*/ |
| 18 |
class CJTBlocksBackupsController extends CJTAjaxController { |
| 19 |
|
| 20 |
/** |
| 21 |
* put your comment there... |
| 22 |
* |
| 23 |
* @var mixed |
| 24 |
*/ |
| 25 |
protected $controllerInfo = array('model' => 'blocks-backups'); |
| 26 |
|
| 27 |
/** |
| 28 |
* Initialize controller object. |
| 29 |
* |
| 30 |
* @see CJTController for more details |
| 31 |
* @return void |
| 32 |
*/ |
| 33 |
public function __construct() { |
| 34 |
parent::__construct(); |
| 35 |
// Supported actions. |
| 36 |
add_action('wp_ajax_cjtoolbox_create', array(&$this, '_doAction')); |
| 37 |
add_action('wp_ajax_cjtoolbox_delete', array(&$this, '_doAction')); |
| 38 |
add_action('wp_ajax_cjtoolbox_list', array(&$this, '_doAction')); |
| 39 |
add_action('wp_ajax_cjtoolbox_restore', array(&$this, '_doAction')); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* put your comment there... |
| 44 |
* |
| 45 |
*/ |
| 46 |
public function createAction() { |
| 47 |
$backupData = array(); |
| 48 |
// Get posted backup data. |
| 49 |
$backupData['name'] = filter_input(INPUT_GET, 'name', FILTER_SANITIZE_STRING); |
| 50 |
$backupRowIndex = filter_input(INPUT_GET, 'rowIndex', FILTER_SANITIZE_NUMBER_INT); |
| 51 |
// Create new backup -- Data will be retruned along with new backup Id. |
| 52 |
$backupData = $this->model->create($backupData); |
| 53 |
$this->model->save(); |
| 54 |
// Get single backup row. |
| 55 |
$view = self::getView('backups/manager'); |
| 56 |
$view->currentBackup = (object) $backupData; |
| 57 |
// Send response back to client. |
| 58 |
$this->httpContentType = 'text/html'; |
| 59 |
$this->response = $view->getTemplate('single-backup', array('rowIndex' => $backupRowIndex)); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* put your comment there... |
| 64 |
* |
| 65 |
*/ |
| 66 |
public function deleteAction() { |
| 67 |
// Get backup id from request parameters. |
| 68 |
$backupId = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); |
| 69 |
// Delete backup. |
| 70 |
$this->model->delete($backupId); |
| 71 |
$this->model->save(); |
| 72 |
// Get backups list . |
| 73 |
$view = self::getView('backups/manager'); |
| 74 |
$view->backups = (object) $backupData; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* put your comment there... |
| 79 |
* |
| 80 |
* @todo Accept template name as parameters and also work |
| 81 |
* if parameter is no passed! |
| 82 |
*/ |
| 83 |
public function listAction($templateName = 'default') { |
| 84 |
// Create backup view. |
| 85 |
$view = self::getView('backups/manager'); |
| 86 |
// Push vars into view. |
| 87 |
$view->backups = $this->model->getAll(); |
| 88 |
$view->controllerName = 'blocksBackups'; |
| 89 |
// Set response header. |
| 90 |
$this->httpContentType = 'text/html'; |
| 91 |
// Send view content back to client. |
| 92 |
$this->response = $view->getTemplate($templateName); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* put your comment there... |
| 97 |
* |
| 98 |
*/ |
| 99 |
public function restoreAction() { |
| 100 |
// Get backup id from request parameters. |
| 101 |
$backupId = filter_input(INPUT_GET, 'backupId', FILTER_SANITIZE_NUMBER_INT); |
| 102 |
$this->model->restore($backupId); |
| 103 |
// Save changes into the database. |
| 104 |
$this->model->save(); |
| 105 |
} |
| 106 |
|
| 107 |
} // End class. |