protected function _initParams(RM_Total_Object $object) { $params = array(); $params['table_name'] = $object->tableName(); $params['detail_level'] = $object->detailLevel()->getTableSuffix(); $params['detail_level_id'] = $object->detailLevel()->getFieldNameWithId(); $params['period'] = $object->period()->getTableSuffix(); $params['category'] = $object->category()->categoryId(); $params['datail_level_unique'] = $object->detailLevel()->uniqSequence(); $params['datail_level_unique_names'] = $object->detailLevel()->uniqSequence(TRUE); $sumVariabes = $variables = array(); foreach (M('ReportValue')->getCountableValuesList()->filter('disabled is null') as $item) { $sum = 'sum(' . $item->getVarname() . ')'; $variables[] = $item->getVarname(); $sumVariabes[] = $item->noAggregate() ? 'if(' . $object->detailLevel()->getFieldNameWithId() . '=0, NULL , ' . $sum . ')' : $sum; } if (!count($variables)) { $res = M('Base')->error('no_variable_choosed'); throw new RM_Base_Exception_Result($res); } $params['param_names'] = join(',', $variables); $params['sum_params'] = join(',', $sumVariabes); return $params; }
protected function _collectRows(array $showParams = NULL) { $result = array(); foreach ($this->reportRequest() as $item) { $name = $this->getRowCaption($item); $q = $this->_mapper->_dataQuery($this->_object); $q->where($this->_object->detailLevel()->getFieldNameWithId() . '=?', $item->{$this->_object->detailLevel()->getFieldNameWithId()}); $data = array(); $headers = $this->columnHeaders(); foreach ($this->reportRequest($q) as $row) { for ($item2 = array_shift($headers); !isNull($item2) && $item2->value() != $row->period; $item2 = array_shift($headers)) { $data[] = 0; } if (!isNull($item2)) { $data[] = $this->_param->show($row, $showParams); } } for ($item2 = array_shift($headers); !isNull($item2) && $item2->value() != $row->period; $item2 = array_shift($headers)) { $data[] = 0; } $result[] = array('data' => $data, 'name' => $name, 'format' => $this->_param->excelFormat()); } return $result; }
protected function _applyGroupsForData(RM_Total_Object $object) { M('Db')->setCurrentConnection('storage'); $q = M('Db')->createQuery($object->tableName(), 'update'); M('Db')->setCurrentConnection('default'); $lastGroup = NULL; foreach ($object->other() as $id => $group) { if ($lastGroup != $group) { $detailLevel = $object->detailLevel(); $q->set()->reset(); do { $obGroup = M('ReportGroup')->loadById($group); $q->set($detailLevel->getFieldNameWithId(), $obGroup->reportId())->set($detailLevel->getFieldNameWithName(), $obGroup->name()); } while (!isNull($detailLevel = $detailLevel->getUpperLevel())); $lastGroup = $group; } $q->where()->reset(); $q->where($object->detailLevel()->getFieldNameWithId() . '=?', $id); $q->execute(); } }