/** * put your comment there... * * @param mixed $blockId */ public function create(&$pin = null) { // Import dependecnes. cssJSToolbox::import('tables:block-pins.php'); // Change metabox status to be created. $this->setState(self::STATE_CREATED); // Add post pin to pins table. $blockPinsTable = new CJTBlockPinsTable($this->dbDriver); // Pin data. $pin = (object) array(); // Import CJTBlockModel class. CJTModel::import('block'); /** @todo Only temporary in version 6.0. Later versions should group all post types by post type name! */ switch ($this->getPost()->post_type) { case 'page': $pin->pin = 'pages'; $pin->flag = CJTBlockModel::PINS_PAGES_CUSTOM_PAGE; break; default: $pin->pin = 'posts'; $pin->flag = CJTBlockModel::PINS_POSTS_CUSTOM_POST; break; } $pin->value = $this->getPost()->ID; // Add pin record. $blockPinsTable->insertRaw($this->getMetaboxId(), array($pin)); // Chains! return $this; }
/** * put your comment there... * */ protected function pinsMap() { // Initialize. $blockId = $this->getBlockId(); $params = $this->getTypeParams(); $pinsMap = array(); // Prepare block pinned items. $dbDriver = cssJSToolbox::getInstance()->getDBDriver(); $pinsTable = new CJTBlockPinsTable($dbDriver); $pins = $pinsTable->get(null, array('blockId' => $blockId, 'pin' => $params['group'])); // Create ITEM-ID => VALUE array map for the retrieved pins. foreach ($pins as $pin) { $pinsMap[$pin->value] = true; } // Returns. return $pinsMap; }
/** * put your comment there... * * @param mixed $srcBackupId * @param mixed $desBackupId */ public function copyBackupBlocks($srcBackupId, $desBackupId) { // Initialie. $codeFilesQuery = 'INSERT INTO #__cjtoolbox_block_files (blockId, id, name, description, `type`, code, `order`) SELECT %d, id, name, description, `type`, code, `order` FROM #__cjtoolbox_block_files WHERE blockId = %d;'; // Blocks Table & Model.. require_once CJTOOLBOX_TABLES_PATH . '/blocks.php'; require_once CJTOOLBOX_TABLES_PATH . '/block-pins.php'; require_once CJTOOLBOX_MODELS_PATH . '/blocks.php'; // Get blocks Table & Model instances. $blocksTable = new CJTBlocksTable($this->dbDriver); $blockPinsTable = new CJTBlockPinsTable($this->dbDriver); $blocksModel = new CJTBlocksModel(); // Get source backup blocks. $blocks['fields'] = array('*'); $blocks['filters']['backupId'] = $srcBackupId; $blocks['filters']['types'] = array('block', 'revision'); // Its important to get revision blocks at the end // to create blocks id map. $blocks['orderby'] = array('type'); $blocks = $blocksModel->getBlocks(null, $blocks['filters'], $blocks['fields'], OBJECT_K, $blocks['orderby']); // Prepare vars before copying. $desBlockId = $blocksTable->getNextId(); // For every block give new Id and insert block and pins data. $blocksMap = array(); foreach ($blocks as $id => $block) { // Change block Id & backupId. $block->id = $desBlockId++; $block->backupId = $desBackupId; // Change revision "parentId" to the new block id. if ($block->type == 'block') { // Map the old id to the new one. $blocksMap[$id] = $block->id; } else { if ($block->type = 'revision') { // Exclude revision blocks for other types than 'block' type (e.g metabox revisions). if (!isset($blocksMap[$block->parent])) { continue; } else { $block->parent = $blocksMap[$block->parent]; } } } // Cast stdClass to array. $block = (array) $block; // Insert block. $blockData = array_intersect_key($block, $blocksTable->getFields()); $blocksTable->insert($blockData); // Insert block Pins. $pinsData = array_intersect_key($block, array_flip(array('pages', 'posts', 'categories'))); $blockPinsTable->insert($block['id'], $pinsData); // Copy code files. $this->dbDriver->insert(sprintf($codeFilesQuery, $block['id'], $id))->processQueue(); } }
/** * 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 $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); }