We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Pass value to user list fields? | Forum

Topic location: Forum home » Support » General Questions
Marcus
Marcus Oct 17 '17
I am trying to pass a value generate above to users list fields! How can I do that please?

$test = "test";
        $listCmp = new TEST_UserList($dtoList, $listCount, $perPage, $test);
       
       
       
        $this->addComponent('listCmp', $listCmp);

class TEST_UserList extends BASE_CMP_Users
{
    public function __construct( array $list, $itemCount, $usersOnPage, $showOnline = true, $test)
    {
        parent::__construct($list, $itemCount, $usersOnPage, $showOnline, $test);
       
    }

    public function getFields( $userIdList, $test)

The Forum post is edited by Marcus Oct 17 '17
ArtMedia
ArtMedia Oct 17 '17
you cant pass $test value to parent class BASE_CMP_Users

corect code


public function __construct( array $list, $itemCount, $usersOnPage, $showOnline = true, $test)
    {
        parent::__construct($list, $itemCount, $usersOnPage, $showOnline);
       
    }

then must override
getFields function, where you use your $test value
Marcus
Marcus Oct 18 '17
Thank you very much! Could you please help me out here I am not very good at this in fact I am a newbie when it comes to class. What do you mean by rewrite getFields???
ArtMedia
ArtMedia Oct 18 '17
copy code from oryginal and then add $test value where you want using it
Marcus
Marcus Oct 18 '17
Sorry buddy you mean like this:

$test = "test";
        $listCmp = new TEST_UserList($dtoList, $listCount, $perPage);
      
      
      
        $this->addComponent('listCmp', $listCmp);

class TEST_UserList extends BASE_CMP_Users
{
    public function __construct( array $list, $itemCount, $usersOnPage, $showOnline = true, $test)
    {
        parent::__construct($list, $itemCount, $usersOnPage, $showOnline);
      
    }

    public function getFields( $userIdList)

// I can use $test here
ArtMedia
ArtMedia Oct 18 '17
no, read about extending class

$test = "test";
        $listCmp = new TEST_UserList($dtoList, $listCount, $perPage, true, $test);
      
      
      
        $this->addComponent('listCmp', $listCmp);

class TEST_UserList extends BASE_CMP_Users
{
    public function __construct( array $list, $itemCount, $usersOnPage, $showOnline = true, $test)
    {
        parent::__construct($list, $itemCount, $usersOnPage, $showOnline);
      
    }

    public function getFields( $userIdLis, $test) {
// now i can use test value, which i can using extending class BASE_CMP_Users and overriding method getFields

echo $test
}

Marcus
Marcus Oct 21 '17
@ArtMedia thanks very much buddy. I get this error:

Declaration of TEST_UserList::getFields() must be compatible with BASE_CMP_Users::getFields($userIdList)
The Forum post is edited by Marcus Oct 21 '17
ArtMedia
ArtMedia Oct 24 '17
then try

class TEST_UserList extends BASE_CMP_Users
{
public $test;
    public function __construct( array $list, $itemCount, $usersOnPage, $showOnline = true, $test)
    {
$this->test = $test;
        parent::__construct($list, $itemCount, $usersOnPage, $showOnline);
      
    }

    public function getFields( $userIdList) {

echo $this->test
}
The Forum post is edited by ArtMedia Oct 24 '17
Marcus
Marcus Oct 28 '17
Buddy thanks very much for your effort. It looks like it's not passing $test value! Here is an array:

TEST_UserList Object ( [test] =>
[showOnline:protected] => test_value
[list:protected] => Array


Just noticed that adding 2 $test to this line works but why??

TEST_UserList($dtoList, $listCount, $perPage, $test, $test);   

I did this and it seems to look fine could you check please??

TEST_UserList($dtoList, $listCount, $perPage,true, $test);
The Forum post is edited by Marcus Oct 28 '17
ArtMedia
ArtMedia Oct 28 '17
pass all code which you use, class TEST_UserList and code when you calling this class
Marcus
Marcus Oct 30 '17
Hi Amigo well I am just trying to learn how to create plugins and I am stuck with this issue! I am simply reverse engendering some plugins like this one!

 $test = "do you see me";
$listCmp = new FOLLOWLIST_UserList($dtoList, $listCount, $perPage, true, $test);

class FOLLOWLIST_UserList extends BASE_CMP_Users
{
    public $test;
    public function __construct( array $list, $itemCount, $usersOnPage, $showOnline = true, $test)
    {
       
        $this->test = $test;
        parent::__construct($list, $itemCount, $usersOnPage, $showOnline);
    }

    public function getFields( $userIdList)
    {
echo $this->test;
        $fields = array();

        $qs = array();

        $qBdate = BOL_QuestionService::getInstance()->findQuestionByName('birthdate');

        if ( $qBdate !== null && $qBdate->onView )
            $qs[] = 'birthdate';

        $qSex = BOL_QuestionService::getInstance()->findQuestionByName('sex');

        if ( $qSex !== null && $qSex->onView )
            $qs[] = 'sex';

        $questionList = BOL_QuestionService::getInstance()->getQuestionData($userIdList, $qs);

        foreach ( $questionList as $uid => $question )
        {

            $fields[$uid] = array();

            $age = '';

            if ( !empty($question['birthdate']) )
            {
                $date = UTIL_DateTime::parseDate($question['birthdate'], UTIL_DateTime::MYSQL_DATETIME_DATE_FORMAT);

                $age = UTIL_DateTime::getAge($date['year'], $date['month'], $date['day']);
            }

            $sexValue = '';
            if ( !empty($question['sex']) )
            {
                $sex = $question['sex'];

                for ( $i = 0; $i < 31; $i++ )
                {
                    $val = pow(2, $i);
                    if ( (int) $sex & $val )
                    {
                        $sexValue .= BOL_QuestionService::getInstance()->getQuestionValueLang('sex', $val) . ', ';
                    }
                }

                if ( !empty($sexValue) )
                {
                    $sexValue = substr($sexValue, 0, -2);
                }
            }

            if ( !empty($sexValue) && !empty($age) )
            {
                $fields[$uid][] = array(
                    'label' => '',
                    'value' => $sexValue . ' ' . $age
                );
            }
        }

        return $fields;
    }
}


I am not sure why I need to add true or whatever to here to make it pass $test value???

$listCmp = new FOLLOWLIST_UserList($dtoList, $listCount, $perPage, true, $test);
The Forum post is edited by Marcus Oct 30 '17
Mike
Mike Oct 30 '17
Hey marcus,

Your parameter $test is the fifth parameter in the constructor.
The fourth is an optional parameter. But that wont work because optional parameter have to be after the others.


so change:array $list, $itemCount, $usersOnPage, $showOnline = true, $test)
in: array $list, $itemCount, $usersOnPage, $test, $showOnline = true)

then you can create the class with:
$listCmp = new FOLLOWLIST_UserList($dtoList, $listCount, $perPage, $test);
Marcus
Marcus Oct 31 '17
@Mike baby you nailed it man thanks so much. @ArtMedia appreciate very much the time you dedicated to help me out thank yo buddy. [SOLVED]
The Forum post is edited by Marcus Oct 31 '17