Source of file LinksQueryCreator.php
Size: 2,488 Bytes - Last Modified: 2021-12-24T06:50:05+00:00
/var/www/docs.ssmods.com/process/src/src/graphql/LinksQueryCreator.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 | <?php namespace gorriecoe\Link\GraphQL; use GraphQL\Type\Definition\ResolveInfo; use GraphQL\Type\Definition\Type; use SilverStripe\GraphQL\OperationResolver; use SilverStripe\GraphQL\QueryCreator; use gorriecoe\Link\Models\Link; /** * LinksQueryCreator * * @package silverstripe-link */ class LinksQueryCreator extends QueryCreator implements OperationResolver { public function attributes() { return [ 'name' => 'links' ]; } public function args() { return [ 'ID' => [ 'type' => Type::id() ], 'Type' => [ 'type' => Type::string() ], 'Title' => [ 'type' => Type::string() ], 'URL' => [ 'type' => Type::string() ], 'Email' => [ 'type' => Type::string() ], 'Phone' => [ 'type' => Type::string() ], 'OpenInNewWindow' => [ 'type' => Type::boolean() ], 'LinkURL' => [ 'type' => Type::string() ], 'Template' => [ 'type' => Type::string() ] ]; } public function type() { return Type::listOf($this->manager->getType('link')); } public function resolve($object, array $args, $context, ResolveInfo $info) { $link = Link::singleton(); if (!$link->canView($context['currentUser'])) { throw new \InvalidArgumentException(sprintf( '%s view access not permitted', Link::class )); } $filters = [ 'ID', 'Title:PartialMatch', 'Type', 'URL:PartialMatch', 'Email:PartialMatch', 'Phone', 'OpenInNewWindow', ]; return $this->Filter(Link::get(), $filters, $args); } public function Filter($list, array $filters, array $args) { foreach ($filters as $filter) { $modifier = ''; if(strpos($filter, ':') !== false) { list($filter, $modifier) = explode(':', $filter); $modifier = ':' . $modifier; } if (isset($args[$filter])) { $list = $list->filter($filter . $modifier, $args[$filter]); } } return $list; } } |