public function testSinglePolicy() { $p = new MySociety\TheyWorkForYou\Policies(); $this->assertEquals(count($p->getArray()), 74); $p = $p->limitToSet('health'); $this->assertEquals(count($p->getArray()), 4); $p = new MySociety\TheyWorkForYou\Policies(); $p = $p->limitToSet('education'); $this->assertEquals(count($p->getArray()), 5); $p = new MySociety\TheyWorkForYou\Policies(363); $this->assertEquals(count($p->getArray()), 1); $p = $p->limitToSet('health'); $this->assertEquals(count($p->getArray()), 1); $p = new MySociety\TheyWorkForYou\Policies(363); $p = $p->limitToSet('education'); $this->assertEquals(count($p->getArray()), 0); }
if ($policyID) { $data['policydivisions'] = $divisions->getMemberDivisionsForPolicy($policyID); } else { $data['policydivisions'] = $divisions->getAllMemberDivisionsByPolicy(); } // data for the 'what else would you like to see' question box $data['user_code'] = bin2hex(urandom_bytes(16)); $data['auth_signature'] = auth_sign_with_shared_secret($data['user_code'], OPTION_SURVEY_SECRET); $data['page_url'] = "http://" . DOMAIN . $_SERVER['REQUEST_URI'] . ($policyID ? '&' : '?') . 'answered=1'; $data['answered_q'] = $answered_q; // Send the output for rendering MySociety\TheyWorkForYou\Renderer::output('mp/divisions', $data); break; case '': default: $policiesList = new MySociety\TheyWorkForYou\Policies(); $policies = $policiesList->limitToSet('summary')->shuffle(); // Generate limited voting record list $data['policyPositions'] = new MySociety\TheyWorkForYou\PolicyPositions($policies, $MEMBER, 6); // Send the output for rendering MySociety\TheyWorkForYou\Renderer::output('mp/profile', $data); break; } ///////////////////////////////////////////////////////// // SUPPORTING FUNCTIONS /* Person lookup functions */ function get_person_by_id($pid) { global $pagetype, $this_page; $MEMBER = new MySociety\TheyWorkForYou\Member(array('person_id' => $pid)); if (!$MEMBER->valid) {
if ($policyID) { $data['policydivisions'] = $divisions->getMemberDivisionsForPolicy($policyID); } else { $data['policydivisions'] = $divisions->getAllMemberDivisionsByPolicy(); } // data for the 'what else would you like to see' question box $data['user_code'] = bin2hex(urandom_bytes(16)); $data['auth_signature'] = auth_sign_with_shared_secret($data['user_code'], OPTION_SURVEY_SECRET); $data['page_url'] = "http://" . DOMAIN . $_SERVER['REQUEST_URI'] . ($policyID ? '&' : '?') . 'answered=1'; $data['answered_q'] = $answered_q; // Send the output for rendering MySociety\TheyWorkForYou\Renderer::output('mp/divisions', $data); break; case '': default: $policiesList = new MySociety\TheyWorkForYou\Policies(); $policies = $policiesList->limitToSet('summary')->shuffle(); // Generate limited voting record list $data['policyPositions'] = new MySociety\TheyWorkForYou\PolicyPositions($policies, $MEMBER, 6); // generate party policy diffs $party = new MySociety\TheyWorkForYou\Party($MEMBER->party()); $positions = new MySociety\TheyWorkForYou\PolicyPositions($policiesList, $MEMBER); $party_positions = $party->getAllPolicyPositions($policiesList); $policy_diffs = $MEMBER->getPartyPolicyDiffs($party, $policiesList, $positions, true); $data['sorted_diffs'] = $policy_diffs; $data['party_positions'] = $party_positions; $data['positions'] = $positions->positionsById; $data['policies'] = $policiesList->getPolicies(); // Send the output for rendering MySociety\TheyWorkForYou\Renderer::output('mp/profile', $data); break;