+ private function hasKeyField(PlDBTableEntry $entry, array $fields)
+ {
+ foreach ($fields as $field) {
+ if (isset($entry->$field)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private function keyFields($keyName)
+ {
+ if ($keyName == self::PRIMARY_KEY) {
+ return $this->primaryKey;
+ } else if (isset($this->uniqueKeys[$keyName])) {
+ return $this->uniqueKeys[$keyName];
+ } else if (isset($this->multipleKeys[$keyName])) {
+ return $this->multipleKeys[$keyName];
+ }
+ throw new PlDBNoSuchKeyException($keyName, $this);
+ }
+
+ private function bestKeyFields(PlDBTableEntry $entry, $allowMultiple)
+ {
+ if ($this->hasKeyField($entry, $this->primaryKey)) {
+ return $this->primaryKey;
+ }
+ foreach ($this->uniqueKeys as $fields) {
+ if ($this->hasKeyField($entry, $fields)) {
+ return $fields;
+ }
+ }
+ if ($allowMultiple) {
+ foreach ($this->multipleKeys as $fields) {
+ if ($this->hasKeyField($entry, $fields)) {
+ return $fields;
+ }
+ }
+ }
+ return $this->primaryKey;
+ }
+
+ public function key(PlDBTableEntry $entry, array $keyFields)