コード例 #1
0
 /**
  * Проверяем что отчёт строится и в нём появляются заголовки
  * и таблица с числами
  */
 public function testBuildReport()
 {
     $user = Doctrine::getTable('User')->findOneByLogin('tester');
     $dateStart = new DateTime('2010-05-01');
     $dateEnd = new DateTime('2010-12-01');
     $currency = $user->getCurrency();
     $report = new myReportMatrix($currency);
     $report->buildReport($user, null, $dateStart, $dateEnd);
     $headerLeft = $report->getHeaderLeft();
     $headerTop = $report->getHeaderTop();
     $matrix = $report->getMatrix();
     $getCategoryByLabel = function ($elements, $label) {
         foreach ($elements as $element) {
             if ($element->label == $label) {
                 return $element;
             }
         }
         return false;
     };
     $categoryParent = $getCategoryByLabel($headerLeft, 'Parent Cat 1');
     $categoryChild = $getCategoryByLabel($categoryParent->children, 'Child Cat 1');
     $categoryAnother = $getCategoryByLabel($headerLeft, 'Another Cat');
     $this->assertEquals(1200, $matrix[$categoryParent->flatIndex]['tag_bar'], 'Сумма в родительской категории ' . $categoryParent->label);
     $this->assertEquals(800, $matrix[$categoryChild->flatIndex]['tag_bar'], 'Сумма в дочерней категории ' . $categoryChild->label);
     $this->assertEquals(50, $matrix[$categoryAnother->flatIndex]['tag_foo'], 'Сумма в третьей категории ' . $categoryAnother->label);
 }
コード例 #2
0
 /**
  * Executes matrix action
  *
  * @param sfRequest $request A request object
  */
 public function executeMatrix(sfWebRequest $request)
 {
     $dateFrom = $request->getGetParameter('dateFrom', date('Y-m-01'));
     $dateTo = $request->getGetParameter('dateTo', date('Y-m-01'));
     $currency = $request->getGetParameter('currency', 1);
     $account = $request->getGetParameter('account', null);
     $type = $request->getGetParameter('type', null);
     $dateFrom = new DateTime(preg_replace("/(\\d{2}).(\\d{2}).(\\d{4})/", "\$3-\$2-\$1", $dateFrom));
     $dateTo = new DateTime(preg_replace("/(\\d{2}).(\\d{2}).(\\d{4})/", "\$3-\$2-\$1", $dateTo));
     $currency = Doctrine::getTable('Currency')->findOneById($currency);
     $user = $this->getUser()->getUserRecord();
     $account = $account ? Doctrine::getTable('Account')->findOneById($account) : null;
     $report = new myReportMatrix($currency);
     $report->buildReport($user, $account, $dateFrom, $dateTo, $type);
     $result = array('headerLeft' => $report->getHeaderLeft(), 'headerTop' => $report->getHeaderTop(), 'matrix' => $report->getMatrix());
     return $this->renderJson($result);
 }