This topic is locked
[SOLVED]

Hide resources in calendar based on a condition

6/10/2022 4:19:24 AM
Calendar Template general questions
A
abhijit2020 author

I am trying to hide resources in the calendar based on a condition. I have added a column, available in rc_resources table. It has two values (1 - show in the calendar and 0 - hide in the calendar).

In the List event page, "List page: Before Process" of "Resource Calender" table I modify the following sql code (i.e. added "r.available = 1" in the where clause)

$categoryid = 0;

$rs = DB::Query("select r., r.".addFieldWrappers("id")." as ".addFieldWrappers("rid").", c.".addFieldWrappers("cname").", a., a.".addFieldWrappers("id")." as ".addFieldWrappers("aid")." from (".addTableWrappers("rc_resources")." r left join ".addTableWrappers("rc_resourcedetails")." a on r.".addFieldWrappers("id")." = a.".addFieldWrappers("resid").") left join ".addTableWrappers("rc_categories")." c on r.".addFieldWrappers("categoryid")."=c.".addFieldWrappers("id")." ".$whereOwnerID." and r.available=1 order by ".addFieldWrappers("categoryid").",r.".addFieldWrappers("id").",".addFieldWrappers("resid").",".addFieldWrappers("startdate"));

$tooltiparr = array();

It seems straight forward, but it's not working. Any pointer to above issue will be much appreciated.

Thank you,

Abhi

A
abhijit2020 author 6/21/2022

Following is the solution to my requirement. Fernando helped me in resolving this issue. Thank you, Fernando. There are many examples in his site (https://fhumanes.com/blog/gestor-de-proyectos/) that you may find relevent to your projects.

Add a column, "available" (data type: INT) in rc_resources table. Modify the List event page, "List page: Before Process" of "Resource Calender":

Extract (arround line 219, in my case): Add an if clause in the while loop as below. You would be able to hide/unhide a resource from the calendar.

$posGroup = array();
$categoryid = 0;
while($data = $rs->fetchAssoc()){
**if ($data["available"] <>0){ <---- Add this code**
if($data["categoryid"] && $data["categoryid"]!=$categoryid){
if(strlen($data["cname"])>26)
$res[] = substr($data["cname"],0,23)."...";
else
$res[] = $data["cname"];
$resid[] = 0;
$group[] = "grid=group_".$data["categoryid"];
$categoryid = $data["categoryid"];
$posGroup[$data["categoryid"]] = "-";
}
$res[] = $data["name"];
$resid[] = $data["id"];
if($data["categoryid"])
$group[] = "grid=subgroup_".$data["categoryid"]." mid=".$data["id"];
else
$group[] = "grid=nogroup mid=".$data["id"];

} <---- Add this to close the if loop
}

global $locale_info;

Hope above helps other.

Cheers!