Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#543 SchemaBundle: Changed limit search in LastestUploads #748

Merged
merged 5 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/Pumukit/SchemaBundle/Services/AnnounceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,28 @@ public function getLatestUploadsByDates($dateStart, $dateEnd, $withPudenewTag =
*/
public function getNextLatestUploads($date, $withPudenewTag = true)
{
$counter = 0;
$dateStart = clone $date;
$dateStart->modify('first day of next month');
$dateEnd = clone $date;
$dateEnd->modify('last day of next month');
$dateEnd->setTime(23, 59, 59);

$queryBuilderMms = $this->mmobjRepo->createQueryBuilder();
$queryBuilderMms->sort('public_date', 'asc');
$queryBuilderMms->field('tags.cod')->equals('PUDENEW');
$queryBuilderMms->limit(1);

$lastMm = $queryBuilderMms->getQuery()->getSingleResult();

do {
++$counter;
$dateStart->modify('first day of last month');
$dateEnd->modify('last day of last month');
$last = $this->getLatestUploadsByDates($dateStart, $dateEnd, $withPudenewTag);
} while (empty($last) && $counter < 24);
} while (empty($last) && $lastMm && $lastMm->getPublicDate() <= $dateEnd);

if (empty($last)) {
$dateEnd = null;
}

return array($dateEnd, $last);
}
Expand Down
14 changes: 2 additions & 12 deletions src/Pumukit/SchemaBundle/Tests/Services/AnnounceServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Pumukit\SchemaBundle\Document\Series;
use Pumukit\SchemaBundle\Document\SeriesType;
use Pumukit\SchemaBundle\Document\MultimediaObject;
use Pumukit\SchemaBundle\Document\Role;
use Pumukit\SchemaBundle\Document\Tag;

class AnnounceServiceTest extends WebTestCase
Expand Down Expand Up @@ -93,6 +90,7 @@ public function testGetLast()

$this->assertEquals(array(), $this->announceService->getLast());
}

public function testNextLatestUploads()
{
$tagPudenew = new Tag();
Expand Down Expand Up @@ -147,14 +145,6 @@ public function testNextLatestUploads()
$dateEnd->modify('first day of last month');
list($dateEnd, $last) = $this->announceService->getNextLatestUploads($dateEnd);
$this->assertEquals(array(), $last);
$this->assertEquals('04/1997', $dateEnd->format('m/Y'));
$dateEnd->modify('first day of last month');
list($dateEnd, $last) = $this->announceService->getNextLatestUploads($dateEnd);
$this->assertEquals(array(), $last);
$this->assertEquals('04/1995', $dateEnd->format('m/Y'));
$dateEnd->modify('first day of last month');
list($dateEnd, $last) = $this->announceService->getNextLatestUploads($dateEnd, false);
$this->assertEquals(array(), $last);
$this->assertEquals('04/1993', $dateEnd->format('m/Y'));
$this->assertEquals(null, $dateEnd);
}
}
14 changes: 8 additions & 6 deletions src/Pumukit/WebTVBundle/Controller/AnnouncesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,18 @@ public function latestUploadsPagerAction(Request $request)
throw $this->createNotFoundException();
}
list($date, $last) = $announcesService->getNextLatestUploads($date, $showPudenew);
if (empty($last)) {
$dateHeader = '---';
} else {

$response = new Response();
$dateHeader = '---';

if (!empty($last)) {
$response = new Response($this->renderView('PumukitWebTVBundle:Announces:latestUploadsPager.html.twig', array('last' => $last, 'date' => $date, 'number_cols' => $numberCols)), 200);
$dateHeader = $date->format('m/Y');
$response->headers->set('X-Date-Month', $date->format('m'));
$response->headers->set('X-Date-Year', $date->format('Y'));
}

$response = new Response($this->renderView('PumukitWebTVBundle:Announces:latestUploadsPager.html.twig', array('last' => $last, 'date' => $date, 'number_cols' => $numberCols)), 200);
$response->headers->set('X-Date', $dateHeader);
$response->headers->set('X-Date-Month', $date->format('m'));
$response->headers->set('X-Date-Year', $date->format('Y'));

return $response;
}
Expand Down
8 changes: 6 additions & 2 deletions src/Pumukit/WebTVBundle/Resources/public/js/announces_ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ jQuery(document).ready(function() {
};
var now = new Date();
var anDate = new AnnounceDate( now.getMonth() + 1, now.getFullYear() );
var emptyMmos = true;

function reloadMoreData()
function reloadMoreData(emptyMmos)
{
if( month_loaded && !in_array(anDate,loaded_months))
{
Expand All @@ -53,11 +54,14 @@ jQuery(document).ready(function() {
if( $('.main-content').height() <= $(window).height() ) {
reloadMoreData();
}
}else if( emptyMmos ){
emptyMmos = false;
$(noMmo).show();
}
});
}
}
reloadMoreData();
reloadMoreData(emptyMmos);
$(window).scroll(function () {
if ($(window).scrollTop() + window.innerHeight + $('footer').height() >= $(document).height()) {
reloadMoreData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@
<source>Try searching for something else:</source>
<target>Prueba a buscar otra cosa:</target>
</trans-unit>
<trans-unit id="004b3a52924c1c8012893ca4ed30ddc7" resname="There are no multimedia objects">
<source>There are no multimedia objects</source>
<target>No hay objetos multimedia</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<h1 class="title-for-crumbs">{{template_title}}</h1>
<div class="announces" id="announces">
</div>
<div class="noMmo" id="noMmo" hidden>
<h2>
{% trans %}There are no multimedia objects{% endtrans %}
</h2>
</div>
<div id="announces_loading" style="display:none"><img class="center-block" src="{{ asset('bundles/pumukitwebtv/images/icons/spinner.gif') }}"/></div>
<script type="text/javascript">
var url_latestuploads_pager = "{{ path('pumukit_webtv_announces_latestuploads_pager') }}";
Expand Down