/**
  * Public interface to targeting getter/setter. Ensures that all inherited classes
  * access the same value.
  */
 public static function use_targeting($targeting = null)
 {
     return MyPortalObject::_use_targeting($targeting);
 }
 /**
  * Magic getter.
  */
 public function &__get($k)
 {
     if ($k == 'num_cols') {
         $num_cols = 0;
         foreach ($this->channels() as $channel) {
             $num_cols = $num_cols > $channel->col_num ? $num_cols : $channel->col_num;
         }
         $this->data['num_cols'] = $num_cols;
     }
     return parent::__get($k);
 }
Ejemplo n.º 3
0
 /**
  * Clone the current layout to the logged in portal user. (Used to copy the
  * default layout into a user layout.)
  */
 public function cloneLayout()
 {
     // This is imperfect, but there's too much static stuff going on elsewhere
     // to do this any other way right now.
     MyPortalObject::use_targeting(false);
     $this->reset();
     // iterate over all portal tabs
     foreach ($this->tabs() as $tab) {
         $tab->channels();
         // touch channels so it loads before we change the usertab id
         $original_tabid = $tab->id;
         $tab->id = null;
         $tab->wp_id = $this->person->wp_id;
         $tab->parent_ut_id = $original_tabid;
         // blank out meta ids
         foreach ($tab->meta()->get() as $meta) {
             $meta->id = null;
         }
         // iterate over all this tab's channels
         foreach ($tab->channels() as $channel) {
             $original_channelid = $channel->id;
             // remove the shortcut to this channel; this will be added
             // back in by MyUserTab::save()
             unset($this->channels[$original_channelid]);
             $channel->id = null;
             $channel->parent_uc_id = $original_channelid;
             $channel->parent_ut_id = $original_tabid;
             // we won't set $channel->usertab_id here, because we don't know the new
             // usertab_id yet (it hasn't been saved). MyUserTab::save() will pass along
             // the new id to the channel when it has saved.
             $channel_class = get_class($channel);
             // blank out meta ids. do a class check so all class defined in userchannels_meta
             // is cloned, but we don't unnecessarily clone channel_meta
             foreach ($channel->meta()->get() as $meta) {
                 if ($meta->class != $channel_class) {
                     continue;
                 }
                 // mark as changed so a save is forced
                 $meta->id = null;
                 $meta->changed = true;
             }
         }
     }
     $this->save();
     $this->cloned = true;
 }
 /**
  * targets tester
  * @todo delete this when testing is done
  */
 public static function targets($id, $class = __CLASS__)
 {
     $this->_force_admin();
     MyPortalObject::targets($id, $class);
 }
 /**
  * Function to save this meta collection to the database. Will only save meta marked as "changed."
  */
 public function save()
 {
     // cache prepared statement-style queries per table
     $statements = array();
     $base_query = "\n\t\t\tINSERT INTO %s (id, %s, meta_key, meta_value, activity_date)\n\t\t\tVALUES (?, ?, ?, ?, NOW())\n\t\t\tON DUPLICATE KEY UPDATE meta_value = ?, activity_date = NOW()\n\t\t";
     // all metadata in this container gets saved to the same table
     $class = get_class($this->parent);
     if (!isset($statements[$class])) {
         $statements[$class] = sprintf($base_query, MyPortalObject::dbstr($class, 'meta'), MyPortalObject::dbstr($class, 'fk'));
     }
     foreach ($this->data as $meta) {
         if (!$meta instanceof MyMeta) {
             continue;
         }
         if (!$meta->changed) {
             continue;
         }
         PSU::db('portal')->Execute($statements[$class], array($meta->id, $this->parent->id, $meta->key, $meta->value, $meta->value));
     }
 }
 /**
  * @todo delete
  */
 public function fetch($id, $obj_or_class)
 {
     MyPortalObject::fetch($id, $obj_or_class);
 }
 /**
  * pass our child targets function to myportalobject
  */
 public static function targetNames($id, $class = __CLASS__)
 {
     return parent::targetNames($id, $class);
 }
 /**
  * Custom constructor to load base meta in addition to userchannel meta.
  */
 public function __construct($params = array())
 {
     if (!$params['channel_id']) {
         throw new Exception("You cannot create a MyUserChannel without an underlying channel id");
     }
     // load meta so we get a proper overlay of:
     //
     //  1. Channel, replaced by...
     //  2. UserChannel, replaced by...
     //  3. $params['meta']
     //
     // TODO: this is slightly inefficient, since we will also load the meta
     // below.
     $this->meta()->load($params['channel_id'], 'MyChannel');
     parent::__construct($params);
     $this->base = MyChannel::fetch($this->channel_id);
     $this->base->parent = $this;
     $this->data['name'] =& $this->base->name;
     $this->data['slug'] =& $this->base->slug;
     $this->data['content_url'] =& $this->base->content_url;
     $this->data['content_text'] =& $this->base->content_text;
 }