update doctrine filtering fwk to support
params replacements Change-Id: If97cd7b524148e0409034181597cb129ef4ad0d1
This commit is contained in:
parent
50f14bb897
commit
32eb4af98a
@ -45,9 +45,10 @@ class DoctrineFilterMapping extends FilterMapping
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function apply(QueryBuilder $query, FilterElement $filter){
|
||||
$where = str_replace(":value", $filter->getValue(), $this->where);
|
||||
$param_count = $query->getParameters()->count() + 1;
|
||||
$where = str_replace(":value", ":value_".$param_count, $this->where);
|
||||
$where = str_replace(":operator", $filter->getOperator(), $where);
|
||||
return $query->andWhere($where);
|
||||
return $query->andWhere($where)->setParameter(":value_".$param_count, $filter->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,8 +57,10 @@ class DoctrineFilterMapping extends FilterMapping
|
||||
* @return string
|
||||
*/
|
||||
public function applyOr(QueryBuilder $query, FilterElement $filter){
|
||||
$where = str_replace(":value", $filter->getValue(), $this->where);
|
||||
$param_count = $query->getParameters()->count() + 1;
|
||||
$where = str_replace(":value", ":value_".$param_count, $this->where);
|
||||
$where = str_replace(":operator", $filter->getOperator(), $where);
|
||||
$query->setParameter(":value_".$param_count, $filter->getValue());
|
||||
return $where;
|
||||
}
|
||||
}
|
@ -51,11 +51,12 @@ class DoctrineJoinFilterMapping extends FilterMapping
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function apply(QueryBuilder $query, FilterElement $filter){
|
||||
$where = str_replace(":value", $filter->getValue(), $this->where);
|
||||
$param_count = $query->getParameters()->count() + 1;
|
||||
$where = str_replace(":value", ":value_".$param_count, $this->where);
|
||||
$where = str_replace(":operator", $filter->getOperator(), $where);
|
||||
if(!in_array($this->alias, $query->getAllAliases()))
|
||||
$query->innerJoin($this->table, $this->alias, Join::WITH);
|
||||
return $query->andWhere($where);
|
||||
return $query->andWhere($where)->setParameter(":value_".$param_count, $filter->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,10 +65,12 @@ class DoctrineJoinFilterMapping extends FilterMapping
|
||||
* @return string
|
||||
*/
|
||||
public function applyOr(QueryBuilder $query, FilterElement $filter){
|
||||
$where = str_replace(":value", $filter->getValue(), $this->where);
|
||||
$param_count = $query->getParameters()->count() + 1;
|
||||
$where = str_replace(":value", ":value_".$param_count, $this->where);
|
||||
$where = str_replace(":operator", $filter->getOperator(), $where);
|
||||
if(!in_array($this->alias, $query->getAllAliases()))
|
||||
$query->innerJoin($this->table, $this->alias, Join::WITH);
|
||||
$query->setParameter(":value_".$param_count, $filter->getValue());
|
||||
return $where;
|
||||
}
|
||||
}
|
@ -25,11 +25,13 @@ class DoctrineLeftJoinFilterMapping extends DoctrineJoinFilterMapping
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function apply(QueryBuilder $query, FilterElement $filter){
|
||||
$where = str_replace(":value", $filter->getValue(), $this->where);
|
||||
$param_count = $query->getParameters()->count() + 1;
|
||||
$where = str_replace(":value", ":value_".$param_count, $this->where);
|
||||
$where = str_replace(":operator", $filter->getOperator(), $where);
|
||||
if(!in_array($this->alias, $query->getAllAliases()))
|
||||
$query->leftJoin($this->table, $this->alias, Join::WITH);
|
||||
return $query->andWhere($where);
|
||||
|
||||
return $query->andWhere($where)->setParameter(":value_".$param_count, $filter->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,10 +40,12 @@ class DoctrineLeftJoinFilterMapping extends DoctrineJoinFilterMapping
|
||||
* @return string
|
||||
*/
|
||||
public function applyOr(QueryBuilder $query, FilterElement $filter){
|
||||
$where = str_replace(":value", $filter->getValue(), $this->where);
|
||||
$param_count = $query->getParameters()->count() + 1;
|
||||
$where = str_replace(":value", ":value_".$param_count, $this->where);
|
||||
$where = str_replace(":operator", $filter->getOperator(), $where);
|
||||
if(!in_array($this->alias, $query->getAllAliases()))
|
||||
$query->leftJoin($this->table, $this->alias, Join::WITH);
|
||||
$query->setParameter(":value_".$param_count, $filter->getValue());
|
||||
return $where;
|
||||
}
|
||||
}
|
@ -41,7 +41,7 @@ abstract class DoctrineCompanyServiceRepository extends SilverStripeDoctrineRepo
|
||||
(
|
||||
'e.company',
|
||||
'c',
|
||||
"c.name :operator ':value'"
|
||||
"c.name :operator :value"
|
||||
),
|
||||
];
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||
use models\main\IMemberRepository;
|
||||
use models\main\Member;
|
||||
use App\Repositories\SilverStripeDoctrineRepository;
|
||||
use utils\DoctrineFilterMapping;
|
||||
use utils\DoctrineJoinFilterMapping;
|
||||
use utils\Filter;
|
||||
use utils\Order;
|
||||
@ -71,13 +72,13 @@ final class DoctrineMemberRepository
|
||||
'first_name' => 'm.first_name:json_string',
|
||||
'last_name' => 'm.last_name:json_string',
|
||||
'github_user' => 'm.github_user:json_string',
|
||||
'full_name' => "concat(m.first_name, ' ', m.last_name) :operator ':value'",
|
||||
'full_name' => new DoctrineFilterMapping("concat(m.first_name, ' ', m.last_name) :operator :value"),
|
||||
'email' => ['m.email:json_string', 'm.second_email:json_string', 'm.third_email:json_string'],
|
||||
'group_slug' => new DoctrineJoinFilterMapping
|
||||
(
|
||||
'm.groups',
|
||||
'g',
|
||||
"g.code :operator ':value'"
|
||||
"g.code :operator :value"
|
||||
),
|
||||
'group_id' => new DoctrineJoinFilterMapping
|
||||
(
|
||||
|
@ -58,19 +58,19 @@ final class DoctrinePresentationCategoryGroupRepository
|
||||
),
|
||||
'track_title' => new DoctrineFilterMapping
|
||||
(
|
||||
"(cat.title :operator ':value')"
|
||||
"(cat.title :operator :value)"
|
||||
),
|
||||
'track_code' => new DoctrineFilterMapping
|
||||
(
|
||||
"(cat.code :operator ':value')"
|
||||
"(cat.code :operator :value)"
|
||||
),
|
||||
'group_title' => new DoctrineFilterMapping
|
||||
(
|
||||
"(grp.title :operator ':value')"
|
||||
"(grp.title :operator :value)"
|
||||
),
|
||||
'group_code' => new DoctrineFilterMapping
|
||||
(
|
||||
"(grp.code :operator ':value')"
|
||||
"(grp.code :operator :value)"
|
||||
),
|
||||
];
|
||||
}
|
||||
|
@ -49,16 +49,16 @@ final class DoctrinePresentationSpeakerSummitAssistanceConfirmationRequestReposi
|
||||
'confirmation_date' => 'r.confirmation_date:datetime_epoch',
|
||||
'speaker' => new DoctrineFilterMapping
|
||||
(
|
||||
"( concat(spkr.first_name, ' ', spkr.last_name) :operator ':value' ".
|
||||
"OR concat(spmm.first_name, ' ', spmm.last_name) :operator ':value' ".
|
||||
"OR spkr.first_name :operator ':value' ".
|
||||
"OR spkr.last_name :operator ':value' ".
|
||||
"OR spmm.first_name :operator ':value' ".
|
||||
"OR spmm.last_name :operator ':value' )"
|
||||
"( concat(spkr.first_name, ' ', spkr.last_name) :operator :value ".
|
||||
"OR concat(spmm.first_name, ' ', spmm.last_name) :operator :value ".
|
||||
"OR spkr.first_name :operator :value ".
|
||||
"OR spkr.last_name :operator :value ".
|
||||
"OR spmm.first_name :operator :value ".
|
||||
"OR spmm.last_name :operator :value )"
|
||||
),
|
||||
'speaker_email' => new DoctrineFilterMapping
|
||||
(
|
||||
"(sprr.email :operator ':value' OR spmm.email :operator ':value')"
|
||||
"(sprr.email :operator :value OR spmm.email :operator :value)"
|
||||
),
|
||||
];
|
||||
}
|
||||
|
@ -67,31 +67,31 @@ final class DoctrineSummitAttendeeRepository
|
||||
(
|
||||
'a.member',
|
||||
'm',
|
||||
"m.first_name :operator ':value'"
|
||||
"m.first_name :operator :value"
|
||||
),
|
||||
'last_name' => new DoctrineLeftJoinFilterMapping
|
||||
(
|
||||
'a.member',
|
||||
'm',
|
||||
"m.last_name :operator ':value'"
|
||||
"m.last_name :operator :value"
|
||||
),
|
||||
'email' => new DoctrineLeftJoinFilterMapping
|
||||
(
|
||||
'a.member',
|
||||
'm',
|
||||
"m.email :operator ':value'"
|
||||
"m.email :operator :value"
|
||||
),
|
||||
'external_order_id' => new DoctrineLeftJoinFilterMapping
|
||||
(
|
||||
'a.tickets',
|
||||
't',
|
||||
"t.external_order_id :operator ':value'"
|
||||
"t.external_order_id :operator :value"
|
||||
),
|
||||
'external_attendee_id' => new DoctrineLeftJoinFilterMapping
|
||||
(
|
||||
'a.tickets',
|
||||
't',
|
||||
"t.external_attendee_id :operator ':value'"
|
||||
"t.external_attendee_id :operator :value"
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ final class DoctrineSummitBookableVenueRoomAttributeTypeRepository
|
||||
(
|
||||
'e.summit',
|
||||
's',
|
||||
"s.id :operator ':value'"
|
||||
"s.id :operator :value"
|
||||
),
|
||||
];
|
||||
}
|
||||
|
@ -35,13 +35,13 @@ final class DoctrineSummitBookableVenueRoomAttributeValueRepository
|
||||
(
|
||||
'e.summit',
|
||||
's',
|
||||
"s.id :operator ':value'"
|
||||
"s.id :operator :value"
|
||||
),
|
||||
'type_id' => new DoctrineJoinFilterMapping
|
||||
(
|
||||
'e.type',
|
||||
't',
|
||||
"t.id :operator ':value'"
|
||||
"t.id :operator :value"
|
||||
),
|
||||
];
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ final class DoctrineSummitEventRepository
|
||||
(
|
||||
'e.tags',
|
||||
't',
|
||||
"t.tag :operator ':value'"
|
||||
"t.tag :operator :value"
|
||||
),
|
||||
'summit_id'=> new DoctrineJoinFilterMapping
|
||||
(
|
||||
@ -120,19 +120,19 @@ final class DoctrineSummitEventRepository
|
||||
),
|
||||
'speaker' => new DoctrineFilterMapping
|
||||
(
|
||||
"( concat(sp.first_name, ' ', sp.last_name) :operator ':value' ".
|
||||
"OR concat(spm.first_name, ' ', spm.last_name) :operator ':value' ".
|
||||
"OR concat(spmm.first_name, ' ', spmm.last_name) :operator ':value' ".
|
||||
"OR sp.first_name :operator ':value' ".
|
||||
"OR sp.last_name :operator ':value' ".
|
||||
"OR spm.first_name :operator ':value' ".
|
||||
"OR spm.last_name :operator ':value' ".
|
||||
"OR spmm.first_name :operator ':value' ".
|
||||
"OR spmm.last_name :operator ':value' )"
|
||||
"( concat(sp.first_name, ' ', sp.last_name) :operator :value ".
|
||||
"OR concat(spm.first_name, ' ', spm.last_name) :operator :value ".
|
||||
"OR concat(spmm.first_name, ' ', spmm.last_name) :operator :value ".
|
||||
"OR sp.first_name :operator :value ".
|
||||
"OR sp.last_name :operator :value ".
|
||||
"OR spm.first_name :operator :value ".
|
||||
"OR spm.last_name :operator :value ".
|
||||
"OR spmm.first_name :operator :value ".
|
||||
"OR spmm.last_name :operator :value) "
|
||||
),
|
||||
'speaker_email' => new DoctrineFilterMapping
|
||||
(
|
||||
"(sprr.email :operator ':value' OR spmm.email :operator ':value')"
|
||||
"(sprr.email :operator :value OR spmm.email :operator :value)"
|
||||
),
|
||||
'speaker_id' => new DoctrineFilterMapping
|
||||
(
|
||||
|
@ -69,7 +69,7 @@ final class DoctrineSummitLocationRepository
|
||||
'capacity' => 'r.capacity',
|
||||
'attribute' => new DoctrineFilterMapping
|
||||
(
|
||||
"(bra.value :operator ':value' or bra.id = ':value')"
|
||||
"(bra.value :operator :value or bra.id = :value)"
|
||||
),
|
||||
'class_name' => new DoctrineInstanceOfFilterMapping(
|
||||
"al",
|
||||
|
@ -70,44 +70,44 @@ class DoctrineSummitRegistrationPromoCodeRepository
|
||||
|
||||
'sponsor' => new DoctrineFilterMapping
|
||||
(
|
||||
"(spnr.name :operator ':value')"
|
||||
"(spnr.name :operator :value)"
|
||||
),
|
||||
'creator' => new DoctrineFilterMapping
|
||||
(
|
||||
"( concat(ct.first_name, ' ', ct.last_name) :operator ':value' ".
|
||||
"OR ct.first_name :operator ':value' ".
|
||||
"OR ct.last_name :operator ':value' )"
|
||||
"( concat(ct.first_name, ' ', ct.last_name) :operator :value ".
|
||||
"OR ct.first_name :operator :value ".
|
||||
"OR ct.last_name :operator :value )"
|
||||
),
|
||||
'creator_email' => new DoctrineFilterMapping
|
||||
(
|
||||
"(ct.email :operator ':value')"
|
||||
"(ct.email :operator :value)"
|
||||
),
|
||||
'owner' => new DoctrineFilterMapping
|
||||
(
|
||||
"( concat(owr.first_name, ' ', owr.last_name) :operator ':value' ".
|
||||
"OR owr.first_name :operator ':value' ".
|
||||
"OR owr.last_name :operator ':value' )"
|
||||
"( concat(owr.first_name, ' ', owr.last_name) :operator :value ".
|
||||
"OR owr.first_name :operator :value ".
|
||||
"OR owr.last_name :operator :value )"
|
||||
),
|
||||
'owner_email' => new DoctrineFilterMapping
|
||||
(
|
||||
"(owr.email :operator ':value')"
|
||||
"(owr.email :operator :value)"
|
||||
),
|
||||
'speaker' => new DoctrineFilterMapping
|
||||
(
|
||||
"( concat(spkr.first_name, ' ', spkr.last_name) :operator ':value' ".
|
||||
"OR concat(spmm.first_name, ' ', spmm.last_name) :operator ':value' ".
|
||||
"OR spkr.first_name :operator ':value' ".
|
||||
"OR spkr.last_name :operator ':value' ".
|
||||
"OR spmm.first_name :operator ':value' ".
|
||||
"OR spmm.last_name :operator ':value' )"
|
||||
"( concat(spkr.first_name, ' ', spkr.last_name) :operator :value ".
|
||||
"OR concat(spmm.first_name, ' ', spmm.last_name) :operator :value ".
|
||||
"OR spkr.first_name :operator :value ".
|
||||
"OR spkr.last_name :operator :value ".
|
||||
"OR spmm.first_name :operator :value ".
|
||||
"OR spmm.last_name :operator :value )"
|
||||
),
|
||||
'speaker_email' => new DoctrineFilterMapping
|
||||
(
|
||||
"(sprr.email :operator ':value' OR spmm.email :operator ':value')"
|
||||
"(sprr.email :operator :value OR spmm.email :operator :value)"
|
||||
),
|
||||
'type' => new DoctrineFilterMapping
|
||||
(
|
||||
"(mpc.type :operator ':value' OR spkpc.type :operator ':value')"
|
||||
"(mpc.type :operator :value OR spkpc.type :operator :value)"
|
||||
),
|
||||
'class_name' => new DoctrineInstanceOfFilterMapping(
|
||||
"pc",
|
||||
|
@ -60,7 +60,7 @@ final class DoctrineSummitRoomReservationRepository
|
||||
(
|
||||
'e.room',
|
||||
'r',
|
||||
"r.name :operator ':value'"
|
||||
"r.name :operator :value"
|
||||
),
|
||||
'venue_id' => new DoctrineJoinFilterMapping
|
||||
(
|
||||
@ -78,13 +78,13 @@ final class DoctrineSummitRoomReservationRepository
|
||||
(
|
||||
'e.owner',
|
||||
'o',
|
||||
"LOWER(CONCAT(o.first_name, ' ', o.last_name)) :operator ':value'"
|
||||
"LOWER(CONCAT(o.first_name, ' ', o.last_name)) :operator :value"
|
||||
),
|
||||
'owner_email' => new DoctrineJoinFilterMapping
|
||||
(
|
||||
'e.owner',
|
||||
'o',
|
||||
"o.email :operator ':value'"
|
||||
"o.email :operator :value"
|
||||
),
|
||||
];
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ final class DoctrineSummitTrackRepository
|
||||
'code' => 't.code:json_string',
|
||||
'group_name' => new DoctrineFilterMapping
|
||||
(
|
||||
"(g.name :operator ':value')"
|
||||
"(g.name :operator :value)"
|
||||
),
|
||||
];
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ final class DoctrineTrackTagGroupAllowedTagsRepository
|
||||
return [
|
||||
'tag' => new DoctrineFilterMapping
|
||||
(
|
||||
"(tg.tag :operator ':value')"
|
||||
"(tg.tag :operator :value)"
|
||||
),
|
||||
];
|
||||
}
|
||||
|
@ -41,6 +41,32 @@ final class OAuth2MembersApiTest extends ProtectedApiTest
|
||||
$this->assertResponseStatus(200);
|
||||
}
|
||||
|
||||
public function testGetMemberByFullName()
|
||||
{
|
||||
|
||||
$params = [
|
||||
//AND FILTER
|
||||
'filter' => ['full_name=@Seba'],
|
||||
'order' => '+first_name,-last_name'
|
||||
];
|
||||
|
||||
$headers = array("HTTP_Authorization" => " Bearer " . $this->access_token);
|
||||
$response = $this->action(
|
||||
"GET",
|
||||
"OAuth2MembersApiController@getAll",
|
||||
$params,
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$members = json_decode($content);
|
||||
$this->assertTrue(!is_null($members));
|
||||
$this->assertResponseStatus(200);
|
||||
}
|
||||
|
||||
public function testGetMembersEmpty()
|
||||
{
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user