/** * put your comment there... * */ public function id() { $id = false; // If its a normal block just get the id from the KEY! if ($this->type == self::BLOCK_TYPE_BACKUP) { $dbDriver = cssJSToolbox::getInstance()->getDBDriver(); $blocksTable = new CJTBlocksTable($dbDriver); $id = $blocksTable->getNextId(); } else { // If backup block generate new ID! $id = parent::id(); } return $id; }
/** * put your comment there... * */ public function reservedMetaboxBlockId() { // Reserved if only if not already taken! if (!($reservedId = $this->getMetaboxId())) { // Get Blocks table instance. $BlocksTable = new CJTBlocksTable($this->dbDriver); // Get next Id. $reservedId = $BlocksTable->getNextId(); // Set metabox reserved id. update_post_meta($this->getPost()->ID, CJTBlocksTable::BLOCK_META_BOX_ID_META_NAME, $reservedId); } return $reservedId; }
/** * put your comment there... * * @param mixed $block */ public function update($block, $updatePins) { $block = (array) $block; $blocks = new CJTBlocksTable($this->dbDriver); $pins = new CJTBlockPinsTable($this->dbDriver); // Update block pins if requested. if ($updatePins) { // Isolate block pins freom native block data. $pinsData = array_intersect_key($block, array_flip(array_keys(CJTBlockModel::getCustomPins()))); do_action(CJTPluggableHelper::FILTER_BLOCK_MODEL_PRE_UPDATE_BLOCK_PINS, $block, $pinsData); $pins->update($block['id'], $pinsData); } // Update code file if (isset($block['activeFileId'])) { $codeFile = new CJTBlockFilesTable($this->dbDriver); $codeFile->set('blockId', $block['id'])->set('id', $block['activeFileId'])->set('code', $block['code'])->save(); } // Isolate block fields. $blockData = array_intersect_key($block, $blocks->getFields()); do_action(CJTPluggableHelper::FILTER_BLOCK_MODEL_PRE_UPDATE_BLOCK, $updatePins, $blockData); $blocks->update($blockData); }
/** * 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()); }
/** * put your comment there... * * @param mixed $block */ public function update($block, $updatePins) { // To be used by array_intersect_key. $block = (array) $block; // Create Tables objects. $blocks = new CJTBlocksTable($this->dbDriver); $pins = new CJTBlockPinsTable($this->dbDriver); // Update block pins if requested. if ($updatePins) { // Isolate block pins freom native block data. $pinsData = array_intersect_key($block, array_flip(array('pages', 'posts', 'categories'))); $pins->update($block['id'], $pinsData); } // Update code file if (isset($block['activeFileId'])) { $codeFile = new CJTBlockFilesTable($this->dbDriver); $codeFile->set('blockId', $block['id'])->set('id', $block['activeFileId'])->set('code', $block['code'])->save(); } // Isolate block fields. $blockData = array_intersect_key($block, $blocks->getFields()); $blocks->update($blockData); }