/** * To check this relationship belongs to a specfic entity property * * @param ResourceType $resourceType The type of the entity * @param ResourceProperty/NULL $resourceProperty The property in the entity * * @return boolean */ public function isBelongsTo(ResourceType $resourceType, $resourceProperty) { $flag1 = is_null($resourceProperty); $flag2 = is_null($this->_resourceProperty); if ($flag1 != $flag2) { return false; } if ($flag1 === true) { return strcmp($resourceType->getFullName(), $this->_resourceType->getFullName()) == 0; } return strcmp($resourceType->getFullName(), $this->_resourceType->getFullName()) == 0 && strcmp($resourceProperty->getName(), $this->_resourceProperty->getName()) == 0; }
/** * Add a property belongs to this resource type instance * * @param ResourceProperty $property Property to add * * @throws InvalidOperationException * @return void */ public function addProperty(ResourceProperty $property) { if ($this->_resourceTypeKind == ResourceTypeKind::PRIMITIVE) { throw new InvalidOperationException(Messages::resourceTypeNoAddPropertyForPrimitive()); } $name = $property->getName(); foreach (array_keys($this->_propertiesDeclaredOnThisType) as $propertyName) { if (strcasecmp($propertyName, $name) == 0) { throw new InvalidOperationException(Messages::resourceTypePropertyWithSameNameAlreadyExists($propertyName, $this->_name)); } } if ($property->isKindOf(ResourcePropertyKind::KEY)) { if ($this->_resourceTypeKind != ResourceTypeKind::ENTITY) { throw new InvalidOperationException(Messages::resourceTypeKeyPropertiesOnlyOnEntityTypes()); } if ($this->_baseType != null) { throw new InvalidOperationException(Messages::resourceTypeNoKeysInDerivedTypes()); } } if ($property->isKindOf(ResourcePropertyKind::ETAG) && $this->_resourceTypeKind != ResourceTypeKind::ENTITY) { throw new InvalidOperationException(Messages::resourceTypeETagPropertiesOnlyOnEntityTypes()); } //Check for Base class properties $this->_propertiesDeclaredOnThisType[$name] = $property; // Set $this->_allProperties to null, this is very important because the // first call to getAllProperties will initilaize $this->_allProperties, // further call to getAllProperties will not reinitialize _allProperties // so if addProperty is called after calling getAllProperties then the // property just added will not be reflected in $this->_allProperties unset($this->_allProperties); $this->_allProperties = array(); }
/** * Get related resource for a resource * * @param ResourceSet $sourceResourceSet The source resource set * @param mixed $sourceEntityInstance The source resource * @param ResourceSet $targetResourceSet The resource set of * the navigation property * @param ResourceProperty $targetProperty The navigation property to be * retrieved * * @return Object/null The related resource if exists else null */ public function getRelatedResourceReference(ResourceSet $sourceResourceSet, $sourceEntityInstance, ResourceSet $targetResourceSet, ResourceProperty $targetProperty) { $result = null; $srcClass = get_class($sourceEntityInstance); $navigationPropName = $targetProperty->getName(); if ($srcClass === 'Order') { if ($navigationPropName === 'Customer') { if (empty($sourceEntityInstance->CustomerID)) { $result = null; } else { $query = "SELECT * FROM Customers WHERE CustomerID = '{$sourceEntityInstance->CustomerID}'"; $stmt = sqlsrv_query($this->_connectionHandle, $query); if ($stmt === false) { $errorAsString = self::_getSQLSRVError(); ODataException::createInternalServerError($errorAsString); } if (!sqlsrv_has_rows($stmt)) { $result = null; } $result = $this->_serializeCustomer(sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)); } } else { ODataException::createInternalServerError('Customer does not have navigation porperty with name: ' . $navigationPropName . ' Contact Service Provider'); } } else { if ($srcClass === 'Order_Details') { if ($navigationPropName === 'Order') { if (empty($sourceEntityInstance->OrderID)) { $result = null; } else { $query = "SELECT * FROM Orders WHERE OrderID = {$sourceEntityInstance->OrderID}"; $stmt = sqlsrv_query($this->_connectionHandle, $query); if ($stmt === false) { $errorAsString = self::_getSQLSRVError(); ODataException::createInternalServerError($errorAsString); } if (!sqlsrv_has_rows($stmt)) { $result = null; } $result = $this->_serializeOrder(sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)); } } else { ODataException::createInternalServerError('Order_Details does not have navigation porperty with name: ' . $navigationPropName . ' Contact Service Provider'); } } } return $result; }
/** * Write a navigation property * * @param ResourceType $resourceType Resource type * @param array $associationTypesInResourceTypeNamespace Collection * of association types for the given resource types * array(ResourceAssociatedType) * @param ResourceProperty $navigationProperty Navigation * property * * @throws InvalidOperationException * @return nothing */ private function _writeNavigationProperty(ResourceType $resourceType, $associationTypesInResourceTypeNamespace, ResourceProperty $navigationProperty) { $associationTypeLookupName = $resourceType->getName() . '_' . $navigationProperty->getName(); if (!array_key_exists($associationTypeLookupName, $associationTypesInResourceTypeNamespace)) { throw new InvalidOperationException(Messages::metadataWriterNoResourceAssociationSetForNavigationProperty($navigationProperty->getName(), $resourceType->getName())); } $associationType = $associationTypesInResourceTypeNamespace[$associationTypeLookupName]; $thisEnd = $associationType->getResourceAssociationTypeEnd($resourceType, $navigationProperty); $relatedEnd = $associationType->getRelatedResourceAssociationSetEnd($resourceType, $navigationProperty); $this->_iOdataWriter->startElement(ODataConstants::NAVIGATION_PROPERTY); $this->_iOdataWriter->writeAttribute(ODataConstants::NAME, $navigationProperty->getName()); $this->_iOdataWriter->writeAttribute(ODataConstants::RELATIONSHIP, $associationType->getFullName()); $this->_iOdataWriter->writeAttribute(ODataConstants::FROM_ROLE, $thisEnd->getName()); $this->_iOdataWriter->writeAttribute(ODataConstants::TO_ROLE, $relatedEnd->getName()); $this->_iOdataWriter->endElement(); }
/** * Get related resource for a resource * * @param ResourceSet $sourceResourceSet The source resource set * @param mixed $sourceEntityInstance The source resource * @param ResourceSet $targetResourceSet The resource set of * the navigation property * @param ResourceProperty $targetProperty The navigation property to be * retrieved * * @return Object/null The related resource if exists else null */ public function getRelatedResourceReference(ResourceSet $sourceResourceSet, $sourceEntityInstance, ResourceSet $targetResourceSet, ResourceProperty $targetProperty) { $result = null; $srcClass = get_class($sourceEntityInstance); $navigationPropName = $targetProperty->getName(); if ($srcClass === 'category') { } else { if ($srcClass === 'customers') { } else { if ($srcClass === 'employee') { } else { if ($srcClass === 'order_detail') { if ($navigationPropName === 'order') { if (empty($sourceEntityInstance->OrderID)) { $result = null; } else { $query = "SELECT * FROM orders WHERE OrderID = '{$sourceEntityInstance->OrderID}'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializeorder(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { if ($navigationPropName === 'product') { if (empty($sourceEntityInstance->ProductID)) { $result = null; } else { $query = "SELECT * FROM products WHERE ProductID = '{$sourceEntityInstance->ProductID}'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializeproduct(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { die('order_detail does not have navigation porperty with name: ' . $navigationPropName); } } } else { if ($srcClass === 'order') { if ($navigationPropName === 'customer') { if (empty($sourceEntityInstance->CustomerID)) { $result = null; } else { $query = "SELECT * FROM customers WHERE CustomerID = '{$sourceEntityInstance->CustomerID}'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializecustomer(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { if ($navigationPropName === 'employee') { if (empty($sourceEntityInstance->EmployeeID)) { $result = null; } else { $query = "SELECT * FROM employees WHERE EmployeeID = '{$sourceEntityInstance->EmployeeID}'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializeemployee(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { if ($navigationPropName === 'shipper') { if (empty($sourceEntityInstance->ShipVia)) { $result = null; } else { $query = "SELECT * FROM shippers WHERE ShipVia = '{$sourceEntityInstance->ShipVia}'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializeshipper(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { die('order does not have navigation porperty with name: ' . $navigationPropName); } } } } else { if ($srcClass === 'product') { if ($navigationPropName === 'category') { if (empty($sourceEntityInstance->CategoryID)) { $result = null; } else { $query = "SELECT * FROM categories WHERE CategoryID = '{$sourceEntityInstance->CategoryID}'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializecategory(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { if ($navigationPropName === 'supplier') { if (empty($sourceEntityInstance->SupplierID)) { $result = null; } else { $query = "SELECT * FROM suppliers WHERE SupplierID = '{$sourceEntityInstance->SupplierID}'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializesupplier(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { die('product does not have navigation porperty with name: ' . $navigationPropName); } } } else { if ($srcClass === 'shipper') { } else { if ($srcClass === 'supplier') { } } } } } } } } return $result; }
/** * Writes a primitive value and related information to the given * ODataProperty instance. * * @param mixed &$primitiveValue The primitive value to write. * @param ResourceProperty &$resourceProperty The metadata of the primitive * property value. * @param ODataProperty &$odataProperty ODataProperty instance to which * the primitive value and related * information to write out. * * @throws ODataException If given value is not primitive. * * @return void */ private function _writePrimitiveValue(&$primitiveValue, ResourceProperty &$resourceProperty, ODataProperty &$odataProperty) { if (is_object($primitiveValue)) { //TODO ERROR: The property 'PropertyName' //is defined as primitive type but value is an object } $odataProperty->name = $resourceProperty->getName(); $odataProperty->typeName = $resourceProperty->getInstanceType()->getFullTypeName(); if (is_null($primitiveValue)) { $odataProperty->value = null; } else { $resourceType = $resourceProperty->getResourceType(); $this->_primitiveToString($resourceType, $primitiveValue, $odataProperty->value); } }
/** * Gets name of the sub path segment * * @return string */ public function getName() { return $this->_resourceProperty->getName(); }
/** * Gets the resource type on which the resource property is declared on, * If property is not declared in the given resource type, then this * function drilldown to the inheritance hierarchy of the given resource * type to find out the baseclass in which the property is declared * * @param ResourceType $resourceType The resource type to start looking * @param ResourceProperty $resourceProperty The resource property in question * * @return ResourceType/NULL Returns reference to the ResourceType on which * the $resourceProperty is declared, NULL if * $resourceProperty is not declared anywhere * in the inheritance hierarchy */ private function _getResourceTypeWherePropertyIsDeclared(ResourceType $resourceType, ResourceProperty $resourceProperty) { $type = $resourceType; while ($type !== null) { if ($type->tryResolvePropertyTypeDeclaredOnThisTypeByName($resourceProperty->getName()) !== null) { break; } $type = $type->getBaseType(); } return $type; }
/** * Get related resource for a resource * * @param ResourceSet $sourceResourceSet The source resource set * @param mixed $sourceEntityInstance The source resource * @param ResourceSet $targetResourceSet The resource set of * the navigation property * @param ResourceProperty $targetProperty The navigation property to be * retrieved * * @return Object/null The related resource if exists else null */ public function getRelatedResourceReference(ResourceSet $sourceResourceSet, $sourceEntityInstance, ResourceSet $targetResourceSet, ResourceProperty $targetProperty) { $result = null; $srcClass = get_class($sourceEntityInstance); $navigationPropName = $targetProperty->getName(); switch (true) { case $srcClass == 'Post': if ($navigationPropName == 'User') { $query = "SELECT * FROM `wp_users` WHERE ID = {$sourceEntityInstance->Author}"; $stmt = mysql_query($query); $stmt = mysql_query($query); $data = mysql_fetch_assoc($stmt); $result = $this->_serializeUser($data); if ($stmt === false) { die(mysql_error()); } if (!mysql_num_rows($stmt)) { $result = null; } } else { die('Post does not have navigation porperty with name: ' . $navigationPropName); } break; case $srcClass == 'Comment': if ($navigationPropName == 'User') { $query = "SELECT * FROM `wp_users` WHERE ID = {$sourceEntityInstance->UserID}"; $stmt = mysql_query($query); if ($stmt === false) { die(mysql_error()); } if (!mysql_num_rows($stmt)) { $result = null; } $data = mysql_fetch_assoc($stmt); $result = $this->_serializeUser($data); } elseif ($navigationPropName == 'Post') { $query = "SELECT * FROM `wp_posts` WHERE" . " wp_posts.post_type = 'post'" . " AND wp_posts.post_status = 'publish'" . " AND wp_posts.ID = {$sourceEntityInstance->PostID}"; $stmt = mysql_query($query); if ($stmt === false) { die(mysql_error()); } if (!mysql_num_rows($stmt)) { $result = null; } $data = mysql_fetch_assoc($stmt); $result = $this->_serializePost($data); } else { die('Comment does not have navigation porperty with name: ' . $navigationPropName); } break; } mysql_free_result($stmt); return $result; }
/** * Gets the ResourceAssociationType instance for the given * ResourceAssociationSet and one of it's end. * * This function first searches the ResourceAssociationType cache, * if found return it otherwise create the Association type for the given * association set, cache and return it. * * Creation of ResourceAssociationType includes two sub-tasks: * 1. Deciding name of 'ResourceAssociationType' * (see the function _getAssociationTypeName) * 2. Deciding names for two 'ResourceAssociationTypeEnd' of the * 'ResourceAssociationType' * Refer ./AssociationSetAndTypeNamingRules.txt for naming rules. * * @param ResourceAssociationSet $resourceAssociationSet Association set to * get the * association type * @param ResourceSetWrapper $resourceSet Resource set for * one of the ends of * given association set * @param ResourceType $resourceType Resource type for * one of the ends of * given association set * @param ResourceProperty $navigationProperty Resource property for * one of the ends of * given association set * * @return ResourceAssociationType The association type * for the given association set */ private function _getResourceAssociationType(ResourceAssociationSet $resourceAssociationSet, ResourceSetWrapper $resourceSet, ResourceType $resourceType, ResourceProperty $navigationProperty) { $resourceTypeNamespace = $this->getResourceTypeNamespace($resourceType); $resourceAssociationTypesInNamespace =& $this->getResourceAssociationTypesForNamespace($resourceTypeNamespace); $associationTypeLookupKey = $resourceType->getName() . '_' . $navigationProperty->getName(); if (array_key_exists($associationTypeLookupKey, $resourceAssociationTypesInNamespace)) { return $resourceAssociationTypesInNamespace[$associationTypeLookupKey]; } //Generate resource association type end names //Refer ./AssociationSetAndTypeNamingRules.txt $associationTypeEnd1Name = $associationTypeEnd2Name = null; $isBiDirectional = $resourceAssociationSet->isBidirectional(); if ($isBiDirectional) { $associationTypeEnd1Name = $resourceAssociationSet->getEnd1()->getResourceType()->getName() . '_' . $resourceAssociationSet->getEnd1()->getResourceProperty()->getName(); $associationTypeEnd2Name = $resourceAssociationSet->getEnd2()->getResourceType()->getName() . '_' . $resourceAssociationSet->getEnd2()->getResourceProperty()->getName(); } else { if (!is_null($resourceAssociationSet->getEnd1()->getResourceProperty())) { $associationTypeEnd1Name = $resourceAssociationSet->getEnd1()->getResourceType()->getName(); $associationTypeEnd2Name = $resourceAssociationSet->getEnd1()->getResourceProperty()->getName(); } else { $associationTypeEnd1Name = $resourceAssociationSet->getEnd2()->getResourceProperty()->getName(); $associationTypeEnd2Name = $resourceAssociationSet->getEnd2()->getResourceType()->getName(); } } //Generate resource assoication type name //Refer ./AssociationSetAndTypeNamingRules.txt $resourceAssociationTypeName = $this->_getAssociationTypeName($resourceAssociationSet); //Create and cache the association type $resourceAssociationType = new ResourceAssociationType($resourceAssociationTypeName, $resourceTypeNamespace, new ResourceAssociationTypeEnd($associationTypeEnd1Name, $resourceAssociationSet->getEnd1()->getResourceType(), $resourceAssociationSet->getEnd1()->getResourceProperty(), $resourceAssociationSet->getEnd2()->getResourceProperty()), new ResourceAssociationTypeEnd($associationTypeEnd2Name, $resourceAssociationSet->getEnd2()->getResourceType(), $resourceAssociationSet->getEnd2()->getResourceProperty(), $resourceAssociationSet->getEnd1()->getResourceProperty())); $resourceAssociationTypesInNamespace[$associationTypeLookupKey] = $resourceAssociationType; if ($isBiDirectional) { $relatedAssociationSetEnd = $resourceAssociationSet->getRelatedResourceAssociationSetEnd($resourceSet->getResourceSet(), $resourceType, $navigationProperty); $relatedEndLookupKey = $relatedAssociationSetEnd->getResourceType()->getName() . '_' . $relatedAssociationSetEnd->getResourceProperty()->getName(); $resourceAssociationTypesInNamespace[$relatedEndLookupKey] = $resourceAssociationType; } return $resourceAssociationType; }
/** * Gets the ResourceAssociationSet instance for the given source * association end. * * @param ResourceSet $sourceResourceSet Resource set * of the source * association end * @param ResourceType $sourceResourceType Resource type of the source * association end * @param ResourceProperty $targetResourceProperty Resource property of * the source * association end * * @return ResourceAssociationSet */ public function getResourceAssociationSet(ResourceSet $sourceResourceSet, ResourceType $sourceResourceType, ResourceProperty $targetResourceProperty) { //e.g. //ResourceSet => Representing 'Customers' entity set //ResourceType => Representing'Customer' entity type //ResourceProperty => Representing 'Orders' property //We have created ResourceAssoicationSet while adding //ResourceSetReference or ResourceReference //and kept in $this->associationSets //$metadata->addResourceSetReferenceProperty( // $customersEntityType, // 'Orders', // $ordersResourceSet // ); $targetResourceSet = $targetResourceProperty->getResourceType()->getCustomState(); if (is_null($targetResourceSet)) { throw new InvalidOperationException('Failed to retrieve the custom state from ' . $resourceProperty->getResourceType()->getName()); } //Customer_Orders_Orders, Order_Customer_Customers $key = $sourceResourceType->getName() . '_' . $targetResourceProperty->getName() . '_' . $targetResourceSet->getName(); if (array_key_exists($key, $this->associationSets)) { return $this->associationSets[$key]; } return null; }
public function testResourceProperty() { try { $addressResType = new ResourceType(new ReflectionClass('Address2'), ResourceTypeKind::COMPLEX, 'Address', 'Northwind'); $booleanResourcetype = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::BOOLEAN); $isPrimaryPrimProperty = new ResourceProperty('IsPrimary', null, ResourcePropertyKind::PRIMITIVE, $booleanResourcetype); $addressResType->addProperty($isPrimaryPrimProperty); $exceptionThrown = false; try { $addressComplexProperty = new ResourceProperty('Address', null, ResourcePropertyKind::COMPLEX_TYPE | ResourcePropertyKind::KEY, $addressResType); } catch (\InvalidArgumentException $exception) { $exceptionThrown = true; $this->AssertStringEndsWith('not a valid ResourcePropertyKind enum value or valid combination of ResourcePropertyKind enum values', $exception->getMessage()); } if (!$exceptionThrown) { $this->fail('An expected InvalidArgumentException for \'invalid ResourcePropertyKind\' has not been raised'); } $exceptionThrown = false; try { $stringResourceType = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::STRING); $addressComplexProperty = new ResourceProperty('Address', null, ResourcePropertyKind::COMPLEX_TYPE, $stringResourceType); } catch (\InvalidArgumentException $exception) { $exceptionThrown = true; $this->AssertStringStartsWith('The \'$kind\' parameter does not match with the type of the resource type', $exception->getMessage()); } if (!$exceptionThrown) { $this->fail('An expected InvalidArgumentException for \'Property and ResourceType kind mismatch\' has not been raised'); } $customerResType = new ResourceType(new ReflectionClass('Customer2'), ResourceTypeKind::ENTITY, 'Customer', 'Northwind'); $stringResourceType = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::STRING); $customerIDPrimProperty = new ResourceProperty('CustomerID', null, ResourcePropertyKind::PRIMITIVE | ResourcePropertyKind::KEY, $stringResourceType); $customerNamePrimProperty = new ResourceProperty('CustomerName', null, ResourcePropertyKind::PRIMITIVE, $stringResourceType); $intResourceType = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::INT32); $ratingPrimProperty = new ResourceProperty('Rating', null, ResourcePropertyKind::PRIMITIVE, $intResourceType); $customerResType->addProperty($customerIDPrimProperty); $customerResType->addProperty($customerNamePrimProperty); $customerResType->addProperty($ratingPrimProperty); $this->AssertTrue($customerIDPrimProperty->isKindOf(ResourcePropertyKind::KEY)); $this->AssertTrue($customerIDPrimProperty->isKindOf(ResourcePropertyKind::PRIMITIVE)); $customerReferenceSetProperty = new ResourceProperty('Customers', null, ResourcePropertyKind::RESOURCESET_REFERENCE, $customerResType); $this->AssertEquals($customerReferenceSetProperty->getName(), 'Customers'); $this->AssertEquals($customerReferenceSetProperty->getKind(), ResourcePropertyKind::RESOURCESET_REFERENCE); $this->AssertEquals($customerReferenceSetProperty->getInstanceType() instanceof \ReflectionClass, true); $this->AssertEquals($customerReferenceSetProperty->getResourceType()->getName(), 'Customer'); $this->AssertEquals($customerReferenceSetProperty->getTypeKind(), ResourceTypeKind::ENTITY); $this->AssertFalse($customerReferenceSetProperty->isKindOf(ResourcePropertyKind::RESOURCE_REFERENCE)); } catch (\Exception $exception) { $this->fail('An unexpected Exception has been raised' . $exception->getMessage()); } }
/** * Get related resource for a resource * * @param ResourceSet $sourceResourceSet The source resource set * @param mixed $sourceEntityInstance The source resource * @param ResourceSet $targetResourceSet The resource set of * the navigation property * @param ResourceProperty $targetProperty The navigation property to be * retrieved * * @return Object/null The related resource if exists else null */ public function getRelatedResourceReference(ResourceSet $sourceResourceSet, $sourceEntityInstance, ResourceSet $targetResourceSet, ResourceProperty $targetProperty) { $result = null; $srcClass = get_class($sourceEntityInstance); $navigationPropName = $targetProperty->getName(); if ($srcClass === 'event') { if ($navigationPropName === 'user') { if (empty($sourceEntityInstance->userName)) { $result = null; } else { $query = "SELECT * FROM user WHERE userName = '******'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializeuser(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { die('event does not have navigation porperty with name: ' . $navigationPropName); } } else { if ($srcClass === 'event_inventory') { if ($navigationPropName === 'event') { if (empty($sourceEntityInstance->eventId)) { $result = null; } else { $query = "SELECT * FROM event WHERE eventId = '{$sourceEntityInstance->eventId}'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializeevent(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { if ($navigationPropName === 'inventory') { if (empty($sourceEntityInstance->itemId)) { $result = null; } else { $query = "SELECT * FROM inventory WHERE itemId = '{$sourceEntityInstance->itemId}'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializeinventory(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { die('event_inventory does not have navigation porperty with name: ' . $navigationPropName); } } } else { if ($srcClass === 'event_user') { if ($navigationPropName === 'event') { if (empty($sourceEntityInstance->eventId)) { $result = null; } else { $query = "SELECT * FROM event WHERE eventId = '{$sourceEntityInstance->eventId}'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializeevent(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { if ($navigationPropName === 'user') { if (empty($sourceEntityInstance->userName)) { $result = null; } else { $query = "SELECT * FROM user WHERE userName = '******'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializeuser(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { die('event_user does not have navigation porperty with name: ' . $navigationPropName); } } } else { if ($srcClass === 'inventory') { if ($navigationPropName === 'user') { if (empty($sourceEntityInstance->lastCheckedOutBy)) { $result = null; } else { $query = "SELECT * FROM user WHERE lastCheckedOutBy = '{$sourceEntityInstance->lastCheckedOutBy}'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializeuser(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { if ($navigationPropName === 'item') { if (empty($sourceEntityInstance->itemId)) { $result = null; } else { $query = "SELECT * FROM item WHERE itemId = '{$sourceEntityInstance->itemId}'"; $stmt = mysql_query($query); if ($stmt === false) { die(print_r(mysql_error(), true)); } if (!mysql_num_rows($stmt)) { $result = null; } $result = $this->_serializeitem(mysql_fetch_array($stmt, MYSQL_ASSOC)); } } else { die('inventory does not have navigation porperty with name: ' . $navigationPropName); } } } else { if ($srcClass === 'item') { } else { if ($srcClass === 'user') { } } } } } } return $result; }
/** * Get the value of a given property from an instance. * * @param mixed &$object Instance of a type which * contains this property. * @param ResourceType &$resourceType Resource type instance * containing metadata about * the instance. * @param ResourceProperty &$resourceProperty Resource property instance * containing metadata about the * property whose value * to be retrieved. * * @return mixed The value of the given property. * * @throws ODataException If reflection exception occured * while trying to access the property. */ protected function getPropertyValue(&$object, ResourceType &$resourceType, ResourceProperty &$resourceProperty) { try { $reflectionProperty = new \ReflectionProperty($object, $resourceProperty->getName()); $propertyValue = $reflectionProperty->getValue($object); return $propertyValue; } catch (\ReflectionException $reflectionException) { throw ODataException::createInternalServerError(Messages::objectModelSerializerFailedToAccessProperty($resourceProperty->getName(), $resourceType->getName())); } }
/** * TODO * * @return Object/null */ public function getRelatedResourceReference(ResourceSet $sourceResourceSet, $sourceEntityInstance, ResourceSet $targetResourceSet, ResourceProperty $targetProperty) { $result = null; $srcClass = get_class($sourceEntityInstance); $navigationPropName = $targetProperty->getName(); if ($srcClass === 'Order') { if ($navigationPropName === 'Customer') { if (empty($sourceEntityInstance->CustomerID)) { $result = null; } else { $query = "SELECT * FROM Customers WHERE CustomerID = '{$sourceEntityInstance->CustomerID}'"; $stmt = sqlsrv_query($this->_connectionHandle, $query); if ($stmt === false) { die(print_r(sqlsrv_errors(), true)); } if (!sqlsrv_has_rows($stmt)) { $result = null; } $result = $this->_serializeCustomer(sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)); } } else { die('Customer does not have navigation porperty with name: ' . $navigationPropName); } } /**else if ($srcClass === 'Order_Details') { if ($navigationPropName === 'Order') { if (empty($sourceEntityInstance->OrderID)) { $result = null; } else { $query = "SELECT * FROM Orders WHERE OrderID = $sourceEntityInstance->OrderID"; $stmt = sqlsrv_query($this->_connectionHandle, $query); if( $stmt === false) { die( print_r( sqlsrv_errors(), true)); } if (!sqlsrv_has_rows($stmt)) { $result = null; } $result = $this->_serializeOrder(sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)); } } else if ($navigationPropName === 'Product') { if (empty($sourceEntityInstance->ProductID)) { $result = null; } else { $query = "SELECT * FROM Products WHERE ProductID = $sourceEntityInstance->ProductID"; $stmt = sqlsrv_query($this->_connectionHandle, $query); if( $stmt === false) { die( print_r( sqlsrv_errors(), true)); } if (!sqlsrv_has_rows($stmt)) { $result = null; } $result = $this->_serializeProduct(sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)); } } else { die('Order_Details does not have navigation porperty with name: ' . $navigationPropName); } } else if ($srcClass === 'Employee') { if ($navigationPropName === 'Manager') { if (empty($sourceEntityInstance->ReportsTo)) { $result = null; } else { $query = "SELECT * FROM Employees WHERE EmployeeID = $sourceEntityInstance->ReportsTo"; $stmt = sqlsrv_query($this->_connectionHandle, $query); if( $stmt === false) { die( print_r( sqlsrv_errors(), true)); } if (!sqlsrv_has_rows($stmt)) { $result = null; } $result = $this->_serializeEmployee(sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)); } } else { die('Order does not have navigation porperty with name: ' . $navigationPropName); } }**/ return $result; }
/** * To check this relationship belongs to a specfic resource set, type * and property * * @param ResourceSet $resourceSet Resource set for the association * end * @param ResourceType $resourceType Resource type for the association * end * @param ResourceProperty $resourceProperty Resource property for the * association end * * @return boolean */ public function isBelongsTo(ResourceSet $resourceSet, ResourceType $resourceType, ResourceProperty $resourceProperty) { return strcmp($resourceSet->getName(), $this->_resourceSet->getName()) == 0 && $this->_resourceType->isAssignableFrom($resourceType) && (is_null($resourceProperty) && is_null($this->_resourceProperty) || !is_null($resourceProperty) && !is_null($this->_resourceProperty) && strcmp($resourceProperty->getName(), $this->_resourceProperty->getName()) == 0); }