/** * Choose n people up to limit sorted by their total number of AngelList followers * * @since 1.1 * @param array $people an individual startup role with a user subobject * @param int $limit limits the number of objects returned * @return array the passed in people array reordered by follower count */ public static function order_by_follower_count(array $people, $limit = 3) { if (count($people) === 1 || $limit < 1) { return $people; } $top_people = array(); $people_count = 0; $people_by_followers = array(); foreach ($people as $person) { if (!isset($person->tagged)) { continue; } else { if (isset($person->tagged->follower_count) && $person->tagged->follower_count > 0) { $people_by_followers[(string) $person->tagged->follower_count][] = $person; } else { $people_by_followers['0'][] = $person; } } } if (!empty($people_by_followers) && krsort($people_by_followers)) { foreach ($people_by_followers as $followers => $followers_person) { if ($people_count === $limit) { break; } // do two or more people share the same follower count? if (is_array($followers_person)) { // attempt to reorder by start date to break the tie $followers_person = AngelList_Person::order_by_start_date($followers_person, $limit - $people_count); foreach ($followers_person as $followers_person_person) { if ($people_count === $limit) { break; } $top_people[] = $followers_person_person; $people_count++; } } else { $top_people[] = $followers_person; $people_count++; } } } return $top_people; }
/** * Request a list of people associated with the company from the AngelList API, up to limit (default 3) * * @since 1.1 * @param int $limit maximum amount of people * @return string HTML list of people */ private function people($limit = 3) { // check for garbage if (!is_int($limit) || $limit < 1) { $limit = 3; } if (!class_exists('AngelList_API')) { require_once dirname(dirname(__FILE__)) . '/api.php'; } $people = AngelList_API::get_roles_by_company($this->id); if (!is_array($people) || empty($people)) { return ''; } if (!class_exists('AngelList_Person')) { require_once dirname(__FILE__) . '/person.php'; } $founders = array(); $everyone_else = array(); foreach ($people as $person) { // only care about confirmed, active people if (!(isset($person->role) && isset($person->confirmed) && $person->confirmed === true && !isset($person->ended_at))) { continue; } if ($person->role === 'founder') { $founders[] = $person; } else { if (!in_array($person->role, array('referrer', 'attorney'), true)) { $everyone_else[] = $person; } } } unset($people); $top_people = array(); // founders get priority treatment if (!empty($founders)) { $top_people = AngelList_Person::order_by_follower_count($founders, $limit); } $people_count = count($top_people); if ($people_count < $limit && !empty($everyone_else)) { $top_people = array_merge($top_people, AngelList_Person::order_by_follower_count($everyone_else, $limit - $people_count)); } // this should not happen. just in case if (empty($top_people)) { return ''; } $people_html = ''; foreach ($top_people as $person_data) { $person = new AngelList_Person($person_data); if (!(isset($person->name) && isset($person->role))) { continue; } $people_html .= $person->render($this->schema_org, $this->anchor_extra); } if ($people_html) { return '<ol class="angellist-people">' . $people_html . '</ol>'; } else { return ''; } }