Esempio n. 1
0
 static function getCategoriesFromPersons($id, $name, $exactNameOverride = false)
 {
     $categories = array();
     $topCategories = array();
     $filters = self::getNameParts($id, $name);
     //get categories from persons with position in this org
     $numPersonsWithCategories = 0;
     $persons = OrgTable::getPersonsWithPositions($id);
     foreach ($persons as $person) {
         $donations = OsPerson::getMatchedDonations($person['id']);
         if ($exactNameOverride) {
             $exactCategories = self::getCategoriesFromDonationsWithExactName($donations, $name);
             $topCategories = array_merge($topCategories, $exactCategories);
         }
         $donations = self::filterDonations($donations, $filters);
         $categoryIds = OsCategoryTable::getCategoryIdsFromDonations($donations);
         $hasCategory = false;
         foreach ($categoryIds as $categoryId) {
             if (in_array($categoryId, $topCategories)) {
                 $numPersonsWithCategories++;
                 continue;
             }
             if (in_array($categoryId, OsCategoryTable::$ignoreCategories)) {
                 continue;
             }
             if (isset($categories[$categoryId])) {
                 $categories[$categoryId]++;
             } else {
                 $categories[$categoryId] = 1;
             }
             $hasCategory = true;
         }
         if ($hasCategory) {
             $numPersonsWithCategories++;
         }
     }
     $topCategories = array_unique($topCategories);
     arsort($categories);
     foreach ($categories as $categoryId => $num) {
         if ($num >= max(2, $numPersonsWithCategories / 5)) {
             $topCategories[] = $categoryId;
         }
     }
     return array_unique($topCategories);
 }