Creates an array suitable for a map of args in a field
@param Manager $manager
@return array
559268
public function toArray(Manager $manager = null)
    {
        $typeValue = null;
        $type = $this->type;
        if (!$type instanceof Type) {
            if (!$manager) {
                throw new InvalidArgumentException(sprintf(
                    'Custom type %s provided, but no %s instance was given to %s',
                    $type,
                    Manager::class,
                    __CLASS__
                ));
            }
            $type = $manager->getType($type);
        }

        $args = [
            'description' => $this->description,
            'type' => $this->required ? Type::nonNull($type) : $type,
        ];

        if ($this->defaultValue !== null) {
            $args['defaultValue'] = $this->defaultValue;
        }

        return $args;
    }
438081
public function load(ObjectManager $manager)
    {
        // resource type attributes : name, listable, navigable, class
        $resourceTypes = array(
            array('file', true),
            array('directory', true),
            array('text', true),
            array('resource_shortcut', false),
            array('activity', true)
        );

        $types[] = array();

        foreach ($resourceTypes as $attributes) {
            $type = new ResourceType();
            $type->setName($attributes[0]);
            $type->setExportable($attributes[1]);
            $manager->persist($type);
            $this->container->get('claroline.manager.mask_manager')->addDefaultPerms($type);
            $types[$attributes[0]] = $type;
        }

        //add special actions.
        $composeDecoder = new MaskDecoder();
        $composeDecoder->setValue(pow(2, 10));
        $composeDecoder->setName('compose');
        $composeDecoder->setResourceType($types['activity']);
        $manager->persist($composeDecoder);

        $activityMenu = new MenuAction();
        $activityMenu->setName('compose');
        $activityMenu->setAsync(false);
        $activityMenu->setIsCustom(true);
        $activityMenu->setValue(pow(2, 10));
        $activityMenu->setResourceType($types['activity']);
        $activityMenu->setIsForm(false);
        $manager->persist($activityMenu);

        $updateFile = new MenuAction();
        $updateFile->setName('update_file');
        $updateFile->setAsync(true);
        $updateFile->setIsCustom(true);
        $updateFile->setIsForm(false);
        $updateFile->setResourceType($types['file']);
        //16 is default for edit
        $updateFile->setValue(16);
        $manager->persist($updateFile);

        $fileAction = new ActivityRuleAction();
        $fileAction->setAction('resource-read');
        $fileAction->setResourceType($types['file']);
        $manager->persist($fileAction);

        $textAction = new ActivityRuleAction();
        $textAction->setAction('resource-read');
        $textAction->setResourceType($types['text']);
        $manager->persist($textAction);

        $badgeAwardAction = new ActivityRuleAction();
        $badgeAwardAction->setAction('badge-awarding');
        $manager->persist($badgeAwardAction);
    }
860486
public function getGraphQLType(Manager $manager = null)
    {
        $type = $this->createTypeParser()->getType();
        $name = $type->name;
        if ($manager && !$this->isInternal($name)) {
            return $manager->getType($name);
        }

        return $type;
    }
750988
public function import(Manager $manager, ImportRecordsDataTable $importRecordsDataTable)
    {
        return $importRecordsDataTable->with([
            'resource' => $manager,
            'tabs' => 'managerarea.attributes.tabs',
            'url' => route('managerarea.attributes.stash'),
            'id' => "managerarea-attributes-{$manager->getRouteKey()}-import-table",
        ])->render('cortex/foundation::managerarea.pages.datatable-dropzone');
    }
537469
private function getArguments($argsNumber, $arguments)
    {
        if ($argsNumber == 1 && is_string($arguments)) {
            return [$arguments];
        } elseif ($argsNumber === count($arguments)) {
            return $arguments;
        }

        for ($i = 0; $i < $argsNumber; $i++) {
            if (array_key_exists($i, $arguments)) {
                $args[] = $arguments[$i];
                continue;
            }

            return $args;
        }

        return [];
    }
742154
public function load(ObjectManager $manager)
    {
        /**
         * Pack.
         *
         * @var CategoryInterface     $category
         * @var ManufacturerInterface $manufacturer
         * @var CurrencyInterface     $currency
         * @var ObjectDirector        $packDirector
         */
        $category = $this->getReference('category');
        $manufacturer = $this->getReference('manufacturer');
        $product = $this->getReference('product');
        $productReduced = $this->getReference('product-reduced');
        $variant = $this->getReference('variant-red-small');
        $currency = $this->getReference('currency-dollar');
        $packDirector = $this->getDirector('purchasable_pack');

        // Id assigned = 9
        $pack = $packDirector
            ->create()
            ->setName('pack')
            ->setSlug('pack')
            ->setDescription('my pack description')
            ->setShortDescription('my pack short description')
            ->addCategory($category)
            ->setPrincipalCategory($category)
            ->setManufacturer($manufacturer)
            ->addPurchasable($product)
            ->addPurchasable($productReduced)
            ->addPurchasable($variant)
            ->setStockType(ElcodiProductStock::SPECIFIC_STOCK)
            ->setStock(10)
            ->setPrice(Money::create(5000, $currency))
            ->setSku('pack-sku-code-1')
            ->setHeight(30)
            ->setWidth(30)
            ->setDepth(30)
            ->setWeight(200)
            ->setEnabled(true);

        $packDirector->save($pack);
        $this->addReference('pack', $pack);

        // Id assigned = 10
        $packInherit = $packDirector
            ->create()
            ->setName('pack-inherit')
            ->setSlug('pack-inherit')
            ->setDescription('my pack inherit description')
            ->setShortDescription('my pack inherit short description')
            ->addCategory($category)
            ->setPrincipalCategory($category)
            ->setManufacturer($manufacturer)
            ->addPurchasable($product)
            ->addPurchasable($productReduced)
            ->addPurchasable($variant)
            ->setStockType(ElcodiProductStock::INHERIT_STOCK)
            ->setPrice(Money::create(5000, $currency))
            ->setSku('pack-inherit-sku-code-1')
            ->setHeight(30)
            ->setWidth(30)
            ->setDepth(30)
            ->setWeight(200)
            ->setEnabled(true);

        $this->storeProductImage(
            $packInherit,
            'pack.jpg'
        );

        $packDirector->save($packInherit);
        $this->addReference('pack-inherit', $packInherit);
    }
1221013
protected function getPdo(Manager $manager, $environment): PDO
    {
        /* @var AdapterWrapper $dbAdapter */
        $dbAdapter = $manager->getEnvironment($environment)->getAdapter();

        if ($dbAdapter instanceof PdoAdapter) {
            $pdo = $dbAdapter->getConnection();
        } elseif ($dbAdapter instanceof AdapterWrapper) {
            $dbAdapter->connect();
            $pdo = $dbAdapter->getAdapter()->getConnection();
        } else {
            throw new RuntimeException('Adapter not found');
        }
        if (empty($pdo)) {
            $pdo = $dbAdapter->getOption('connection');
        }
        if (!$pdo instanceof PDO) {
            throw new RuntimeException('PDO database connection not found.');
        }

        return $pdo;
    }
477081
public function load(ObjectManager $manager)
    {
        $food          = new Category('Food');
        $fruit         = new Category('Fruit');

        $apples        = new Category('Apples');
        $apples->setUnitDescriptionSingular('lb');
        $apples->setUnitDescriptionPlural('lbs');

        $vegetables    = new Category('Vegetables');

        $tomatoes      = new Category('Tomatoes');
        $tomatoes->setUnitDescriptionSingular('lb');
        $tomatoes->setUnitDescriptionPlural('lbs');

        $carrots       = new Category('Carrots');
        $carrots->setUnitDescriptionSingular('lb');
        $carrots->setUnitDescriptionPlural('lbs');

        $sweetPotatoes = new Category('Sweet Potatoes');
        $sweetPotatoes->setUnitDescriptionSingular('lb');
        $sweetPotatoes->setUnitDescriptionPlural('lbs');

        $onions        = new Category('Onions');
        $onions->setUnitDescriptionSingular('lb');
        $onions->setUnitDescriptionPlural('lbs');

        $meat          = new Category('Meat');
        $dairy         = new Category('Dairy');

        $milk          = new Category('Milk');
        $milk->setUnitDescriptionSingular('quart');
        $milk->setUnitDescriptionPlural('quarts');

        $eggs          = new Category('Eggs');
        $eggs->setUnitDescriptionSingular('dozen');
        $eggs->setUnitDescriptionPlural('dozen');

        $food->addCategory($fruit);
          $fruit->addCategory($apples);
        $food->addCategory($vegetables);
          $vegetables->addCategory($tomatoes);
          $vegetables->addCategory($carrots);
          $vegetables->addCategory($sweetPotatoes);
          $vegetables->addCategory($onions);
        $food->addCategory($meat);
        $food->addCategory($dairy);
          $dairy->addCategory($milk);
          $dairy->addCategory($eggs);

        $manager->persist($food);
        $manager->flush();

        $this->addReference('eggs-category', $eggs);
        $this->addReference('tomatoes-category', $tomatoes);
        $this->addReference('milk-category', $milk);
        $this->addReference('apples-category', $apples);
        $this->addReference('carrots-category', $carrots);
        $this->addReference('onions-category', $onions);
        $this->addReference('sweet-potatoes-category', $sweetPotatoes);
    }
1233292
protected function createConnection(Manager $manager)
    {
        return Connection::create($this->getName())
            ->setConnectionType(function () use ($manager) {
                return $this->getType($manager);
            })
            ->setConnectionResolver($this->createResolverFunction())
            ->setArgs($this->createArgs($manager))
            ->setSortableFields($this->getSortableFields())
            ->setDefaultLimit($this->getPaginationLimit())
            ->setMaximumLimit($this->getMaximumPaginationLimit());
    }
532251
public function getArticle(&$manager = null) {
		$this->manager = $manager;
		$article = $this->json;

		return [
			'index' => $this->index,
			'thumb_material_media_id' => $article['thumb_material_media_id'],
			'articles' => $article,
		];

	}
970284
protected function createFields(Manager $manager)
    {
        $fieldMap = [];
        $instance = $this->getDataObjectInstance();
        $extraDataObjects = $this->nestedDataObjectClasses();
        $this->fields->removeDuplicates('Name');

        if (!$this->fields->exists()) {
            $this->addFields(
                Config::inst()->get(self::class, 'default_fields')
            );
        }

        $resolver = function ($obj, $args, $context, $info) {
            /**
             * @var DataObject $obj
             */
            $field = $obj->obj($info->fieldName);
            // return the raw field value, or checks like `is_numeric()` fail
            if ($field instanceof DBField && $field->isInternalGraphQLType()) {
                return $field->getValue();
            }
            return $field;
        };

        foreach ($this->fields as $fieldData) {
            $fieldName = $fieldData->Name;
            if (!StaticSchema::inst()->isValidFieldName($instance, $fieldName)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Invalid field "%s" on %s',
                        $fieldName,
                        $this->getDataObjectClass()
                    )
                );
            }

            $result = $instance->obj($fieldName);

            if ($result instanceof SS_List) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Fieldname %s added to %s returns a list. This should be defined as a nested query using addNestedQuery(%s)',
                        $fieldName,
                        $this->getDataObjectClass(),
                        $fieldName
                    )
                );
            }

            if ($result instanceof DBField) {
                /** @var DBField|TypeCreatorExtension $result */
                $fieldMap[$fieldName] = [];
                $fieldMap[$fieldName]['type'] = $result->getGraphQLType($manager);
                $fieldMap[$fieldName]['resolve'] = $resolver;
                $fieldMap[$fieldName]['description'] = $fieldData->Description;
            }
        }

        foreach ($extraDataObjects as $fieldName => $className) {
            $description = $this->getFieldDescription($fieldName);
            $fieldMap[$fieldName] = [
                'type' => StaticSchema::inst()->fetchFromManager($className, $manager),
                'description' => $description,
                'resolve' => $resolver,
            ];
        }

        foreach ($this->nestedQueries as $name => $scaffolder) {
            $scaffold = $scaffolder->scaffold($manager);
            $scaffold['name'] = $name;
            $fieldMap[$name] = $scaffold;
        }

        return $fieldMap;
    }
741745
public function load(ObjectManager $manager)
    {
        $user = new User();
        $user->setFirstname('admin');
        $user->setFirstname('admin');
        $user->setUsername('admin');
        $user->setEmail('admin@test.com');
        $user->setState(1);

        $newPass = 'playground';

        $bcrypt = new Bcrypt;
        $bcrypt->setCost(14);

        $pass = $bcrypt->create($newPass);
        $user->setPassword($pass);

        $user->addRole(
            $this->getReference('admin-role') // load the stored reference
        );

        $manager->persist($user);

        $manager->flush();

        $user = new User();
        $user->setFirstname('supervisor');
        $user->setFirstname('supervisor');
        $user->setUsername('supervisor');
        $user->setEmail('supervisor@test.com');
        $user->setState(1);

        $newPass = 'playground';

        $bcrypt = new Bcrypt;
        $bcrypt->setCost(14);

        $pass = $bcrypt->create($newPass);
        $user->setPassword($pass);

        $user->addRole(
            $this->getReference('supervisor-role') // load the stored reference
        );

        $manager->persist($user);

        $manager->flush();

        $user = new User();
        $user->setFirstname('game-manager');
        $user->setFirstname('game-manager');
        $user->setUsername('gamemanager');
        $user->setEmail('game-manager@test.com');
        $user->setState(1);

        $newPass = 'playground';

        $bcrypt = new Bcrypt;
        $bcrypt->setCost(14);

        $pass = $bcrypt->create($newPass);
        $user->setPassword($pass);

        $user->addRole(
            $this->getReference('game-role') // load the stored reference
        );

        $manager->persist($user);

        $manager->flush();
    }
446652
public function load(ObjectManager $manager)
    {
        $enTag = new Language;
        $enTag->setId('en');
        $enTag->setName(Translatable::createFromOriginalString('English'));

        $manager->persist($enTag);
        $manager->flush();
    }
39508
public function scaffold(Manager $manager)
    {
        if ($this->usePagination) {
            $paginationScaffolder = $this->getPaginationScaffolder($manager);

            return $paginationScaffolder->scaffold($manager);
        }

        return [
            'name' => $this->getName(),
            'description' => $this->getDescription(),
            'args' => $this->createArgs($manager),
            'type' => Type::listOf($this->getType($manager)),
            'resolve' => $this->createResolverFunction(),
        ];
    }
464134
public function load(ObjectManager $manager)
    {
        for($i=1; $i <= 4; $i++)
        {

            $post = new Post();
            $post->setName('title'.$i);
            $post->setSlug('title-'.$i);
            $post->setContent('content '.$i);
            $post->setCreatedAt(new \DateTime());

            $manager->persist($post);
            $manager->flush();

        }
    }
81134
public function scaffold(Manager $manager)
    {
        return [
            'name' => $this->getName(),
            'description' => $this->getDescription(),
            'args' => $this->createArgs($manager),
            'type' => $this->getType($manager),
            'resolve' => $this->createResolverFunction(),
        ];
    }
1106728
protected function getMappedArguments()
    {
        $requiredArgs = array(
            'client'       => 'Prefix',
            'tool-title'   => 'Tool title',
            'transparent'  => '(1 or 0)',
            'rotatable'    => '(1 or 0)',
            'movable'      => '(1 or 0)',
            'adjustable-x' => '(1 or 0)',
            'adjustable-y' => '(1 or 0)',
        );
        $argHelp = "<p>Required arguments are:</p><ul>";
        foreach ($requiredArgs as $key => $value) {
            $argHelp .= '<li>' . $key . ': ' . $value . '</li>';
        }
        $argHelp .= '</ul>';

        foreach ($requiredArgs as $key => $value) {
            // !string '0' is a valid entry!
            if (!isset($_POST[$key]) || $_POST[$key] === '') {
                throw new \Exception($argHelp);
                break;
            }
            // trim all, cast 0|1 to bool
            $_POST[$key] = trim($_POST[$key]);
            if (in_array($_POST[$key], array('0', '1'))) {
                $_POST[$key] = (bool)$_POST[$key];
            }
        }

        $_POST['client']           = strtoupper($_POST['client']);
        $_POST['tool-base']        = StringUtils::removeSpecChars($_POST['tool-title']);
        $_POST['tool-fn']          = StringUtils::camelize($_POST['tool-base']);
        $_POST['tool-obj']         = ucfirst($_POST['tool-fn']);
        $_POST['tool-id']          = strtolower($_POST['client']) . $_POST['tool-obj'];
        $_POST['is-transparent']   = json_encode($_POST['transparent']);
        $_POST['is-rotatable-tl']  = json_encode($_POST['rotatable']); // default position of rotator

                                        // only visible when not adjustable
        $_POST['is-rotatable-tr']  = json_encode($_POST['rotatable'] && (!$_POST['adjustable-x'] && !$_POST['adjustable-y']));
        $_POST['is-rotatable-br']  = json_encode($_POST['rotatable'] && (!$_POST['adjustable-x'] && !$_POST['adjustable-y']));

        $_POST['is-rotatable-bl']  = json_encode($_POST['rotatable']); // also default position of rotator

        // alternative positions, need to be configured manually
        $_POST['is-rotatable-t']  = json_encode(false);
        $_POST['is-rotatable-r']  = json_encode(false);
        $_POST['is-rotatable-b']  = json_encode(false);
        $_POST['is-rotatable-l']  = json_encode(false);

        $_POST['is-movable']       = json_encode($_POST['movable']);
        $_POST['is-adjustable-x']  = json_encode($_POST['adjustable-x']);
        $_POST['is-adjustable-y']  = json_encode($_POST['adjustable-y']);
        $_POST['is-adjustable-xy'] = json_encode($_POST['adjustable-x'] && $_POST['adjustable-y']);

        unset($_POST['transparent']);
        unset($_POST['rotatable']);
        unset($_POST['movable']);
        unset($_POST['adjustable-x']);
        unset($_POST['adjustable-y']);

        return $_POST;
    }