Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
DAORelationsPrepareTrait.php
Go to the documentation of this file.
1<?php
2
3namespace Ubiquity\orm\traits;
4
9
20
30 protected static function prepareManyToMany($db, &$ret, $instance, $member, $annot = null) {
31 $class = get_class ( $instance );
32 if (! isset ( $annot )) {
33 $annot = OrmUtils::getAnnotationInfoMember ( $class, "#ManyToMany", $member );
34 }
35 if ($annot !== false) {
36 $key = $annot ["targetEntity"] . "|" . $member . "|" . $annot ["inversedBy"] . "|";
37 if (! isset ( $ret [$key] )) {
38 $parser = new ManyToManyParser ( $db, $instance, $member );
39
40 $parser->init ( $annot );
41 $ret [$key] = $parser;
42 }
43 $accessor = "get" . ucfirst ( $ret [$key]->getMyPk () );
44 if (method_exists ( $instance, $accessor )) {
45 $fkv = $instance->$accessor ();
46 $ret [$key]->addValue ( $fkv );
47 }
48 }
49 }
50
59 protected static function prepareOneToMany(&$ret, $instance, $member, $annot = null) {
60 $class = get_class ( $instance );
61 if (! isset ( $annot ))
62 $annot = OrmUtils::getAnnotationInfoMember ( $class, "#oneToMany", $member );
63 if ($annot !== false) {
64 $fkClass = $annot ["className"];
65 $fkAnnot = OrmUtils::getAnnotationInfoMember ( $fkClass, "#joinColumn", $annot ["mappedBy"] );
66 if ($fkAnnot !== false) {
67 $fkMemberName = $annot ["mappedBy"];
68 if (\property_exists ( $fkClass, $fkAnnot ['name'] )) { // $fkClass is a class association (manyToMany with property)
69 $fkMemberName = $fkAnnot ['name'];
70 }
71 $fkv = OrmUtils::getFirstKeyValue ( $instance );
72 $key = $annot ["className"] . "|" . $member . "|" . $fkMemberName . "|" . $fkAnnot ["className"];
73 if (! isset ( $ret [$key] )) {
74 $ret [$key] = new PendingRelationsRequest ();
75 }
76 $quote = SqlUtils::$quote;
77 $ret [$key]->addPartObject ( $instance, $quote . $fkAnnot ["name"] . $quote . "= ?", $fkv );
78 }
79 }
80 }
81
91 protected static function prepareManyToOne(&$ret, $instance, $value, $fkField, $annotationArray) {
92 $member = $annotationArray ["member"];
93 $fk = OrmUtils::getFirstKey ( $annotationArray ["className"] );
94 $key = $annotationArray ["className"] . "|" . $member . "|" . $fkField . "|";
95 if (! isset ( $ret [$key] )) {
96 $ret [$key] = new PendingRelationsRequest ();
97 }
98 $ret [$key]->addPartObject ( $instance, SqlUtils::$quote . $fk . SqlUtils::$quote . "= ?", $value );
99 }
100}
SQL utilities.
Definition SqlUtils.php:13
Object/relational mapping utilities.
Definition OrmUtils.php:17
static getFirstKeyValue($instance)
Definition OrmUtils.php:107
static getAnnotationInfoMember($class, $keyAnnotation, $member)
Definition OrmUtils.php:155
Used by DAO class, prepare relations for loading.
static prepareManyToOne(&$ret, $instance, $value, $fkField, $annotationArray)
Prepares members associated with $instance with a manyToOne type relationship.
static prepareOneToMany(&$ret, $instance, $member, $annot=null)
Prepares members associated with $instance with a oneToMany type relationship.
static prepareManyToMany($db, &$ret, $instance, $member, $annot=null)
Prepares members associated with $instance with a ManyToMany type relationship.
Ubiquity\orm\traits This class is part of Ubiquity.