{
$userProfile = $this->_facebookRequest->getGraphObject(GraphUser::className());
- $homeTownPageId = $userProfile->getProperty('hometown')->getProperty('id');
- $pageRequest = (new FacebookRequest($this->_facebookSession, 'GET', '/' . $homeTownPageId ))->execute();
- $pageLocation = $pageRequest->getGraphObject(GraphLocation::className())->getProperty('location')->cast(GraphLocation::className());
+ $homeTown = $userProfile->getProperty('hometown');
+
+ if($homeTown)
+ {
+ $homeTownPageId = $homeTown ? $homeTown->getProperty('id') : null;
+
+ $pageRequest = (new FacebookRequest($this->_facebookSession, 'GET', '/' . $homeTownPageId ))->execute();
+ $pageLocation = $pageRequest->getGraphObject(GraphLocation::className())->getProperty('location')->cast(GraphLocation::className());
+
+ $country = Util::countryNameFromLatLong($pageLocation->getLatitude(), $pageLocation->getLongitude());
+ }
- $country = Util::countryNameFromLatLong($pageLocation->getLatitude(), $pageLocation->getLongitude());
$firstName = $userProfile->getFirstName();
$lastName = $userProfile->getLastName();
$facebookId = $userProfile->getId();
-
+
//TODO: Is insantiating the VO classes here a good idea?
- $newUser = $this->_userStepByStepBuilder->With_Country(new \Domain\VOs\Country($country))
- ->With_DisplayName($firstName)
+ $newUser = $this->_userStepByStepBuilder->With_DisplayName($firstName)
->With_Name(new \Domain\VOs\Name($firstName, $lastName))
->With_Tags(array())
->With_FacebookId($facebookId)
->With_Quota(100000000) //XXX: quota is in bytes
+ //XXX: Is this confusing? Maybe better to do a conditional and only call with_country when we have a country
+ ->With_Country(isset($country) ? new \Domain\VOs\Country($country) : null)
->build();
$this->_userRepository->save($newUser);
'name' => $user->getName()->getFullName(),
'displayName' => $user->getDisplayName(),
'tags' => $user->getTags(),
- 'country' => $user->getCountry()->getCountryName(),
+ 'country' => $user->getCountry() ? $user->getCountry()->getCountryName() : null,
);
if($this->_userSession->getCurrentUser())
try
{
if(isset($userUpdateData->displayName)) $user->setDisplayName($userUpdateData->displayName);
- //TODO: Direct instantiation bad?
- if(isset($userUpdateData->country)) $user->setCountry(new Country($userUpdateData->country));
+
+ if(property_exists($userUpdateData,'country'))
+ {
+ //TODO: Direct instantiation bad?
+ $user->setCountry(isset($userUpdateData->country) ? new Country($userUpdateData->country) : null);
+ }
$this->_userRepository->save($user);
} catch (Exception $e) {
if(strpos($e->getMessage(), 'Duplicate entry') !== false)
\r
namespace DataAccess\DataMapper\Helpers;\r
\r
+use Exception;\r
use ReflectionClass;\r
\r
class VOMapsHelper\r
{\r
return new $className;\r
} else {\r
- $r = new ReflectionClass($className);\r
- return $r->newInstanceArgs($constructors);\r
+ try {\r
+ $r = new ReflectionClass($className);\r
+ return $r->newInstanceArgs($constructors);\r
+ } catch (Exception $e) {\r
+ return null;\r
+ }\r
}\r
}\r
}\r
public function getQuota();\r
\r
public function setDisplayName($displayName);\r
- public function setCountry(ICountry $country);\r
+ public function setCountry(ICountry $country = null);\r
}\r
\r
interface IUserBuilder\r
{\r
- public function With_Country(ICountry $country);\r
+ public function With_Country(ICountry $country = null);\r
public function With_DisplayName($name);\r
public function With_Name(IName $name);\r
public function With_Tags(array $tags);\r
private $_quota;\r
\r
public function __construct(\r
- ICountry $country,\r
+ ICountry $country = null,\r
$displayName,\r
IName $name,\r
array $tags,\r
$this->_displayName = $displayName;\r
}\r
\r
- public function setCountry(ICountry $country)\r
+ public function setCountry(ICountry $country = null)\r
{\r
$this->_country = $country;\r
}\r
$this->_userFactory = $userFactory;\r
}\r
\r
- public function With_Country(ICountry $country) {\r
+ public function With_Country(ICountry $country = null) {\r
$this->_country = $country;\r
return $this;\r
}\r
class UserFactory implements IUserFactory\r
{\r
public function createInstance(\r
- ICountry $country,\r
+ ICountry $country = null,\r
$displayName,\r
IName $name,\r
array $tags,\r
\r
interface IUserStepByStepBuilder\r
{\r
- public function With_Country(ICountry $country);\r
-}\r
-\r
-interface IUserStepByStepBuilder_With_Country\r
-{\r
public function With_DisplayName($name);\r
}\r
\r
interface IUserStepByStepBuilder_With_Quota\r
{\r
public function With_YearsStepArtist($years); //not going to make this mandatory as it is kind of a joke\r
+ public function With_Country(ICountry $country = null);\r
public function build();\r
}\r
\r
\r
class UserStepByStepBuilder extends AbstractUserStepByStepBuilder implements IUserStepByStepBuilder\r
{\r
- public function With_Country(ICountry $country) {\r
- $this->_userBuilder->With_Country($country);\r
- return new UserStepByStepBuilder_With_Country($this->_userBuilder);\r
- }\r
-}\r
-\r
-class UserStepByStepBuilder_With_Country extends AbstractUserStepByStepBuilder implements IUserStepByStepBuilder_With_Country\r
-{\r
public function With_DisplayName($name) {\r
$this->_userBuilder->With_DisplayName($name);\r
return new UserStepByStepBuilder_With_DisplayName($this->_userBuilder);\r
return $this;\r
}\r
\r
+ public function With_Country(ICountry $country = null) {\r
+ $this->_userBuilder->With_Country($country);\r
+ return $this;\r
+ }\r
+\r
public function build() {\r
return $this->_userBuilder\r
->build();\r