<commit_before><?php
/*
 * This file is part of the Goteo Package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the README.md
 * and LICENSE files that was distributed with this source code.
 */

namespace Goteo\Controller\Api;

use Symfony\Component\HttpFoundation\Request;
use Goteo\Application\Exception\ControllerAccessDeniedException;
use Goteo\Application\Exception\ControllerException;
use Goteo\Application\Config;
use Goteo\Model\Image;
use Goteo\Model\Project;
use Goteo\Model\Call;
use Goteo\Model\Node;
use Goteo\Model\Project\ProjectLocation;

use Goteo\Application\View;

class MapsApiController extends AbstractApiController {

    public function __construct() {
        parent::__construct();
        // Activate cache & replica read for this controller
        $this->dbReplica(true);
        $this->dbCache(true);
        View::setTheme('responsive');

    }

    public function channelAction($cid = null, Request $request) {
        
        $projects = [];
        $workshops = [];

        if ($cid) {
            try {
              $channel = Node::get($cid);
            } catch (ModelNotFoundException $e) {
              Message::error($e->getMessage());
            }
            
            $list_projects = [];
            $conf = $channel->getConfig();

            if ($conf['projects']) {
              $projects = Project::getList($conf['projects'], $cid);
            } else {
              $projects = Project::getList(['node' => $channel->id]);
            }
            
            foreach($projects as $project) {
                $ob = ['id' => $project->id,
                   'name' => $project->name,
                   'amount' => $project->amount,
                   'invested' => $project->invested,
                   'num_investors' => $project->num_investors,
                   'image' => Image::get($project->image)->getLink(120,120),
                   'project_location' => ProjectLocation::get($project->id),
                   'popup' => View::render('map/partials/project_popup.php', array('project' => $project))];
                $list_projects[] = $ob;
            }
            
            $workshops = $channel->getAllWorkshops();
            $list_workshops = array_map(function($workshop) {
              $ob = [
                'id' => $workshop->id,
                'title' => $workshop->title,
                'subtitle' => $workshop->subtitle,
                'workshop_location' => $workshop->getLocation(),
                'image' => Image::get($workshop->header_image)->getLink(120,120),<commit_msg>fix number of projects shown in map<commit_after><?php
/*
 * This file is part of the Goteo Package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the README.md
 * and LICENSE files that was distributed with this source code.
 */

namespace Goteo\Controller\Api;

use Symfony\Component\HttpFoundation\Request;
use Goteo\Application\Exception\ControllerAccessDeniedException;
use Goteo\Application\Exception\ControllerException;
use Goteo\Application\Config;
use Goteo\Model\Image;
use Goteo\Model\Project;
use Goteo\Model\Call;
use Goteo\Model\Node;
use Goteo\Model\Project\ProjectLocation;

use Goteo\Application\View;

class MapsApiController extends AbstractApiController {

    public function __construct() {
        parent::__construct();
        // Activate cache & replica read for this controller
        $this->dbReplica(true);
        $this->dbCache(true);
        View::setTheme('responsive');

    }

    public function channelAction($cid = null, Request $request) {
        
        $projects = [];
        $workshops = [];

        if ($cid) {
            try {
              $channel = Node::get($cid);
            } catch (ModelNotFoundException $e) {
              Message::error($e->getMessage());
            }
            
            $list_projects = [];
            $conf = $channel->getConfig();

            if ($conf['projects']) {
              $total = Project::getList($conf['projects'], $cid, 0, 0, true);
              $projects = Project::getList($conf['projects'], $cid, 0, $total);
            } else {
              $total = Project::getList($conf['projects'], $cid, 0, 0, true);
              $projects = Project::getList(['node' => $channel->id], $cid, 0, $total);
            }
            
            foreach($projects as $project) {
                $ob = ['id' => $project->id,
                   'name' => $project->name,
                   'amount' => $project->amount,
                   'invested' => $project->invested,
                   'num_investors' => $project->num_investors,
                   'image' => Image::get($project->image)->getLink(120,120),
                   'project_location' => ProjectLocation::get($project->id),
                   'popup' => View::render('map/partials/project_popup.php', array('project' => $project))];
                $list_projects[] = $ob;
            }
            
            $workshops = $channel->getAllWorkshops();
            $list_workshops = array_map(function($workshop) {
              $ob = [
                'id' => $workshop->id,
                'title' => $workshop->title,
                'subtitle' => $workshop->subtitle,
                'workshop_location' => $workshop->getLocation(),
                'image' => Image::get($workshop->header_image)->getLink(120,120),
{'fraction_non_alphanumeric': 0.14432611090708777, 'fraction_numerical': 0.005508630187293426, 'mean_word_length': 2.0948863636363635, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1682828', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1480, 'n_words': 304}