Example #1
0
 /**
  * @param SJB_Listing $listing
  */
 public static function createTemplateStructureForListing($listing, $extraInfo = array())
 {
     $listing_info = parent::getObjectInfo($listing);
     if (SJB_MemoryCache::has('listingTypeInfo' . $listing->getListingTypeSID())) {
         $listing_type_info = SJB_MemoryCache::get('listingTypeInfo' . $listing->getListingTypeSID());
     } else {
         $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($listing->getListingTypeSID());
         SJB_MemoryCache::set('listingTypeInfo' . $listing->getListingTypeSID(), $listing_type_info);
     }
     foreach ($listing->getProperties() as $property) {
         if ($property->isComplex()) {
             $isPropertyEmpty = true;
             $properties = $property->type->complex->getProperties();
             $properties = is_array($properties) ? $properties : array();
             foreach ($properties as $subProperty) {
                 if (!empty($listing_info['user_defined'][$property->getID()][$subProperty->getID()]) && is_array($listing_info['user_defined'][$property->getID()][$subProperty->getID()])) {
                     foreach ($listing_info['user_defined'][$property->getID()][$subProperty->getID()] as $subValue) {
                         if (!empty($subValue)) {
                             $isPropertyEmpty = false;
                         }
                     }
                 }
             }
             if ($isPropertyEmpty) {
                 $listing_info['user_defined'][$property->getID()] = '';
             }
         }
         if ($property->getType() == 'list') {
             $value = $property->getValue();
             $properties = $property->type->property_info;
             $listValues = isset($properties['list_values']) ? $properties['list_values'] : array();
             foreach ($listValues as $listValue) {
                 if ($listValue['id'] == $value) {
                     $listing_info['user_defined'][$property->getID()] = $listValue['caption'];
                 }
             }
         } elseif ($property->getType() == 'multilist') {
             $value = $property->getValue();
             if (!is_array($property->getValue())) {
                 $value = explode(',', $property->getValue());
             }
             $properties = $property->type->property_info;
             $listValues = isset($properties['list_values']) ? $properties['list_values'] : array();
             $listing_info['user_defined'][$property->getID()] = array();
             foreach ($listValues as $listValue) {
                 if (in_array($listValue['id'], $value)) {
                     $listing_info['user_defined'][$property->getID()][$listValue['id']] = $listValue['caption'];
                 }
             }
         } elseif ($property->getType() == 'location' && is_array($listing_info['user_defined'][$property->getID()])) {
             foreach ($property->type->fields as $locationField) {
                 if (array_key_exists($locationField['id'], $listing_info['user_defined'][$property->getID()])) {
                     if ($locationField['id'] == 'State') {
                         $listValues = SJB_StatesManager::getStateNamesBySid($property->value['State'], 'state_name');
                     } else {
                         $listValues = isset($locationField['list_values']) ? $locationField['list_values'] : array();
                     }
                     $value = $property->getValue();
                     $value = isset($value[$locationField['id']]) ? $value[$locationField['id']] : '';
                     foreach ($listValues as $listValue) {
                         if ($listValue['id'] == $value) {
                             $listing_info['user_defined'][$property->getID()][$locationField['id']] = $listValue['caption'];
                             $listing_info['user_defined'][$property->getID()][$locationField['id'] . '_Code'] = $listValue['Code'];
                             $listing_info['user_defined'][$property->getID()][$locationField['id'] . '_Name'] = $listValue['Name'];
                         }
                     }
                 }
             }
         }
     }
     $cache = SJB_Cache::getInstance();
     $cacheId = md5('SJB_UserManager::getObjectBySID' . $listing_info['system']['user_sid']);
     $user_info = array();
     if ($cache->test($cacheId)) {
         $user_info = $cache->load($cacheId);
     } else {
         $user = SJB_UserManager::getObjectBySID($listing_info['system']['user_sid']);
         $user_info = !empty($user) ? SJB_UserManager::createTemplateStructureForUser($user) : null;
         $cache->save($user_info, $cacheId, array(SJB_Cache::TAG_USERS));
     }
     $productInfo = SJB_ProductsManager::createTemplateStructureForProduct($listing_info['system']['product_info']);
     $priceForUpgradeToFeatured = 0;
     $priceForUpgradeToPriority = 0;
     if (!empty($listing_info['system']['product_info'])) {
         $listingProductInfo = unserialize($listing_info['system']['product_info']);
         $priceForUpgradeToFeatured = SJB_Array::get($listingProductInfo, 'upgrade_to_featured_listing_price', 0);
         $priceForUpgradeToPriority = SJB_Array::get($listingProductInfo, 'upgrade_to_priority_listing_price', 0);
     }
     $structure = array('id' => $listing_info['system']['id'], 'type' => array('id' => $listing_type_info['id'], 'caption' => $listing_type_info['name']), 'user' => $user_info, 'activation_date' => $listing_info['system']['activation_date'], 'expiration_date' => $listing_info['system']['expiration_date'], 'featured' => $listing_info['system']['featured'], 'priority' => $listing_info['system']['priority'], 'views' => $listing_info['system']['views'], 'active' => $listing_info['system']['active'], 'product' => $productInfo, 'contract_id' => $listing_info['system']['contract_id'], 'number_of_pictures' => isset($listing_info['user_defined']['pictures']) ? count($listing_info['user_defined']['pictures']) : 0, 'approveStatus' => $listing_info['system']['status'], 'complete' => $listing_info['system']['complete'], 'external_id' => $listing_info['system']['external_id'], 'priceForUpgradeToFeatured' => $priceForUpgradeToFeatured, 'priceForUpgradeToPriority' => $priceForUpgradeToPriority);
     if (SJB_Settings::getSettingByName('jobg8Installed') && SJB_PluginManager::isPluginActive('JobG8IntegrationPlugin')) {
         $structure['jobType'] = JobG8::getJobProperty($listing_info['system']['id'], 'jobType');
     }
     if (array_search('comments', $extraInfo)) {
         $structure['comments_num'] = SJB_CommentManager::getCommentsNumToListing($listing_info['system']['id']);
     }
     if (array_search('ratings', $extraInfo)) {
         $structure['rating_num'] = SJB_Rating::getRatingNumToListing($listing_info['system']['id']);
         $structure['rating'] = SJB_Rating::getRatingToListing($listing_info['system']['id']);
         $structure['rating_array'] = SJB_Rating::getRatingTplToListing($listing_info['system']['id']);
     }
     if (!empty($listing_info['system']['subuser_sid'])) {
         $structure['subuser'] = SJB_UserManager::getUserInfoBySID($listing_info['system']['subuser_sid']);
     }
     $structure['METADATA'] = array('activation_date' => array('type' => 'date'), 'expiration_date' => array('type' => 'date'), 'views' => array('type' => 'integer'), 'number_of_pictures' => array('type' => 'integer'), 'approveStatus' => array('type' => 'string'), 'rejectReason' => array('type' => 'string'));
     $structure = array_merge($structure, $listing_info['user_defined']);
     $structure['METADATA'] = array_merge($structure['METADATA'], parent::getObjectMetaData($listing));
     $listing_user_meta_data = array();
     if (isset($user_info['METADATA'])) {
         $listing_user_meta_data = $user_info['METADATA'];
         unset($user_info['METADATA']);
     }
     $listing_product_meta_data = array();
     if (isset($productInfo['METADATA'])) {
         $listing_product_meta_data = $productInfo['METADATA'];
         unset($productInfo['METADATA']);
     }
     $listing_type_meta_data = array('caption' => array('type' => 'string', 'propertyID' => 'listing_type'));
     $structure['METADATA'] = array_merge($structure['METADATA'], array('user' => $listing_user_meta_data, 'product' => $listing_product_meta_data, 'type' => $listing_type_meta_data));
     return array_merge($structure, $listing_info['user_defined']);
 }