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.

 

Please help with CB template recipe…!

Please help with CB template recipe…!

Hi there smile

I’m new at all this and need some help with this recipe. I’ve been trying to understand and adapt the code posted here: http://www.metamodpro.com/forums/topic?id=74 but without luck sad

Like sunnyjey, I want to have a different page for different member groups. My community is for characters of a book, so no one is actually going to log in (except me). But I want to show a different template based on the races of my characters.

So the differences between sunnyjey request and mine are that I’m on Community Builder 1.3 (not joomsocial) and I want to show a template, not a module.

I changed your code to look like this:


if  ($option == "com_comprofiler" and $view == "profile" ) {
  $userid = JRequest::getInt('userid',0);
  if ( $userid > 0 ) {
    $query = "select listid from #__comprofiler_lists where listid = '$userid' and approved = 1";
    $db->setQuery( $query );
    $results = $db->loadResultArray();
    if ( is_array( $results ) ) {
      if ( in_array(4, $results) ) return "Araphel"; // for list 4, use Template Araphel
     
    }
  }
}

But it still doesn’t work… and though I’ve been playing around with this for quite some time, and made several experiments, I must confess this php stuff is driving me crazy! T_T

If you could help me I’d really grateful.
Thank you for all your hard work,

Marta C.

Silvareiel
Beginner Modder
ranks
useravatar
Offline
3 Posts
Administrator has disabled public posting

Re: Please help with CB template recipe…!

Hi Marta,

I've just been looking at CB again to see how the lists/groups are structured. From what I see, the lists are dynamic based on rules that you set up (e.g. "username = fred"). So *generally* it's quite difficult to do query to find out who is in a list and who is not.

In your case it sounds like you might have created one list per "race". In the List setup, you've probably said that the list contains "all people with a certain value for race". Correct?

Unfortunately, CB makes it quite difficult to do a list lookup. The list is dynamic, i.e. calculated, rather than explicit (i.e. all the members listed in a table than you can quickly query).

Looking at the code above, you're trying to look up the list by an id number. The id you are using is the userid as given in the URL. This isn't going to work -- the user id and the list id are not the same thing.

I'd suggest a different approach. Instead of trying to look up the list membership (which is difficult), it's going to be easier to do a direct lookup for the particular field value that indicates "race" for each "user".

Let's assume that the field title is "race".

if  ($option == "com_comprofiler" and $view == "profile" ) {
  $userid = JRequest::getInt('userid',0);
  if ( $userid > 0 ) {
    $query = "select cb_race from #__comprofiler where user_id = '$userid' and approved = 1";
    $db->setQuery( $query );
    $result = $db->loadResult();
    if ($result == "foo" ) return "Araphel"; // for race "foo", use Template Araphel
  }
}


The code does this:
- checks to see if you are on a profile page
- if so, gets the "userid" from the URL
- looks up that user's record to find the "cb_race" field
- if the race is "foo", return the "Araphel" template.

Note: I think the template name has to be the name of the folder that the template is in on the server. I think this is typically all lower case. Try changing "Araphel" to "araphel" if you can't get the template to load even when the rest of the rule is working.

Hope that 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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Please help with CB template recipe…!

Hi Stephen smile

Thank you so much for replying…
But bad news… It won’t work sad

Anyway, I tried lots of changes to your code with no luck (not that I understand a lot about what I’m doing)

So I decided to break it to a simple code, trying to understand where it was failing.

So… I inserted it like this:

if  ($option == "com_comprofiler" and $view == "profile" ) return “araphel”;

And nothing… so it can’t even check to see if I’m on a profile page, right?

Then I tried like this:

if  ($option == "com_comprofiler" and $task == "userProfile" ) return “araphel”;

And nothing. (I tried like this because my url  says: index.php?option=com_comprofiler&task=userProfile&user=63&Itemid=53. Maybe it was stupid… but since I was experimenting…)

Then I tried:

if  ($option == "com_comprofiler" and $itemid == "63”) return “araphel”;

And it worked!! Of course it changed the template to all user profiles. Then I tried adding the rest of the code, like this:

if  ($option == "com_comprofiler" and $itemid == "63”) {
  $userid = JRequest::getInt('userid',0);
  if ( $userid > 0 ) {
    $query = "select cb_raa from #__comprofiler where user_id = '$userid' and approved = 1";
    $db->setQuery( $query );
    $result = $db->loadResult();
    if ($result == "Araphel" ) return "araphel"; // for race "Araphel", use Template Araphel
  }
}

And nothing again. So I’m guessing that the code isn’t reaching the comprofiler database. But then I don’t understand much about this…

Am I asking for something impossible? Is it easier to use user_id to change the template?

Anyway, sorry for taking up your time and thanks for the help.

Marta*

Silvareiel
Beginner Modder
ranks
useravatar
Offline
3 Posts
Administrator has disabled public posting

Re: Please help with CB template recipe…!

Hi Marta,

I have to confess I didn't actually try out the code that I wrote in my reply. It also relied on some of the code that you sent in the original request, and now that I double checked it, I see that it's wrong.

The correct code for determining if you are on a user profile page is not ' $view == "profile" ', but should be: JRequest::getVar("task") == "userProfile"

Therefore you should be able to detect any userprofile page like this:

if  ($option == "com_comprofiler" and JRequest::getVar("task") == "userProfile" ) return "araphel";

And, the modification to the original recipe I sent would be:

if ($option == "com_comprofiler" and JRequest::getVar("task") == "userProfile" ) {
  $userid = JRequest::getInt('userid',0);
  if ( $userid > 0 ) {
    $query = "select cb_race from #__comprofiler where user_id = '$userid' and approved = 1";
    $db->setQuery( $query );
    $result = $db->loadResult();
    if ($result == "foo" ) return "Araphel"; // for race "foo", use Template Araphel
  }
}


Let us know how you get on with it - this is not a black art; there will be a perfectly good solution that looks very similar to what I have written above.

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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Please help with CB template recipe…!

Hi Stephen smile

Once more thank you for your effort.

In fact

if  ($option == "com_comprofiler" and JRequest::getVar("task") == "userProfile" ) return "araphel";

works perfectly.

But not so lucky with the query part.

I’ve been trying changes to your code for the last 2 days. I even tried something a little different, based on one of your posts concerning cb and metamod

$user_id = $db->getEscaped((int)($user->id));
if  ($option == "com_comprofiler" and JRequest::getVar("task") == "userProfile" and $user_id > 0)
{
$query = "select * from #__comprofiler  where user_id = '$user_id'";
$db->setQuery( $query );
$row     = $db->loadObject();

$race = $row->cb_raa;

    if ($race == "Araphel")


return "araphel";

  }


And nothing.

I’ve been around the cb forum, too, reading posts, searching for different ways of query for the cb database, though I don’t understand much. I did noticed that they use

$db->setQuery( "select * from #__comprofiler WHERE id ==  $user->id");

But don’t know if this even applies to my case.

Anyway… I’ll keep searching for a way and I’ll update this post if I ever find one.

If you have any new ideas I’ll certainly appreciate them smile

I’m sure there’s a way to do this.

Thank you very much for all the support.

Best regards,

Marta C.

Silvareiel
Beginner Modder
ranks
useravatar
Offline
3 Posts
Administrator has disabled public posting

Re: Please help with CB template recipe…!

Hi Marta,

Happy New Year!

Just a quick note about the database query: can you please check what the "database prefix" is on your Joomla installation? By default it's "jos_" and that's what I have used in the examples above. You can find it in the "Server" tab of the Global Configuration in Joomla.

The db query I specified above is definitely correct, other than a possible different database prefix. e.g.:

select * from #__comprofiler where id = '62'

The table is not com_comprofiler (that's the name of the component), and in a database query you use "=" not "==".

One thing that can help to debug database connections is outputting the $db object after doing the query.

So after this line:

$row     = $db->loadObject();

put this line:

print_r($db);


Then at the top of your page you should get a big scrambled list of output. View page source in your browser so that it makes a little more sense - and if you're lucky you may be able to spot a database error being reported there.

Hope that 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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Please help with CB template recipe…!

Hello Stephen

Need the following help. I want to check on each profile page it is accessed, the value of the field cb_metatemplate. If the value is 1, display template "xxxx", if it is 2, display template "yyyy", if it is 3, display template "kkkk "...

However, I changed the recipe above, but did not work.

Another detail: every user will be displayed with the template he chose.

big hug

Gilson filho

sniper_rio
Beginner Modder
ranks
useravatar
Offline
15 Posts
Administrator has disabled public posting

Re: Please help with CB template recipe…!

Hi Gilson,

nice to hear from you again smile

This recipe should work for your purposes. It will ONLY change the template on CB profile pages. The template will reflect the selected template for the user whose page you are viewing (I think that's what you are asking for):

if  ($option == "com_comprofiler" and $view == "profile" ) {
  $userid = JRequest::getInt('userid',0);
  if ( $userid > 0 ) {
    $query = "select cb_metatemplate from #"
    . "__comprofiler where user_id = '$userid' and approved = 1";
    $db->setQuery( $query );
    $result = $db->loadResult();
    if ($result == "1" ) return "xxx";
    if ($result == "2" ) return "yyy";
    if ($result == "3" ) return "kkk";
  }
}


Hope that 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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Please help with CB template recipe…!

My friend Stephen ...
A good son son always comes home ...

Thank you for your words!

You understood exactly what I want.

well,

Checked table, # = #__comprofiler
Configured to skip the sh404SEF component.

But it seems not work.
Tested in several ways. The code looks fine, however does not respond. Any suggestions?

Thank you. hug

sniper_rio
Beginner Modder
ranks
useravatar
Offline
15 Posts
Administrator has disabled public posting

Re: Please help with CB template recipe…!

Hi,

ok, so I TOTALLY messed up the last one - sorry! This time I actually tested it and it works a lot better. It also uses the template when you are viewing your own page.

To use this, I set up a "field" on one of the CB tabs called "cb_metatemplate" and made it a dropdown list with values "foo", "bar" and "wombat".

Code:

$task = JRequest::getVar("task");

if  ($option == "com_comprofiler"
  and ( $task == "userprofile" or $task == "userdetails" or $task == null
    or $task == "useravatar" or $task == "manageconnections") ) {
  $userid = ( $task == "userprofile") ? JRequest::getInt('user',0) : $user->id;
  if ( $userid > 0 ) {
    $query = "select cb_metatemplate from #"
    . "__comprofiler where user_id = '$userid' and approved = 1";
    $db->setQuery( $query );
    $result = $db->loadResult();
    if ($result == "foo" ) return "yoo_nu";
    if ($result == "bar" ) return "fireworks";
    if ($result == "wombat" ) return "yoo_expo";
  }
}

Works for me this time :-)

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
3329 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1698
Total Polls:
6
Total Posts:
5945
Total Posts Today:
1
User Info:
 
Total Users:
5610
Newest User:
idim4
Members Online:
1
Guests Online:
386

Online: 
bseba9l

Forum Legend:

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