/** * updates/creates/deletes the reciprocal property * * @param string $action * @param int $userId * @param int $schemaId * @param Connection $con * * @throws \PropelException */ public function updateReciprocal($action, $userId, $schemaId, $con = null) { $inverseProfilePropertyId = $this->getProfileProperty()->getInverseProfilePropertyId(); if (empty($inverseProfilePropertyId) and $this->getProfileProperty()->getIsReciprocal()) { $inverseProfilePropertyId = $this->getProfileProperty()->getId(); } if (!$inverseProfilePropertyId) { //there's no reciprocal or inverse to process return; } $relatedPropertyId = $this->getRelatedSchemaPropertyId(); if (!$relatedPropertyId) { $relatedProperty = SchemaPropertyPeer::retrieveByUri($this->getObject()); if (!$relatedProperty) { //there's no related property in the registry return; } else { $relatedPropertyId = $relatedProperty->getId(); $this->setRelatedSchemaPropertyId($relatedPropertyId); $this->save(); } } $schemaPropertyID = $this->getSchemaPropertyId(); $property = $this->getSchemaPropertyRelatedBySchemaPropertyId(); //does the user have editorial rights to the reciprocal... $permission = false; //get the maintainers of the reciprocal property $maintainers = $property->getSchema()->getMaintainerIds(); foreach ($maintainers as $maintainerId) { if ($userId == $maintainerId) { $permission = true; break; } } if (false === $permission) { return; } $c = new Criteria(); $c->add(SchemaPropertyElementPeer::SCHEMA_PROPERTY_ID, $relatedPropertyId); $c->add(SchemaPropertyElementPeer::PROFILE_PROPERTY_ID, $inverseProfilePropertyId); $c->add(SchemaPropertyElementPeer::OBJECT, $property->getUri()); $recipElement = SchemaPropertyElementPeer::doSelectOne($c, $con); $recipSchemaProperty = SchemaPropertyPeer::retrieveByPK($relatedPropertyId, $con); $recipProfileProperty = ProfilePropertyPeer::retrieveByPK($inverseProfilePropertyId, $con); $statusId = $this->getStatusId(); $language = ''; if ($recipProfileProperty) { $recipField = $recipProfileProperty->getName(); if ($recipProfileProperty->getHasLanguage()) { $language = $this->getLanguage(); } } //if action == deleted then if ('deleted' == $action && $recipElement) { //delete the reciprocal $recipElement->delete($con); return; } //undelete the element if it's deleted and we get this far if (isset($recipElement)) { $recipElement->setDeletedAt(null); } //if action == added, and reciprocal doesn't exist if ('added' == $action && !$recipElement) { //add the reciprocal $recipElement = SchemaPropertyElementPeer::createElement($recipSchemaProperty, $userId, $inverseProfilePropertyId, $statusId, $language, false, true); } //if action == updated if ('updated' == $action) { //check to see if there's a reciprocal if (!$recipElement) { //create a new one $recipElement = SchemaPropertyElementPeer::createElement($recipSchemaProperty, $userId, $inverseProfilePropertyId, $statusId, $language, false, true); } } if ($recipElement) { if (isset($this->importId)) { $recipElement->importId = $this->importId; } $recipElement->setUpdatedUserId($userId); $recipElement->setRelatedSchemaPropertyId($schemaPropertyID); $recipElement->setObject($this->getSchemaPropertyRelatedBySchemaPropertyId()->getUri()); $recipElement->save($con); } return; }