/**
     * Fetch user channels for a specific tab. Also loads the "real" channel into
     * $this->base, and clones the channel's meta into $this.
     *
     * @param $usertab_id \b int
     * @todo move some stuff into a new function so loadUserChannel() can take advantage of channel load logic
     */
    public static function getUserChannels($person, $usertab_id)
    {
        $targeting = self::targetSQL($person, 'MyChannel');
        //
        // userchannels -> channels -> targets
        //
        $sql = sprintf('
			SELECT %1$s.*
			FROM %1$s 
           LEFT JOIN %2$s ON %2$s.id = %1$s.%3$s %5$s
				WHERE %4$s = ? %6$s
			  AND delete_id = 0
			ORDER BY col_num, sort_order
			', self::dbstr(__CLASS__, 'table'), self::dbstr('MyChannel', 'table'), self::dbstr('MyChannel', 'fk'), self::dbstr('MyUserTab', 'fk'), $targeting['tables'], $targeting['where']);
        $rset = PSU::db('portal')->Execute($sql, array($usertab_id));
        $channels = array();
        foreach ($rset as $row) {
            // do not instantiate the channel if it's already in our channel list
            if (isset($channels[$row['id']])) {
                continue;
            }
            $channel = new self($row);
            if (self::use_targeting() == false || ChannelAuthZ::_authz($channel->slug)) {
                $channels[$channel->id] = $channel;
                unset($channel);
            }
        }
        return $channels;
    }
 /**
  * Portal Content browser
  */
 public function channels($view = null, $page = 1)
 {
     if ($view == 'newest' || $view == 'popular') {
         $channels = MyChannel::$view($this->portal->person);
     } else {
         $channels = MyChannel::fetchAll($this->portal->person);
     }
     $data = array();
     foreach ($channels as $channel) {
         if (ChannelAuthZ::_authz($channel->slug)) {
             $data[] = $channel;
         }
     }
     //end foreach
     $per_page = 20;
     $num_records = count($data);
     $data = array_slice($data, ($page - 1) * $per_page, $per_page);
     $overrides = array('last_page' => ceil($num_records / $per_page), 'total_records' => $num_records, 'num_rows' => count($data), 'rows_per_page' => $per_page, 'current_page' => $page);
     $pagination = PSU::paginationResults(PSU::paginationInfo($_GET, $results, $overrides), $data);
     $this->tpl->assign('channels', $pagination['items']);
     $this->tpl->assign('pages', $pagination);
     $this->tpl->assign('user_channels', MyChannel::fetchAll($this->person));
     $this->tpl->display('channels.tpl');
 }
 /**
  * Returns whether or not the user is authorized to 
  * view the channel
  */
 public static function _authz($slug)
 {
     if (!self::$person) {
         self::$person = new PSUPerson($GLOBALS['identifier']);
         self::$person->_load_myrelationship_grants();
         self::$grants = self::$person->myrelationship_grants;
     }
     //end if
     $slug = str_replace('-', '_', $slug);
     if (method_exists('ChannelAuthZ', $slug)) {
         return call_user_func('ChannelAuthZ::' . $slug);
     }
     return true;
     //default to have privs for a given channel
 }
 /**
  *
  */
 public function index()
 {
     $this->_force_admin();
     $tabs = MyTab::fetchAll();
     $channels = MyChannel::fetchAll();
     foreach ($channels as $channel) {
         $targets = MyChannel::targetNames($channel->id);
         if (ChannelAuthZ::_has_authz($channel->slug)) {
             $targets[] = '<strong>custom</strong>';
         }
         if (count($targets) > 0) {
             $channel->target_names = implode(', ', $targets);
         }
     }
     $this->tpl->assign_by_ref('tabs', $tabs);
     $this->tpl->assign_by_ref('channels', $channels);
     $this->display('admin-index.tpl');
 }