I found a way with minimum changes but I haven't finished coding it
yet.
The basic idea:
Define a model (like IncomeReport) in you schema having the attribute
"export: none". Which stops Doctrine from making any database
representation (tables) for this model. A simple example:
IncomeReport:
tableName: income_reports
columns:
name:
type: string
primary: true
selling_price:
type: float
cost_price:
type: float
count:
type: float
total:
type: float
date:
type: date
time:
type: time
attributes:
export: none
Now, when IncomeReport is a model you can declare it in modules.yml
and then generate admin module by running "sf dmAdmin:generate".
Open the IncomeReportTable class and define a method to retrieve the
entries. A simplified version (derived from my use-case) is the
following:
public function getListQuery( ) {
$q = new Doctrine_RawSql();
$q->select( '{i.*}' )
->from( <<<END_SQL
((
SELECT
bp.name AS name,
bp.price AS selling_price,
bp.cost_price AS cost_price,
COUNT(
br.id) AS count,
bp.price*COUNT(
br.id) AS total,
br.scheduled_on AS date,
br.scheduled_at AS time
FROM beauty_reservation br
LEFT JOIN beauty_procedure bp ON
bp.id=br.procedure_id
GROUP BY name
ORDER BY br.scheduled_on, scheduled_at
)
UNION
(
SELECT
p.name AS name,
p.selling_price AS selling_price,
p.delivery_price AS cost_price,
SUM(po.quantity) AS count,
p.selling_price*COUNT(
po.id) AS total,
po.created_at AS date,
'00:00:00' AS time
FROM product_order po
LEFT JOIN product p ON
p.id=po.product_id
GROUP BY name
ORDER BY po.created_at
)
ORDER BY date, time) i
END_SQL
)
->addComponent( 'i' , 'IncomeReport' );
return $q;
}
Now you have Doctrine_RawSql query which allows almost all methods of
Doctrine_Query and you end up with Collection!
A small bit of tweaking of Form and Configuration classes is required
to support Doctrine_RawSql. When I'm done with them I'll post them.
On 24 Юни, 11:08, Roel Sint <
rmsi...@gmail.com> wrote:
> I have been searching for a similar solution and did not found much
> either. Therefore I experimented by retrieving a list of id's. And
> then hydrate the records individually, because of this result caching
> will be probably needed if it is used in production. The result is
> that you have an array, not a collection :-(, with all different
> objects, because it is a pager the results are nicely sorted. Don't
> know if this helps, perhaps it gives you an idea.
>
> See:
https://github.com/beeldspraak/bsdmSocialMediaPlugin/blob/master/lib/...https://github.com/beeldspraak/bsdmSocialMediaPlugin/blob/master/README