Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * put your comment there...
  * 
  */
 public static function getCustomPins()
 {
     static $pins = array('pages' => array('default' => array(), 'pinValue' => self::PINS_PAGES_CUSTOM_PAGE), 'posts' => array('default' => array(), 'pinValue' => self::PINS_POSTS_CUSTOM_POST), 'categories' => array('default' => array(), 'pinValue' => self::PINS_CATEGORIES_CUSTOM_CATEGORY));
     // Cache custom pins
     if (!self::$customPins) {
         self::$customPins = apply_filters(CJTPluggableHelper::FILTER_BLOCK_MODEL_CUSTOM_PINS, $pins);
     }
     return self::$customPins;
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }
Ejemplo n.º 4
0
 /**
  * put your comment there...
  * 
  * @deprecated All will be moved to other controllers in the future versions.
  */
 public function getRevisionAction()
 {
     // Initialize
     $model = $this->getModel('blocks');
     $tblCodeFile = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver());
     // Inputs.
     $revisionId = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
     // Get request parameters.
     $revision['id'] = $revisionId;
     $revision['fields'] = array('id', 'links', 'expressions', 'masterFile');
     $revision = $model->getBlock($revision['id'], array(), $revision['fields']);
     // Get revisioned code file.
     $revision->code = $tblCodeFile->set('blockId', $revisionId)->set('id', $revision->masterFile)->load()->getData()->code;
     // Discard Pins.
     $customPins = array_keys(CJTBlockModel::getCustomPins());
     foreach ($customPins as $customPinName) {
         $revision->{$customPinName} = false;
     }
     // Return revision.
     $this->response = $revision;
 }
Ejemplo n.º 5
0
 /**
  * put your comment there...
  * 
  */
 public function saveBlocksAction()
 {
     $response = array();
     // Blocks are sent ins single array list.
     $blocksToSave = filter_input(INPUT_POST, 'blocks', FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY);
     $calculatePinPoint = (bool) filter_input(INPUT_POST, 'calculatePinPoint', FILTER_SANITIZE_NUMBER_INT);
     $createRevision = (bool) filter_input(INPUT_POST, 'createRevision', FILTER_SANITIZE_NUMBER_INT);
     // For any reason that cause Client/Javascript to send empty blocks,
     // make sure we're save.
     if (is_array($blocksToSave) && !empty($blocksToSave)) {
         foreach ($blocksToSave as $id => $postedblockPartialData) {
             // Push block id into block data.
             $blockData = (object) $postedblockPartialData;
             $blockData->id = $id;
             // Recalculate pinPoint field value.
             !$calculatePinPoint or CJTBlockModel::arrangePins($blockData) && CJTBlockModel::calculateBlockPinPoint($blockData);
             // Create block revision.
             !$createRevision or $this->model->addRevision($id, $blockData->activeFileId);
             // Set lastModified field to current time.
             $blockData->lastModified = current_time('mysql');
             // Update database.
             $this->model->update($blockData, $calculatePinPoint);
             $this->model->save();
             // Send the changes properties back to client.
             foreach ($postedblockPartialData as $property => $value) {
                 $response[$id][$property]['value'] = $value;
             }
         }
     }
     // Delete other blocks.
     empty($_POST['deletedBlocks']) or $this->model->delete($_POST['deletedBlocks']);
     // Save changes.
     $this->model->save();
     // Set response.
     $this->response = $response;
 }