function launch() { global $configArray; global $interface; global $user; // Publisher Filter $allPublishers = $this->getAllPublishers(); $interface->assign('publisherFilter', $allPublishers); $selectedPublisherFilter = null; if (isset($_REQUEST['publisherFilter'])) { $selectedPublisherFilter = $_REQUEST['publisherFilter']; } else { $selectedPublisherFilter = array(); } $interface->assign('selectedPublisherFilter', $selectedPublisherFilter); $publishers = empty($selectedPublisherFilter) ? $allPublishers : $selectedPublisherFilter; $interface->assign('publishers', $publishers); // Date range filter $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"); } elseif ($period == '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"); } elseif ($period == '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); } // create a SQL clause to filter by selected publishers $publisherRestriction = null; if (isset($_REQUEST['publisherFilter'])) { $publishersToShow = array(); foreach ($_REQUEST['publisherFilter'] as $item) { $publishersToShow[] = "'" . mysql_escape_string(strip_tags($item)) . "'"; } if (!empty($publishersToShow)) { $publisherRestriction = "publisher IN (" . implode(",", $publishersToShow) . ") "; } } //Load data for each period $periodDataByPublisher = array(); $periodDataByStatus = array(); for ($i = 0; $i < count($periods) - 1; $i++) { $periodStart = clone $periods[$i]; //$periodStart->setTime(0,0,0); $periodEnd = clone $periods[$i + 1]; //$periodStart->setTime(23, 59, 59); $periodDataByPublisher[$periodStart->getTimestamp()] = array(); $periodDataByStatus[$periodStart->getTimestamp()] = array(); //Determine how many files were imported by publisher $importDetails = new EContentImportDetailsEntry(); $importDetails->selectAdd(); $importDetails->selectAdd('COUNT(id) as numberOfFiles, publisher'); $importDetails->whereAdd('dateFound >= ' . $periodStart->getTimestamp() . ' AND dateFound < ' . $periodEnd->getTimestamp()); if ($publisherRestriction) { $importDetails->whereAdd($publisherRestriction); } $importDetails->groupBy('publisher'); $importDetails->orderBy('publisher'); $importDetails->find(); while ($importDetails->fetch()) { $periodDataByPublisher[$periodStart->getTimestamp()][$importDetails->publisher] = $importDetails->numberOfFiles; } //Determine how many files were imported by status $importDetails = new EContentImportDetailsEntry(); $importDetails->selectAdd(); $importDetails->selectAdd('COUNT(id) as numberOfFiles, status'); $importDetails->whereAdd('dateFound >= ' . $periodStart->getTimestamp() . ' AND dateFound < ' . $periodEnd->getTimestamp()); if ($publisherRestriction) { $importDetails->whereAdd($publisherRestriction); } $importDetails->groupBy('status'); $importDetails->orderBy('status'); $importDetails->find(); while ($importDetails->fetch()) { $periodDataByStatus[$periodStart->getTimestamp()][$importDetails->status] = $importDetails->numberOfFiles; } } $interface->assign('periodDataByPublisher', $periodDataByPublisher); $interface->assign('periodDataByStatus', $periodDataByStatus); //Get a list of all of the statuses that will be shown $statusesUntranslated = $this->getStatuses(); $statuses = array(); foreach ($statusesUntranslated as $status) { $statuses[$status] = translate($status); } $interface->assign('statuses', $statuses); //Check to see if we are exporting to Excel if (isset($_REQUEST['exportToExcel'])) { $this->exportToExcel($periodDataByPublisher, $publishers, $periodDataByStatus, $statuses); } else { //Generate the graphs $this->generateGraphByPublisher($periodDataByPublisher, $periods, $publishers); $this->generateGraphByStatus($periodDataByStatus, $periods, $statuses); } $interface->setTemplate('eContentImportSummary.tpl'); $interface->setPageTitle('eContent Import Summary Report'); $interface->display('layout.tpl'); }