Elgg  Version 3.0
EntitySortByClause.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Database\Clauses;
4 
6 use ElggEntity;
7 
12 
16  public $property;
17 
21  public $direction;
22 
26  public $signed;
27 
31  public $join_type;
32 
37 
41  public function prepare(QueryBuilder $qb, $table_alias = null) {
42 
43  if (!isset($this->property_type)) {
44  if (in_array($this->property, ElggEntity::$primary_attr_names)) {
45  $this->property_type = 'attribute';
46  } else {
47  $this->property_type = 'metadata';
48  }
49  }
50 
51  switch ($this->property_type) {
52  case 'metadata' :
53  $md_alias = $qb->joinMetadataTable($table_alias, 'guid', $this->property, $this->join_type);
54  $column = "$md_alias.value";
55  break;
56 
57  case 'attribute' :
58  if (!in_array($this->property, ElggEntity::$primary_attr_names)) {
59  throw new \InvalidParameterException("'$this->property' is not a valid entity attribute");
60  }
61  $column = "$table_alias.$this->property";
62  break;
63 
64  case 'private_setting' :
65  $ps_alias = $qb->joinPrivateSettingsTable($table_alias, 'guid', $this->property, $this->join_type);
66  $column = "$ps_alias.value";
67  break;
68 
69  case 'annotation' :
70  $an_alias = $qb->joinAnnotationTable($table_alias, 'guid', $this->property, $this->join_type);
71  $column = "$an_alias.value";
72  break;
73 
74  default :
75  throw new \InvalidParameterException("'$this->property_type' is not a valid entity property type");
76  }
77 
78  if ($this->signed) {
79  $column = "CAST($column AS SIGNED)";
80  }
81 
82  $this->expr = $column;
83 
84  return parent::prepare($qb, $table_alias);
85  }
86 }
prepare(QueryBuilder $qb, $table_alias=null)
{Build an expression and/or apply it to an instance of query builder.Query builder Table aliasComposi...
$column
Definition: add.php:10
Database abstraction query builder.
Extends QueryBuilder with clauses necesary to sort entity lists by entity properties.
static $primary_attr_names
Definition: ElggEntity.php:49
joinAnnotationTable($from_alias= '', $from_column= 'guid', $name=null, $join_type= 'inner', $joined_alias=null)
Join annotations table from alias and return joined table alias.
Extends QueryBuilder with ORDER BY clauses.
joinPrivateSettingsTable($from_alias= '', $from_column= 'guid', $name=null, $join_type= 'inner', $joined_alias=null)
Join private settings table from alias and return joined table alias.
joinMetadataTable($from_alias= '', $from_column= 'guid', $name=null, $join_type= 'inner', $joined_alias=null)
Join metadata table from alias and return joined table alias.
elgg ElggEntity
Definition: ElggEntity.js:15