<?php
/*
 * Developer : John D'Alto (jdalto@yahoo.com)
 * Date : 9/1/2012
 * All code (c)2012 JLS Consulting, all rights reserved
 */

namespace Dorcas\TabithaBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
//use Dorcas\TabithaBundle\Entity\Client;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
//use Dorcas\TabithaBundle\Form\Type\ClientInformationType;
//use Dorcas\TabithaBundle\Form\Type\FinanceType;
//use Dorcas\TabithaBundle\Entity\Finance;


class DefaultController extends Controller
{
    
    public function showAction()
    {
        $totalrecs = $this->getCount();
        return $this->render('DorcasTabithaBundle:Default:index.html.twig', array(
                'totalrecs'      => $totalrecs,
                ));   
    }
    
    
  /**
   * @return int
   */
  public function getCount(){
    $aResultTotal = $this->getDoctrine()->getEntityManager()
      ->createQuery('SELECT COUNT(a) FROM DorcasTabithaBundle:Client a WHERE a.is_active = 1')
      ->setMaxResults(1)
      ->getResult();
     return $aResultTotal[0][1];
  }
    
     public function messageAction()
    {
       // Get the Manager's Message
        // Get newest record         
        $em = $this->getDoctrine()->getEntityManager();
        $query = $em->createQuery(
            'SELECT m FROM DorcasTabithaBundle:Messages m ORDER BY m.created_dt DESC');
        $query->setFirstResult('0');
        $query->setMaxResults('1');
         if(!$query->getResult())
        {
            $messageMess = 'Welcome to the Tabitha Manager Message.';
        }
        else
        {
            // Return a single record - important
            $message = $query->getSingleResult();
            $messageMess = $message->getMessage();
        }

        return new Response('<html><body>' . $messageMess . '</body></html>');   

    }
    
    
   
}
