| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version $ Id; block-ajax.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 |
* Server single block OR block specific actions. |
| 14 |
* |
| 15 |
* @author Ahmed Said |
| 16 |
* @version 6 |
| 17 |
* @deprecated DONT ADD MORE ACTIONS. USE CJTBlockController and other controllers instead! |
| 18 |
*/ |
| 19 |
class CJTBlockAjaxController extends CJTAjaxController { |
| 20 |
|
| 21 |
/** |
| 22 |
* Initialize controller object. |
| 23 |
* |
| 24 |
* @see CJTController for more details |
| 25 |
* @return void |
| 26 |
*/ |
| 27 |
public function __construct() |
| 28 |
{ |
| 29 |
|
| 30 |
parent::__construct(); |
| 31 |
|
| 32 |
// Supported actions. |
| 33 |
$this->registryAction('get_info_view'); |
| 34 |
$this->registryAction('set_property'); |
| 35 |
$this->registryAction('getBlockBy'); |
| 36 |
$this->registryAction('getAPOP'); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* put your comment there... |
| 41 |
* |
| 42 |
* @deprecated this is just a redirect to the CJTBlockContoller::getAction(). |
| 43 |
*/ |
| 44 |
protected function getAPOPAction() { |
| 45 |
// Pass to CJTBlockController! |
| 46 |
$this->redirect('block'); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* put your comment there... |
| 51 |
* |
| 52 |
* @deprecated this is just a redirect to the CJTBlockContoller::getAction(). |
| 53 |
*/ |
| 54 |
protected function getBlockByAction() { |
| 55 |
// Pass to CJTBlockController! |
| 56 |
$this->redirect('block'); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* put your comment there... |
| 61 |
* |
| 62 |
* @deprecated All will be moved to other controllers in the future versions. |
| 63 |
*/ |
| 64 |
public function getInfoViewAction() { |
| 65 |
$model = $this->getModel('blocks'); |
| 66 |
// Set content type as HTML. |
| 67 |
$this->httpContentType = "text/html"; |
| 68 |
// Get block info. |
| 69 |
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); |
| 70 |
$Info = $model->getInfo($id); |
| 71 |
// Create info view object. |
| 72 |
$view = CJTController::getView('blocks/info'); |
| 73 |
// Get view info content. |
| 74 |
$view->info = $Info; |
| 75 |
$this->response = $view->getTemplate('default'); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
/** |
| 80 |
* Update exists block property value. |
| 81 |
* |
| 82 |
* |
| 83 |
* Call this method using POST method with the following parameters. |
| 84 |
* - id integer Block id. |
| 85 |
* - property string Property Name to change. |
| 86 |
* - value mixed Property value to change. |
| 87 |
* |
| 88 |
* Response body is array with the following elements. |
| 89 |
* - string oldValue Old property value. |
| 90 |
* - string value New value. |
| 91 |
* |
| 92 |
* @deprecated |
| 93 |
* @return void |
| 94 |
*/ |
| 95 |
public function setPropertyAction() { |
| 96 |
// Initialize. |
| 97 |
$response = array(); |
| 98 |
$blocks = $this->getModel('blocks'); |
| 99 |
// Prepare parameters. |
| 100 |
$blockId = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT); |
| 101 |
$property = filter_input(INPUT_POST, 'property', FILTER_SANITIZE_STRING); |
| 102 |
$newValue = filter_input(INPUT_POST, 'value', FILTER_UNSAFE_RAW); |
| 103 |
// Get old value. |
| 104 |
$block = $blocks->getBlock($blockId); |
| 105 |
$oldValue = $block->$property; |
| 106 |
// Update only if there is a change. |
| 107 |
if ($oldValue != $newValue) { |
| 108 |
// Update block property. |
| 109 |
$block->$property = $newValue; |
| 110 |
$blocks->setBlock($block); |
| 111 |
$blocks->save(); |
| 112 |
// Set response object. |
| 113 |
$response['oldValue'] = $oldValue; |
| 114 |
$response['value'] = $newValue; |
| 115 |
} |
| 116 |
$this->response = $response; |
| 117 |
} |
| 118 |
|
| 119 |
} // End class. |