I needed to count the quantity of rows in a table of Workers (similar to the classic person) entity:
class Worker
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $idWorker;
/**
* @ORM\Column(type="string", length=20)
*/
private $omang;
/**
* @ORM\Column(type="string", length=100)
*/
private $workerTitle;
/**
* @ORM\Column(type="string", length=100)
*/
private $workerName;
......these other variables are also in the entity, but they are generated with the day of bith of the worker:
//date of retirement
private $retireYear;
//time to retirement
private $timeToRetirement;
//Time left in: Years, Months and days these are INTEGER VALUES
private $yearsLeft;
private $monthsLetf;
private $daysLeft;
In the Worker repository I have this function that works to count all rows:
public function countTotalWorkers (){
$query = $this->createQueryBuilder('Worker')->select('COUNT(Worker)');
$total = $query->getQuery()->getSingleScalarResult();
return $total;
}
Now I want to do something different, I want to count all the Rows that for instance have yearsLeft
smaller than 1, but years left is not in the database, as I said it is a generated value that lives inside Worker, and it's generated in a public function of the class...
Feel free to ask if you think you need more information... thank you in advanced.