15 if (! is_string($name))
18 if ($this->
id !==
null)
21 unset($this->attributes[$name]);
25 private function getCountersDeprecated(array $filter =
null, array $steps =
null)
27 $query =
new Query(Internals\ContextCounterDayTable::getEntity());
31 $query->setFilter($filter);
36 foreach ($this->attributes as $name => $value)
38 self::setAttributeFilter($query,
'_conversion_attribute_'.(++ $i).
'_', $name, $value);
41 $query->registerRuntimeField(
null,
new ExpressionField(
'VALUE_SUM',
'SUM(%s)', array(
'VALUE')));
43 $query->setSelect(array(
'NAME',
'VALUE_SUM'));
45 $query->addGroup(
'NAME');
49 $query->addGroup(
'DAY');
50 $query->addSelect(
'DAY');
53 $result = $query->exec();
61 while ($row = $result->fetch())
64 $value = $row[
'VALUE_SUM'];
66 $counters[$name] += $value;
68 $steps[$row[
'DAY']->format(
'Y-m-d')][$name] = $value;
71 $counters[
'STEPS'] = $steps;
75 while ($row = $result->fetch())
77 $counters[$row[
'NAME']] = $row[
'VALUE_SUM'];
94 $counters = $this->getCountersDeprecated($filter, $steps);
96 return self::getRatesCommonDeprecated($rateTypes, $counters, $steps);
99 static private function getRatesCommonDeprecated(array $rateTypes, array $counters, array $steps =
null)
105 foreach ($rates as & $rate)
107 $rate[
'STEPS'] = array();
111 foreach ($counters[
'STEPS'] as $step => $stepCounters)
115 $rates[$name][
'STEPS'][$step] = $rate[
'RATE'];
125 private function getSplitCountersDeprecated(array $splits, array $filter =
null, array $steps =
null)
129 $totalCounters = $this->getCountersDeprecated($filter, $steps);
130 $otherCounters = $totalCounters;
132 foreach ($splits as $splitKey => $attribute)
134 if ($attribute[
'NAME'])
136 $this->
setAttribute($attribute[
'NAME'], $attribute[
'VALUE']);
138 $counters = $this->getCountersDeprecated($filter, $steps);
140 $result[$splitKey] = $counters;
142 self::subtructCounters($otherCounters, $counters, $steps);
148 $result[
'other'] = $otherCounters > 0 ? $otherCounters : 0;
149 $result[
'total'] = $totalCounters;
154 private static function subtructCounters(array & $one, array $two, array $steps =
null)
158 $oneSteps = $one[
'STEPS'];
159 $twoSteps = $two[
'STEPS'];
161 unset($one[
'STEPS']);
163 if ($oneSteps && $twoSteps)
165 foreach ($oneSteps as $key => & $oneStep)
167 if ($twoStep = $twoSteps[$key])
169 self::subtructCountersOnce($oneStep, $twoStep);
174 self::subtructCountersOnce($one, $two);
176 $one[
'STEPS'] = $oneSteps;
180 self::subtructCountersOnce($one, $two);
184 private static function subtructCountersOnce(array & $one, array $two)
186 foreach ($one as $key => & $value)
188 $value -= $two[$key];
202 $splitCounters = $this->getSplitCountersDeprecated($splits, $filter, $steps);
206 foreach ($splitCounters as $split => $counters)
208 $result[$split] = $this->getRatesCommonDeprecated($rateTypes, $counters, $steps);
216 static private function setAttributeFilter(
Query $query, $field, $name, $value =
null)
218 $query->
registerRuntimeField(
null,
new ReferenceField($field, Internals\ContextAttributeTable::getEntity(),
219 array(
'=this.CONTEXT_ID' =>
'ref.CONTEXT_ID'),
220 array(
'join_type' =>
'INNER')
223 $query->
addFilter(
"=$field.NAME" , $name);
227 $query->
addFilter(
"=$field.VALUE", $value);
233 $query =
new Query(Internals\ContextCounterDayTable::getEntity());
235 if ($filter = $parameters[
'filter'])
242 foreach ($this->attributes as $name => $value)
244 self::setAttributeFilter($query,
'_conversion_attribute_'.(++ $i).
'_', $name, $value);
249 $splitNames = array();
251 if ($split = $parameters[
'split'])
253 if (! is_array($split))
256 foreach ($split as $name => $value)
260 case 'ATTRIBUTE_NAME':
262 if (! is_string($value))
265 self::setAttributeFilter($query,
'split_attribute', $value);
266 $query->
addGroup(
'split_attribute.VALUE');
267 $query->
addSelect(
'split_attribute.VALUE',
'ATTRIBUTE_VALUE');
268 $splitNames []=
'ATTRIBUTE_VALUE';
281 $result = $query->
exec();
287 while ($row = $result->fetch())
291 foreach ($splitNames as $name)
293 if (! $level =& $level[$row[$name]])
299 $level[$row[
'NAME']] = $row[
'VALUE_SUM'];
305 public function getRates(array $rateTypes, array $parameters = array())
307 if (! $filter =& $parameters[
'filter'])
314 return self::getRatesRecursive($rateTypes, $this->
getCounters($parameters), ($s = $parameters[
'split']) ? count($s) : 0);
317 static private function getRatesRecursive(array $rateTypes, array $counters, $level)
325 foreach ($counters as $k => $v)
327 $rates[$k] = self::getRatesRecursive($rateTypes, $v, $level);
setAttribute($name, $value=null)
getSplitRatesDeprecated(array $splits, array $rateTypes, array $filter=null, array $steps=null)
unsetAttribute($name, $value=null)
getRatesDeprecated(array $rateTypes, array $filter=null, array $steps=null)
getCounters(array $parameters=array())
getRates(array $rateTypes, array $parameters=array())
registerRuntimeField($name, $fieldInfo=null)
addSelect($definition, $alias='')