public function executeDegree2($request) { $options = $this->getParams(array('cat1_ids', 'order1', 'cat2_ids', 'order2', 'num', 'page', 'show_count')); if ($request->getParameter('show_count')) { $count = EntityApi::getSecondDegreeNetwork($this->entity['id'], $options, $countOnly = true); $this->getResponse()->setSlot('total', $count); } $this->entities = EntityApi::getSecondDegreeNetwork($this->entity['id'], $options); return 'Xml'; }
public function executeGiving() { if ($this->entity['primary_ext'] == 'Person') { $options = array('cat1_ids' => RelationshipTable::DONATION_CATEGORY, 'order1' => 1, 'cat2_ids' => RelationshipTable::DONATION_CATEGORY, 'order2' => 2, 'page' => $this->page, 'num' => $this->num); $entities = EntityApi::getSecondDegreeNetwork($this->entity['id'], $options); $count = EntityApi::getSecondDegreeNetwork($this->entity['id'], $options, $countOnly = true); //hack to get the pager working with a slice of data if ($this->page > 1) { $filler = array_fill(0, ($this->page - 1) * $this->num, null); $entities = array_merge($filler, $entities); } $this->donor_pager = new LsDoctrinePager($entities, $this->page, $this->num); $this->donor_pager->setNumResults($count); } else { //write custom queries to get total amounts per recipient //first get everyone with position or membership in this org $db = Doctrine_Manager::connection(); $sql = 'SELECT DISTINCT r.entity1_id FROM relationship r ' . 'WHERE r.entity2_id = ? AND r.category_id IN (1, 3) AND r.is_deleted = 0'; $stmt = $db->execute($sql, array($this->entity['id'])); $relatedIds = $stmt->fetchAll(PDO::FETCH_COLUMN); if (count($relatedIds)) { //now get recipients, totals, and degree1_ids $select = 'e.*, r.entity2_id AS degree2_id, GROUP_CONCAT(DISTINCT r.entity1_id) AS degree1_ids, COUNT(DISTINCT r.entity1_id) AS num, SUM(r.amount) AS total'; $from = 'relationship r FORCE INDEX (entity1_category_idx) LEFT JOIN entity e ON (e.id = r.entity2_id)'; $where = 'r.entity1_id IN (' . implode(',', $relatedIds) . ') AND r.category_id = ? AND r.is_deleted = 0'; $sql = 'SELECT ' . $select . ' FROM ' . $from . ' WHERE ' . $where . ' GROUP BY r.entity2_id ORDER BY total DESC'; $stmt = $db->execute($sql, array(RelationshipTable::DONATION_CATEGORY)); $entities = $stmt->fetchAll(PDO::FETCH_ASSOC); } else { $entities = array(); } //use pager to limit shown results $this->person_recipient_pager = new LsDoctrinePager($entities, $this->page, $this->num); } }
public function executeInterlocksMap($request) { $this->checkEntity($request, false, false); $num = $request->getParameter("num", 6); $degree1_num = $request->getParameter("degree1_num", 10); $order1 = $this->entity['primary_ext'] == 'Person' ? 1 : 2; $order2 = $this->entity['primary_ext'] == 'Person' ? 2 : 1; $options = array('cat1_ids' => RelationshipTable::POSITION_CATEGORY . ',' . RelationshipTable::MEMBERSHIP_CATEGORY, 'order1' => $order1, 'cat2_ids' => RelationshipTable::POSITION_CATEGORY . ',' . RelationshipTable::MEMBERSHIP_CATEGORY, 'order2' => $order2, 'page' => 1, 'num' => $num); $interlocks = EntityApi::getSecondDegreeNetwork($this->entity['id'], $options); $degree1_ids = array(); $degree2_ids = array(); $degree1_scores = array(); foreach ($interlocks as $i) { $new_degree1_ids = explode(",", $i["degree1_ids"]); foreach ($new_degree1_ids as $id) { $degree1_scores[$id] = isset($degree1_scores[$id]) ? $degree1_scores[$id] + 1 : 1; } $degree1_ids = array_merge($degree1_ids, $new_degree1_ids); $degree2_ids[] = $i["id"]; } arsort($degree1_scores); $degree1_ids = array_keys($degree1_scores); $degree1_ids = array_slice($degree1_ids, 0, $degree1_num); $entity_ids = array_unique(array_merge(array($this->entity["id"]), $degree1_ids, $degree2_ids)); $cats = array(RelationshipTable::POSITION_CATEGORY, RelationshipTable::MEMBERSHIP_CATEGORY); $data = EntityTable::getEntitiesAndRelsForMap($entity_ids, $cats); /* foreach ($data["entities"] as $i => $entity) { $data["entities"][$i]["url"] = preg_replace("/map$/", "interlocksMap", $entity["url"]); } */ $entities = array(); foreach ($data["entities"] as $e) { array_push($entities, $e); } $this->data = json_encode(array("entities" => $entities, "rels" => $data["rels"])); $this->degree1_ids = $degree1_ids; $this->degree2_ids = $degree2_ids; }