Example #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;
 }
 /**
  * put your comment there...
  * 
  * @return CJTV10CEUpgrade Return $this
  */
 public function finalize()
 {
     // Temporary for a period of time we need to clean up
     // users database as the access points cache wordpress option
     // will not be used any more!
     delete_option(self::ACCESS_POINTS_CACHE_POINTER);
     // Delete all install operations for versions other than 'current' version!
     CJTModel::import('installer');
     $operationsState = get_option(CJTInstallerModel::INSTALLATION_STATE);
     update_option(CJTInstallerModel::INSTALLATION_STATE, array(CJTPlugin::DB_VERSION => $operationsState[CJTPlugin::DB_VERSION]));
     // Chaining!
     return $this;
 }
 /**
  * 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;
 }
 /**
  * Initialize controller object.
  * 
  * @see CJTController for more details
  * @return void
  */
 public function __construct()
 {
     // Only one instance is allowed.
     if (self::$instance) {
         throw new Exception('Trying to instantiate multiple coupling instances!!');
     }
     // Hold the single instance we've!
     self::$instance = $this;
     $siteHook = cssJSToolbox::$config->core->siteHook;
     // Initialize controller.
     parent::__construct(false);
     // Import related libraries
     CJTModel::import('block');
     // Not default action needed.
     $this->defaultAction = null;
     // Initialize controller.
     $initCouplingCallback = $this->onassigncouplingcallback(array(&$this, 'initCoupling'));
     add_action('admin_init', $initCouplingCallback);
     add_action($siteHook->tag, $initCouplingCallback, $siteHook->priority);
     // Add Shortcode callbacks.
     add_shortcode('cjtoolbox', array(&$this, 'shortcode'));
 }