22 protected static function setToMember($member, $instance, $value, $accessor) {
23 $instance->$accessor ( $value );
24 $instance->_rest [$member] = $value;
27 protected static function getAccessor($member, $instance, $part) {
28 $accessor =
"set" . ucfirst ( $member );
29 if (method_exists ( $instance, $accessor )) {
32 $class = get_class ( $instance );
33 Logger::warn (
"DAO",
"Missing modifier " . $accessor .
" in " . $class, $part );
37 public static function _affectsRelationObjects($className, $classPropKey, $manyToOneQueries, $oneToManyQueries, $manyToManyParsers, $objects, $included, $useCache): void {
38 if (\count ( $manyToOneQueries ) > 0) {
43 if (\count ( $oneToManyQueries ) > 0) {
44 self::_affectsObjectsFromArray ( $oneToManyQueries, $included,
function ($object, $member, $relationObjects, $fkField, $accessor, $class, $prop) use ($classPropKey) {
48 if (\count ( $manyToManyParsers ) > 0) {
54 if (isset ( $object->$fkField )) {
55 $value = $manyToOneObjects [$object->$fkField];
56 self::setToMember ( $member, $object, $value, $accessor );
69 private static function affectsOneToManyFromArray($instance, $member, $array =
null, $mappedByAccessor =
null, $accessor =
'', $class =
'', $prop =
null, $classPropKey =
null) {
71 self::_getOneToManyFromArray ( $ret, $array, Reflexion::getPropValue ( $instance, $classPropKey ), $mappedByAccessor, $prop );
72 self::setToMember ( $member, $instance, $ret, $accessor );
76 $includedNext =
false;
77 foreach ( $queries as $key => $pendingRelationsRequest ) {
78 list ( $class, $member, $fkField, $fkClass ) = \explode (
'|', $key );
79 if (\is_array ( $included )) {
80 $includedNext = self::_getIncludedNext ( $included, $member );
82 $objectsParsers = $pendingRelationsRequest->getObjectsConditionParsers ();
84 if (
'getOneToMany' === $part) {
86 $fkField =
'get' . \ucfirst ( $fkField );
88 foreach ( $objectsParsers as $objectsConditionParser ) {
89 $objectsConditionParser->compileParts ();
90 $relationObjects = self::_getAll ( self::getDb ( $class ), $class, $objectsConditionParser->getConditionParser (), $includedNext, $useCache );
91 $objects = $objectsConditionParser->getObjects ();
92 if ($accessor = self::getAccessor ( $member, current ( $objects ), $part )) {
93 foreach ( $objects as $object ) {
94 $affectsCallback ( $object, $member, $relationObjects, $fkField, $accessor, $class, $prop );
102 $includedNext =
false;
104 foreach ( $parsers as $key => $parser ) {
105 list ( $class, $member ) = \explode (
"|", $key );
106 if (is_array ( $included )) {
107 $includedNext = self::_getIncludedNext ( $included, $member );
110 $cParser = self::generateManyToManyParser ( $parser, $myPkValues );
111 $relationObjects = self::_getAll ( self::getDb ( $class ), $class, $cParser, $includedNext, $useCache );
112 if ($accessor = self::getAccessor ( $member, current ( $objects ),
'getManyToMany' )) {
113 foreach ( $objects as $object ) {
114 $pkV = Reflexion::getPropValue ( $object, $prop );
115 if (isset ( $myPkValues [$pkV] )) {
116 $ret = self::getManyToManyFromArrayIds ( $class, $relationObjects, $myPkValues [$pkV] );
117 self::setToMember ( $member, $object, $ret, $accessor );
125 foreach ( $array as $element ) {
126 $elementRef = $element->$elementAccessor ();
127 if (($elementRef == $fkv) || (\is_object ( $elementRef ) && Reflexion::getPropValue ( $elementRef, $prop ) == $fkv)) {
134 $sql = $parser->generateConcatSQL ();
138 foreach ( $result as $row ) {
139 $values = explode (
',', $row [
'_concat'] );
140 $myPkValues [$row [
'_field']] = $values;
141 $cParser->addParts ( $condition, $values );
143 $cParser->compileParts ();
148 return (isset ( $included [$member] )) ? (\is_bool ( $included [$member] ) ? $included [$member] : [ $included [$member] ]) :
false;
153 $prop = OrmUtils::getFirstPropKey ( $objectClass );
154 foreach ( $relationObjects as $targetEntityInstance ) {
155 $id = Reflexion::getPropValue ( $targetEntityInstance, $prop );
156 if (\array_search ( $id, $ids ) !==
false) {
157 \array_push ( $ret, $targetEntityInstance );
Abstract class for logging Ubiquity\log$Logger This class is part of Ubiquity.
Object/relational mapping utilities.
Represents a query condition.
getParserWhereMask($mask="'{value}'")
Reflection utilities in dev environment only.
Used by DAO class, realize relations assignments.
static _getOneToManyFromArray(&$ret, $array, $fkv, $elementAccessor, $prop)
static generateManyToManyParser(ManyToManyParser $parser, &$myPkValues)
static affectsOneToManyFromArray($instance, $member, $array=null, $mappedByAccessor=null, $accessor='', $class='', $prop=null, $classPropKey=null)
static _affectsObjectsFromArray($queries, $included, $affectsCallback, $part, $useCache=NULL)
static affectsManyToOneFromArray($object, $member, $manyToOneObjects, $fkField, $accessor)
static _affectsManyToManyObjectsFromArray($objectsClass, $parsers, $objects, $included, $useCache=NULL)
static _getIncludedNext($included, $member)
static getAccessor($member, $instance, $part)
static getManyToManyFromArrayIds($objectClass, $relationObjects, $ids)
static _affectsRelationObjects($className, $classPropKey, $manyToOneQueries, $oneToManyQueries, $manyToManyParsers, $objects, $included, $useCache)
static setToMember($member, $instance, $value, $accessor)
static getFirstPropKey($class)
Ubiquity\orm\traits This class is part of Ubiquity.