| @@ -41,8 +41,9 @@ | ||
| 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'); | |
| 45 | 46 | } |
| 46 | 47 | |
| 47 | 48 | /** |
| 48 | 49 | * Create new block. |
| @@ -97,9 +98,9 @@ | ||
| 97 | 98 | $blocksModel =& $this->model; |
| 98 | 99 | $blockId = $blocksModel->add($block->getValues()); |
| 99 | 100 | $blocksModel->save(); |
| 100 | 101 | // Read newly added block from database. |
| 101 | - $newBlockData = $blocksModel->getBlock($blockId); | |
| 102 | + $newBlockData = $blocksModel->getBlock($blockId, array('returnCodeFile' => true)); | |
| 102 | 103 | |
| 103 | 104 | if ($newBlockData === null) { |
| 104 | 105 | throw new Exception('Could not add new block!!!'); |
| 105 | 106 | } |
| @@ -111,9 +112,9 @@ | ||
| 111 | 112 | // Push vars into the view. |
| 112 | 113 | $blockView->setBlock($block); |
| 113 | 114 | $response['view'] = $blockView->getTemplate('new'); |
| 114 | 115 | } |
| 115 | - $response['id'] = $id; | |
| 116 | + $response['id'] = $blockId; | |
| 116 | 117 | // Set response object. |
| 117 | 118 | $this->response = $response; |
| 118 | 119 | } |
| 119 | 120 | } |
| @@ -148,9 +149,9 @@ | ||
| 148 | 149 | $viewInfo = $allowedViews[$viewName]; |
| 149 | 150 | // Get view object. |
| 150 | 151 | $view = CJTController::getView($viewName); |
| 151 | 152 | // Push view variables. |
| 152 | - foreach ((array) $viewInfo['vars'] as $var) { | |
| 153 | + foreach ((isset($viewInfo['vars']) ? $viewInfo['vars'] : array()) as $var) { | |
| 153 | 154 | $view->$var = $_GET["view.{$var}"]; |
| 154 | 155 | } |
| 155 | 156 | // Some views required custom pushing, this is can |
| 156 | 157 | // be done by the registered controller. |
| @@ -168,12 +169,25 @@ | ||
| 168 | 169 | /** |
| 169 | 170 | * put your comment there... |
| 170 | 171 | * |
| 171 | 172 | */ |
| 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 | + */ | |
| 172 | 188 | public function saveBlocksAction() { |
| 173 | 189 | $response = array(); |
| 174 | - // Single block model class. | |
| 175 | - require_once CJTOOLBOX_MODELS_PATH . '/block.php'; | |
| 176 | 190 | // Blocks are sent ins single array list. |
| 177 | 191 | $blocksToSave = filter_input(INPUT_POST, 'blocks', FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY); |
| 178 | 192 | $calculatePinPoint = (bool) filter_input(INPUT_POST, 'calculatePinPoint', FILTER_SANITIZE_NUMBER_INT); |
| 179 | 193 | $createRevision = (bool) filter_input(INPUT_POST, 'createRevision', FILTER_SANITIZE_NUMBER_INT); |
| @@ -184,11 +198,11 @@ | ||
| 184 | 198 | // Push block id into block data. |
| 185 | 199 | $blockData = (object) $postedblockPartialData; |
| 186 | 200 | $blockData->id = $id; |
| 187 | 201 | // Recalculate pinPoint field value. |
| 188 | - !$calculatePinPoint or CJTBlockModel::calculateBlockPinPoint($blockData); | |
| 202 | + !$calculatePinPoint or (CJTBlockModel::arrangePins($blockData) && CJTBlockModel::calculateBlockPinPoint($blockData)); | |
| 189 | 203 | // Create block revision. |
| 190 | - !$createRevision or $this->model->addRevision($id); | |
| 204 | + !$createRevision or $this->model->addRevision($id, $blockData->activeFileId); | |
| 191 | 205 | // Set lastModified field to current time. |
| 192 | 206 | $blockData->lastModified = current_time('mysql'); |
| 193 | 207 | // Update database. |
| 194 | 208 | $this->model->update($blockData, $calculatePinPoint); |