myCRM/src/Repository/ContactRepository.php
olli b84dc6c6e9 feat: add typography and utility styles for layout
- Introduced typography styles in _typography.scss for headings, paragraphs, blockquotes, and horizontal rules.
- Added utility classes in _utils.scss for card styling and clearfix.
- Updated layout.scss to include new typography and utility styles.
- Defined common CSS variables in _common.scss for consistent theming.
- Created dark and light theme variables in _dark.scss and _light.scss respectively.
- Integrated Tailwind CSS with custom configurations in tailwind.config.js and postcss.config.js.
- Implemented database migrations for contact and contact_persons tables.
- Added data fixtures for generating sample contact data.
- Developed Contact and ContactPerson entities with appropriate validation and serialization.
- Enhanced ContactRepository with search and type filtering methods.
2025-11-09 11:02:15 +01:00

61 lines
1.8 KiB
PHP

<?php
namespace App\Repository;
use App\Entity\Contact;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Contact>
*/
class ContactRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Contact::class);
}
/**
* Find contacts by type (debtor, creditor, or both)
*/
public function findByType(?bool $isDebtor = null, ?bool $isCreditor = null): array
{
$qb = $this->createQueryBuilder('c')
->where('c.isActive = :active')
->setParameter('active', true)
->orderBy('c.companyName', 'ASC');
if ($isDebtor !== null) {
$qb->andWhere('c.isDebtor = :isDebtor')
->setParameter('isDebtor', $isDebtor);
}
if ($isCreditor !== null) {
$qb->andWhere('c.isCreditor = :isCreditor')
->setParameter('isCreditor', $isCreditor);
}
return $qb->getQuery()->getResult();
}
/**
* Search contacts by company name, contact person, or email
*/
public function search(string $searchTerm): array
{
return $this->createQueryBuilder('c')
->leftJoin('c.contactPersons', 'cp')
->where('c.companyName LIKE :search')
->orWhere('c.email LIKE :search')
->orWhere('c.city LIKE :search')
->orWhere('cp.firstName LIKE :search')
->orWhere('cp.lastName LIKE :search')
->orWhere('cp.email LIKE :search')
->setParameter('search', '%' . $searchTerm . '%')
->orderBy('c.companyName', 'ASC')
->getQuery()
->getResult();
}
}