/**
  * Deletes a user channel or tab
  */
 public function delete($id, $class)
 {
     $sql = "INSERT INTO deletes (wp_id, object_type) VALUES (?, ?)";
     PSU::db('portal')->Execute($sql, array($GLOBALS['identifier'], self::dbstr($class, 'type')));
     if ($delete_id = PSU::db('portal')->Insert_ID()) {
         $channel = MyUserChannel::fetch($id);
         $channel->delete_id = $delete_id;
         $channel->save();
     }
     //end if
     return $delete_id;
 }
 /**
  * All channels, or a single channel specified by its ID.
  * @param $id int
  * @return Array|MyChannel
  */
 public function channels($id = null)
 {
     if ($id == null) {
         // we need all channels
         $this->load_everything();
         return $this->channels;
     }
     // if we don't know this channel. load its tab
     if (!isset($this->channels[$id])) {
         $usertab_id = MyUserChannel::get_parent_usertab($id);
         if (!$this->tabs($usertab_id)->channels($id)) {
             return false;
         }
     }
     return $this->channels[$id];
 }
 public function test()
 {
     $this->_force_admin();
     PSU::db('portal')->debug = true;
     var_dump(MyUserTab::get_child_id($this->portal->person, 1));
     var_dump(MyUserChannel::get_child_id($this->portal->person, 1));
 }
 /**
  * Fetch channels for this tab.
  * @return void
  */
 public function channels($id = null)
 {
     if ($this->channels === null) {
         $this->channels = MyUserChannel::getUserChannels($this->parent()->person, $this->id);
         foreach ($this->channels as $channel) {
             $channel->tab = $this;
             $this->parent()->add_channel_shortcut($channel);
         }
     }
     if ($id !== null) {
         return $this->channels[$id];
     } else {
         return $this->channels;
     }
 }
 /**
  * handles the moving of a channel
  * @param $channel \b int the channel id
  * @param $location \b string destination: tab, before, after, col
  * @param $target \b id of the target element
  */
 public function move($channel, $location, $target = null)
 {
     ignore_user_abort();
     MyPortal::force_clone($this->portal);
     $channel_id = str_replace('channel-', '', $channel);
     $target = str_replace('channel-', '', $target);
     //
     // if portal was just cloned, the incoming tab and channel ids must be updated.
     // they referred to the default layout in the ui, but we will actually update
     // the custom user layout.
     //
     // @todo account for admins updating the default layout (GET param?)
     //
     if ($this->portal->cloned) {
         $channel_id = MyUserChannel::get_child_id($this->portal->person, $channel_id);
         if ($location == 'tab') {
             $target = MyUserTab::get_child_id($this->portal->person, $target);
         } elseif ($location == 'before' || $location == 'after') {
             $target = MyUserChannel::get_child_id($this->portal->person, $target);
         }
     }
     //
     // perform the channel moving
     //
     $channel = MyUserChannel::fetch($channel_id);
     if ($location == 'before') {
         $target = MyUserChannel::fetch($target);
         $direction = $target->sort_order <= $channel->sort_order ? 'up' : 'down';
         $channel->setLocation($target->col_num, $target->sort_order, null, $direction);
     } elseif ($location == 'after') {
         $target = MyUserChannel::fetch($target);
         $channel->setLocation($target->col_num, $target->sort_order + 1, null, 'down');
     } elseif ($location == 'col') {
         $channel->setLocation($target, 1);
     } elseif ($location == 'tab') {
         $channel->setLocation(1, 1, $target);
     }
     //end if
     echo $is_default_layout ? 'default' : 'user';
 }