/**
  * put your comment there...
  * 
  */
 public function upgrade()
 {
     // Read block!
     $srcBlock =& $this[$this->key()];
     // Build block in new structure!
     $block = array_diff_key($srcBlock, array_flip(array('page', 'category')));
     $pins = array();
     // Set interna data!
     $block['id'] = $this->id();
     $block['created'] = $block['lastModified'] = current_time('mysql');
     $block['owner'] = get_current_user_id();
     // Translate old assignment panel to use the new structure!
     if (isset($srcBlock['category'])) {
         $pins['categories'] = $srcBlock['category'];
     }
     // Translate named map from last versions to the value used in the new versions!
     CJTModel::import('block');
     // Import CJTBlockModel
     $namedPins = array('allpages' => CJTBlockModel::PINS_PAGES_ALL_PAGES, 'allposts' => CJTBlockModel::PINS_POSTS_ALL_POSTS, 'frontpage' => CJTBlockModel::PINS_PAGES_FRONT_PAGE);
     foreach (isset($srcBlock['page']) ? $srcBlock['page'] : array() as $assignedObject) {
         // Translate named pin to flag!
         if (isset($namedPins[$assignedObject])) {
             // Set pinPoint flags!
             $block['pinPoint'][] = dechex($namedPins[$assignedObject]);
         } else {
             // Previous versions support only pages but not posts!
             $pins['pages'][] = $assignedObject;
         }
     }
     // Calculate Pin Points!
     $block['pinPoint'] = CJTBlockModel::calculatePinPoint($block, $pins);
     // Create new Block!
     $this->model->add($block);
     // Save Block pins/assigned objects as it doesnt saved when created!
     $pins['id'] = $block['id'];
     $this->model->update($pins, true);
     // Chaining
     return $this;
 }
 /**
  * put your comment there...
  * 
  */
 protected function restoreRevisionAction()
 {
     // Initialize.
     $mdlBlocks = new CJTBlocksModel();
     $tblCodeFile = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver());
     // Get revision ID.
     $rId = (int) $_GET['rid'];
     $bId = (int) $_GET['bid'];
     // Get Revision Block + Revision Code.
     $revisionBlock = $mdlBlocks->getBlock($rId, array(), array('id', 'pinPoint', 'links', 'expressions', 'masterFile'));
     $revisionBlock->code = $tblCodeFile->set('blockId', $rId)->set('id', $revisionBlock->masterFile)->load()->getData()->code;
     // If code === null set it to empoty string '' as null woulod
     // prevent the field from being in the query, cause SQL error.
     if ($revisionBlock->code === null) {
         $revisionBlock->code = '';
     }
     // Code File Fields.
     $revisionBlock->activeFileId = $revisionBlock->masterFile;
     $revisionBlock->masterFile = null;
     // This is just for querying CodeFile. DONT UPDATE.
     // Restore Block.
     $revisionBlock->id = $bId;
     $mdlBlocks->update($revisionBlock, true);
     $mdlBlocks->save();
     // Return TRUE.
     $this->response = true;
 }