-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
310599a
commit 7cd555b
Showing
18 changed files
with
329 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.search-container { | ||
background: var(--kbin-input-bg); | ||
border: var(--kbin-input-border); | ||
border-radius: var(--kbin-rounded-edges-radius) !important; | ||
|
||
input.form-control { | ||
border-radius: 0 !important; | ||
border: none; | ||
background: transparent; | ||
margin: 0 .5em; | ||
padding: .5rem .25rem; | ||
} | ||
|
||
button { | ||
border-radius: 0 var(--kbin-rounded-edges-radius) var(--kbin-rounded-edges-radius) 0 !important; | ||
border: 0; | ||
padding: 1rem 0.5rem; | ||
|
||
&:not(:hover) { | ||
background: var(--kbin-input-bg); | ||
color: var(--kbin-input-text-color) !important; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Form; | ||
|
||
use App\Form\Type\MagazineAutocompleteType; | ||
use App\Form\Type\UserAutocompleteType; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
class SearchType extends AbstractType | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->setMethod('GET') | ||
->add('q', TextType::class, [ | ||
'required' => true, | ||
'attr' => [ | ||
'placeholder' => 'type_search_term', | ||
], | ||
]) | ||
->add('magazine', MagazineAutocompleteType::class, ['required' => false]) | ||
->add('user', UserAutocompleteType::class, ['required' => false]) | ||
->add('type', ChoiceType::class, [ | ||
'choices' => [ | ||
'search_type_all' => null, | ||
'search_type_entry' => 'entry', | ||
'search_type_post' => 'post', | ||
], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Form\Type; | ||
|
||
use App\Entity\Contracts\VisibilityInterface; | ||
use App\Entity\User; | ||
use App\Entity\UserBlock; | ||
use Doctrine\ORM\QueryBuilder; | ||
use Symfony\Bundle\SecurityBundle\Security; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField; | ||
use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType; | ||
|
||
#[AsEntityAutocompleteField] | ||
class UserAutocompleteType extends AbstractType | ||
{ | ||
public function __construct(private readonly Security $security) | ||
{ | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefaults([ | ||
'class' => User::class, | ||
'choice_label' => 'username', | ||
'placeholder' => 'select_user', | ||
'filter_query' => function (QueryBuilder $qb, string $query) { | ||
if ($currentUser = $this->security->getUser()) { | ||
$qb | ||
->andWhere( | ||
\sprintf( | ||
'entity.id NOT IN (SELECT IDENTITY(ub.blocked) FROM %s ub WHERE ub.blocker = :user)', | ||
UserBlock::class, | ||
) | ||
) | ||
->setParameter('user', $currentUser); | ||
} | ||
|
||
if (!$query) { | ||
return; | ||
} | ||
|
||
$qb->andWhere('entity.username LIKE :filter') | ||
->andWhere('entity.visibility = :visibility') | ||
->setParameter('filter', '%'.$query.'%') | ||
->setParameter('visibility', VisibilityInterface::VISIBILITY_VISIBLE) | ||
; | ||
}, | ||
]); | ||
} | ||
|
||
public function getParent(): string | ||
{ | ||
return BaseEntityAutocompleteType::class; | ||
} | ||
} |
Oops, something went wrong.