Esempio n. 1
0
 public static function getMostFrequentValues(array $data, $mostFrequentQuantity = NULL, $allocationPeriod = NULL)
 {
     $mostFrequentValues = [];
     $allocatedData = self::allocateInfo($data, $allocationPeriod);
     usort($allocatedData, function ($a, $b) {
         if ($a->getValueQuantity() === $b->getValueQuantity()) {
             if ($a->getValue() === $b->getValueQuantity()) {
                 return 0;
             }
             return $a->getValue() < $b->getValue() ? -1 : 1;
         } else {
             return $a->getValueQuantity() > $b->getValueQuantity() ? -1 : 1;
         }
     });
     if (!$mostFrequentQuantity) {
         $mostFrequentQuantity = self::MOST_FREQUENT_QUANTITY;
     }
     for ($i = 0; $i < $mostFrequentQuantity; $i++) {
         $frequentValue = new SortData();
         $frequentValue->setValue($allocatedData[$i]->getValue());
         $frequentValue->setValueQuantity($allocatedData[$i]->getValueQuantity());
         $valueExamples = $allocatedData[$i]->getValueExamples() !== "" ? substr($allocatedData[$i]->getValueExamples(), 0, -2) : $allocatedData[$i]->getValueExamples();
         $frequentValue->setValueExamples($valueExamples);
         if ($mostFrequentQuantity === 1) {
             $mostFrequentValues = $frequentValue;
         } else {
             $mostFrequentValues[] = $frequentValue;
         }
     }
     return $mostFrequentValues;
 }
Esempio n. 2
0
 protected function groupDirect($groupKeeper, $itemPropertyName, $itemPropertyValue, $groupCriteria = NULL, $basicKey, $item = NULL)
 {
     foreach ($groupKeeper as $groupedKeeperPropertyName => &$groupedKeeperPropertyValue) {
         if ($groupCriteria) {
             if ($item->{$groupCriteria} !== $groupKeeper->{$groupCriteria}) {
                 continue;
             }
         }
         if ($groupedKeeperPropertyName === $itemPropertyName && $itemPropertyName !== self::$groupCriteriaHigherLevel) {
             switch (self::$groupResultType) {
                 case GroupConsts::RESULT_GROUP_SORT_DATA:
                     $keepData = new SortData();
                     $keepData->setValue($itemPropertyValue);
                     $quantityPropertyName = $groupedKeeperPropertyName . self::$quantityPropertyName;
                     $keepData->setValueQuantity(self::$data[$basicKey]->{$quantityPropertyName});
                     $groupedKeeperPropertyValue[] = $keepData;
                     break;
                 case GroupConsts::RESULT_GROUP_STRING:
                     $groupedKeeperPropertyValue .= $itemPropertyValue . ",";
                     break;
             }
         }
     }
     return $groupKeeper;
 }