| @@ 968-1025 (lines=58) @@ | ||
| 965 | } |
|
| 966 | ||
| 967 | try { |
|
| 968 | foreach ($properties as $propObj) { |
|
| 969 | $propName = $propObj->name; |
|
| 970 | ||
| 971 | if ($this->BO->getPropObject($propName) instanceof Relation) { |
|
| 972 | $prop = $this->BO->getPropObject($propName); |
|
| 973 | ||
| 974 | // handle the saving of MANY-TO-MANY relation values |
|
| 975 | if ($prop->getRelationType() == 'MANY-TO-MANY' && count($prop->getRelatedOIDs()) > 0) { |
|
| 976 | try { |
|
| 977 | try { |
|
| 978 | // check to see if the rel is on this class |
|
| 979 | $side = $prop->getSide(get_class($this->BO)); |
|
| 980 | } catch (IllegalArguementException $iae) { |
|
| 981 | $side = $prop->getSide(get_parent_class($this->BO)); |
|
| 982 | } |
|
| 983 | ||
| 984 | $lookUp = $prop->getLookup(); |
|
| 985 | ||
| 986 | // first delete all of the old RelationLookup objects for this rel |
|
| 987 | try { |
|
| 988 | if ($side == 'left') { |
|
| 989 | $lookUp->deleteAllByAttribute('leftID', $this->BO->getOID()); |
|
| 990 | } else { |
|
| 991 | $lookUp->deleteAllByAttribute('rightID', $this->BO->getOID()); |
|
| 992 | } |
|
| 993 | } catch (\Exception $e) { |
|
| 994 | throw new FailedSaveException('Failed to delete old RelationLookup objects on the table ['.$prop->getLookup()->getTableName().'], error is ['.$e->getMessage().']'); |
|
| 995 | } |
|
| 996 | ||
| 997 | $OIDs = $prop->getRelatedOIDs(); |
|
| 998 | ||
| 999 | if (isset($OIDs) && !empty($OIDs[0])) { |
|
| 1000 | // now for each posted OID, create a new RelationLookup record and save |
|
| 1001 | foreach ($OIDs as $oid) { |
|
| 1002 | $newLookUp = new RelationLookup($lookUp->get('leftClassName'), $lookUp->get('rightClassName')); |
|
| 1003 | if ($side == 'left') { |
|
| 1004 | $newLookUp->set('leftID', $this->BO->getOID()); |
|
| 1005 | $newLookUp->set('rightID', $oid); |
|
| 1006 | } else { |
|
| 1007 | $newLookUp->set('rightID', $this->BO->getOID()); |
|
| 1008 | $newLookUp->set('leftID', $oid); |
|
| 1009 | } |
|
| 1010 | $newLookUp->save(); |
|
| 1011 | } |
|
| 1012 | } |
|
| 1013 | } catch (\Exception $e) { |
|
| 1014 | throw new FailedSaveException('Failed to update a MANY-TO-MANY relation on the object, error is ['.$e->getMessage().']'); |
|
| 1015 | ||
| 1016 | return; |
|
| 1017 | } |
|
| 1018 | } |
|
| 1019 | ||
| 1020 | // handle the saving of ONE-TO-MANY relation values |
|
| 1021 | if ($prop->getRelationType() == 'ONE-TO-MANY') { |
|
| 1022 | $prop->setValue($this->BO->getOID()); |
|
| 1023 | } |
|
| 1024 | } |
|
| 1025 | } |
|
| 1026 | } catch (\Exception $e) { |
|
| 1027 | throw new FailedSaveException('Failed to save object, error is ['.$e->getMessage().']'); |
|
| 1028 | ||
| @@ 1011-1068 (lines=58) @@ | ||
| 1008 | } |
|
| 1009 | ||
| 1010 | try { |
|
| 1011 | foreach ($properties as $propObj) { |
|
| 1012 | $propName = $propObj->name; |
|
| 1013 | ||
| 1014 | if ($this->BO->getPropObject($propName) instanceof Relation) { |
|
| 1015 | $prop = $this->BO->getPropObject($propName); |
|
| 1016 | ||
| 1017 | // handle the saving of MANY-TO-MANY relation values |
|
| 1018 | if ($prop->getRelationType() == 'MANY-TO-MANY' && count($prop->getRelatedOIDs()) > 0) { |
|
| 1019 | try { |
|
| 1020 | try { |
|
| 1021 | // check to see if the rel is on this class |
|
| 1022 | $side = $prop->getSide(get_class($this->BO)); |
|
| 1023 | } catch (IllegalArguementException $iae) { |
|
| 1024 | $side = $prop->getSide(get_parent_class($this->BO)); |
|
| 1025 | } |
|
| 1026 | ||
| 1027 | $lookUp = $prop->getLookup(); |
|
| 1028 | ||
| 1029 | // first delete all of the old RelationLookup objects for this rel |
|
| 1030 | try { |
|
| 1031 | if ($side == 'left') { |
|
| 1032 | $lookUp->deleteAllByAttribute('leftID', $this->BO->getOID()); |
|
| 1033 | } else { |
|
| 1034 | $lookUp->deleteAllByAttribute('rightID', $this->BO->getOID()); |
|
| 1035 | } |
|
| 1036 | } catch (Exception $e) { |
|
| 1037 | throw new FailedSaveException('Failed to delete old RelationLookup objects on the table ['.$prop->getLookup()->getTableName().'], error is ['.$e->getMessage().']'); |
|
| 1038 | } |
|
| 1039 | ||
| 1040 | $OIDs = $prop->getRelatedOIDs(); |
|
| 1041 | ||
| 1042 | if (isset($OIDs) && !empty($OIDs[0])) { |
|
| 1043 | // now for each posted OID, create a new RelationLookup record and save |
|
| 1044 | foreach ($OIDs as $oid) { |
|
| 1045 | $newLookUp = new RelationLookup($lookUp->get('leftClassName'), $lookUp->get('rightClassName')); |
|
| 1046 | if ($side == 'left') { |
|
| 1047 | $newLookUp->set('leftID', $this->BO->getOID()); |
|
| 1048 | $newLookUp->set('rightID', $oid); |
|
| 1049 | } else { |
|
| 1050 | $newLookUp->set('rightID', $this->BO->getOID()); |
|
| 1051 | $newLookUp->set('leftID', $oid); |
|
| 1052 | } |
|
| 1053 | $newLookUp->save(); |
|
| 1054 | } |
|
| 1055 | } |
|
| 1056 | } catch (Exception $e) { |
|
| 1057 | throw new FailedSaveException('Failed to update a MANY-TO-MANY relation on the object, error is ['.$e->getMessage().']'); |
|
| 1058 | ||
| 1059 | return; |
|
| 1060 | } |
|
| 1061 | } |
|
| 1062 | ||
| 1063 | // handle the saving of ONE-TO-MANY relation values |
|
| 1064 | if ($prop->getRelationType() == 'ONE-TO-MANY') { |
|
| 1065 | $prop->setValue($this->BO->getOID()); |
|
| 1066 | } |
|
| 1067 | } |
|
| 1068 | } |
|
| 1069 | } catch (Exception $e) { |
|
| 1070 | throw new FailedSaveException('Failed to save object, error is ['.$e->getMessage().']'); |
|
| 1071 | ||