| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version $ Id; ?FILE_NAME ?DATE ?TIME ?AUTHOR $ |
| 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 |
* DESCRIPTION |
| 15 |
* |
| 16 |
* @author ?? |
| 17 |
* @version ?? |
| 18 |
*/ |
| 19 |
class CJTTemplatesLookupController extends CJTAjaxController { |
| 20 |
|
| 21 |
/** |
| 22 |
* put your comment there... |
| 23 |
* |
| 24 |
* @var mixed |
| 25 |
*/ |
| 26 |
protected $controllerInfo = array('model' => 'templates-lookup', 'view' => 'templates/lookup'); |
| 27 |
|
| 28 |
/** |
| 29 |
* |
| 30 |
* Initialize new object. |
| 31 |
* |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
public function __construct() { |
| 35 |
parent::__construct(); |
| 36 |
// Registry controller actions. |
| 37 |
$this->registryAction('display'); |
| 38 |
$this->registryAction('embedded'); |
| 39 |
$this->registryAction('link'); |
| 40 |
$this->registryAction('unlink'); |
| 41 |
$this->registryAction('unlinkAll'); |
| 42 |
$this->registryAction('getBlockLinkedTemplates'); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* put your comment there... |
| 47 |
* |
| 48 |
* @param mixed $tpl |
| 49 |
*/ |
| 50 |
protected function displayAction($tpl = null) { |
| 51 |
// Prepare inputs |
| 52 |
$this->model->inputs['blockId'] = $_REQUEST['blockId']; |
| 53 |
// Display view! |
| 54 |
parent::displayAction(); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* put your comment there... |
| 59 |
* |
| 60 |
*/ |
| 61 |
protected function embeddedAction() { |
| 62 |
// Read inputs. |
| 63 |
$this->model->inputs['templateId'] = $_REQUEST['templateId']; |
| 64 |
$this->model->inputs['blockId'] = $_REQUEST['blockId']; |
| 65 |
// Get embedded template code! |
| 66 |
$this->response['code'] = $this->model->embedded(); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* put your comment there... |
| 71 |
* |
| 72 |
*/ |
| 73 |
protected function getBlockLinkedTemplatesAction() { |
| 74 |
|
| 75 |
|
| 76 |
$blockId = isset($_GET['blockId']) ? esc_html($_GET['blockId']) : null; |
| 77 |
|
| 78 |
try { |
| 79 |
|
| 80 |
if (!$blockId) { |
| 81 |
|
| 82 |
throw new Exception('Invalid Request parameters'); |
| 83 |
} |
| 84 |
|
| 85 |
$this->response = CJTBlockTemplatesModel::getLinkedTemplatesCount($blockId); |
| 86 |
} |
| 87 |
catch (Exception $exception) { |
| 88 |
|
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* put your comment there... |
| 97 |
* |
| 98 |
*/ |
| 99 |
protected function linkAction() { |
| 100 |
// Read inputs. |
| 101 |
$this->model->inputs['templateId'] = $_REQUEST['templateId']; |
| 102 |
$this->model->inputs['blockId'] = $_REQUEST['blockId']; |
| 103 |
// Link template! |
| 104 |
$this->model->link(); |
| 105 |
// Response with new state! |
| 106 |
$this->response['newState'] = array( |
| 107 |
'action' => 'unlink', |
| 108 |
'text' => cssJSToolbox::getText('Unlink'), |
| 109 |
'className' => 'template-action unlink-template', |
| 110 |
'count' => CJTBlockTemplatesModel::getLinkedTemplatesCount($_REQUEST['blockId']) |
| 111 |
); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* put your comment there... |
| 116 |
* |
| 117 |
*/ |
| 118 |
protected function unlinkAction() { |
| 119 |
// Read inputs. |
| 120 |
$this->model->inputs['templateId'] = $_REQUEST['templateId']; |
| 121 |
$this->model->inputs['blockId'] = $_REQUEST['blockId']; |
| 122 |
// Link template! |
| 123 |
$this->model->unlink(); |
| 124 |
// Response with new state! |
| 125 |
$this->response['newState'] = array( |
| 126 |
'action' => 'link', |
| 127 |
'text' => cssJSToolbox::getText('Link'), |
| 128 |
'className' => 'template-action link-template', |
| 129 |
'count' => CJTBlockTemplatesModel::getLinkedTemplatesCount($_REQUEST['blockId']) |
| 130 |
); |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* put your comment there... |
| 135 |
* |
| 136 |
*/ |
| 137 |
protected function unlinkAllAction() { |
| 138 |
// Read inputs! |
| 139 |
$this->model->inputs['blockId'] = $_REQUEST['blockId']; |
| 140 |
$this->model->unlinkAll(); |
| 141 |
// Response with new state! |
| 142 |
$this->response['newState'] = array( |
| 143 |
'action' => 'link', |
| 144 |
'text' => cssJSToolbox::getText('Link'), |
| 145 |
'className' => 'template-action link-template' |
| 146 |
); |
| 147 |
} |
| 148 |
|
| 149 |
} // End class. |
| 150 |
|