Show modules based on TPLancers status

(0 votes, average 0 out of 5)

In these recipes you can switch or display modules based on whether or not the logged-in user is a Freelancer or a Buyer (even based on what category of Freelancer they are in) or based on individual sub-pages of the TPLancers extension. These recipes are based on the “Madiston” enhanced version of TPLancers.

Notes:

  • Please start with the Quick Start Guide!
  • Recipes 1–4 don’t take account of what page you are on – only the status of the user. If you want to control which pages the modules appear on, either use the normal module “menu selection” controls, or integrate the page selection methods in recipes 5-13.

1. Show module based on whether the logged-in user is a Freelancer:

$userid = (int)$user->id;
if ($userid > 0) {
  $query = "SELECT userid FROM #__tplancers_lancer WHERE userid = $userid";
  $db->setQuery( $query, 0, 1 );
  $found = $db->loadResult();
  if ($found) return XXX; /* replace XXX with the module ID you want to include */
  /* optional line: */
  else return YYY; /* replace YYY with module ID to be used if user is logged in
                              but NOT a freelancer */
}
/* optional line: */
else return ZZZ; /* replace ZZZ with module ID to be used if user is not logged in at all */

2. Show module based on which Freelancer category the logged-in user is in:

$userid = (int)$user->id;
$categories = "1,6"; /* CUSTOMISE! You can use comma-separated list */
if ($userid > 0) {
  $query = "SELECT tl.userid FROM #__tplancers_lancer tl,
    #__tplancers_lancer_cat tlc
    WHERE tl.userid = $userid
    and tlc.id_lancer = tl.userid
    and tlc.id_cat in ($categories)";
  $db->setQuery( $query, 0, 1 );
  $found = $db->loadResult();
  if ($found) return XXX; /* replace XXX with the module ID you want to include */
  /* optional line: */
  else return YYY; /* replace YYY with module ID to be used if user is logged in
                              but NOT in categories */
}
/* optional line: */
else return ZZZ; /* replace ZZZ with module ID to be used if user is not logged in at all */

3. Show module based on whether the logged-in user is a Buyer:

$userid = (int)$user->id;
if ($userid > 0) {
  $query = "SELECT userid FROM #__tplancers_buyer WHERE userid = $userid";
  $db->setQuery( $query, 0, 1 );
  $found = $db->loadResult();
  if ($found) return XXX; /* replace XXX with the module ID you want to include */
  /* optional line: */
  else return YYY; /* replace YYY with module ID to be used if user is logged in
                              but NOT a buyer */
}
/* optional line: */
else return ZZZ; /* replace ZZZ with module ID to be used if user is not logged in at all */

4. Show module based on which Buyer category the logged-in user is in:

$userid = (int)$user->id;
$categories = "1,6"; /* CUSTOMISE! You can use comma-separated list */
if ($userid > 0) {
  $query = "SELECT tb.userid FROM #__tplancers_buyer tb,
    #__tplancers_buyer_cat tbc
    WHERE tb.userid = $userid
    and tbc.id_buyer = tb.userid
    and tbc.id_cat in ($categories)";
  $db->setQuery( $query, 0, 1 );
  $found = $db->loadResult();
  if ($found) return XXX; /* replace XXX with the module ID you want to include */
  /* optional line: */
  else return YYY; /* replace YYY with module ID to be used if user is logged in
                              but NOT in these buyer categories */
}
/* optional line: */
else return ZZZ; /* replace ZZZ with module ID to be used if user is not logged in at all */

5. Show module on “Open Projects” page:

This recipe detects whether the user is on the TPLancers “Front page”, which is the same as the “Open Projects” page.

$task = JRequest::getVar("task");
if ($option == "com_tplancers" and ($task == "" or $task == "openproj") ) {
 return XXX; /* replace XXX with the module ID you want to include */
}
/* optional line: */
else return YYY; /* replace YYY with module ID to be used for all other pages */

6. Show module on “Terms” page:

$task = JRequest::getVar("task");
if ($option == "com_tplancers" and $task == "terms" ) {
 return XXX; /* replace XXX with the module ID you want to include */
}
/* optional line: */
else return YYY; /* replace YYY with module ID to be used for all other pages */

7. Show module on “Search Projects” page:

$task = JRequest::getVar("task");
if ($option == "com_tplancers" and $task == "searchproj") {
 return XXX; /* replace XXX with the module ID you want to include */
}
/* optional line: */
else return YYY; /* replace YYY with module ID to be used for all other pages */

8. Show module on “Search Freelancers” page:

$task = JRequest::getVar("task");
if ($option == "com_tplancers"
        and $task == "advsearch"
        and JRequest::getVar("type") == "free" ) {
 return XXX; /* replace XXX with the module ID you want to include */
}
/* optional line: */
else return YYY; /* replace YYY with module ID to be used for all other pages */

9. Show module on “Search Buyers” page:

$task = JRequest::getVar("task");
if ( $option == "com_tplancers"
         and $task == "advsearch"
         and JRequest::getVar("type") == "buyer" ) {
 return XXX; /* replace XXX with the module ID you want to include */
}
/* optional line: */
else return YYY; /* replace YYY with module ID to be used for all other pages */

10. Show module on “Edit Profile” page:

$task = JRequest::getVar("task");
if ( $option == "com_tplancers" and $task == "beditinfo" ) {
 return XXX; /* replace XXX with the module ID you want to include */
}
/* optional line: */
else return YYY; /* replace YYY with module ID to be used for all other pages */

11. Show module on “Private Messages” page:

$task = JRequest::getVar("task");
if ( $option == "com_tplancers" and $task == "pmessage" ) {
 return XXX; /* replace XXX with the module ID you want to include */
}
/* optional line: */
else return YYY; /* replace YYY with module ID to be used for all other pages */

12. Show module on “Open New Project” page:

$task = JRequest::getVar("task");
if ( $option == "com_tplancers" and $task == "bopenproj" ) {
 return XXX; /* replace XXX with the module ID you want to include */
}
/* optional line: */
else return YYY; /* replace YYY with module ID to be used for all other pages */

13. Show module on “My Projects” page:

$task = JRequest::getVar("task");
if ( $option == "com_tplancers" and $task == "bproj" ) {
 return XXX; /* replace XXX with the module ID you want to include */
}
/* optional line: */
else return YYY; /* replace YYY with module ID to be used for all other pages */