Bouncy Melons 0.2
declarative style orm
view-model-extended.php
Go to the documentation of this file.
1 <?php
2 namespace bm\example;
3 /*
4  * sometimes we do not need any specific behaviour from singles and lists,
5  * for example - if we want to create just one more view.
6  * in this example we will create veiw where WineBottles will be grouped
7  * by brand and we will count how much WineBottles of each brand we have
8  *
9  * this style will save you some time on simple views, but it won't allow you to
10  * modify default behaviour of \bm\DataList and \bm\Single, and you won't be able
11  * to extends \bm\Single with new methods, so
12  * it's not recommended for working with important data.
13  */
15 
16  /*
17  * same declaration as in \bm\Single children
18  */
19  public function declareFields() {
20  return [
21  new \bm\IdField('brand', 'Brand',['list'=>VBrands::getSlug()]),
22  new \bm\NumericField('count','Count')
23  ];
24  }
25 
26  /*
27  * this is report, based on different tables, so we will mark it as not editable
28  */
29  public function isEditable() {
30  return false;
31  }
32 
33  /*
34  * same as in \bm\DataList children
35  */
36  public function declareView() {
37  $brands = new Brands();
38  $bottles = new WineBottles();
39  $this->createTemptableAs("
40  SELECT
41  tBrands.title, COUNT(tBottles.id) AS `count`
42  FROM
43  `".$brands->getTableName()."` AS tBrands
44  LEFT JOIN
45  `".$bottles->getViewName()."` AS tBottles ON (
46  tBottles.brand = tBrands.id
47  )
48  GROUP BY
49  tBrands.id
50  ");
51  }
52 }
53 
createTemptableAs($sql)
Definition: VModel.php:63