| @@ -27,57 +27,25 @@ | ||
| 27 | 27 | public function __construct() { |
| 28 | 28 | parent::__construct(); |
| 29 | 29 | // Supported actions. |
| 30 | 30 | add_action('wp_ajax_cjtoolbox_get_info_view', array(&$this, '_doAction')); |
| 31 | + add_action('wp_ajax_cjtoolbox_set_property', array(&$this, '_doAction')); | |
| 31 | 32 | add_action('wp_ajax_cjtoolbox_get_revision', array(&$this, '_doAction')); |
| 32 | 33 | add_action('wp_ajax_cjtoolbox_get_revisions', array(&$this, '_doAction')); |
| 33 | 34 | // Redirects |
| 34 | 35 | $this->registryAction('getBlockBy'); |
| 35 | - $this->registryAction('getAPOP'); | |
| 36 | - $this->registryAction('restoreRevision'); | |
| 37 | - $this->registryAction('loadUrl'); | |
| 38 | - $this->registryAction('downloadCodeFile'); | |
| 39 | - $this->registryAction('getAllAssignment'); | |
| 40 | 36 | } |
| 41 | - | |
| 37 | + | |
| 42 | 38 | /** |
| 43 | 39 | * put your comment there... |
| 44 | 40 | * |
| 45 | 41 | * @deprecated this is just a redirect to the CJTBlockContoller::getAction(). |
| 46 | 42 | */ |
| 47 | - protected function downloadCodeFileAction() { | |
| 48 | - // Pass to CJTBlockController! | |
| 49 | - $this->redirect('block'); | |
| 50 | - } | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * put your comment there... | |
| 54 | - * | |
| 55 | - */ | |
| 56 | - protected function getAllAssignmentAction() { | |
| 57 | - $this->redirect('block'); | |
| 58 | - } | |
| 59 | - | |
| 60 | - /** | |
| 61 | - * put your comment there... | |
| 62 | - * | |
| 63 | - * @deprecated this is just a redirect to the CJTBlockContoller::getAction(). | |
| 64 | - */ | |
| 65 | - protected function getAPOPAction() { | |
| 66 | - // Pass to CJTBlockController! | |
| 67 | - $this->redirect('block'); | |
| 68 | - } | |
| 69 | - | |
| 70 | - /** | |
| 71 | - * put your comment there... | |
| 72 | - * | |
| 73 | - * @deprecated this is just a redirect to the CJTBlockContoller::getAction(). | |
| 74 | - */ | |
| 75 | 43 | protected function getBlockByAction() { |
| 76 | 44 | // Pass to CJTBlockController! |
| 77 | 45 | $this->redirect('block'); |
| 78 | 46 | } |
| 79 | - | |
| 47 | + | |
| 80 | 48 | /** |
| 81 | 49 | * put your comment there... |
| 82 | 50 | * |
| 83 | 51 | * @deprecated All will be moved to other controllers in the future versions. |
| @@ -101,31 +69,13 @@ | ||
| 101 | 69 | * |
| 102 | 70 | * @deprecated All will be moved to other controllers in the future versions. |
| 103 | 71 | */ |
| 104 | 72 | public function getRevisionAction() { |
| 105 | - // Initialize | |
| 106 | 73 | $model = $this->getModel('blocks'); |
| 107 | - $tblCodeFile = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver()); | |
| 108 | - // Inputs. | |
| 109 | - $revisionId = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); | |
| 110 | 74 | // Get request parameters. |
| 111 | - $revision['id'] = $revisionId; | |
| 112 | - $revision['fields'] = array('id', 'links', 'expressions', 'masterFile'); | |
| 75 | + $revision['id'] = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); | |
| 76 | + $revision['fields'] = array('id', 'code', 'pinPoint', 'links', 'expressions'); | |
| 113 | 77 | $revision = $model->getBlock($revision['id'], array(), $revision['fields']); |
| 114 | - // Get revisioned code file. | |
| 115 | - $revision->code = $tblCodeFile->set('blockId', $revisionId) | |
| 116 | - ->set('id', $revision->masterFile) | |
| 117 | - ->load() | |
| 118 | - ->getData()->code; | |
| 119 | - // Discard Pins. | |
| 120 | - $customPins = array_keys( CJTBlockModel::getCustomPins() ); | |
| 121 | - | |
| 122 | - foreach ( $customPins as $customPinName ) | |
| 123 | - { | |
| 124 | - $revision->{$customPinName} = false; | |
| 125 | - } | |
| 126 | - | |
| 127 | - // Return revision. | |
| 128 | 78 | $this->response = $revision; |
| 129 | 79 | } |
| 130 | 80 | |
| 131 | 81 | /** |
| @@ -133,14 +83,12 @@ | ||
| 133 | 83 | * |
| 134 | 84 | * @deprecated All will be moved to other controllers in the future versions. |
| 135 | 85 | */ |
| 136 | 86 | public function getRevisionsAction() { |
| 137 | - // initialize. | |
| 138 | 87 | $model = $this->getModel('blocks'); |
| 139 | 88 | // Get request parameters. |
| 140 | 89 | $blockId = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); |
| 141 | 90 | // Get block revisions. |
| 142 | - $revisions['filter']['masterFile'] = $_GET['activeFileId']; | |
| 143 | 91 | $revisions['filter']['parent'] = $blockId; |
| 144 | 92 | $revisions['filter']['type'] = 'revision'; |
| 145 | 93 | // Its mandatory to select fields instead of using just .*. |
| 146 | 94 | // This is because id field must be first to be used as the array key |
| @@ -150,55 +98,52 @@ | ||
| 150 | 98 | // Create view. |
| 151 | 99 | $view = $this->getView('blocks/revisions'); |
| 152 | 100 | // Push view vars. |
| 153 | 101 | $view->blockId = $blockId; |
| 154 | - $view->revisions = array_reverse($revisions); | |
| 102 | + $view->revisions = $revisions; | |
| 155 | 103 | // Set output header. |
| 156 | 104 | $this->httpContentType = 'text/html'; |
| 157 | 105 | // Return view content. |
| 158 | 106 | $this->response = $view->getTemplate('default'); |
| 159 | 107 | } |
| 160 | - | |
| 108 | + | |
| 161 | 109 | /** |
| 162 | - * put your comment there... | |
| 110 | + * Update exists block property value. | |
| 163 | 111 | * |
| 164 | - * @deprecated this is just a redirect to the CJTBlockContoller::getAction(). | |
| 165 | - */ | |
| 166 | - protected function loadUrlAction() { | |
| 167 | - // Pass to CJTBlockController! | |
| 168 | - $this->redirect('block'); | |
| 169 | - } | |
| 170 | - | |
| 171 | - /** | |
| 172 | - * put your comment there... | |
| 173 | 112 | * |
| 113 | + * Call this method using POST method with the following parameters. | |
| 114 | + * - id integer Block id. | |
| 115 | + * - property string Property Name to change. | |
| 116 | + * - value mixed Property value to change. | |
| 117 | + * | |
| 118 | + * Response body is array with the following elements. | |
| 119 | + * - string oldValue Old property value. | |
| 120 | + * - string value New value. | |
| 121 | + * | |
| 122 | + * @deprecated | |
| 123 | + * @return void | |
| 174 | 124 | */ |
| 175 | - protected function restoreRevisionAction() { | |
| 125 | + public function setPropertyAction() { | |
| 176 | 126 | // Initialize. |
| 177 | - $mdlBlocks = new CJTBlocksModel(); | |
| 178 | - $tblCodeFile = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver()); | |
| 179 | - // Get revision ID. | |
| 180 | - $rId = (int) $_GET['rid']; | |
| 181 | - $bId = (int) $_GET['bid']; | |
| 182 | - // Get Revision Block + Revision Code. | |
| 183 | - $revisionBlock = $mdlBlocks->getBlock($rId, array(), array('id', 'pinPoint', 'links', 'expressions', 'masterFile')); | |
| 184 | - $revisionBlock->code = $tblCodeFile->set('blockId', $rId) | |
| 185 | - ->set('id', $revisionBlock->masterFile) | |
| 186 | - ->load() | |
| 187 | - ->getData()->code; | |
| 188 | - // If code === null set it to empoty string '' as null woulod | |
| 189 | - // prevent the field from being in the query, cause SQL error. | |
| 190 | - if ($revisionBlock->code === null) { | |
| 191 | - $revisionBlock->code = ''; | |
| 127 | + $response = array(); | |
| 128 | + $blocks = $this->getModel('blocks'); | |
| 129 | + // Prepare parameters. | |
| 130 | + $blockId = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT); | |
| 131 | + $property = filter_input(INPUT_POST, 'property', FILTER_SANITIZE_STRING); | |
| 132 | + $newValue = filter_input(INPUT_POST, 'value', FILTER_UNSAFE_RAW); | |
| 133 | + // Get old value. | |
| 134 | + $block = $blocks->getBlock($blockId); | |
| 135 | + $oldValue = $block->$property; | |
| 136 | + // Update only if there is a change. | |
| 137 | + if ($oldValue != $newValue) { | |
| 138 | + // Update block property. | |
| 139 | + $block->$property = $newValue; | |
| 140 | + $blocks->setBlock($block); | |
| 141 | + $blocks->save(); | |
| 142 | + // Set response object. | |
| 143 | + $response['oldValue'] = $oldValue; | |
| 144 | + $response['value'] = $newValue; | |
| 192 | 145 | } |
| 193 | - // Code File Fields. | |
| 194 | - $revisionBlock->activeFileId = $revisionBlock->masterFile; | |
| 195 | - $revisionBlock->masterFile = null; // This is just for querying CodeFile. DONT UPDATE. | |
| 196 | - // Restore Block. | |
| 197 | - $revisionBlock->id = $bId; | |
| 198 | - $mdlBlocks->update($revisionBlock, true); | |
| 199 | - $mdlBlocks->save(); | |
| 200 | - // Return TRUE. | |
| 201 | - $this->response = true; | |
| 146 | + $this->response = $response; | |
| 202 | 147 | } |
| 203 | - | |
| 148 | + | |
| 204 | 149 | } // End class. |