<commit_before><?php

namespace Htl\SpendenportalBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class ProjectController extends Controller
{
    public function listAction(){
        $projects = $this->getDoctrine()->getRepository('HtlSpendenportalBundle:Project')->findAll();
        
        $responseArray = array();

        for($i=0;$i<count($projects);$i++){
            $item = array(
                "id"=>$projects[$i]->getId(),
                "title"=>$projects[$i]->getTitle(),
                "titlePictureUrl"=>$projects[$i]->getTitlePictureUrl(),
                "description"=>$projects[$i]->getDescription(),
                "shortinfo"=>$projects[$i]->getShortinfo(),
                "created_at"=>$projects[$i]->getCreatedAt(),
                "targetAmount"=>$projects[$i]->getTargetAmount(),
                "currentAmount"=>$projects[$i]->getCurrentAmount(),
                "currentDonators"=>$projects[$i]->getCurrentDonators()

            );
            array_push($responseArray, $item);
        }

        $responseArray = (object) $responseArray;

        return new JsonResponse($responseArray);
    }
    
    public function listFromCategoryAction($categoryId){
        $category = $this->getDoctrine()->getRepository('HtlSpendenportalBundle:Category')->find($categoryId);

        $projects = $category->getProjects();


        $responseArray = array();

        for($i=0;$i<count($projects);$i++){
            $item = array(
                "id"=>$projects[$i]->getId(),
                "title"=>$projects[$i]->getTitle(),
                "titlePictureUrl"=>$projects[$i]->getTitlePictureUrl(),
                "description"=>$projects[$i]->getDescription(),
                "shortinfo"=>$projects[$i]->getShortinfo(),
                "created_at"=>$projects[$i]->getCreatedAt(),
                "targetAmount"=>$projects[$i]->getTargetAmount(),
                "currentDonators"=>$projects[$i]->getCurrentDonators(),
                "currentAmount"=>$projects[$i]->getCurrentAmount()

            );
            array_push($responseArray, $item);
        }

        $responseArray = (object) $responseArray;

        return new JsonResponse($responseArray);
    }

    public function createAction ($title, $desciption, $shortinfo, $categoryId, $user, $targetAmount, $titlePictureUrl){

        $categoryId = $this->getDoctrine()->getRepository('HtlSpendenportalBundle:Category')->find($categoryId);
        $user = $this->getDoctrine()->getRepository('HtlSpendenportalBundle:User')->find($user);

        $date = new \DateTime('now');

        if (!$categoryId || !$user) {
            throw $this->createNotFoundException(
                'No category found for id '.$categoryId.' or not User found for id '.$user
            );
        }
        else{
            
            $project = new Project();
            $project->setTitle($title);
            $project->setTitlePictureUrl($titlePictureUrl);
            $project->setDescription($desciption);
            $project->setShortinfo($shortinfo);
            $project->setTargetAmount($targetAmount);
            $project->setCurrentAmount(0);
            $project->setCurrentDonators(0);
            $project->setCreatedAt($date);
            $project->setCategory($categoryId);
            $project->setUser($user);
            $project->setActive(true);
            
            $em = $this->getDoctrine()->getManager();

            // tells Doctrine you want to (eventually) save the Product (no queries yet)
            $em->persist($project);

            // actually executes the queries (i.e. the INSERT query)
            $em->flush();

            return new \Symfony\Component\HttpFoundation\Response('Inserted Project successful');
        }
    }

    public function updateAction($projectId, $title, $desciption, $shortinfo, $categoryId, $user, $targetAmount, $currentAmount, $titlePictureUrl, $active){

        $em = $this->getDoctrine()->getManager();
        $project = $em->getRepository('HtlSpendenportalBundle:Project')->find($projectId);

        if (!$project) {
            throw $this->createNotFoundException(
                'No category found for id '.$projectId
            );
        }
        
        $project->setTitle($title);
        $project->setTitlePictureUrl($titlePictureUrl);
        $project->setDescription($desciption);
        $project->setShortinfo($shortinfo);
        $project->setTargetAmount($targetAmount);
        $project->setCurrentAmount($currentAmount);
        $project->setCategory($categoryId);
        $project->setUser($user);
        $project->setActive($active);

        $em->flush();

        return new Response('Updated post successful');
    }

    public function deleteAction($projectId){

        $em = $this->getDoctrine()->getManager();
        $project = $em->getRepository('HtlSpendenportalBundle:Category')->find($projectId);

        if (!$project) {
            throw $this->createNotFoundException(
                'No category found for id '.$project
            );
        }

        /* Schauen ob es für dieses Project childs existieren! */


        $em->remove($project);
        $em->flush();


        return new Response('Picture has been deleted!');
    }
}
<commit_msg>calculate the progress for a receivers receiving goal<commit_after><?php

namespace Htl\SpendenportalBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class ProjectController extends Controller
{
    public function listAction(){
        $projects = $this->getDoctrine()->getRepository('HtlSpendenportalBundle:Project')->findAll();
        
        $responseArray = array();



        for($i=0;$i<count($projects);$i++){
            $progress = Math.floor(($projects[$i]->getCurrentAmount()-$projects[$i]->getTargetAmount())*100);
            $item = array(
                "id"=>$projects[$i]->getId(),
                "title"=>$projects[$i]->getTitle(),
                "titlePictureUrl"=>$projects[$i]->getTitlePictureUrl(),
                "description"=>$projects[$i]->getDescription(),
                "shortinfo"=>$projects[$i]->getShortinfo(),
                "created_at"=>$projects[$i]->getCreatedAt(),
                "targetAmount"=>$projects[$i]->getTargetAmount(),
                "currentAmount"=>$projects[$i]->getCurrentAmount(),
                "progress"=>$progress,
                "currentDonators"=>$projects[$i]->getCurrentDonators()

            );
            array_push($responseArray, $item);
        }

        $responseArray = (object) $responseArray;

        return new JsonResponse($responseArray);
    }
    
    public function listFromCategoryAction($categoryId){
        $category = $this->getDoctrine()->getRepository('HtlSpendenportalBundle:Category')->find($categoryId);

        $projects = $category->getProjects();


        $responseArray = array();

        for($i=0;$i<count($projects);$i++){
            $item = array(
                "id"=>$projects[$i]->getId(),
                "title"=>$projects[$i]->getTitle(),
                "titlePictureUrl"=>$projects[$i]->getTitlePictureUrl(),
                "description"=>$projects[$i]->getDescription(),
                "shortinfo"=>$projects[$i]->getShortinfo(),
                "created_at"=>$projects[$i]->getCreatedAt(),
                "targetAmount"=>$projects[$i]->getTargetAmount(),
                "currentDonators"=>$projects[$i]->getCurrentDonators(),
                "currentAmount"=>$projects[$i]->getCurrentAmount()

            );
            array_push($responseArray, $item);
        }

        $responseArray = (object) $responseArray;

        return new JsonResponse($responseArray);
    }

    public function createAction ($title, $desciption, $shortinfo, $categoryId, $user, $targetAmount, $titlePictureUrl){

        $categoryId = $this->getDoctrine()->getRepository('HtlSpendenportalBundle:Category')->find($categoryId);
        $user = $this->getDoctrine()->getRepository('HtlSpendenportalBundle:User')->find($user);

        $date = new \DateTime('now');

        if (!$categoryId || !$user) {
            throw $this->createNotFoundException(
                'No category found for id '.$categoryId.' or not User found for id '.$user
            );
        }
        else{
            
            $project = new Project();
            $project->setTitle($title);
            $project->setTitlePictureUrl($titlePictureUrl);
            $project->setDescription($desciption);
            $project->setShortinfo($shortinfo);
            $project->setTargetAmount($targetAmount);
            $project->setCurrentAmount(0);
            $project->setCurrentDonators(0);
            $project->setCreatedAt($date);
            $project->setCategory($categoryId);
            $project->setUser($user);
            $project->setActive(true);
            
            $em = $this->getDoctrine()->getManager();

            // tells Doctrine you want to (eventually) save the Product (no queries yet)
            $em->persist($project);

            // actually executes the queries (i.e. the INSERT query)
            $em->flush();

            return new \Symfony\Component\HttpFoundation\Response('Inserted Project successful');
        }
    }

    public function updateAction($projectId, $title, $desciption, $shortinfo, $categoryId, $user, $targetAmount, $currentAmount, $titlePictureUrl, $active){

        $em = $this->getDoctrine()->getManager();
        $project = $em->getRepository('HtlSpendenportalBundle:Project')->find($projectId);

        if (!$project) {
            throw $this->createNotFoundException(
                'No category found for id '.$projectId
            );
        }
        
        $project->setTitle($title);
        $project->setTitlePictureUrl($titlePictureUrl);
        $project->setDescription($desciption);
        $project->setShortinfo($shortinfo);
        $project->setTargetAmount($targetAmount);
        $project->setCurrentAmount($currentAmount);
        $project->setCategory($categoryId);
        $project->setUser($user);
        $project->setActive($active);

        $em->flush();

        return new Response('Updated post successful');
    }

    public function deleteAction($projectId){

        $em = $this->getDoctrine()->getManager();
        $project = $em->getRepository('HtlSpendenportalBundle:Category')->find($projectId);

        if (!$project) {
            throw $this->createNotFoundException(
                'No category found for id '.$project
            );
        }

        /* Schauen ob es für dieses Project childs existieren! */


        $em->remove($project);
        $em->flush();


        return new Response('Picture has been deleted!');
    }
}

{'fraction_non_alphanumeric': 0.1535099699535646, 'fraction_numerical': 0.0010015478466721297, 'mean_word_length': 2.538659793814433, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 180, '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': '136110', 'n_tokens_mistral': 2939, 'n_tokens_neox': 2821, 'n_words': 454}