| @@ -10,13 +10,13 @@ | ||
| 10 | 10 | cssJSToolbox::import('framework:mvc:controller-ajax.inc.php'); |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * Serve blocks page Ajax requests. |
| 14 | -* | |
| 14 | +* | |
| 15 | 15 | * The Actions resident here is global for only the blocks page, its not |
| 16 | 16 | * for a specific/single block. You can find single block |
| 17 | 17 | * actions in block-ajax.php file. |
| 18 | -* | |
| 18 | +* | |
| 19 | 19 | * @deprecated DONT ADD MORE ACTIONS HERE! |
| 20 | 20 | * @author Ahmed Said |
| 21 | 21 | * @version 6 |
| 22 | 22 | */ |
| @@ -23,16 +23,16 @@ | ||
| 23 | 23 | class CJTBlocksAjaxController extends CJTAjaxController { |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * put your comment there... |
| 27 | - * | |
| 27 | + * | |
| 28 | 28 | * @var mixed |
| 29 | 29 | */ |
| 30 | 30 | protected $controllerInfo = array('model' => 'blocks'); |
| 31 | - | |
| 31 | + | |
| 32 | 32 | /** |
| 33 | 33 | * Initialize controller object. |
| 34 | - * | |
| 34 | + * | |
| 35 | 35 | * @see CJTController for more details |
| 36 | 36 | * @return void |
| 37 | 37 | */ |
| 38 | 38 | public function __construct() { |
| @@ -41,27 +41,26 @@ | ||
| 41 | 41 | $this->registryAction('create_block'); |
| 42 | 42 | $this->registryAction('get_view'); |
| 43 | 43 | $this->registryAction('save_blocks'); |
| 44 | 44 | $this->registryAction('saveOrder'); |
| 45 | - $this->registryAction('loadBlock'); | |
| 46 | 45 | } |
| 47 | - | |
| 46 | + | |
| 48 | 47 | /** |
| 49 | 48 | * Create new block. |
| 50 | - * | |
| 49 | + * | |
| 51 | 50 | * Once this method is called a new block is saved into |
| 52 | 51 | * the database. |
| 53 | - * | |
| 52 | + * | |
| 54 | 53 | * Call this method using GET method with the following parameters. |
| 55 | 54 | * - array ids Ids for all the available blocks. |
| 56 | 55 | * - [name] string Block name. |
| 57 | 56 | * - [state] string Block state. |
| 58 | 57 | * - [location] string Block hook location. |
| 59 | - * | |
| 58 | + * | |
| 60 | 59 | * Response body is array with the following elements. |
| 61 | 60 | * - integer id New block id. |
| 62 | 61 | * - string view Block HTML code. |
| 63 | - * | |
| 62 | + * | |
| 64 | 63 | * @return void |
| 65 | 64 | */ |
| 66 | 65 | public function createBlockAction($blockId = null, $blockType = null, $pinPoint = null, $viewName = null) { |
| 67 | 66 | $response = array(); |
| @@ -95,13 +94,13 @@ | ||
| 95 | 94 | require_once CJTOOLBOX_MODELS_PATH . '/block.php'; |
| 96 | 95 | $block = new CJTBlockModel($blockData); |
| 97 | 96 | // Add block. |
| 98 | 97 | $blocksModel =& $this->model; |
| 99 | - $blockId = $blocksModel->add($block->getValues(), true); | |
| 98 | + $blockId = $blocksModel->add($block->getValues()); | |
| 100 | 99 | $blocksModel->save(); |
| 101 | 100 | // Read newly added block from database. |
| 102 | - $newBlockData = $blocksModel->getBlock($blockId, array('returnCodeFile' => true)); | |
| 103 | - | |
| 101 | + $newBlockData = $blocksModel->getBlock($blockId); | |
| 102 | + | |
| 104 | 103 | if ($newBlockData === null) { |
| 105 | 104 | throw new Exception('Could not add new block!!!'); |
| 106 | 105 | } |
| 107 | 106 | else { |
| @@ -112,25 +111,25 @@ | ||
| 112 | 111 | // Push vars into the view. |
| 113 | 112 | $blockView->setBlock($block); |
| 114 | 113 | $response['view'] = $blockView->getTemplate('new'); |
| 115 | 114 | } |
| 116 | - $response['id'] = $blockId; | |
| 115 | + $response['id'] = $blockId; | |
| 117 | 116 | // Set response object. |
| 118 | - $this->response = $response; | |
| 117 | + $this->response = $response; | |
| 119 | 118 | } |
| 120 | 119 | } |
| 121 | - | |
| 120 | + | |
| 122 | 121 | /** |
| 123 | 122 | * Get view content through ajax request. |
| 124 | - * | |
| 123 | + * | |
| 125 | 124 | * The method is useful for requesting Popup forms through ajax (e.g ThickBox). |
| 126 | 125 | * You can request any view specified in the $allowedViews array. |
| 127 | - * | |
| 126 | + * | |
| 128 | 127 | * Call this method using GET method with the following parameters. |
| 129 | 128 | * - viewName string Name of the view. |
| 130 | - * | |
| 129 | + * | |
| 131 | 130 | * Response body is the view content string. |
| 132 | - * | |
| 131 | + * | |
| 133 | 132 | * @return void |
| 134 | 133 | */ |
| 135 | 134 | public function getViewAction() { |
| 136 | 135 | // Some views required objects to be pushed into it before displaying |
| @@ -167,85 +166,51 @@ | ||
| 167 | 166 | } |
| 168 | 167 | |
| 169 | 168 | /** |
| 170 | 169 | * put your comment there... |
| 171 | - * | |
| 170 | + * | |
| 172 | 171 | */ |
| 173 | - public function loadBlockAction() { | |
| 174 | - // Block Id. | |
| 175 | - $blockId = (int) $_GET['blockId']; | |
| 176 | - // Get block content. | |
| 177 | - $view = CJTView::getInstance('blocks/cjt-block'); | |
| 178 | - $view->setBlock(CJTModel::create('blocks')->getBlock($blockId, array('returnCodeFile' => true))); | |
| 179 | - // Return View content. | |
| 180 | - $view->getTemplate('default'); | |
| 181 | - $this->response = $view->structuredContent; | |
| 182 | - } | |
| 183 | - | |
| 184 | - /** | |
| 185 | - * put your comment there... | |
| 186 | - * | |
| 187 | - */ | |
| 188 | - public function saveBlocksAction() | |
| 189 | - { | |
| 172 | + public function saveBlocksAction() { | |
| 190 | 173 | $response = array(); |
| 191 | - | |
| 174 | + // Single block model class. | |
| 175 | + require_once CJTOOLBOX_MODELS_PATH . '/block.php'; | |
| 192 | 176 | // Blocks are sent ins single array list. |
| 193 | - $blocksToSave = filter_input( INPUT_POST, 'blocks', FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY ); | |
| 194 | - $calculatePinPoint = ( bool ) filter_input( INPUT_POST, 'calculatePinPoint', FILTER_SANITIZE_NUMBER_INT ); | |
| 195 | - $createRevision = ( bool ) filter_input( INPUT_POST, 'createRevision', FILTER_SANITIZE_NUMBER_INT ); | |
| 196 | - | |
| 197 | - // For any reason that cause Client/JavaScript to send empty blocks, | |
| 177 | + $blocksToSave = filter_input(INPUT_POST, 'blocks', FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY); | |
| 178 | + $calculatePinPoint = (bool) filter_input(INPUT_POST, 'calculatePinPoint', FILTER_SANITIZE_NUMBER_INT); | |
| 179 | + $createRevision = (bool) filter_input(INPUT_POST, 'createRevision', FILTER_SANITIZE_NUMBER_INT); | |
| 180 | + // For any reason that cause Client/Javascript to send empty blocks, | |
| 198 | 181 | // make sure we're save. |
| 199 | - if ( is_array( $blocksToSave ) && ! empty( $blocksToSave ) ) | |
| 200 | - { | |
| 201 | - | |
| 202 | - foreach ( $blocksToSave as $id => $postedblockPartialData ) | |
| 203 | - { | |
| 182 | + if (is_array($blocksToSave) && !empty($blocksToSave)) { | |
| 183 | + foreach ($blocksToSave as $id => $postedblockPartialData) { | |
| 204 | 184 | // Push block id into block data. |
| 205 | - $blockData = ( object ) $postedblockPartialData; | |
| 185 | + $blockData = (object) $postedblockPartialData; | |
| 206 | 186 | $blockData->id = $id; |
| 207 | - | |
| 208 | 187 | // Recalculate pinPoint field value. |
| 209 | - ! $calculatePinPoint or ( CJTBlockModel::arrangePins( $blockData ) && CJTBlockModel::calculateBlockPinPoint( $blockData ) ); | |
| 210 | - | |
| 188 | + !$calculatePinPoint or CJTBlockModel::calculateBlockPinPoint($blockData); | |
| 211 | 189 | // Create block revision. |
| 212 | - ! $createRevision or $this->model->addRevision( $id, $blockData->activeFileId ); | |
| 213 | - | |
| 190 | + !$createRevision or $this->model->addRevision($id); | |
| 214 | 191 | // Set lastModified field to current time. |
| 215 | - $blockData->lastModified = current_time( 'mysql' ); | |
| 216 | - | |
| 192 | + $blockData->lastModified = current_time('mysql'); | |
| 217 | 193 | // Update database. |
| 218 | - $this->model->update( $blockData, $calculatePinPoint ); | |
| 194 | + $this->model->update($blockData, $calculatePinPoint); | |
| 219 | 195 | $this->model->save(); |
| 220 | - | |
| 221 | 196 | // Send the changes properties back to client. |
| 222 | - $updatedBlockData = $this->model->getBlock($id, null, array('*'), ARRAY_A); | |
| 223 | - | |
| 224 | - foreach ( $updatedBlockData as $property => $value ) | |
| 225 | - { | |
| 226 | - $response[ $id ][ $property ][ 'value' ] = $value; | |
| 197 | + foreach ($postedblockPartialData as $property => $value) { | |
| 198 | + $response[$id][$property]['value'] = $value; | |
| 227 | 199 | } |
| 228 | - | |
| 229 | 200 | } |
| 230 | - | |
| 231 | 201 | } |
| 232 | - | |
| 233 | 202 | // Delete other blocks. |
| 234 | - empty( $_POST[ 'deletedBlocks' ] ) or $this->model->delete( $_POST[ 'deletedBlocks' ] ); | |
| 235 | - | |
| 203 | + empty($_POST['deletedBlocks']) or $this->model->delete($_POST['deletedBlocks']); | |
| 236 | 204 | // Save changes. |
| 237 | 205 | $this->model->save(); |
| 238 | - | |
| 239 | - // Return | |
| 240 | 206 | // Set response. |
| 241 | 207 | $this->response = $response; |
| 242 | - | |
| 243 | 208 | } |
| 244 | - | |
| 209 | + | |
| 245 | 210 | /** |
| 246 | 211 | * put your comment there... |
| 247 | - * | |
| 212 | + * | |
| 248 | 213 | */ |
| 249 | 214 | public function saveOrderAction() { |
| 250 | 215 | // Read order. |
| 251 | 216 | $order = array('normal' => $_GET['order']); |
| @@ -252,6 +217,6 @@ | ||
| 252 | 217 | // Centralized orders to be shared between all users! |
| 253 | 218 | $this->model->setOrder($order); |
| 254 | 219 | $this->response = array('order' => $order, 'state' => 'saved'); |
| 255 | 220 | } |
| 256 | - | |
| 221 | + | |
| 257 | 222 | } // End class. |