Skip to content

Commit

Permalink
Merge pull request #292 from campusdomar/feature_13139_series_broadcast
Browse files Browse the repository at this point in the history
TTK-13139 SchemaBundle: add findByTitleWithLocale Series repo function
  • Loading branch information
rubenrua authored Feb 1, 2017
2 parents 8af0e0f + 38df645 commit e22bcd1
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/Pumukit/SchemaBundle/Repository/SeriesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,63 @@ public function findByEmbeddedBroadcastTypeAndGroups($type = '', $groups = array
return $query->execute();
}

/**
* Find by title with locale query builder.
*
* @param string $search
* @param string $locale
* @param array $sort
* @param int $limit
* @param int $page
*
* @return QueryBuilder
*/
public function findByTitleWithLocaleQueryBuilder($title = '', $locale = 'en', $sort = array(), $limit = 0, $page = 0)
{
$qb = $this->createQueryBuilder()
->field('title.'.$locale)->equals(new \MongoRegex(sprintf('/%s/i', $title)));

$qb = $this->addSortAndLimitToQueryBuilder($qb, $sort, $limit, $page);

return $qb;
}

/**
* Find by title with locale query.
*
* @param string $search
* @param string $locale
* @param array $sort
* @param int $limit
* @param int $page
*
* @return Query
*/
public function findByTitleWithLocaleQuery($title = '', $locale = 'en', $sort = array(), $limit = 0, $page = 0)
{
$qb = $this->findByTitleWithLocaleQueryBuilder($title, $locale, $sort, $limit, $page);

return $qb->getQuery();
}

/**
* Find by title with locale.
*
* @param string $search
* @param string $locale
* @param array $sort
* @param int $limit
* @param int $page
*
* @return Query
*/
public function findByTitleWithLocale($title = '', $locale = 'en', $sort = array(), $limit = 0, $page = 0)
{
$query = $this->findByTitleWithLocaleQuery($title, $locale, $sort, $limit, $page);

return $query->execute();
}

/**
* Add limit (and page) to Query Builder.
*
Expand Down
48 changes: 48 additions & 0 deletions src/Pumukit/SchemaBundle/Tests/Repository/SeriesRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,54 @@ public function testFindByPersonIdAndRoleCodOrGroupsSorted()
$this->assertTrue(in_array($series3, $seriesPerson2Role3Group2->toArray()));
}

public function testfindByTitleWithLocale()
{
$test1 = 'test1';
$test2 = 'test2';
$prueba1 = 'prueba1';
$prueba2 = 'prueba2';
$enLocale = 'en';
$esLocale = 'es';
$series1I8nTitle = array($enLocale => $test1, $esLocale => $prueba1);
$series1 = new Series();
$series1->setI18nTitle($series1I8nTitle);

$series2I8nTitle = array($enLocale => $test2, $esLocale => $prueba2);
$series2 = new Series();
$series2->setI18nTitle($series2I8nTitle);

$this->dm->persist($series1);
$this->dm->persist($series2);
$this->dm->flush();

$seriesTest1En = $this->repo->findByTitleWithLocale($test1, $enLocale)->toArray();
$seriesTest1Es = $this->repo->findByTitleWithLocale($test1, $esLocale)->toArray();
$seriesPrueba1En = $this->repo->findByTitleWithLocale($prueba1, $enLocale)->toArray();
$seriesPrueba1Es = $this->repo->findByTitleWithLocale($prueba1, $esLocale)->toArray();
$seriesTest2En = $this->repo->findByTitleWithLocale($test2, $enLocale)->toArray();
$seriesTest2Es = $this->repo->findByTitleWithLocale($test2, $esLocale)->toArray();
$seriesPrueba2En = $this->repo->findByTitleWithLocale($prueba2, $enLocale)->toArray();
$seriesPrueba2Es = $this->repo->findByTitleWithLocale($prueba2, $esLocale)->toArray();

$this->assertTrue(in_array($series1, $seriesTest1En));
$this->assertFalse(in_array($series1, $seriesTest1Es));
$this->assertFalse(in_array($series1, $seriesPrueba1En));
$this->assertTrue(in_array($series1, $seriesPrueba1Es));
$this->assertFalse(in_array($series1, $seriesTest2En));
$this->assertFalse(in_array($series1, $seriesTest2Es));
$this->assertFalse(in_array($series1, $seriesPrueba2En));
$this->assertFalse(in_array($series1, $seriesPrueba2Es));

$this->assertFalse(in_array($series2, $seriesTest1En));
$this->assertFalse(in_array($series2, $seriesTest1Es));
$this->assertFalse(in_array($series2, $seriesPrueba1En));
$this->assertFalse(in_array($series2, $seriesPrueba1Es));
$this->assertTrue(in_array($series2, $seriesTest2En));
$this->assertFalse(in_array($series2, $seriesTest2Es));
$this->assertFalse(in_array($series2, $seriesPrueba2En));
$this->assertTrue(in_array($series2, $seriesPrueba2Es));
}

private function createSeriesType($name)
{
$description = 'description';
Expand Down

0 comments on commit e22bcd1

Please sign in to comment.