public function updateApps() { $apps = new SteamApps($this->_getApi()); $apps = $apps->getAppList(); $new = Objects::ppull($apps, 'name', 'appid'); $current = Manager::table('apps')->lists('id'); $diff = array_diff(array_keys($new), $current); $apps = []; foreach ($diff as $appId) { $apps[] = ['id' => $appId, 'name' => $new[$appId], 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]; } Manager::table('apps')->insert($apps); // Clear cache $cache = new AppsLatestCache(); $cache->remove(); error_log('Apps updated'); die('Apps updated'); }
public function sum($property = 'id') { $this->_prepareDaos(); if (empty($this->_daos)) { return null; } return array_sum(Objects::ppull($this->_daos, $property)); }
public function testPpull() { $a = new stdClass(); $a->name = "a"; $a->value = 1; $b = new stdClass(); $b->name = "b"; $b->value = 2; $c = new stdClass(); $c->name = "c"; $c->value = 3; $list = [$a, $b, $c]; $expected = ["a", "b", "c"]; $this->assertEquals($expected, Objects::ppull($list, 'name')); $expected = ['a' => 1, 'b' => 2, 'c' => 3]; $this->assertEquals($expected, Objects::ppull($list, 'value', 'name')); $expected = ['a' => $a, 'b' => $b, 'c' => $c]; $this->assertEquals($expected, Objects::ppull($list, null, 'name')); }
/** * Access a property on a list of objects. Short for "property pull", this * function works just like @{function:mpull}, except that it accesses object * properties instead of methods. This function simplifies a common type of * mapping operation: * * COUNTEREXAMPLE * $names = array(); * foreach ($objects as $key => $object) { * $names[$key] = $object->name; * } * * You can express this more concisely with ppull(): * * $names = ppull($objects, 'name'); * * ppull() takes a third argument, which allows you to do the same but for * the array's keys: * * COUNTEREXAMPLE * $names = array(); * foreach ($objects as $object) { * $names[$object->id] = $object->name; * } * * This is the ppull version(): * * $names = ppull($objects, 'name', 'id'); * * If you pass ##null## as the second argument, the objects will be preserved: * * COUNTEREXAMPLE * $id_map = array(); * foreach ($objects as $object) { * $id_map[$object->id] = $object; * } * * With ppull(): * * $id_map = ppull($objects, null, 'id'); * * See also @{function:mpull}, which works similarly but calls object methods * instead of accessing object properties. * * @param $list array Some list of objects. * @param $property string|null Determines which **values** will appear * in the result * array. Use a string like 'name' to store the value of * accessing the named property in each value, or * ##null## to preserve the original objects. * @param $keyProperty string|null Determines how **keys** will be assigned * in the result * array. Use a string like 'id' to use the result of * accessing the named property as each object's key, or * ##null## to preserve the original keys. * * @return array A dictionary with keys and values derived according * to whatever you passed as $property and $key_property. * @group util * * @deprecated */ function ppull(array $list, $property, $keyProperty = null) { return \Packaged\Helpers\Objects::ppull($list, $property, $keyProperty); }