merge() public method

Returns a new combined collection
public merge ( $collection2 ) : Collection
return Collection
Beispiel #1
0
 public static function newMerged(array $decks)
 {
     $merged = new Collection();
     foreach ($decks as $deck) {
         $merged->merge($deck);
     }
     return new static($merged);
 }
 public function testMerge()
 {
     $collection1 = new Collection(['a', 'b']);
     $collection2 = new Collection(['a', 'c']);
     $collection3 = new Collection(['d', 'e']);
     $result = $collection1->merge($collection2, $collection3);
     $this->assertNotSame($collection1, $result);
     $this->assertInstanceOf(get_class($collection1), $result);
     $this->assertSame(['a', 'b', 'a', 'c', 'd', 'e'], (array) $result);
 }
function smarty_function_origin_picker($params, &$smarty)
{
    $gf = new GroupFilter(new PFC_And(new PFC_Not(new GFC_Namespace(Group::NS_USER)), new GFC_User(S::user(), Rights::admin())), new GFO_Score());
    $gs = $gf->get();
    if ($params['not_only_admin']) {
        $gfo = new GroupFilter(new PFC_And(new GFC_Namespace(array(Group::NS_BINET, Group::NS_FREE)), new GFC_User(S::user(), Rights::restricted())), new GFO_Score());
        $gso = $gfo->get()->diff($gs);
        $temp = new Collection();
        $temp->merge($gs)->merge($gso);
        $temp->select(GroupSelect::base());
        $smarty->assign('not_admin', $gso);
    } else {
        $gs = $gf->get()->select(GroupSelect::base());
    }
    $smarty->assign($params['out'], $gs);
}
 /**
  * @param string $table
  * @param mixed $hash
  * @param Context\Query $context
  * @return \Riverline\DynamoDB\Collection
  */
 public function query($table, $hash, Context\Query $context = null)
 {
     $collection = new Collection();
     do {
         try {
             $items = $this->connection->query($table, $hash, $context);
             $collection->merge($items);
             if ($items->more()) {
                 $context = $items->getNextContext();
             } else {
                 // End
                 break;
             }
         } catch (\Riverline\DynamoDB\Exception\ProvisionedThroughputExceededException $e) {
             // Continue
         }
     } while (true);
     return $collection;
 }
function smarty_function_target_picker($params, &$smarty)
{
    // Get user groups
    $everybody_groups = S::user()->castes(Rights::everybody())->groups();
    // Get Frankiz special groups
    $fkz = new Collection('Group');
    $fkz->add(array('everybody', 'public'));
    $fkz->select(new GroupSelect(array('description')));
    // BDE, study and promo groups
    $study_groups = $everybody_groups->filter('ns', Group::NS_BDE);
    $study_groups->merge($everybody_groups->filter('ns', Group::NS_PROMO));
    $study_groups->merge($everybody_groups->filter('ns', Group::NS_STUDY));
    // Get all groups user is admin, without the user one
    $gs = S::user()->castes(Rights::admin())->groups();
    $gs->diff($fkz);
    $gs->filter(function ($g) {
        return $g->ns() != Group::NS_USER;
    });
    if ($params['even_only_friend']) {
        $gfo = new GroupFilter(new PFC_And(new GFC_Namespace(array(Group::NS_BINET, Group::NS_FREE)), new GFC_User(S::user(), Rights::everybody())), new GFO_Score());
        $gso = $gfo->get()->diff($gs)->diff($fkz);
        $temp = new Collection();
        $temp->merge($gs)->merge($gso);
        $temp->select(GroupSelect::base());
        $smarty->assign('only_friend', $gso);
        $temp = new Collection();
        $temp->merge($gs)->merge($fkz)->merge($gso);
        $temp->select(GroupSelect::base());
    } else {
        $temp = new Collection();
        $temp->merge($gs)->merge($fkz);
        $temp->select(GroupSelect::base());
    }
    $smarty->assign($params['user_groups'], $gs);
    $smarty->assign($params['fkz_groups'], $fkz);
    $smarty->assign($params['study_groups'], $study_groups);
    $smarty->assign($params['own_group'], S::user()->group());
}
Beispiel #6
0
 public function test3_Appending()
 {
     $collection = new Collection(new Yaml());
     $collection_of_values = new Collection(new Yaml());
     # appending
     static::$collection->append('part1.item2', ['name' => 'Janice']);
     $this->assertEquals('Janice', static::$collection->get('part1.item2.name'));
     static::$collection->forget('part1');
     static::$collection->append('part1', ['item2' => ['name' => 'Janice']]);
     static::$collection->with('with', 'with test');
     $this->assertEquals('with test', static::$collection->get('with'));
     $this->assertTrue(static::$collection->count() === 2);
     static::$collection->forget('with');
     $this->assertTrue(static::$collection->count() === 1);
     # setup
     $test_array = ['merge_with' => ['merge' => 'this']];
     $collection_of_values->with($test_array);
     # test with an array
     $collection->merge($test_array);
     $this->assertEquals($collection->get('merge_with.merge'), 'this');
     $collection->forget('merge_with');
     # test with a collection as a value object
     $collection->merge($collection_of_values);
     $this->assertEquals($collection->get('merge_with.merge'), 'this');
     $collection->forget('merge_with');
     # test with value object
     $value_object = new \stdClass();
     $value_object->merge_with = $test_array['merge_with'];
     $collection->merge($value_object);
     $this->assertEquals($collection->get('merge_with.merge'), 'this');
     # test with flat array
     $collection->merge(Util::array_from_str('merge with'));
     $this->assertEquals($collection->get('merge'), NULL);
     $this->assertEquals($collection->get('with'), NULL);
     $this->setExpectedException('InvalidArgumentException', "Cannot append an already existing key: 'part1'");
     static::$collection->append('part1', ['item2' => ['name' => 'Mary']]);
 }
Beispiel #7
0
 function handler_groups($page)
 {
     global $globals;
     $except = new PFC_True();
     $max = $globals->groups->limit;
     // Re-fetch user's groups
     S::user()->select(UserSelect::castes());
     // Fetch samples of other groups
     $binet = new GroupFilter(new PFC_And(new GFC_Namespace(Group::NS_BINET), $except), new GFO_Score(true));
     $binet = $binet->get(new PlLimit($max));
     $course = new GroupFilter(new PFC_And(new GFC_Namespace(Group::NS_COURSE), $except), new GFO_Score(true));
     $course = $course->get(new PlLimit($max));
     $free = new GroupFilter(new PFC_And(new GFC_Namespace(Group::NS_FREE), $except), new GFO_Score(true));
     $free = $free->get(new PlLimit($max));
     // Load associated datas
     $temp = new Collection('Group');
     $temp->merge($binet)->merge($course)->merge($free);
     $temp->select(GroupSelect::base());
     // Fetch the total count of groups
     $allf = new GroupFilter(new GFC_Visible());
     $total = $allf->getTotalCount();
     $user_binet = S::user()->castes()->groups()->filter('ns', Group::NS_BINET)->remove($binet);
     $page->assign('binet', $binet);
     $page->assign('user_binet', $user_binet);
     $user_course = S::user()->castes()->groups()->filter('ns', Group::NS_COURSE)->remove($course);
     $page->assign('course', $course);
     $page->assign('user_course', $user_course);
     $user_free = S::user()->castes()->groups()->filter('ns', Group::NS_FREE)->remove($free);
     $page->assign('free', $free);
     $page->assign('user_free', $user_free);
     $page->assign('user', S::user());
     $page->assign('total', $total);
     $page->assign('title', 'Groupes');
     $page->changeTpl('groups/groups.tpl');
     $page->addCssLink('groups.css');
 }
 public function testMergeCollection()
 {
     $this->collection->merge(new Collection(['test']));
     $this->assertEquals(5, $this->collection->count());
     $this->assertEquals('test', $this->collection->last());
 }
Beispiel #9
0
 public function targetCastes()
 {
     $target_castes = new Collection();
     $target_castes->merge($this->castes(Rights::restricted()));
     $target_castes->merge($this->castes(Rights::everybody()));
     return $target_castes;
 }
Beispiel #10
0
 public function __call($method, $arguments)
 {
     $className = $this->className;
     $inferedMethod = 'batch' . ucfirst($method);
     if (method_exists($className, $inferedMethod)) {
         // Call $className->batch$method($this->collected, ...)
         array_unshift($arguments, $this->collected);
         $r = forward_static_call_array(array($className, $inferedMethod), $arguments);
         if (!is_array($r)) {
             return $r;
         }
         $c = new Collection($className);
         if (!empty($r)) {
             $c->add($r);
         }
         return $c;
     }
     // If there is no argument, build an array with values from $collected->$method
     if (empty($arguments)) {
         $values = array_map(function ($mixed) use($method) {
             return $mixed->{$method}();
         }, $this->collected);
         // Try magic things with the schema
         $schema = Schema::get($className);
         if ($schema->isScalar($method)) {
             // Return an array of scalar values
             return $values;
         } elseif ($schema->isObject($method)) {
             // Return a collection
             return Collection::fromArray($values, $schema->objectType($method));
         } elseif ($schema->isFlagset($method)) {
             // Return a merged flagset
             $fs = new PlFlagSet();
             foreach ($values as $flags) {
                 foreach ($flags as $flag) {
                     $fs->addFlag($flag);
                 }
             }
             return $fs;
         } elseif ($schema->isCollection($method)) {
             // Return a merged collection
             $col = new Collection();
             foreach ($values as $c) {
                 $col->merge($c);
             }
             return $col;
         }
         throw new Exception("Unknown automatic field {$method} is schema for {$className}");
     }
     throw new Exception("The method {$className}::{$inferedMethod} doesn't exist");
 }
Beispiel #11
0
 public static function batchLeaves(array $nodes)
 {
     $leaves = new Collection();
     foreach ($nodes as $n) {
         $leaves->merge($n->leaves());
     }
     return $leaves;
 }