<commit_before><?php
// src/JYPS/RegisterBundle/Controller/MemberController.php;
namespace JYPS\RegisterBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContext;
use JYPS\RegisterBundle\Entity\Member;
use JYPS\RegisterBundle\Entity\MemberFee;
use JYPS\RegisterBundle\Entity\Intrest;
use JYPS\RegisterBundle\Entity\IntrestConfig;
use JYPS\RegisterBundle\Entity\MemberFeeConfig;
use JYPS\RegisterBundle\Form\Type\MemberJoinType;
use JYPS\RegisterBundle\Form\Type\MemberAddType;
use JYPS\RegisterBundle\Form\Type\MemberEditType;
use Doctrine\ORM\EntityRepository;
use Endroid\QrCode\QrCode;

class MemberController extends Controller 
{
 public function indexAction()
 {
  $repository = $this->getDoctrine()
   ->getRepository('JYPSRegisterBundle:Member');

  $query = $repository->createQueryBuilder('m')
    ->where('m.membership_end_date >= :current_date')
    ->setParameter('current_date', new \DateTime("now") )
    ->orderBy('m.surname', 'ASC')
    ->getQuery();
  
  $members = $query->getResult();

  return $this->render('JYPSRegisterBundle:Member:show_members.html.twig', array('members' => $members));
}

 public function showClosedAction()
 {
 $repository = $this->getDoctrine()
   ->getRepository('JYPSRegisterBundle:Member');

  $query = $repository->createQueryBuilder('m')
    ->where('m.membership_end_date <= :current_date')
    ->setParameter('current_date', new \DateTime("now") )
    ->orderBy('m.member_id', 'ASC')
    ->getQuery();
  
  $members = $query->getResult();

  return $this->render('JYPSRegisterBundle:Member:show_members_old.html.twig', array('members' => $members));
}


public function showAllAction($memberid)
{

  $request = $this->get('request');
  
  if (is_null($memberid)) {
        $postData = $request->get('member');
        $memberid = $postData['memberid'];
  }

  $member = $this->getDoctrine()
  ->getRepository('JYPSRegisterBundle:Member')
  ->findOneBy(array('member_id' => $memberid));

  if (!$member) {
    throw $this->createNotFoundException(
      'No member found for memberid '.$memberid
      );
  }

  $memberfees = $this->getDoctrine()
    ->getRepository('JYPSRegisterBundle:MemberFee')
    ->findBy(array('member_id' => $member->getId()),
             array('fee_period' => 'ASC'));
  
  $form = $this->createForm(new MemberEditType(), $member, array('action' => $this->generateUrl('member', array('memberid' => $member->getMemberId())),
  ));

    if ($request->getMethod() == 'POST') {
      $em = $this->getDoctrine()->getEntityManager();

        $form->submit($request);

        if ($form->isValid()) {
           $em->flush();
           $fees = $request->get('Fees_to_be_marked');
           $member_all_fees = $member->getMemberFees();
           if($fees != "") {
             foreach($member_all_fees as $member_fee) {
                if(in_array($member_fee->getId(), $fees)) {
                   $markfee = $this->getDoctrine()
                    ->getRepository('JYPSRegisterBundle:MemberFee')
                    ->findOneBy(array('id' => $member_fee->getId(),));
                  $markfee->setPaid(True);
                  $em->flush();
                } 
                else {
                   $markfee = $this->getDoctrine()
                    ->getRepository('JYPSRegisterBundle:MemberFee')
                    ->findOneBy(array('id' => $member_fee->getId(),));
                  $markfee->setPaid(False);
                  $em->flush();
                }
             }
           }
           else {
              foreach($member_all_fees as $member_fee) {
                   $markfee = $this->getDoctrine()
                    ->getRepository('JYPSRegisterBundle:MemberFee')
                    ->findOneBy(array('id' => $member_fee->getId(),));
                  $markfee->setPaid(False);
                  $em->flush();
              
              }
           }       
         
         return $this->redirect($this->generateUrl('member',array('memberid' => $memberid)));
        }
    }
  return $this->render('JYPSRegisterBundle:Member:show_member.html.twig', array('member' => $member,
    'memberfees' => $memberfees,
    'form' => $form->createView(),
    ));
 
}
public function addMemberAction() 
{
  $member = new Member();

  $all_confs = $this->getDoctrine()
  ->getManager()
  ->getRepository('JYPSRegisterBundle:IntrestConfig');

  $memberfee_confs = $this->getDoctrine()
  ->getManager()
  ->getRepository('JYPSRegisterBundle:MemberFeeConfig');

  $form = $this->createForm(new MemberAddType(), $member, array('action' => $this->generateUrl('join_internal_save'),
   'intrest_configs' => $all_confs,
   'memberfee_configs' => $memberfee_confs,));

  return $this->render('JYPSRegisterBundle:Member:add_member.html.twig', array(
   'form' => $form->createView(),
   ));
}

public function joinMemberAction(Request $request) 
{

  $member = new Member();

  $all_confs = $this->getDoctrine()
  ->getManager()
  ->getRepository('JYPSRegisterBundle:IntrestConfig');

  $memberfee_confs = $this->getDoctrine()
  ->getManager()
  ->getRepository('JYPSRegisterBundle:MemberFeeConfig');

  $form = $this->createForm(new MemberJoinType(), $member, array('action' => $this->generateUrl('join_save'),
   'intrest_configs' => $all_confs,
   'memberfee_configs' => $memberfee_confs,));

  return $this->render('JYPSRegisterBundle:Member:join_member.html.twig', array(
   'form' => $form->createView(),
   ));

}

public function generate_membership_card(Member $member) 
{
 
  $base_image_path = $this->get('kernel')->locateResource('@JYPSRegisterBundle/Resources/public/images/JYPS_Jasenkortti.png');
  $base_image = imagecreatefrompng($base_image_path);
  $output_image = $this->get('kernel')->locateResource('@JYPSRegisterBundle/Resources/savedCards/').'MemberCard_'.$member->getMemberId().'.png';
  
  /* member data to image */
  $width = imagesx($base_image);
  $height = imagesy($base_image);
  $black = imagecolorallocate($base_image, 0, 0, 0);
  $memberid = $member->getMemberId();
  $join_year = $member->getMembershipStartDate()->format('Y');
  $font = $this->get('kernel')->locateResource('@JYPSRegisterBundle/Resources/public/fonts/LucidaGrande.ttf');
  
  imagettftext($base_image, 38, 0, 390, 505, $black, $font, $memberid);
  imagettftext($base_image, 38, 0, 390, 570, $black, $font, $join_year);
  
  /*qr code to image & serialize json for qr code*/ 
  $member_data = array('member_id'=>$member->getMemberId(),
                       'join_year'=>$member->getMembershipStartDate()->format('Y'),
                       'name'=>$member->getFullName());
  $member_qr_data = json_encode($member_data);

  $qrCode = new QrCode();
  $qrCode->setSize(380);
  $qrCode->setText($member_qr_data);
  $qrCode = $qrCode->get('png');
  $qr_image = imagecreatefromstring($qrCode);
  imagecopy($base_image,$qr_image,550,22,0,0,imagesx($qr_image),imagesy($qr_image));
  /*write image to disk */
  imagepng($base_image,$output_image);
  
  return $output_image;
}

public function send_join_info_mail(Member $member, MemberFee $memberfee) 
{
  $intrest_names = array();
  if(!empty($member->getIntrests())) {
    foreach($member->getIntrests() as $intrest) {
      $intrest_config = $this->getDoctrine()<commit_msg>fixed public -> private<commit_after><?php
// src/JYPS/RegisterBundle/Controller/MemberController.php;
namespace JYPS\RegisterBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContext;
use JYPS\RegisterBundle\Entity\Member;
use JYPS\RegisterBundle\Entity\MemberFee;
use JYPS\RegisterBundle\Entity\Intrest;
use JYPS\RegisterBundle\Entity\IntrestConfig;
use JYPS\RegisterBundle\Entity\MemberFeeConfig;
use JYPS\RegisterBundle\Form\Type\MemberJoinType;
use JYPS\RegisterBundle\Form\Type\MemberAddType;
use JYPS\RegisterBundle\Form\Type\MemberEditType;
use Doctrine\ORM\EntityRepository;
use Endroid\QrCode\QrCode;

class MemberController extends Controller 
{
 public function indexAction()
 {
  $repository = $this->getDoctrine()
   ->getRepository('JYPSRegisterBundle:Member');

  $query = $repository->createQueryBuilder('m')
    ->where('m.membership_end_date >= :current_date')
    ->setParameter('current_date', new \DateTime("now") )
    ->orderBy('m.surname', 'ASC')
    ->getQuery();
  
  $members = $query->getResult();

  return $this->render('JYPSRegisterBundle:Member:show_members.html.twig', array('members' => $members));
}

 public function showClosedAction()
 {
 $repository = $this->getDoctrine()
   ->getRepository('JYPSRegisterBundle:Member');

  $query = $repository->createQueryBuilder('m')
    ->where('m.membership_end_date <= :current_date')
    ->setParameter('current_date', new \DateTime("now") )
    ->orderBy('m.member_id', 'ASC')
    ->getQuery();
  
  $members = $query->getResult();

  return $this->render('JYPSRegisterBundle:Member:show_members_old.html.twig', array('members' => $members));
}


public function showAllAction($memberid)
{

  $request = $this->get('request');
  
  if (is_null($memberid)) {
        $postData = $request->get('member');
        $memberid = $postData['memberid'];
  }

  $member = $this->getDoctrine()
  ->getRepository('JYPSRegisterBundle:Member')
  ->findOneBy(array('member_id' => $memberid));

  if (!$member) {
    throw $this->createNotFoundException(
      'No member found for memberid '.$memberid
      );
  }

  $memberfees = $this->getDoctrine()
    ->getRepository('JYPSRegisterBundle:MemberFee')
    ->findBy(array('member_id' => $member->getId()),
             array('fee_period' => 'ASC'));
  
  $form = $this->createForm(new MemberEditType(), $member, array('action' => $this->generateUrl('member', array('memberid' => $member->getMemberId())),
  ));

    if ($request->getMethod() == 'POST') {
      $em = $this->getDoctrine()->getEntityManager();

        $form->submit($request);

        if ($form->isValid()) {
           $em->flush();
           $fees = $request->get('Fees_to_be_marked');
           $member_all_fees = $member->getMemberFees();
           if($fees != "") {
             foreach($member_all_fees as $member_fee) {
                if(in_array($member_fee->getId(), $fees)) {
                   $markfee = $this->getDoctrine()
                    ->getRepository('JYPSRegisterBundle:MemberFee')
                    ->findOneBy(array('id' => $member_fee->getId(),));
                  $markfee->setPaid(True);
                  $em->flush();
                } 
                else {
                   $markfee = $this->getDoctrine()
                    ->getRepository('JYPSRegisterBundle:MemberFee')
                    ->findOneBy(array('id' => $member_fee->getId(),));
                  $markfee->setPaid(False);
                  $em->flush();
                }
             }
           }
           else {
              foreach($member_all_fees as $member_fee) {
                   $markfee = $this->getDoctrine()
                    ->getRepository('JYPSRegisterBundle:MemberFee')
                    ->findOneBy(array('id' => $member_fee->getId(),));
                  $markfee->setPaid(False);
                  $em->flush();
              
              }
           }       
         
         return $this->redirect($this->generateUrl('member',array('memberid' => $memberid)));
        }
    }
  return $this->render('JYPSRegisterBundle:Member:show_member.html.twig', array('member' => $member,
    'memberfees' => $memberfees,
    'form' => $form->createView(),
    ));
 
}
public function addMemberAction() 
{
  $member = new Member();

  $all_confs = $this->getDoctrine()
  ->getManager()
  ->getRepository('JYPSRegisterBundle:IntrestConfig');

  $memberfee_confs = $this->getDoctrine()
  ->getManager()
  ->getRepository('JYPSRegisterBundle:MemberFeeConfig');

  $form = $this->createForm(new MemberAddType(), $member, array('action' => $this->generateUrl('join_internal_save'),
   'intrest_configs' => $all_confs,
   'memberfee_configs' => $memberfee_confs,));

  return $this->render('JYPSRegisterBundle:Member:add_member.html.twig', array(
   'form' => $form->createView(),
   ));
}

public function joinMemberAction(Request $request) 
{

  $member = new Member();

  $all_confs = $this->getDoctrine()
  ->getManager()
  ->getRepository('JYPSRegisterBundle:IntrestConfig');

  $memberfee_confs = $this->getDoctrine()
  ->getManager()
  ->getRepository('JYPSRegisterBundle:MemberFeeConfig');

  $form = $this->createForm(new MemberJoinType(), $member, array('action' => $this->generateUrl('join_save'),
   'intrest_configs' => $all_confs,
   'memberfee_configs' => $memberfee_confs,));

  return $this->render('JYPSRegisterBundle:Member:join_member.html.twig', array(
   'form' => $form->createView(),
   ));

}

private function generate_membership_card(Member $member) 
{
 
  $base_image_path = $this->get('kernel')->locateResource('@JYPSRegisterBundle/Resources/public/images/JYPS_Jasenkortti.png');
  $base_image = imagecreatefrompng($base_image_path);
  $output_image = $this->get('kernel')->locateResource('@JYPSRegisterBundle/Resources/savedCards/').'MemberCard_'.$member->getMemberId().'.png';
  
  /* member data to image */
  $width = imagesx($base_image);
  $height = imagesy($base_image);
  $black = imagecolorallocate($base_image, 0, 0, 0);
  $memberid = $member->getMemberId();
  $join_year = $member->getMembershipStartDate()->format('Y');
  $font = $this->get('kernel')->locateResource('@JYPSRegisterBundle/Resources/public/fonts/LucidaGrande.ttf');
  
  imagettftext($base_image, 38, 0, 390, 505, $black, $font, $memberid);
  imagettftext($base_image, 38, 0, 390, 570, $black, $font, $join_year);
  
  /*qr code to image & serialize json for qr code*/ 
  $member_data = array('member_id'=>$member->getMemberId(),
                       'join_year'=>$member->getMembershipStartDate()->format('Y'),
                       'name'=>$member->getFullName());
  $member_qr_data = json_encode($member_data);

  $qrCode = new QrCode();
  $qrCode->setSize(380);
  $qrCode->setText($member_qr_data);
  $qrCode = $qrCode->get('png');
  $qr_image = imagecreatefromstring($qrCode);
  imagecopy($base_image,$qr_image,550,22,0,0,imagesx($qr_image),imagesy($qr_image));
  /*write image to disk */
  imagepng($base_image,$output_image);
  
  return $output_image;
}

private function send_join_info_mail(Member $member, MemberFee $memberfee) 
{
  $intrest_names = array();
  if(!empty($member->getIntrests())) {
    foreach($member->getIntrests() as $intrest) {
      $intrest_config = $this->getDoctrine()
{'fraction_non_alphanumeric': 0.17011995637949837, 'fraction_numerical': 0.004225736095965104, 'mean_word_length': 3.6595744680851063, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 260, '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': '823825', 'n_tokens_mistral': 4828, 'n_tokens_neox': 4663, 'n_words': 651}