Skip to content

Instantly share code, notes, and snippets.

View codecowboy's full-sized avatar

Luke Mackenzie codecowboy

  • UK
View GitHub Profile
@codecowboy
codecowboy / gist:1082246
Created July 14, 2011 10:44
ProfileFormType
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
services:
gymloop_profile_type:
class: Gymloop\CoreBundle\Form\ProfileFormType
tags:
- { name: form.type, alias: gymloop.profile.type }
arguments: [%fos_user.model.user.class%]
gymloop_profile_handler:
class: Gymloop\CoreBundle\Form\ProfileFormHandler
scope: request
@codecowboy
codecowboy / gist:1109764
Created July 27, 2011 16:35
catch EM error
if (isset($date)) {
$trainingSession = new TrainingSession();
$user = $this->get('security.context')->getToken()->getUser();
$trainingSession->setUser($user);
$date = date_create_from_format('d/m/y', $date);
$trainingSession->setDate($date);
$trainingSession->setStatus('pending');
$trainingSession->setType('gym');
$em = $this->getDoctrine()->getEntityManager();
if($request->isXmlHttpRequest()) {
if (isset($date)) {
$date = date_create_from_format('y-m-d', $date);
//remove the training session row from the db for this user
$user = $this->get('security.context')->getToken()->getUser();
$em = $this->getDoctrine()->getEntityManager();
$query = $em->createQuery('SELECT ts from GymloopDiaryBundle:TrainingSession ts
WHERE ts.user = :user AND CAST(ts.date as DATE) = :date')
->setParameter('user', $user)
$('.fc-day-number').each(function(){
lDay = parseInt($(this).text());
//check if it is another month date
if($(this).parents('td').hasClass('fc-other-month'))
{
lYear = parseInt(cYear);
//if it is belong to the previous month
if(lDay>15)
{
lMonth = parseInt(cMonth) - 1;
@codecowboy
codecowboy / gist:1185840
Created September 1, 2011 09:48
User Entity
<?php
namespace Gymloop\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
@codecowboy
codecowboy / gist:1185843
Created September 1, 2011 09:49
Motivation repository
<?php
namespace Gymloop\CoreBundle\Entity;
use Doctrine\ORM\EntityRepository;
/**
* MotivationRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
@codecowboy
codecowboy / gist:1185861
Created September 1, 2011 09:59
Motivation Entity
<?php
namespace Gymloop\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Gymloop\CoreBundle\Entity\Motivation
*
* @ORM\Table(name="gymloop_motivation")
@codecowboy
codecowboy / gist:1185908
Created September 1, 2011 10:34
Get users for admin
public function findUserAdminDetails()
{
$query = $this->getEntityManager()->createQuery('
SELECT u, p, m
FROM GymloopCoreBundle:User u
JOIN u.programmes p
JOIN u.motivation m
');
$result = $query->getArrayResult(); var_dump($result); exit;
@codecowboy
codecowboy / gist:1186513
Created September 1, 2011 16:06
Array result
$query = $this->getEntityManager()->createQuery('
SELECT COUNT(s) FROM GymloopDiaryBundle:TrainingSession s
WHERE s.status = :completed
AND s.user = :user')
->setParameter('user',$user)
->setParameter('completed','confirmed');
$result = $query->getResult();
array(1) { [0]=> array(1) { [1]=> string(1) "0" } }