/**
  * Method to get the data that should be injected in the form.
  *
  * @return    mixed    The data for the form.
  * @since    1.6
  */
 protected function loadFormData()
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     $data = $app->getUserState($this->option . '.profile.contact', array());
     if (!$data) {
         $userId = (int) JFactory::getUser()->get('id');
         $data = $this->getItem($userId);
         if (!empty($data['location_id'])) {
             $location = new Socialcommunity\Location\Location(JFactory::getDbo());
             $location->load(array('id' => $data['location_id']));
             $locationName = $location->getName(Socialcommunity\Constants::INCLUDE_COUNTRY_CODE);
             if ($locationName) {
                 $data['location_preview'] = $locationName;
             }
         }
         $secretKey = $app->get('secret');
         try {
             $data['phone'] = $data['phone'] !== null ? Defuse\Crypto\Crypto::decrypt($data['phone'], $secretKey) : null;
             $data['address'] = $data['address'] !== null ? Defuse\Crypto\Crypto::decrypt($data['address'], $secretKey) : null;
         } catch (Exception $e) {
             $data['phone'] = null;
             $data['address'] = null;
         }
     }
     return $data;
 }
 /**
  * Method to get the data that should be injected in the form.
  *
  * @return  mixed   The data for the form.
  * @since   1.6
  */
 protected function loadFormData()
 {
     // Check the session for previously entered form data.
     $data = JFactory::getApplication()->getUserState($this->option . '.edit.profile.data', array());
     if (empty($data)) {
         $data = $this->getItem();
         if ($data !== null and $data->id > 0) {
             // Prepare social profiles
             $socialProfiles = new Socialcommunity\Profile\SocialProfiles($this->getDbo());
             $socialProfiles->load(array('user_id' => $data->user_id));
             if (count($socialProfiles) > 0) {
                 foreach ($socialProfiles as $item) {
                     $data->{$item}['type'] = $item['alias'];
                 }
             }
             // Prepare locations
             if ($data->location_id > 0) {
                 $location = new Socialcommunity\Location\Location(JFactory::getDbo());
                 $location->load($data->location_id);
                 $locationName = $location->getName(Socialcommunity\Constants::INCLUDE_COUNTRY_CODE);
                 if ($locationName !== '') {
                     $data->location_preview = $locationName;
                 }
             }
             $secretKey = JFactory::getApplication()->get('secret');
             $data->phone = $data->phone !== null ? Defuse\Crypto\Crypto::decrypt($data->phone, $secretKey) : null;
             $data->address = $data->address !== null ? Defuse\Crypto\Crypto::decrypt($data->address, $secretKey) : null;
         }
     }
     return $data;
 }