/**
  * put your comment there...
  * 
  */
 protected function pinsMap()
 {
     // Initialize.
     $map = array();
     $mdlBlocks = new CJTBlocksModel();
     $blockId = $this->getBlockId();
     // Query block pinPoint field.
     $assignedPinPoints = $mdlBlocks->getBlock($blockId, array(), array('id', 'pinPoint'), false)->pinPoint;
     // Return map.
     return $this->auxHelper->getPinsArray($assignedPinPoints);
 }
 /**
  * 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;
 }
Example #3
0
 /**
  * put your comment there...
  * 
  * @param mixed $blockData
  */
 public static function arrangePins(&$blockData)
 {
     $pinsGroupNames = array_flip(array_merge(array_keys(self::getCustomPins()), array('pinPoint')));
     $dbDriver = cssJSToolbox::getInstance()->getDBDriver();
     $mdlBlock = new CJTBlocksModel();
     $block = $mdlBlock->getBlock($blockData->id, array(), array('id', 'pinPoint'));
     $submittedPins = array_intersect_key((array) $blockData, $pinsGroupNames);
     $assignedPins = array_intersect_key((array) $block, $pinsGroupNames);
     // Transfer assigned PinPoint from "FLAGGED INTEGER" TO "ARRAY" like
     // the other pins.
     $assignedPins['pinPoint'] = array_keys(CJT_Models_Block_Assignmentpanel_Helpers_Auxiliary::getInstance()->getPinsArray($assignedPins['pinPoint']));
     // Walk through all assigned pins.
     // Unassigned any item with 'value=false'.
     // Whenever an item is found on the submitted
     // pins it should be removed from the submitted list
     foreach ($submittedPins as $groupName => $submittedGroup) {
         // Get assigned pins group if found
         if (!isset($assignedPins[$groupName])) {
             // Initialize new assigned group array.
             $assignedPins[$groupName] = array();
         }
         $assignedGroup =& $assignedPins[$groupName];
         // For every submitted item there is three types.
         // 1. Already assigned :WHEN: (sync == true and value == true)
         // 2. Unassigned :WHEN: (value == false)
         // 3. Newly assigned :WHEN: (sync = false).
         foreach ($submittedGroup as $submittedPinId => $submittedPin) {
             // Unassigned pin
             if (!$submittedPin['value']) {
                 // Find the submittedPinId AssignedPins index.
                 $assignedIndex = array_search($submittedPinId, $assignedGroup);
                 // Unassigned it :REMOVE FROM ARRAY:
                 unset($assignedGroup[$assignedIndex]);
             } else {
                 if (!$submittedPin['sync']) {
                     // Add newly assigned item.
                     $assignedGroup[] = $submittedPinId;
                 }
             }
         }
     }
     // Copy all assigned pins back to the block object.
     foreach ($assignedPins as $groupName => $finalGroupAssigns) {
         $blockData->{$groupName} = $finalGroupAssigns;
     }
     // Important for caller short-circle condition.
     return true;
 }
 /**
  * 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;
 }
 /**
  * put your comment there...
  * 
  * @param mixed $backupId
  * @param boolean Dont delete master blocks with backupId = NULL. This is very important in case $id param is null for any reason!
  */
 public function deleteBackupBlocks($backupId = null, $deleteMaster = false)
 {
     if (!$backupId && !$deleteMaster) {
         throw new Exception('Trying to delete master blocks while deleting normal backup');
     }
     // Blocks Table & Model..
     require_once CJTOOLBOX_TABLES_PATH . '/blocks.php';
     require_once CJTOOLBOX_MODELS_PATH . '/blocks.php';
     // Get blocks Table & Model instances.
     $blocksTable = new CJTBlocksTable($this->dbDriver);
     $blocksModel = new CJTBlocksModel();
     // Get backup blocks Ids.
     $blocks['fields'] = array('id');
     $blocks['filters']['backupId'] = $backupId;
     // Don't delete 'metabox' blocks as its not part of the backup anyway!
     $blocks['filters']['types'] = array('block', 'revision');
     // Query backup blocks.
     $blocks = $blocksTable->get(null, $blocks['fields'], $blocks['filters']);
     // Delete blocks using its Id.
     $ids = array_keys($blocks);
     $blocksModel->delete($ids);
     // Delete code files.
     $this->dbDriver->delete('DELETE FROM #__cjtoolbox_block_files where blockId IN (' . implode(',', $ids) . ');');
     // In order for $this->processQueue to work
     // we need to Merge db driver queues into the current
     // local queue.
     $this->dbDriver->merge($blocksModel->dbDriver());
 }