示例#1
0
 function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     $showOpen = true;
     if (isset($_REQUEST['requestsToShow']) && $_REQUEST['requestsToShow'] == 'allRequests') {
         $showOpen = false;
     }
     $interface->assign('showOpen', $showOpen);
     $defaultStatus = new MaterialsRequestStatus();
     $defaultStatus->isDefault = 1;
     $defaultStatus->libraryId = Library::getPatronHomeLibrary()->libraryId;
     $defaultStatus->find(true);
     $interface->assign('defaultStatus', $defaultStatus->id);
     //Get a list of all materials requests for the user
     $allRequests = array();
     if ($user) {
         $materialsRequests = new MaterialsRequest();
         $materialsRequests->createdBy = $user->id;
         $materialsRequests->orderBy('title, dateCreated');
         $statusQuery = new MaterialsRequestStatus();
         if ($showOpen) {
             $homeLibrary = Library::getPatronHomeLibrary();
             $statusQuery->libraryId = $homeLibrary->libraryId;
             $statusQuery->isOpen = 1;
         }
         $materialsRequests->joinAdd($statusQuery);
         $materialsRequests->selectAdd();
         $materialsRequests->selectAdd('materials_request.*, description as statusLabel');
         $materialsRequests->find();
         while ($materialsRequests->fetch()) {
             $allRequests[] = clone $materialsRequests;
         }
     } else {
         header('Location: ' . $configArray['Site']['path'] . '/MyResearch/Home?followupModule=MaterialsRequest&followupAction=MyRequests');
         //$interface->assign('error', "You must be logged in to view your requests.");
     }
     $interface->assign('allRequests', $allRequests);
     $interface->assign('sidebar', 'MyAccount/account-sidebar.tpl');
     $interface->setTemplate('myMaterialRequests.tpl');
     $interface->setPageTitle('My Materials Requests');
     $interface->display('layout.tpl');
 }
示例#2
0
 function launch()
 {
     global $interface;
     global $user;
     $period = isset($_REQUEST['period']) ? $_REQUEST['period'] : 'week';
     if ($period == 'week') {
         $periodLength = new DateInterval("P1W");
     } elseif ($period == 'day') {
         $periodLength = new DateInterval("P1D");
     } elseif ($period == 'month') {
         $periodLength = new DateInterval("P1M");
     } else {
         //year
         $periodLength = new DateInterval("P1Y");
     }
     $interface->assign('period', $period);
     $endDate = isset($_REQUEST['endDate']) && strlen($_REQUEST['endDate']) > 0 ? DateTime::createFromFormat('m/d/Y', $_REQUEST['endDate']) : new DateTime();
     $interface->assign('endDate', $endDate->format('m/d/Y'));
     if (isset($_REQUEST['startDate']) && strlen($_REQUEST['startDate']) > 0) {
         $startDate = DateTime::createFromFormat('m/d/Y', $_REQUEST['startDate']);
     } else {
         if ($period == 'day') {
             $startDate = new DateTime($endDate->format('m/d/Y') . " - 7 days");
         } elseif ($period == 'week') {
             //Get the sunday after this
             $endDate->setISODate($endDate->format('Y'), $endDate->format("W"), 0);
             $endDate->modify("+7 days");
             $startDate = new DateTime($endDate->format('m/d/Y') . " - 28 days");
         } elseif ($period == 'month') {
             $endDate->modify("+1 month");
             $numDays = $endDate->format("d");
             $endDate->modify(" -{$numDays} days");
             $startDate = new DateTime($endDate->format('m/d/Y') . " - 6 months");
         } else {
             //year
             $endDate->modify("+1 year");
             $numDays = $endDate->format("m");
             $endDate->modify(" -{$numDays} months");
             $numDays = $endDate->format("d");
             $endDate->modify(" -{$numDays} days");
             $startDate = new DateTime($endDate->format('m/d/Y') . " - 2 years");
         }
     }
     $interface->assign('startDate', $startDate->format('m/d/Y'));
     //Set the end date to the end of the day
     $endDate->setTime(24, 0, 0);
     $startDate->setTime(0, 0, 0);
     //Create the periods that are being represented
     $periods = array();
     $periodEnd = clone $endDate;
     while ($periodEnd >= $startDate) {
         array_unshift($periods, clone $periodEnd);
         $periodEnd->sub($periodLength);
     }
     //print_r($periods);
     //Load data for each period
     //this will be a two dimensional array
     //         Period 1, Period 2, Period 3
     //Status 1
     //Status 2
     //Status 3
     $periodData = array();
     for ($i = 0; $i < count($periods) - 1; $i++) {
         /** @var DateTime $periodStart */
         $periodStart = clone $periods[$i];
         /** @var DateTime $periodEnd */
         $periodEnd = clone $periods[$i + 1];
         $periodData[$periodStart->getTimestamp()] = array();
         //Determine how many requests were created
         $materialsRequest = new MaterialsRequest();
         $materialsRequest->joinAdd(new User(), 'INNER', 'user');
         $materialsRequest->selectAdd();
         $materialsRequest->selectAdd('COUNT(id) as numRequests');
         $materialsRequest->whereAdd('dateCreated >= ' . $periodStart->getTimestamp() . ' AND dateCreated < ' . $periodEnd->getTimestamp());
         if ($user->hasRole('library_material_requests')) {
             //Need to limit to only requests submitted for the user's home location
             $userHomeLibrary = Library::getPatronHomeLibrary();
             $locations = new Location();
             $locations->libraryId = $userHomeLibrary->libraryId;
             $locations->find();
             $locationsForLibrary = array();
             while ($locations->fetch()) {
                 $locationsForLibrary[] = $locations->locationId;
             }
             $materialsRequest->whereAdd('user.homeLocationId IN (' . implode(', ', $locationsForLibrary) . ')');
         }
         $materialsRequest->find();
         while ($materialsRequest->fetch()) {
             $periodData[$periodStart->getTimestamp()]['Created'] = $materialsRequest->numRequests;
         }
         //Get a list of all requests by the status of the request
         $materialsRequest = new MaterialsRequest();
         $materialsRequest->joinAdd(new MaterialsRequestStatus());
         $materialsRequest->joinAdd(new User(), 'INNER', 'user');
         $materialsRequest->selectAdd();
         $materialsRequest->selectAdd('COUNT(materials_request.id) as numRequests,description');
         $materialsRequest->whereAdd('dateUpdated >= ' . $periodStart->getTimestamp() . ' AND dateUpdated < ' . $periodEnd->getTimestamp());
         if ($user->hasRole('library_material_requests')) {
             //Need to limit to only requests submitted for the user's home location
             $userHomeLibrary = Library::getPatronHomeLibrary();
             $locations = new Location();
             $locations->libraryId = $userHomeLibrary->libraryId;
             $locations->find();
             $locationsForLibrary = array();
             while ($locations->fetch()) {
                 $locationsForLibrary[] = $locations->locationId;
             }
             $materialsRequest->whereAdd('user.homeLocationId IN (' . implode(', ', $locationsForLibrary) . ')');
         }
         $materialsRequest->groupBy('status');
         $materialsRequest->orderBy('status');
         $materialsRequest->find();
         while ($materialsRequest->fetch()) {
             $periodData[$periodStart->getTimestamp()][$materialsRequest->description] = $materialsRequest->numRequests;
         }
     }
     $interface->assign('periodData', $periodData, $periods);
     //Get a list of all of the statuses that will be shown
     $statuses = array();
     foreach ($periodData as $periodInfo) {
         foreach ($periodInfo as $status => $numRequests) {
             $statuses[$status] = translate($status);
         }
     }
     $interface->assign('statuses', $statuses);
     //Check to see if we are exporting to Excel
     if (isset($_REQUEST['exportToExcel'])) {
         $this->exportToExcel($periodData, $statuses);
     } else {
         //Generate the graph
         $this->generateGraph($periodData, $statuses);
     }
     $interface->setTemplate('summaryReport.tpl');
     $interface->assign('sidebar', 'MyAccount/account-sidebar.tpl');
     $interface->setPageTitle('Materials Request Summary Report');
     $interface->display('layout.tpl');
 }