Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Select module if user has entry?

Select module if user has entry?

Hi Everyone,

I am using all the current software. Everything is running smoothly on testing server. The tips here have been great.

However, I have a quick question. I did a search but got no results.

Is there a way or command I can restrict a module if the user has an ENRTY in the SOBI2 Index ala "if ($sobi2task&userid has entry ) return "xyz";"? I would like to restrict the ads to one per user.

Sorry if this is a dumb one.

Best wishes,

JD

Producerman1
Beginner Modder
ranks
useravatar
Offline
6 Posts
Administrator has disabled public posting

Re: Select module if user has entry?

Hi JD,

yes this should be easy to do.

if (JRequest::getVar('sobi2Task') != "" and MM_LOGGED_IN) return "xyz";

That will check for any time that "sobi2Task" is mentioned in the URL, and a user is logged in.

I don't know if that's exactly what you're looking for... perhaps you're looking for a particular sobi2Task, in which case you might want something like:

if (JRequest::getVar('sobi2Task') == "sobi2Details" and MM_LOGGED_IN) return "xyz";

There are many possible variations on that depending on exactly what you want to happen. Write back if you need any help to tweak it.

Hope this helps,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Select module if user has entry?

Hey Stephen,

Thanks for the quick reply. Although I haven't tried your command line yet... I thought I would elaborate on what my goal is. It is a worldwide database for musicians and rehearsal halls/rooms.

Joomla 1.5, AEC, SOBI2 (with met plugin, multiple entry templates), and METAMOD. As the SOBI MET allows entries based on usertype, it doesn't allow expiration via the non com version. So I am trying to use either AEC (which determines membership length, issues group status (artist free or business paid ) and publishes/unpublishes listing via micro integration and collects payment), or Metamod to hide entries into the SOBI index after they have filled out their initial SOBI entry/profile. They will maintain control over their one listing, just be limited to that one.

So if METAMOD can check if they already have a listing in SOBI2 then I can tell it NOT to show the menu module containing the ADD NEW ENTRY links etc. A link to their entry is already present via an additional SOBI2 module.

I am trying to avoid having to install CB and all that jazz.

I will try your command line today. I will let you know.

Thanks again and best wishes,

JD

Producerman1
Beginner Modder
ranks
useravatar
Offline
6 Posts
Administrator has disabled public posting

Re: Select module if user has entry?

ok, now you've explained a bit more, I can see that my suggestion isn't going to be enough -- I am only testing whether the user is logged in, not whether the entry being *viewed* has expired... or something like that.

Actually I am still confused.

Do you want MetaMod to hide/show a module based on the status of the logged-in user? i.e. do a lookup into SOBI2 somehow based on their logged-in username to see if they already have a listing. If they don't already have one, then display a certain module?

This is going to require quite a lot of knowledge about how all the database tables interact. If you can provide all that then I can knock together a rule for it... otherwise if you want me to log into your site and get it all sorted out for you then you can hire me for reasonable rates smile

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Select module if user has entry?

Hey Stephen,

Well I will give it a better try at explaining.

At the moment 2 ueser types, Artists (AUthor) and Business (Editor), I can already use METAMOD and hide menu items etc based on their usertype. However, I need to be able for META MOD to determine "IF" the user (either one) has already "posted a listing in the SOBI2 Index", to be able to hide or show items based on that premise.

If they have not already posted a listing in the SOBI2, then a particular menu will show with a "LINK TO ADD ENTRY" until they actually POST A LISTING. After that regular menu items.

So...

1. AEC handles registration and billing for the membership (I still have to figure out the return address to lead them to the SOBI2 entry page after the AEC reg)

2. after that the METAMOD already determines if they are Author or Editor, if I can just have it check to see if the CLIENT ID ASSOCIATED WITH THE USER has an EXISTING POSTING in the SOBI2 Index. From there on out they would only be able to access their personal add which is accomplished via an existing SOBI module with standard menus showing.

Unfortunately the site isn't up yet, only on local server. I hope I made it as clear as possible. I don't need METAMOD to deal with expiration or anything.

Thanks again, best wishes,

JD

p.s.

I am gonna look at the code for SOBI a bit closer to see if I can find the "check for items" commands. Maybe I can get lucky and find a way to incorporate it.

UPDATE:

Below is the SOBI2 code that I believe holds the key to my success. I will hack away to try and filter out what is not needed. Is it possible to call any of these commands and show/hide a menu item with METAMOD? As the code contains "{} and ()" I know that the "()" is what will contain the METAMOD command ie: if(sobiitemcheck) else return "xyz";. What would I do about the code in "{will METAMOD recognise this}"?

  * Show User Listings
     *
     */
    function showMyListing()
    {
        $config =& sobi2Config::getInstance();
        $database = $config->getDb();
        $uid = sobi2Config::request( $_REQUEST, "uid", 0 ); //uebergebene uid -> listings eines bestimmten users
        $my =& $config->getUser();
        $now = $config->getTimeAndDate();

        if( !$uid ) {
            $uid = $my->id; //keine uid uebergeben -> listings des aktuellen users sofern einer da
            $url = "index.php?option=com_sobi2&sobi2Task=usersListing&Itemid={$config->sobi2Itemid}";
        }
        else {
            $url = "index.php?option=com_sobi2&sobi2Task=usersListing&uid={$uid}&Itemid={$config->sobi2Itemid}";
        }
        if ($uid && ($uid == $my->id)) { //listings des aktuellen users
            $expired = $config->key( "users_own_listing", "can_see_expired" );
            $published = !$config->key( "users_own_listing", "can_see_unpublished", 0);
            $checkunpublished = ($expired || !$published) ? true : false;
        }       
        else {
            $published = true;
            $expired = $checkunpublished = false;
        }
        if( !$uid ) { //Gast will seine eigenen Eintraege sehen (das gibts nicht)
            sobi2Config::redirect($config->key( "redirects", "user_listing_no_entries", "index.php"), _SOBI2_USER_OWN_NO_LISTING);
        }
        $user =&sobi2bridge::jUser( $database );
        $user->load( $uid );

        $title = str_replace( array( "%username%" ,"%name%" ), array( $user->username, $user->name ), _SOBI2_USER_OWN_LISTING );

        $published = $published ? " AND published = 1 " : null;
           $expired = $expired ? $published : " AND ((publish_down > '{$now}' OR publish_down = '{$config->nullDate}') {$published})";
          
           $query = "SELECT itemid FROM #__sobi2_item WHERE owner = {$user->id}{$expired}";
        $database->setQuery($query);
        $sids = $database->loadResultArray();
        if ($database->getErrorNum()) {
            trigger_error("showMyListing: DB reports: ".$database->stderr(), E_USER_WARNING);
        }

The above code is freely available via the FREE SOBI2 Component. I am not trying to give away the farm. Just build a better barn.

Producerman1
Beginner Modder
ranks
useravatar
Offline
6 Posts
Administrator has disabled public posting

Re: Select module if user has entry?

Hey Stephen,

I have tried the following with no results. The "else return "1" " is the only menu showing. I can't seem to get the formula correct to call "24". I snipped the code from the SOBI2 listing.php from above as it looked to be the relevant part.


if (JRequest::getVar('sobi2Task')=sad"index.php?option=com_sobi2&sobi2Task=usersListing&uid={$uid}&Itemid={$config->sobi2Itemid}") return "24";
else return "1";

and

if (JRequest::getVar('sobi2Task')=sad"usersListing&uid={$uid}&Itemid={$config->sobi2Itemid}")) return "24";
else return "1";

and with enclosing the whole thing with "()". White screen of death.

if ((JRequest::getVar('sobi2Task')=sad"index.php?option=com_sobi2&sobi2Task=usersListing&uid={$uid}&Itemid={$config->sobi2Itemid}")) return "24";
else return "1";

and  with enclosing the whole thing with "{}". White screen of death.

if {(JRequest::getVar('sobi2Task')=sad"index.php?option=com_sobi2&sobi2Task=usersListing&uid={$uid}&Itemid={$config->sobi2Itemid}")} return "24";
else return "1";

and a few more variations. I have run out of ideas.lol

Thanks again Stephen.

Best wishes,


JD

Producerman1
Beginner Modder
ranks
useravatar
Offline
6 Posts
Administrator has disabled public posting

Re: Select module if user has entry?

OK with the following:

if ( MM_NOT_LOGGED_IN ) return "1";
if (JRequest::getVar('sobi2Config')!="index.php?option=com_sobi2&sobi2Task=usersListing&Itemid={$config->sobi2Itemid}" and MM_LOGGED_IN)return "25";
if (JRequest::getVar('sobi2Config')!="index.php?option=com_sobi2&sobi2Task=usersListing&uid={$uid}&Itemid={$config->sobi2Itemid}" and MM_LOGGED_IN) return "24";

or

if ( MM_NOT_LOGGED_IN ) return "1";
if (JRequest::getVar('sobi2Config')!="index.php?option=com_sobi2&sobi2Task=usersListing&Itemid={$config->sobi2Itemid}" and MM_LOGGED_IN)return "25";
else return "24";

It seems to be "working correctly", however the issue is not resolved. I have three "main menus" 1 (#1). shows all links, 2 (#25). to be shown if registered but no entry in SOBI2 and 3. (24) To be shown if the user is registered with an entry .

I think the secret lies within a $query or a "get functionCheckSOBIstatus" similar to above command string. Will METAMOD do a task such as this? I know the answer lies somewhere in the last few lines of the SOBI excerpt above and what I am using so far. I just need it streamlined without all the show array, title crap etc involved. Would you say I am on the right track?

Perhaps just a straight $query to the $db simply asking if the user has a "post/listing" crossing $userid and $itemid (sobi2itemid???).

So close and yet so far! OMG!

Well before it turns into a rant... I will sleep on it.

Thanks again.

Best wishes,

JD

Producerman1
Beginner Modder
ranks
useravatar
Offline
6 Posts
Administrator has disabled public posting

Re: Select module if user has entry?

Well I put the sight up live, but I am still having the issue.

I have got to be over thinking this thing. It seems so simple when researching the other posts. ANy insight would be great!

Thanks again,

JD

Producerman1
Beginner Modder
ranks
useravatar
Offline
6 Posts
Administrator has disabled public posting

Re: Select module if user has entry?

Hi JD,

I've got some time today to help you on this - I'll be in touch off-line.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Select module if user has entry?

Hey we finally got it:

Code:

if ( MM_NOT_LOGGED_IN ) return 1;


class_exists( 'sobi2Config' ) || require_once( JPATH_SITE .DS.'components'.DS.'com_sobi2'.DS.'config.class.php' );
$config =& sobi2Config::getInstance();
$now = $config->getTimeAndDate();

$query = "SELECT * FROM #__sobi2_item WHERE owner = {$user->id}  AND published = 1 AND (publish_down > '{$now}' OR publish_down = '{$config->nullDate}')";

$db->setQuery($query);
$sids = $db->loadResult();

if ($sids == null) return 24; /* if the person did not have an entry in SOBI2 */
else return 25; /* the person did have an entry */

Just in case anyone wants to achieve the same thing... please don't try any of the recipes JD suggested! That turned out to be a dead end street, but the recipe in this post definitely does work.

Best regards,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1686
Total Polls:
6
Total Posts:
5933
Total Posts Today:
7
User Info:
 
Total Users:
4432
Newest User:
kinggambling14
Members Online:
0
Guests Online:
182

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked