1

I am filtering users in my CP by adding a new user source.
I know how to get users for specific criterias.

But in this case I want to make a OR condition on those two users fields :
$user_criteria->emailLogo = true;
$user_criteria->webLogo = true;

public function modifyUserSources(&$sources, $context)
{
    if ($context == 'index')
    {

        // LISTING USERS
        $sources[] = array('heading' => 'Stats Users');

        $user_criteria = craft()->elements->getCriteria(ElementType::User);
        $user_criteria->group = 'myMembers';

        // THIS WILL MAKE A -AND- CONDITION (I WANT A -OR-)
        $user_criteria->emailLogo = true;
        $user_criteria->webLogo = true;

        $sources['users:memberBranding'] = array(
            'label'    => Craft::t('Logo'),
            'criteria' => $user_criteria,
        );
    }
}
1

sorry I didn't try to do this and after trying, couldn't get it to work myself... So...

If you have flexibility and can replace your ligthswitches with a group of checkbox, this becomes a lot easier and potentially more flexible as you could add new 'types of logo' without reviewing your plugin whereas at the moment, you would need to manually add new 'types'.

So, if you can, change your ligthswitches for a group of checkbox called 'logos' for example and add 2 checkbox 'Web' & 'Email', then:

public function modifyUserSources(&$sources, $context)
{
    if ($context == 'index')
    {
    $sources[] = array('heading' => 'Stats Users');

    $user_criteria = craft()->elements->getCriteria(ElementType::User);
    $user_criteria->group = 'editors';
    $user_criteria->logos = ':notempty:';

        $sources['users:memberBranding'] = array(
          'label'    => Craft::t('Logo'),
          'criteria' => $user_criteria,
      );
    }
}

As long as a user 'has' a logo AND is an editor, they will show in your source.

If you can't change the lightswitch setup, I'm afraid I don't know how to do it and I would love to find out if you manage to get it working!

| improve this answer | |
0

If you take a look here, this should get you on the right track.

How can I set up sources based on my custom field data?

| improve this answer | |
  • Hi Olivier. I am sorry I cannot understand how to use it because I am not having custom field on my part. Can you be a litlle bit more precise? Should I make $user_criteria directly with a SQL query thats it ? – migswd Nov 18 '15 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.