| @@ -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() { |
| @@ -43,25 +43,25 @@ | ||
| 43 | 43 | $this->registryAction('save_blocks'); |
| 44 | 44 | $this->registryAction('saveOrder'); |
| 45 | 45 | $this->registryAction('loadBlock'); |
| 46 | 46 | } |
| 47 | - | |
| 47 | + | |
| 48 | 48 | /** |
| 49 | 49 | * Create new block. |
| 50 | - * | |
| 50 | + * | |
| 51 | 51 | * Once this method is called a new block is saved into |
| 52 | 52 | * the database. |
| 53 | - * | |
| 53 | + * | |
| 54 | 54 | * Call this method using GET method with the following parameters. |
| 55 | 55 | * - array ids Ids for all the available blocks. |
| 56 | 56 | * - [name] string Block name. |
| 57 | 57 | * - [state] string Block state. |
| 58 | 58 | * - [location] string Block hook location. |
| 59 | - * | |
| 59 | + * | |
| 60 | 60 | * Response body is array with the following elements. |
| 61 | 61 | * - integer id New block id. |
| 62 | 62 | * - string view Block HTML code. |
| 63 | - * | |
| 63 | + * | |
| 64 | 64 | * @return void |
| 65 | 65 | */ |
| 66 | 66 | public function createBlockAction($blockId = null, $blockType = null, $pinPoint = null, $viewName = null) { |
| 67 | 67 | $response = array(); |
| @@ -99,9 +99,9 @@ | ||
| 99 | 99 | $blockId = $blocksModel->add($block->getValues(), true); |
| 100 | 100 | $blocksModel->save(); |
| 101 | 101 | // Read newly added block from database. |
| 102 | 102 | $newBlockData = $blocksModel->getBlock($blockId, array('returnCodeFile' => true)); |
| 103 | - | |
| 103 | + | |
| 104 | 104 | if ($newBlockData === null) { |
| 105 | 105 | throw new Exception('Could not add new block!!!'); |
| 106 | 106 | } |
| 107 | 107 | else { |
| @@ -112,25 +112,25 @@ | ||
| 112 | 112 | // Push vars into the view. |
| 113 | 113 | $blockView->setBlock($block); |
| 114 | 114 | $response['view'] = $blockView->getTemplate('new'); |
| 115 | 115 | } |
| 116 | - $response['id'] = $blockId; | |
| 116 | + $response['id'] = $blockId; | |
| 117 | 117 | // Set response object. |
| 118 | - $this->response = $response; | |
| 118 | + $this->response = $response; | |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | - | |
| 121 | + | |
| 122 | 122 | /** |
| 123 | 123 | * Get view content through ajax request. |
| 124 | - * | |
| 124 | + * | |
| 125 | 125 | * The method is useful for requesting Popup forms through ajax (e.g ThickBox). |
| 126 | 126 | * You can request any view specified in the $allowedViews array. |
| 127 | - * | |
| 127 | + * | |
| 128 | 128 | * Call this method using GET method with the following parameters. |
| 129 | 129 | * - viewName string Name of the view. |
| 130 | - * | |
| 130 | + * | |
| 131 | 131 | * Response body is the view content string. |
| 132 | - * | |
| 132 | + * | |
| 133 | 133 | * @return void |
| 134 | 134 | */ |
| 135 | 135 | public function getViewAction() { |
| 136 | 136 | // Some views required objects to be pushed into it before displaying |
| @@ -167,9 +167,9 @@ | ||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
| 170 | 170 | * put your comment there... |
| 171 | - * | |
| 171 | + * | |
| 172 | 172 | */ |
| 173 | 173 | public function loadBlockAction() { |
| 174 | 174 | // Block Id. |
| 175 | 175 | $blockId = (int) $_GET['blockId']; |
| @@ -179,73 +179,70 @@ | ||
| 179 | 179 | // Return View content. |
| 180 | 180 | $view->getTemplate('default'); |
| 181 | 181 | $this->response = $view->structuredContent; |
| 182 | 182 | } |
| 183 | - | |
| 183 | + | |
| 184 | 184 | /** |
| 185 | 185 | * put your comment there... |
| 186 | - * | |
| 186 | + * | |
| 187 | 187 | */ |
| 188 | - public function saveBlocksAction() | |
| 188 | + public function saveBlocksAction() | |
| 189 | 189 | { |
| 190 | 190 | $response = array(); |
| 191 | - | |
| 191 | + | |
| 192 | 192 | // Blocks are sent ins single array list. |
| 193 | 193 | $blocksToSave = filter_input( INPUT_POST, 'blocks', FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY ); |
| 194 | 194 | $calculatePinPoint = ( bool ) filter_input( INPUT_POST, 'calculatePinPoint', FILTER_SANITIZE_NUMBER_INT ); |
| 195 | 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, | |
| 196 | + | |
| 197 | + // For any reason that cause Client/Javascript to send empty blocks, | |
| 198 | 198 | // make sure we're save. |
| 199 | - if ( is_array( $blocksToSave ) && ! empty( $blocksToSave ) ) | |
| 199 | + if ( is_array( $blocksToSave ) && ! empty( $blocksToSave ) ) | |
| 200 | 200 | { |
| 201 | - | |
| 202 | - foreach ( $blocksToSave as $id => $postedblockPartialData ) | |
| 201 | + | |
| 202 | + foreach ( $blocksToSave as $id => $postedblockPartialData ) | |
| 203 | 203 | { |
| 204 | 204 | // Push block id into block data. |
| 205 | 205 | $blockData = ( object ) $postedblockPartialData; |
| 206 | 206 | $blockData->id = $id; |
| 207 | - | |
| 207 | + | |
| 208 | 208 | // Recalculate pinPoint field value. |
| 209 | 209 | ! $calculatePinPoint or ( CJTBlockModel::arrangePins( $blockData ) && CJTBlockModel::calculateBlockPinPoint( $blockData ) ); |
| 210 | - | |
| 210 | + | |
| 211 | 211 | // Create block revision. |
| 212 | 212 | ! $createRevision or $this->model->addRevision( $id, $blockData->activeFileId ); |
| 213 | - | |
| 213 | + | |
| 214 | 214 | // Set lastModified field to current time. |
| 215 | 215 | $blockData->lastModified = current_time( 'mysql' ); |
| 216 | - | |
| 216 | + | |
| 217 | 217 | // Update database. |
| 218 | 218 | $this->model->update( $blockData, $calculatePinPoint ); |
| 219 | 219 | $this->model->save(); |
| 220 | - | |
| 220 | + | |
| 221 | 221 | // Send the changes properties back to client. |
| 222 | - $updatedBlockData = $this->model->getBlock($id, null, array('*'), ARRAY_A); | |
| 223 | - | |
| 224 | - foreach ( $updatedBlockData as $property => $value ) | |
| 222 | + foreach ( $postedblockPartialData as $property => $value ) | |
| 225 | 223 | { |
| 226 | 224 | $response[ $id ][ $property ][ 'value' ] = $value; |
| 227 | 225 | } |
| 228 | - | |
| 226 | + | |
| 229 | 227 | } |
| 230 | - | |
| 228 | + | |
| 231 | 229 | } |
| 232 | - | |
| 230 | + | |
| 233 | 231 | // Delete other blocks. |
| 234 | 232 | empty( $_POST[ 'deletedBlocks' ] ) or $this->model->delete( $_POST[ 'deletedBlocks' ] ); |
| 235 | - | |
| 233 | + | |
| 236 | 234 | // Save changes. |
| 237 | 235 | $this->model->save(); |
| 238 | - | |
| 239 | - // Return | |
| 236 | + | |
| 240 | 237 | // Set response. |
| 241 | 238 | $this->response = $response; |
| 242 | - | |
| 239 | + | |
| 243 | 240 | } |
| 244 | - | |
| 241 | + | |
| 245 | 242 | /** |
| 246 | 243 | * put your comment there... |
| 247 | - * | |
| 244 | + * | |
| 248 | 245 | */ |
| 249 | 246 | public function saveOrderAction() { |
| 250 | 247 | // Read order. |
| 251 | 248 | $order = array('normal' => $_GET['order']); |
| @@ -252,6 +249,6 @@ | ||
| 252 | 249 | // Centralized orders to be shared between all users! |
| 253 | 250 | $this->model->setOrder($order); |
| 254 | 251 | $this->response = array('order' => $order, 'state' => 'saved'); |
| 255 | 252 | } |
| 256 | - | |
| 253 | + | |
| 257 | 254 | } // End class. |