/**
  * @action getCsvUrl
  * @param int $id
  * @param int $reportPartnerId
  * @return string
  */
 function getCsvUrlAction($id, $reportPartnerId)
 {
     $dbReport = ReportPeer::retrieveByPK($id);
     if (is_null($dbReport)) {
         throw new KalturaAPIException(KalturaErrors::REPORT_NOT_FOUND, $id);
     }
     $dbPartner = PartnerPeer::retrieveByPK($reportPartnerId);
     if (is_null($dbPartner)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_PARTNER_ID, $reportPartnerId);
     }
     // allow creating urls for reports that are associated with partner 0 and the report owner
     if ($dbReport->getPartnerId() !== 0 && $dbReport->getPartnerId() !== $reportPartnerId) {
         throw new KalturaAPIException(KalturaErrors::REPORT_NOT_PUBLIC, $id);
     }
     $ks = new ks();
     $ks->valid_until = time() + 2 * 365 * 24 * 60 * 60;
     // 2 years
     $ks->type = ks::TYPE_KS;
     $ks->partner_id = $reportPartnerId;
     $ks->master_partner_id = null;
     $ks->partner_pattern = $reportPartnerId;
     $ks->error = 0;
     $ks->rand = microtime(true);
     $ks->user = '';
     $ks->privileges = 'setrole:REPORT_VIEWER_ROLE';
     $ks->additional_data = null;
     $ks_str = $ks->toSecureString();
     $paramsArray = $this->getParametersAction($id);
     $paramsStrArray = array();
     foreach ($paramsArray as $param) {
         $paramsStrArray[] = $param->value . '={' . $param->value . '}';
     }
     $url = "http://" . kConf::get("www_host") . "/api_v3/index.php/service/report/action/getCsvFromStringParams/id/{$id}/ks/" . $ks_str . "/params/" . implode(';', $paramsStrArray);
     return $url;
 }
Beispiel #2
0
 private static function getQueryResults($report_id, $start_date, $end_date, $frequency = QueryResultPeer::FREQUENCY_DAY)
 {
     $report = ReportPeer::retrieveByPK($report_id);
     $temp = array();
     foreach ($report->getReportQuerys() as $report_query) {
         $arr = QueryResultPeer::getChartData($report_query->getQueryId(), $frequency, $start_date, $end_date);
         $temp[] = $arr;
     }
     return $temp;
 }
 /**
  * @action getCsv
  * @param int $id
  * @param KalturaKeyValueArray $params
  * @return file
  */
 public function getCsvAction($id, KalturaKeyValueArray $params = null)
 {
     $dbReport = ReportPeer::retrieveByPK($id);
     if (is_null($dbReport)) {
         throw new KalturaAPIException(KalturaErrors::REPORT_NOT_FOUND, $id);
     }
     $query = $dbReport->getQuery();
     $this->addPartnerIdToParams($params);
     $execParams = KalturaReportHelper::getValidateExecutionParameters($dbReport, $params);
     $kReportsManager = new kReportManager($dbReport);
     list($columns, $rows) = $kReportsManager->execute($execParams);
     $fileName = array('Report', $id, $this->getPartnerId());
     foreach ($params as $param) {
         $fileName[] = $param->key;
         $fileName[] = $param->value;
     }
     $fileName = implode('_', $fileName) . '.csv';
     header('Content-Type: text/csv');
     header("Content-Disposition: attachment; filename=\"{$fileName}\"");
     echo "";
     // a fix for excel, copied from myReportsMgr
     echo implode(',', $columns) . "\n";
     foreach ($rows as $row) {
         echo implode(',', $row) . "\n";
     }
     die;
 }
 public function executeShowImage($request)
 {
     $id = $request->getParameter('id');
     ReportPeer::retrieveByPK(1);
     $report = sfPropelFriendlyUrl::retrieveByFriendlyUrl('Report', $id);
     $this->forward404Unless($report->getPublicRecord());
     $decorator = new PermanentChartDecorator();
     $chart = ReportPeer::getReportChartt($report, $decorator);
     $response = $this->getResponse();
     $response->clearHttpHeaders();
     $response->setContentType('image/png');
     $response->setContent(file_get_contents(sfConfig::get('app_web_images') . '/' . $chart->__toString()));
     $response->send();
 }