Your IP : 216.73.216.224


Current Path : /var/www/html/administrator/components/com_community/views/groups/
Upload File :
Current File : /var/www/html/administrator/components/com_community/views/groups/view.html.php

<?php
/**
* @copyright (C) 2013 iJoomla, Inc. - All rights reserved.
* @license GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html)
* @author iJoomla.com <webmaster@ijoomla.com>
* @url https://www.jomsocial.com/license-agreement
* The PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript *are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0
* More info at https://www.jomsocial.com/license-agreement
*/

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\Helpers\StringHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\CMS\Version;

// Disallow direct access to this file
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view' );

/**
 * Configuration view for JomSocial
 */
class CommunityViewGroups extends HtmlView
{
    /**
     * The default method that will display the output of this view which is called by
     * Joomla
     *
     * @param   string template Template file name
     **/
    public function display( $tpl = null )
    {
        // Trigger load default library.
        CAssets::getInstance();

        // if( $this->getLayout() == 'edit' )
        // {
        //     $this->_displayEditLayout( $tpl );
        //     return;
        // }

        $document   = Factory::getDocument();

        // Set the titlebar text
        ToolbarHelper::title( Text::_('COM_COMMUNITY_GROUPS'), 'groups');

        // Add the necessary buttons
        // ToolBarHelper::addNew( 'newGroup' , Text::_('COM_COMMUNITY_PROFILES_NEW_GROUP') );
        ToolBarHelper::custom( 'import' , 'file' , 'csv' , Text::_( 'COM_COMMUNITY_GROUPS_IMPORT_FROM_CSV' ), false );
        ToolBarHelper::deleteList( Text::_('COM_COMMUNITY_GROUP_DELETION_WARNING') , 'deleteGroup' , Text::_('COM_COMMUNITY_DELETE') );
        ToolBarHelper::divider();
        ToolBarHelper::publishList( 'publish' , Text::_('COM_COMMUNITY_PUBLISH') );
        ToolBarHelper::unpublishList( 'unpublish' , Text::_('COM_COMMUNITY_UNPUBLISH') );

        // Get required data's
        $groups     = $this->get( 'Groups' );
        $categories = $this->get( 'Categories' );
        $pagination = $this->get( 'Pagination' );

        // We need to assign the users object to the groups listing to get the users name.
        for( $i = 0; $i < count( $groups ); $i++ )
        {
            $row        =& $groups[$i];
            $row->user  = CFactory::getUser( $row->ownerid );
            // $row->description = strip_tags($row->description,'<strong><a>');
            $row->description = StringHelper::truncate( $row->description, 200 );
            $row->category = $this->_getCatName($categories,$row->categoryid);

        }
        $mainframe  = Factory::getApplication();
        $jinput = $mainframe->input;

        $filter_order       = $mainframe->getUserStateFromRequest( "com_community.groups.filter_order",     'filter_order',     'a.name',   'cmd' );
        $filter_order_Dir   = $mainframe->getUserStateFromRequest( "com_community.groups.filter_order_Dir", 'filter_order_Dir', '',         'word' );
        $search             = $jinput->get('search','','STRING');
        // table ordering
        $lists['order_Dir'] = $filter_order_Dir;
        $lists['order']     = $filter_order;

        $catHTML    = $this->_getCategoriesHTML( $categories );

        $this->set( 'groups'      , $groups );
        $this->set( 'categories'  , $catHTML);
        $this->set( 'lists'       , $lists );
        $this->set( 'search'      , $search );
        $this->set( 'pagination'  , $pagination );

        parent::display( $tpl );
    }

    public function _displayEditLayout( $tpl )
    {
        $jinput = Factory::getApplication()->input;

        // Load frontend language file.
        $lang   = Factory::getLanguage();
        $lang->load( 'com_community' , JPATH_ROOT );

        // Set the titlebar text
        ToolBarHelper::title( Text::_('COM_COMMUNITY_GROUPS'), 'groups');

        // Add the necessary buttons
        ToolBarHelper::back(Text::_('COM_COMMUNITY_BACK') , 'index.php?option=com_community&view=groups');
        ToolBarHelper::divider();
        ToolBarHelper::save();

        $group  = Table::getInstance( 'Group' , 'CTable' );
        $group->load( $jinput->getInt( 'groupid') );

        $post   = $jinput->post->getArray();
        $group->bind( $post );

        $categories = $this->get( 'Categories' );
        $config = CFactory::getConfig();
        $editorType = ($config->get('allowhtml') ) ? $config->get('htmleditor', 'none') : 'none';

        $editor = new CEditor($editorType);

        $this->set( 'categories', $categories );
        $this->set( 'group'   , $group );
        $this->set( 'editor' , $editor);

        $document = Factory::getDocument();
        HTMLHelper::_('behavior.modal', 'a.modal');

        $this->url    = 'index.php?option=com_users&amp;view=users&amp;layout=modal&amp;tmpl=component&amp;field=jform_user_id_to';

        parent::display( $tpl );
    }

    public function _getCategoriesHTML( &$categories )
    {
        $jinput = Factory::getApplication()->input;
        // Check if there are any categories selected
        $category   = $jinput->getInt( 'category' , 0 );

        $select = '<select class="no-margin" name="category" onchange="Joomla.submitform();">';

        $select .= ( $category == 0 ) ? '<option value="0" selected="true">' : '<option value="0">';
        $select .= Text::_('COM_COMMUNITY_ALL_CATEGORY') . '</option>';

        for( $i = 0; $i < count( $categories ); $i++ )
        {
            $selected   = ( $category == $categories[$i]->id ) ? ' selected="true"' : '';
            $select .= '<option value="' . $categories[$i]->id . '"' . $selected . '>' . $categories[$i]->name . '</option>';
        }
        $select .= '</select>';

        return $select;
    }


    /**
     * Method to get the publish status HTML
     *
     * @param   object  Field object
     * @param   string  Type of the field
     * @param   string  The ajax task that it should call
     * @return  string  HTML source
     **/
    public function getPublish( &$row , $type , $ajaxTask )
    {

        $version = new Version();
        $currentV = $version->getHelpVersion();

        $class = 'jgrid';

        $alt    = $row->$type ? Text::_('COM_COMMUNITY_PUBLISHED') : Text::_('COM_COMMUNITY_UNPUBLISH');
        $state = $row->$type == 1 ? 'publish' : 'unpublish';
        $span = '<span class="state '.$state.'"><span class="text">'.$alt.'</span></span></a>';

        if($currentV >= '0.30')
        {
            $class = $row->$type == 1 ? 'disabled jgrid': '';

            $span = '<i class="icon-'.$state.'""></i>';
        }

        $href = '<a class="'.$class.'" href="javascript:void(0);" onclick="azcommunity.togglePublish(\'' . $ajaxTask . '\',\'' . $row->id . '\',\'' . $type . '\');">';

        $href .= $span;

        // Check: ACL
        if (!CFactory::getUser()->authorise('community.groupeditstate', 'com_community')) {
            return '<i class="icon-'.$state.'"></i>';
        }

        return $href;
    }

    public function setToolBar()
    {
    }

    public function getThumbAvatar($obj) {

        // For group avatars that are stored in a remote location, we should return the proper path.
        if ($obj->storage != 'file' && !empty($obj->thumb)) {
            $storage = CStorage::getStorage($obj->storage);
            return $storage->getURI($obj->thumb);
        }


        $thumb = CUrlHelper::avatarURI($obj->thumb, 'group_thumb.png');

        return $thumb;
    }

    private function _getCatName($categories,$id)
    {
        foreach($categories as $cat)
        {
            if($cat->id == $id)
            {
                return $cat->name;
            }

        }

        return 'No category';
    }

    public function _getStatusHTML()
    {
        $jinput = Factory::getApplication()->input;
        // Check if there are any categories selected
        $status = $jinput->getInt( 'status' , 2 );

        $select = '<select class="no-margin" name="status" onchange="Joomla.submitform();">';

        $statusArray = array(2=>Text::_('COM_COMMUNITY_ALL_STATE'),0=>Text::_('JUNPUBLISHED'),1=>Text::_('JPUBLISHED'));

        foreach($statusArray as $key=>$array)
        {
            $selected = ($status == $key) ? 'selected="true"' : '';
            $select .='<option value="'.$key.'"'.$selected.' >'.Text::_($array).'</option>';
        }

        $select .= '</select>';

        return $select;
    }
}