Skip to content
Open
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
17 changes: 7 additions & 10 deletions Resources/templates/responsive/home/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,25 @@
<?= $this->text('home-menu-toggle-label') ?> <i class="fa fa-angle-right"></i>
<?php $this->replace() ?>



<?php $this->section('home-content') ?>

<!-- Banner section -->

<?= $this->insert('partials/components/main_slider', [
'banners' => $this->banners,
'nav' => 'home/partials/main_slider_nav',
'button_text' => $this->text('invest-more-info')
'banners' => $this->response->getBanners(),
'nav' => 'home/partials/main_slider_nav',
'button_text' => $this->text('invest-more-info')
]) ?>

<?= $this->insert('home/partials/projects') ?>

<?php if ($this->home['values']): ?>
<?php if ($this->response->getHomeItems()['values']): ?>

<?= $this->insert('partials/components/values', [
'title' => $this->t('home-footprint-values-title'),
'footprints' => $this->footprints,
'sdg_by_footprint' => $this->sdg_by_footprint,
'projects_by_footprint' => $this->projects_by_footprint
'footprints' => $this->response->getFootprints(),
'sdg_by_footprint' => $this->response->getSdgByFootprint(),
'projects_by_footprint' => $this->response->getProjectsByFootprint()
]) ?>

<?php endif; ?>
Expand All @@ -61,4 +59,3 @@
<?= $this->insert('home/partials/modals') ?>

<?php $this->replace() ?>

38 changes: 17 additions & 21 deletions Resources/templates/responsive/home/partials/channels.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
<?php if($this->channels && count($this->channels) > 1): ?>
<?php if($this->response->getChannels() && count($this->response->getChannels()) > 1): ?>

<div class="section channels" id="channels" >
<div class="drop-img-container">
<img class="center-block drop-img" src="/assets/img/project/channel.svg" alt="matchfunding">
</div>
<h2 class="title text-center">
<?= $this->text('home-channels-title') ?>
</h2>
<h2 class="title text-center"><?= $this->text('home-channels-title') ?></h2>
<div class="container" id="channel-container">
<div class="row slider slider-channels">
<?php foreach($this->channels as $channel): ?>
<?php foreach($this->response->getChannels() as $channel): ?>
<?php $summary = $channel->getSummary(); ?>
<?php $background = $channel->owner_background; ?>

<div class="channel col-sm-4">
<div class="widget-channel">
<div class="img-container" style="background-color: <?= $background ?> ">
<div class="img">
<a class="a-unstyled" href="<?= '/channel/'.$channel->id ?>">
<img loading="lazy" class="img-responsive" src="<?= $channel->logo ? $channel->logo->getlink(200,0) : '' ?>" alt="<?= $channel->name ?>"/>
</a>
</div>
<div class="widget-channel">
<div class="img-container" style="background-color: <?= $background ?> ">
<div class="img">
<a class="a-unstyled" href="<?= '/channel/'.$channel->id ?>">
<img loading="lazy" class="img-responsive"
src="<?= $channel->logo ? $channel->logo->getlink(200,0) : '' ?>"
alt="<?= $channel->name ?>"/>
</a>
</div>
<div class="content" style="<?php if($background) echo ' background-color:' . $this->to_rgba($background, 0.8); if($channel->owner_font_color) echo '; color:' . $channel->owner_font_color; ?>" >
<div class="title" title="<?= $channel->name ?>">
<a class="a-unstyled" href="<?= '/channel/'.$channel->id ?>">
<?= $channel->name ?>
</a>
</div>
<div class="description">
<?= $this->text_truncate($channel->description, 120) ?>
</div>
</div>
<div class="content" style="<?php if($background) echo ' background-color:' . $this->to_rgba($background, 0.8); if($channel->owner_font_color) echo '; color:' . $channel->owner_font_color; ?>" >
<div class="title" title="<?= $channel->name ?>">
<a class="a-unstyled" href="<?= '/channel/'.$channel->id ?>"><?= $channel->name ?></a>
</div>
<div class="description"><?= $this->text_truncate($channel->description, 120) ?></div>
</div>
</div>
</div>
<?php endforeach ;?>
</div>
Expand Down
6 changes: 3 additions & 3 deletions Resources/templates/responsive/home/partials/projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

</div>
<div class="container" id="projects-container">
<?php if($this->projects): ?>
<?php if ($this->response->getProjects()): ?>
<?= $this->insert('home/partials/projects_list', [
'projects' => $this->projects,
'total_projects' => $this->total_projects
'projects' => $this->response->getProjects(),
'total_projects' => $this->response->getTotalProjects()
]) ?>
<?php endif ?>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<div class="slider slider-projects" data-total="<?= (int)$this->total_projects ?>" data-limit="<?= (int)$this->limit ?>">
<?php foreach ($this->projects as $project) : ?>
<div class="slider slider-projects"
data-total="<?= $this->response->getTotalProjects() ?>"
data-limit="<?= $this->response->getLimit() ?>">
<?php foreach ($this->response->getProjects() as $project) : ?>
<div class="item widget-slide">
<?= $this->insert('project/widgets/normal', [
'project' => $project
Expand Down
6 changes: 3 additions & 3 deletions Resources/templates/responsive/home/partials/sponsors.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="section sponsors" >
<?php if($this->sponsors): ?>
<?php if($this->response->getSponsors()): ?>
<div class="container">
<?php foreach($this->sponsors as $type => $sponsors): ?>
<?php foreach($this->response->getSponsors() as $type => $sponsors): ?>
<?php if ($sponsors): ?>
<div class="row">
<div class="sponsor-type">
Expand All @@ -21,4 +21,4 @@
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<?php endforeach ?>
</div>
<div class="slider slider-footprint-projects">
<?php foreach($projects_by_footprint[$footprint->id] as $index => $project): ?>
<?php foreach($projects_by_footprint[$footprint->id] as $project): ?>
<div class="footprint-project">
<img src="<?= $project->image->getLink(600, 416, true); ?>" class="bg-project" data-footprint=<?= $footprint->id ?>>
<div class="project-footprint">
Expand Down
82 changes: 5 additions & 77 deletions src/Goteo/Controller/DiscoverController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,85 +21,13 @@

class DiscoverController extends Controller {

private Project\ProjectFilters $projectFilters;

public function __construct() {
$this->dbReplica(true);
$this->dbCache(true);

View::setTheme('responsive');
}

/**
* Returns an array suitable for Project::getList($filters)
*/
protected function getProjectFilters($filter, $vars = []): array
{
$filters = [
'status' => [Project::STATUS_IN_CAMPAIGN, Project::STATUS_FUNDED, Project::STATUS_FULFILLED],
'published_since' => (new DateTime('-6 month'))->format('Y-m-d')
];

$filters['order'] = 'project.status ASC, project.published DESC, project.name ASC';
if($vars['q']) {
$filters['global'] = $vars['q'];
unset($filters['published_since']);
$filters['status'] = [Project::STATUS_IN_CAMPAIGN, Project::STATUS_FUNDED, Project::STATUS_FULFILLED, Project::STATUS_UNFUNDED];
}

if ($vars['category']) {
$filters['category'] = $vars['category'];
unset($filters['published_since']);
$filters['status'] = [ Project::STATUS_IN_CAMPAIGN, Project::STATUS_FUNDED, Project::STATUS_FULFILLED, Project::STATUS_UNFUNDED ];
}

if ($vars['location'] || ($vars['latitude'] && $vars['longitude'])) {
unset($filters['published_since']);
$filters['location'] = new ProjectLocation(['location' => $vars['location'], 'latitude' => $vars['latitude'], 'longitude' => $vars['longitude'], 'radius' => 300]);
$filters['status'] = [Project::STATUS_IN_CAMPAIGN, Project::STATUS_FUNDED, Project::STATUS_FULFILLED, Project::STATUS_UNFUNDED];
$filters['order'] = 'Distance ASC, project.status ASC, project.published DESC, project.name ASC';
}

if ($filter === 'near') {
// Nearby defined as 300Km distance
// Any LocationInterface will do (UserLocation, ProjectLocation, ...)
$filters['location'] = new ProjectLocation([ 'latitude' => $vars['latitude'], 'longitude' => $vars['longitude'], 'radius' => 300 ]);
$filters['order'] = 'Distance ASC, project.status ASC, project.published DESC, project.name ASC';
} elseif($filter === 'outdated') {
$filters['type'] = 'outdated';
$filters['status'] = Project::STATUS_IN_CAMPAIGN;
$filters['order'] = 'project.days ASC, project.published DESC, project.name ASC';
} elseif($filter === 'promoted') {
$filters['type'] = 'promoted';
$filters['status'] = Project::STATUS_IN_CAMPAIGN;
$filters['order'] = 'promote.order ASC, project.published DESC, project.name ASC';
} elseif($filter === 'popular') {
$filters['type'] = 'popular';
$filters['status'] = Project::STATUS_IN_CAMPAIGN;
$filters['order'] = 'project.popularity DESC, project.published DESC, project.name ASC';
} elseif($filter === 'succeeded') {
$filters['type'] = 'succeeded';
$filters['status'] = [Project::STATUS_FUNDED, Project::STATUS_FULFILLED];
$filters['order'] = 'project.published DESC, project.name ASC';
unset($filters['published_since']);
} elseif($filter === 'fulfilled') {
$filters['status'] = [Project::STATUS_FULFILLED];
$filters['order'] = 'project.published DESC, project.name ASC';
unset($filters['published_since']);
} elseif($filter === 'archived') {
$filters['status'] = [Project::STATUS_UNFUNDED];
$filters['order'] = 'project.published DESC, project.name ASC';
$filters['published_since'] = (new DateTime('-24 month'))->format('Y-m-d');
} elseif($filter === 'matchfunding') {
$filters['type'] = 'matchfunding';
unset($filters['published_since']);
} elseif($filter === 'recent') {
$filters['type'] = 'recent';
}

if($vars['review']) {
$filters['status'] = [ Project::STATUS_EDITING, Project::STATUS_REVIEWING, Project::STATUS_IN_CAMPAIGN, Project::STATUS_FUNDED, Project::STATUS_FULFILLED, Project::STATUS_UNFUNDED ];
$filters['is_draft'] = true;
}
return $filters;
$this->projectFilters = new Project\ProjectFilters();
}

/*
Expand Down Expand Up @@ -127,7 +55,7 @@ public function searchAction (Request $request, $filter = '') {
$vars['review'] = $request->query->get('review') === '1' ? 1 : 0 ;
}

$filters = $this->getProjectFilters($filter, $vars);
$filters = $this->projectFilters->getFilters($filter, $vars);

$projects = Project::getList($filters, null, 0, $limit);
$total = Project::getList($filters, null, 0, 0, true);
Expand Down Expand Up @@ -165,7 +93,7 @@ public function ajaxSearchAction(Request $request) {
'status' => [Project::STATUS_IN_CAMPAIGN, Project::STATUS_FUNDED],
'published_since' => (new DateTime('-6 month'))->format('Y-m-d')
];
$filters = $this->getProjectFilters($filter, $vars);
$filters = $this->projectFilters->getFilters($filter, $vars);

$offset = $pag * $limit;
$total_projects = 0;
Expand Down
62 changes: 7 additions & 55 deletions src/Goteo/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,75 +11,27 @@
namespace Goteo\Controller;

use Goteo\Application\View;
use Goteo\Application\Config;
use Goteo\Model\Banner;
use Goteo\Model\Footprint;
use Goteo\Model\Home;
use Goteo\Model\Project;
use Goteo\Model\Sdg;
use Goteo\Model\Stories;
use Goteo\Model\Node;
use Goteo\Model\Sponsor;
use Goteo\Util\Stats\Stats;
use Goteo\UseCase\Home\HomeUseCase;
use Symfony\Component\HttpFoundation\Response;


class IndexController extends DiscoverController
class IndexController extends BaseSymfonyController
{

public function __construct()
{
parent::__construct();
$this->dbReplica(true);
$this->dbCache(true);
View::setTheme('responsive');
}

public function indexAction(): Response
{
$limit = 24;
$filters = $this->getProjectFilters('promoted');
$projects = Project::getList($filters, null, 0, $limit);
$total_projects = Project::getList($filters, null, 0, 0, true);
$stories = Stories::getList(['active' => true]);
$channels = Node::getAll(['status' => 'active', 'type' => 'channel']);
$banners = Banner::getAll(true);
$stats = Stats::create('home_stats');
$sponsors = $this->getSponsors();
$footprints = Footprint::getList();
$home = Home::getAll(Config::get('node'), 'index');

$projects_by_footprint = [];
$sdg_by_footprint = [];
foreach($footprints as $footprint) {
$footprintImpactData[$footprint->id] = $footprint->getAllImpactData();
$projects_by_footprint[$footprint->id] = Project::getByFootprint(['footprints' => $footprint->id, 'rand' => true, 'amount_bigger_than' => 7000]);
$sdg_by_footprint[$footprint->id] = Sdg::getList(['footprint' => $footprint->id]);
}
$useCase = new HomeUseCase();
$response = $useCase->execute();

return $this->viewResponse('home/index', [
'banners' => $banners,
'projects' => $projects,
'total_projects' => $total_projects,
'limit' => $limit,
'limit_add' => 12, // Limit for javascript on addSlick
'stories' => $stories,
'channels' => $channels,
'stats' => $stats,
'sponsors' => $sponsors,
'footprints' => $footprints,
'home' => $home,
'projects_by_footprint' => $projects_by_footprint,
'sdg_by_footprint' => $sdg_by_footprint,
'footprint_impact_data' => $footprintImpactData,
return $this->renderFoilTemplate('home/index', [
'response' => $response,
]);
}

private function getSponsors(): array
{
$sponsors = [];
foreach(Sponsor::getTypes() as $type) {
$sponsors[$type] = Sponsor::getList(['type' => $type]);
}
return $sponsors;
}
}
Loading