<commit_before><?php
/**
 * Author: <NAME>
 * Date: 6/11/15
 * Dime
 */

namespace Dime\ReportBundle\Handler;

use Carbon\Carbon;
use Dime\ReportBundle\Entity\ExpenseReport;
use Dime\TimetrackerBundle\Entity\Timeslice;
use Dime\TimetrackerBundle\Handler\AbstractHandler;

class ReportHandler extends AbstractHandler{


	public function getExpenseReport(array $params)
	{
		$this->repository->createCurrentQueryBuilder($this->alias);


		// Filter
		if($this->hasParams($params)) {
			$this->repository->filter($this->cleanParameterBag($params));
		}

		$this->repository->getCurrentQueryBuilder()
			->Select('SUM('.$this->alias.'.value)')
			->addSelect($this->alias.'.startedAt')
			->addSelect('IDENTITY('.$this->alias.'.activity)')
			->groupBy($this->alias.'.startedAt')
			->addGroupBy($this->alias.'.activity')
			->orderBy($this->alias.'.startedAt', 'ASC')
		;


		$tmpResults = $this->repository->getCurrentQueryBuilder()->getQuery()->getResult();
		$result = array();
		foreach($tmpResults as $tmpResult){
			$slice = new Timeslice();
			$slice->setValue($tmpResult[1])
				->setStartedAt($tmpResult['startedAt'])
				->setActivity($this->om->getRepository('DimeTimetrackerBundle:Activity')->find($tmpResult[2]));
			$result[] = $slice;
		}
		$report = new ExpenseReport();
		$report->setTimeslices($result);
		if(isset($params['project'])) {
			$report->setProject($this->container->get('dime.project.handler')->get($params['project']));
		}
		if(isset($params['user'])) {
			$report->setUser($this->container->get('dime.user.handler')->get($params['user']));
		}
		if(isset($params['date'])) {
			$date = explode(',', $params['date']);
			if(is_array($date)) {
				$report->setStart(Carbon::createFromFormat('Y-m-d', $date[0]));
				$report->setEnd(Carbon::createFromFormat('Y-m-d', $date[1]));
			} else {
				$report->setStart($date);
			}
		}
		return $report;
	}

	public function getZiviWeekReport(array $params)
	{
		$this->repository->createCurrentQueryBuilder($this->alias);


		// Filter
		if($this->hasParams($params)) {
			$this->repository->filter($this->cleanParameterBag($params));
		}

		$this->repository->getCurrentQueryBuilder()
			->Select('SUM('.$this->alias.'.value)')
			->addSelect($this->alias.'.startedAt')
			->addSelect('IDENTITY('.$this->alias.'.user)')
			->addSelect('IDENTITY('.$this->alias.'.activity)')
			->leftJoin($this->alias.'.activity', 'act')
			->andWhere('act.rateUnitType != :noChange')
			->groupBy($this->alias.'.user')
			->addGroupBy($this->alias.'.startedAt')
			->setParameter('noChange', 'a')
		;

		$tmpResults = $this->repository->getCurrentQueryBuilder()->getQuery()->getResult();
		$result = array();
		foreach($tmpResults as $tmpResult){
			$slice = new Timeslice();
			$slice->setValue($tmpResult[1])
				->setStartedAt($tmpResult['startedAt'])
				->setStandardUnit('h')
				->setActivity($this->om->getRepository('DimeTimetrackerBundle:Activity')->find($tmpResult[3]))
				->setUser($this->om->getRepository('DimeEmployeeBundle:Employee')->find($tmpResult[2]));
			$result[] = $slice;
		}
		$report = new ExpenseReport();
		$report->setTimeslices($result);
		return $report;<commit_msg>Fixed: Case of User_id of Timeslice being NULL<commit_after><?php
/**
 * Author: <NAME>
 * Date: 6/11/15
 * Dime
 */

namespace Dime\ReportBundle\Handler;

use Carbon\Carbon;
use Dime\ReportBundle\Entity\ExpenseReport;
use Dime\TimetrackerBundle\Entity\Timeslice;
use Dime\TimetrackerBundle\Handler\AbstractHandler;

class ReportHandler extends AbstractHandler{


	public function getExpenseReport(array $params)
	{
		$this->repository->createCurrentQueryBuilder($this->alias);


		// Filter
		if($this->hasParams($params)) {
			$this->repository->filter($this->cleanParameterBag($params));
		}

		$this->repository->getCurrentQueryBuilder()
			->Select('SUM('.$this->alias.'.value)')
			->addSelect($this->alias.'.startedAt')
			->addSelect('IDENTITY('.$this->alias.'.activity)')
			->groupBy($this->alias.'.startedAt')
			->addGroupBy($this->alias.'.activity')
			->orderBy($this->alias.'.startedAt', 'ASC')
		;


		$tmpResults = $this->repository->getCurrentQueryBuilder()->getQuery()->getResult();
		$result = array();
		foreach($tmpResults as $tmpResult){
			$slice = new Timeslice();
			$slice->setValue($tmpResult[1])
				->setStartedAt($tmpResult['startedAt'])
				->setActivity($this->om->getRepository('DimeTimetrackerBundle:Activity')->find($tmpResult[2]));
			$result[] = $slice;
		}
		$report = new ExpenseReport();
		$report->setTimeslices($result);
		if(isset($params['project'])) {
			$report->setProject($this->container->get('dime.project.handler')->get($params['project']));
		}
		if(isset($params['user'])) {
			$report->setUser($this->container->get('dime.user.handler')->get($params['user']));
		}
		if(isset($params['date'])) {
			$date = explode(',', $params['date']);
			if(is_array($date)) {
				$report->setStart(Carbon::createFromFormat('Y-m-d', $date[0]));
				$report->setEnd(Carbon::createFromFormat('Y-m-d', $date[1]));
			} else {
				$report->setStart($date);
			}
		}
		return $report;
	}

	public function getZiviWeekReport(array $params)
	{
		$this->repository->createCurrentQueryBuilder($this->alias);


		// Filter
		if($this->hasParams($params)) {
			$this->repository->filter($this->cleanParameterBag($params));
		}

		$this->repository->getCurrentQueryBuilder()
			->Select('SUM('.$this->alias.'.value)')
			->addSelect($this->alias.'.startedAt')
			->addSelect('IDENTITY('.$this->alias.'.user)')
			->addSelect('IDENTITY('.$this->alias.'.activity)')
			->leftJoin($this->alias.'.activity', 'act')
			->andWhere('act.rateUnitType != :noChange')
			->groupBy($this->alias.'.user')
			->addGroupBy($this->alias.'.startedAt')
			->setParameter('noChange', 'a')
		;

		$tmpResults = $this->repository->getCurrentQueryBuilder()->getQuery()->getResult();
		$result = array();
		foreach($tmpResults as $tmpResult){
			$slice = new Timeslice();
			$slice->setValue($tmpResult[1])
				->setStartedAt($tmpResult['startedAt'])
				->setStandardUnit('h')
				->setActivity($this->om->getRepository('DimeTimetrackerBundle:Activity')->find($tmpResult[3]));
			//Works around an Issue Where User Id Of a Timeslice is NULL in DB.
			//TODO Fix user_id NULL in Database. For now assume that NULL means Default User.
			if(isset($tmpResult[2])) {
				$slice->setUser($this->om->getRepository('DimeEmployeeBundle:Employee')->find($tmpResult[2]));
			} else {
				$slice->setUser($this->om->getRepository('DimeEmployeeBundle:Employee')->find(1));
			}
			$result[] = $slice;
		}
		$report = new ExpenseReport();
		$report->setTimeslices($result);
		return $report;
{'fraction_non_alphanumeric': 0.21484492622704005, 'fraction_numerical': 0.003914483589280337, 'mean_word_length': 5.077767612076853, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 177, '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': '2610870', 'n_tokens_mistral': 2451, 'n_tokens_neox': 2165, 'n_words': 269}