Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * put your comment there...
  * 
  * @param mixed $blockId
  * @param mixed $activeFileId
  */
 public function addRevision($blockId, $activeFileId)
 {
     // Create Tables objects.
     $blocks = new CJTBlocksTable($this->dbDriver);
     $pins = new CJTBlockPinsTable($this->dbDriver);
     $codeFile = new CJTBlockFilesTable($this->dbDriver);
     // We allow only up to self::MAX_REVISIONS_PER_BLOCK revisions per
     // block code files So that a single block may has up to
     // self::MAX_REVISIONS_PER_BLOCK * count(codeFiles)
     $revisions['fields'] = array('id');
     $revisions['filters'] = array('type' => 'revision', 'parent' => $blockId, 'masterFile' => $activeFileId);
     $revisions = $blocks->get(null, $revisions['fields'], $revisions['filters']);
     // If revisions reached self::MAX_REVISIONS_PER_BLOCK delete first one.
     if (count($revisions) == self::MAX_REVISIONS_PER_BLOCK) {
         $this->delete(array_shift($revisions)->id);
     }
     // Get block data.
     $block['fields'] = array('id', 'lastModified', 'pinPoint', 'links', 'expressions');
     // get() developed to return multiple blocks, fetch the first.
     $result = $blocks->get($blockId, $block['fields']);
     $block = reset($result);
     // Set other fields.
     $block->location = $block->state = '';
     $block->parent = $blockId;
     $block->type = 'revision';
     $block->created = current_time('mysql');
     $block->owner = get_current_user_id();
     $block->masterFile = $activeFileId;
     // Only the revisioned code file would be exists and must be
     // used as the masterFile!
     $block->id = $blocks->getNextId();
     // Get new id for revision rrecord.
     // Add block data.
     $blocks->insert($block);
     // Get block pins and insert pins for the revision block.
     $blockPins = $pins->get($blockId);
     if (!empty($blockPins)) {
         $pins->insertRaw($block->id, $blockPins);
     }
     // Revision current ActiveFileId code record.
     // Simply, get a copy of it from the target block
     // and assign the copy to the new created block revision.
     $codeFile->set('id', $activeFileId)->set('blockId', $blockId)->load()->set('blockId', $block->id)->save(true, true);
 }