<commit_before><?php
/**
 * @package Var
 * @subpackage Partners
 */
class PartnerUsageController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$request = $this->getRequest();
		$page = $this->_getParam('page', 1);
		$pageSize = $this->_getParam('pageSize', 10);
		$from = $this->_getParam('from_date', $this->getDefaultFromDate());
		$to = $this->_getParam('to_date', $this->getDefaultToDate());
		
		$client = Infra_ClientHelper::getClient();
		
		$form = new Form_PartnerUsageFilter();
		
		$form->populate($request->getParams());
		
		// when no statuses selected
		if (!$form->getElement('include_active')->getValue() && !$form->getElement('include_blocked')->getValue() && !$form->getElement('include_removed')->getValue())
		{
			$form->getElement('include_active')->setValue(1);
			$form->getElement('include_blocked')->setValue(1);
			$form->getElement('include_removed')->setValue(1);
		}
		
		// init filters
		
		$usageFilter = new Kaltura_Client_Type_ReportInputFilter();
		$usageFilter->fromDate = DateTime::createFromFormat('m/d/Y', $from)->getTimestamp();
		$usageFilter->toDate = DateTime::createFromFormat('m/d/Y', $to)->getTimestamp();
		$usageFilter->timeZoneOffset = Infra_AuthHelper::getAuthInstance()->getIdentity()->getTimezoneOffset();
		if ($form->getElement('interval')->getValue())
		{
		    $usageFilter->interval = ($form->getElement('interval')->getValue() == 'daily') ? Kaltura_Client_Enum_ReportInterval::DAYS : Kaltura_Client_Enum_ReportInterval::MONTHS;
		}
		
		$varConsolePlugin = Kaltura_Client_VarConsole_Plugin::get($client);
		
		// get results and paginate
		$partnerFilter = $this->getPartnerFilterFromForm($form);
		$paginatorAdapter = new Form_PartnerUsageFilterPaginator($varConsolePlugin->varConsole, "getPartnerUsage", null, $partnerFilter, $usageFilter);
		$paginator = new Form_PartnerUsagePaginator($paginatorAdapter, $request);
		$paginator->setCurrentPageNumber($page);
		$paginator->setItemCountPerPage($pageSize);
		// set view
		$this->view->from = $from;
		$this->view->to = $to;
		$this->view->form = $form;
		$this->view->paginator = $paginator;
	}
	
	public function exportCsvAction() 
	{
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
		$request = $this->getRequest();
		$from = $this->_getParam('from_date', $this->getDefaultFromDate());
		$to = $this->_getParam('to_date', $this->getDefaultToDate());
		$client = Infra_ClientHelper::getClient();
		if ($client->getKs() == null) {
			$client->setKs(self::generateKs());
		}
		$form = new Form_PartnerUsageFilter();
		$form->populate($request->getParams());
		
		// init filters
		$partnerFilter = $this->getPartnerFilterFromForm($form);
		$usageFilter = new Kaltura_Client_Type_ReportInputFilter();
		$usageFilter->fromDate = DateTime::createFromFormat('m/d/Y', $from)->getTimestamp();
		$usageFilter->toDate = DateTime::createFromFormat('m/d/Y', $to)->getTimestamp();
		$usageFilter->timeZoneOffset =Infra_AuthHelper::getAuthInstance()->getIdentity()->getTimezoneOffset();
		
		$pager = new Kaltura_Client_Type_FilterPager();
		$pager->pageIndex = 1;
		$pager->pageSize = 500;
		
		$varConsolePlugin = Kaltura_Client_VarConsole_Plugin::get($client);
		
		$items = array();
		while(true)
		{
		    $response = $varConsolePlugin->varConsole->getPartnerUsage($partnerFilter, $usageFilter, $pager);
			if (count($response->objects) <= 0)
				break;
				
			foreach($response->objects as &$object)
				$items[] = $object;
			$pager->pageIndex++;
		}
		
		$format = $this->view->translate('csv date');
		$fileName = 'Usage report '.$from.' to '.$to.'.csv';
		header('Content-type: text/csv');
		header('Content-Disposition: attachment; filename="'.$fileName.'"');<commit_msg>fwr:  fix pager reference in CSV output<commit_after><?php
/**
 * @package Var
 * @subpackage Partners
 */
class PartnerUsageController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$request = $this->getRequest();
		$page = $this->_getParam('page', 1);
		$pageSize = $this->_getParam('pageSize', 10);
		$from = $this->_getParam('from_date', $this->getDefaultFromDate());
		$to = $this->_getParam('to_date', $this->getDefaultToDate());
		
		$client = Infra_ClientHelper::getClient();
		
		$form = new Form_PartnerUsageFilter();
		
		$form->populate($request->getParams());
		
		// when no statuses selected
		if (!$form->getElement('include_active')->getValue() && !$form->getElement('include_blocked')->getValue() && !$form->getElement('include_removed')->getValue())
		{
			$form->getElement('include_active')->setValue(1);
			$form->getElement('include_blocked')->setValue(1);
			$form->getElement('include_removed')->setValue(1);
		}
		
		// init filters
		
		$usageFilter = new Kaltura_Client_Type_ReportInputFilter();
		$usageFilter->fromDate = DateTime::createFromFormat('m/d/Y', $from)->getTimestamp();
		$usageFilter->toDate = DateTime::createFromFormat('m/d/Y', $to)->getTimestamp();
		$usageFilter->timeZoneOffset = Infra_AuthHelper::getAuthInstance()->getIdentity()->getTimezoneOffset();
		if ($form->getElement('interval')->getValue())
		{
		    $usageFilter->interval = ($form->getElement('interval')->getValue() == 'daily') ? Kaltura_Client_Enum_ReportInterval::DAYS : Kaltura_Client_Enum_ReportInterval::MONTHS;
		}
		
		$varConsolePlugin = Kaltura_Client_VarConsole_Plugin::get($client);
		
		// get results and paginate
		$partnerFilter = $this->getPartnerFilterFromForm($form);
		$paginatorAdapter = new Form_PartnerUsageFilterPaginator($varConsolePlugin->varConsole, "getPartnerUsage", null, $partnerFilter, $usageFilter);
		$paginator = new Form_PartnerUsagePaginator($paginatorAdapter, $request);
		$paginator->setCurrentPageNumber($page);
		$paginator->setItemCountPerPage($pageSize);
		// set view
		$this->view->from = $from;
		$this->view->to = $to;
		$this->view->form = $form;
		$this->view->paginator = $paginator;
	}
	
	public function exportCsvAction() 
	{
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
		$request = $this->getRequest();
		$from = $this->_getParam('from_date', $this->getDefaultFromDate());
		$to = $this->_getParam('to_date', $this->getDefaultToDate());
		$client = Infra_ClientHelper::getClient();
		if ($client->getKs() == null) {
			$client->setKs(self::generateKs());
		}
		$form = new Form_PartnerUsageFilter();
		$form->populate($request->getParams());
		
		// init filters
		$partnerFilter = $this->getPartnerFilterFromForm($form);
		$usageFilter = new Kaltura_Client_Type_ReportInputFilter();
		$usageFilter->fromDate = DateTime::createFromFormat('m/d/Y', $from)->getTimestamp();
		$usageFilter->toDate = DateTime::createFromFormat('m/d/Y', $to)->getTimestamp();
		$usageFilter->timeZoneOffset =Infra_AuthHelper::getAuthInstance()->getIdentity()->getTimezoneOffset();
	    if ($form->getElement('interval')->getValue())
		{
		    $usageFilter->interval = ($form->getElement('interval')->getValue() == 'daily') ? Kaltura_Client_Enum_ReportInterval::DAYS : Kaltura_Client_Enum_ReportInterval::MONTHS;
		}
		
		$pager = new Kaltura_Client_Type_FilterPager();
		$pager->pageIndex = 1;
		$pager->pageSize = 500;
		
		$varConsolePlugin = Kaltura_Client_VarConsole_Plugin::get($client);
		
		$items = array();
		while(true)
		{
		    $response = $varConsolePlugin->varConsole->getPartnerUsage($partnerFilter, $usageFilter, $pager);
			if (count($response->objects) <= 0)
				break;
				
			foreach($response->objects as &$object)
				$items[] = $object;
			$pager->pageIndex++;
		}
		
		$format = $this->view->translate('csv date');
		$fileName = 'Usage report '.$from.' to '.$to.'.csv';
		header('Content-type: text/csv');
		header('Content-Disposition: attachment; filename="'.$fileName.'"');
{'fraction_non_alphanumeric': 0.18306046151862834, 'fraction_numerical': 0.0028361479953590307, 'mean_word_length': 5.682170542635659, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 162, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7552458', 'n_tokens_mistral': 2693, 'n_tokens_neox': 2427, 'n_words': 356}