public function testPluck() { // Arrange $a = [['foo' => 'bar', 'bis' => 'ter'], ['foo' => 'bar2', 'bis' => 'ter2']]; // Act $x = __::pluck($a, 'foo'); // Assert $this->assertEquals(['bar', 'bar2'], $x); }
/* ======================= Configuration Bootstrapping ----------------------- */ $config = new ConfigManager(SUITE, SVC); /* ======================= Get the currently configured Subscriptions ----------------------- */ $couch_subscriptions = new couchClient($config->databases->subscriptions->connectionString, $config->databases->subscriptions->name); $subscription_results = $couch_subscriptions->getView('views','subscriptions'); if( $subscription_results->total_rows == 0 || empty($subscription_results->rows)){ echo "No Subscriptions Found. Exiting\n"; exit(0); } $subscriptions = __::pluck($subscription_results->rows, "value"); /* ======================= Get the currently defined Talking Points ----------------------- */ $couch_talkingPoints = new couchClient($config->databases->talkingpoints->connectionString, $config->databases->talkingpoints->name); $points_results = $couch_talkingPoints->key(date("m-d-Y"))->getView('views','pointsByDate'); if( $points_results->total_rows == 0 || empty($points_results->rows)){ echo "No Talking Points Found. Exiting\n"; exit(0); } $points = __::reduce( $points_results->rows, function($memo, $row){
public function testPluck() { $object = array(array('a' => '1', 'b' => '643'), array('a' => '2', 'b' => '423'), array('a' => '3', 'b' => '123')); $return = array(1, 2, 3); $result = __::pluck($object, 'a'); $this->assertEquals($return, $result); }
public function testGroupBy() { // from js $parity = __::groupBy(array(1, 2, 3, 4, 5, 6), function ($num) { return $num % 2; }); $this->assertEquals(array(array(2, 4, 6), array(1, 3, 5)), $parity, 'created a group for each value'); // extra $parity = __(array(1, 2, 3, 4, 5, 6))->groupBy(function ($num) { return $num % 2; }); $this->assertEquals(array(array(2, 4, 6), array(1, 3, 5)), $parity, 'created a group for each value using OO-style call'); $vals = array(array('name' => 'rejected', 'yesno' => 'no'), array('name' => 'accepted', 'yesno' => 'yes'), array('name' => 'allowed', 'yesno' => 'yes'), array('name' => 'denied', 'yesno' => 'no')); $grouped = __::groupBy($vals, 'yesno'); $this->assertEquals('rejected denied', join(' ', __::pluck($grouped['no'], 'name')), 'pulls no entries'); $this->assertEquals('accepted allowed', join(' ', __::pluck($grouped['yes'], 'name')), 'pulls yes entries'); // docs $result = __::groupBy(array(1, 2, 3, 4, 5), function ($n) { return $n % 2; }); $this->assertEquals(array(0 => array(2, 4), 1 => array(1, 3, 5)), $result); $values = array(array('name' => 'Apple', 'grp' => 'a'), array('name' => 'Bacon', 'grp' => 'b'), array('name' => 'Avocado', 'grp' => 'a')); $expected = array('a' => array(array('name' => 'Apple', 'grp' => 'a'), array('name' => 'Avocado', 'grp' => 'a')), 'b' => array(array('name' => 'Bacon', 'grp' => 'b'))); $this->assertEquals($expected, __::groupBy($values, 'grp')); }
} // We're okay to proceed $updates = json_decode($body, true); if ($updates['object'] == 'user') { foreach ($updates['entry'] as $entry) { $uid = $entry['uid']; foreach ($entry['changed_fields'] as $field) { if ($field == 'friends') { $user = $c['db']->users('fb_id = ?', $uid)->fetch(); if ($user) { $data = unserialize($user['friends']); $friendIDs = __::pluck($data, 'id'); $facebook->setAccessToken($user['fb_access_token']); $response = $facebook->api('/me/friends'); $friendsData = $response['data']; $newFriendIDs = __::pluck($friendsData, 'id'); $removedIDs = array_diff($friendIDs, $newFriendIDs); if (count($removedIDs)) { $html = '<p>The following people have un-friended you:</p>'; $html .= '<ul>'; foreach ($removedIDs as $id) { $friend = $facebook->api($id); $html .= '<ul>' . $friend['name'] . '</li>'; } $html .= '</ul>'; $mail = $c['phpmailer']; $mail->AddAddress($user['email'], $user['name']); $mail->Subject = 'Someone has un-friended you on Facebook!'; $mail->Body = $html; $mail->Send(); }