phpScheduleIt
May 23, 2013, 07:20:33 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: phpScheduleIt 2.4.2 has been released!
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Resource Status  (Read 1539 times)
aj
Newbie
*

Karma: 0
Posts: 23


« on: January 22, 2011, 07:27:12 PM »

I would like to create a function that will return the number of current participants and the max_participants for a reservation.
I would like to use the function in the schedule to append to the title like so "Volunteer Group Alpha (4/25)".  This would indicate that there are 4 current participants and a max of 25 for that resource.  I would like to provide that status in multiple locations thats why I am looking at a function.

I have tried to do it this way but it does not seem to return valid info:

function get_capacity($resid) {
   $res = new Reservation($resid);
   $resource = new Resource();
   $max_participants = $resource->get_property('max_participants', $res->get_machid());
   $user_info = $res->users;   
   $total_users = 0;           
   if ($max_participants != '') {
      echo '<div ">' . translate('Participants', array($max_participants)) . '</div>';
   }
   else if ($max_participants != '') {
      // Show how many openings are taken
      for ($i = 0; $i < count($user_info); $i++) {
         if ($user_info[$i]['invited'] != 1 && $user_info[$i]['owner'] != 1) {
            $total_users++;
         }
      }
      echo "<div">$total_users/$max_participants " . translate('Participants') . '</div>';
   }
   
}


Any help would be apprciated...

/aj
Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5419


WWW
« Reply #1 on: January 31, 2011, 12:53:17 PM »

You're almost there.  You'll need to pass the resourceId in to the Resource constructor.  You can get this off of the reservation object that you loaded up.
Logged
aj
Newbie
*

Karma: 0
Posts: 23


« Reply #2 on: February 06, 2011, 02:23:35 PM »

Sitll stuck...  Here is what I tried...
I added the funtion to the Schedule.class.php and the call to schedule.template.php in function write_reservation() but it displays the header for the schedule and gets to the first reservation and hangs right after the first line of get_capacity().  Its like it did not finsh the reservation constructor and lost it.
Below is the function....

    function get_capacity($resid) {
       $curr_reservation = new Reservation($resid);
       $curr_resource = new Resource($curr_reservation->get_machid());
       $max_participants = $curr_resource->get_property('max_participants', $curr_reservation->get_machid());
       $user_info = $curr_reservation->users;
       $total_users = 0;           
       if ($max_participants != '') {
          // Show how many openings are taken
          for ($i = 0; $i < count($user_info); $i++) {
             if ($user_info[$i]['invited'] != 1 && $user_info[$i]['owner'] != 1) {
                $total_users++;
             }
          }
       }
       return "<div>" . $total_users . "/" . $max_participants  . " Participants</div>";
    }

Thanks for your help.
/aj
Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5419


WWW
« Reply #3 on: February 07, 2011, 01:26:40 PM »

You may need to alter Schedule.class.php to include Reservation.class.php.  Are you seeing any error details in the server log files?
Logged
aj
Newbie
*

Karma: 0
Posts: 23


« Reply #4 on: February 07, 2011, 06:41:54 PM »

Including "include_once($basedir . '/lib/Reservation.class.php');" in Schedule.class.php worked perfectly....

Thanks,
/aj
Logged
aliweb
Jr. Member
**

Karma: 0
Posts: 84


« Reply #5 on: February 08, 2011, 10:57:38 AM »

Hi AJ,
Would you mind posting your step-by-step modifications for this?

Thank you,

Alison
Logged
aj
Newbie
*

Karma: 0
Posts: 23


« Reply #6 on: February 08, 2011, 11:27:00 AM »

Here you go...

I included the below function in Schedule.template.php

Code:
     /**                                                                       
     * Gets the capacity of a resources for the reservation
     * @param array $resid reservation id
     */                                                                         
     function get_capacity($resid) {
       $curr_reservation = new Reservation($resid);
       $curr_resource = new Resource($curr_reservation->get_machid());
       $max_participants = $curr_resource->get_property('max_participants', $curr_reservation->get_machid());
       $user_info = $curr_reservation->users;
       $total_users = 0;           
       if ($max_participants != '') {
          // Show how many openings are taken
          for ($i = 0; $i < count($user_info); $i++) {
              //if ($user_info[$i]['invited'] != 1 && $user_info[$i]['owner'] != 1) {
                 $total_users++;
             //}
          }
       }
       if ($total_users > $max_participants) {
           return "<font color=red> (" . $total_users . "/" . $max_participants  . ")</font>";
       } else {
                return " (" . $total_users . "/" . $max_participants  . ")";
       }
     }

Then I modified "function write_reservation" in Schedule.template .php:

...
Code:
    $slots = get_capacity($resid);
    $summary_text = $summary->toScheduleCell();   

$cellSummary = '';
if ($summary_text != $summary->EMPTY_SUMMARY)
{   
   $summary_text .= $slots;
   $cellSummary = "<div class=\"inlineSummary\">$summary_text</div>";
   
}

And then Nicks suggestion to add: include_once($basedir . '/lib/Reservation.class.php');  in Schedule.class.php.


This modification will display the open slots vs the max participants for the reservation.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2006-2007, Simple Machines Valid XHTML 1.0! Valid CSS!