Beispiel #1
0
 /**
  * @param \Zend\Stdlib\Parameters $data
  * @param array $file
  * @return bool
  */
 public function saveApartel($data, $file = [])
 {
     try {
         /** @var \DDD\Dao\Apartel\General $apartelGeneralDao */
         $apartelGeneralDao = $this->getServiceLocator()->get('dao_apartel_general');
         /** @var \DDD\Dao\Apartel\Details $apartelDetailsDao */
         $apartelDetailsDao = $this->getServiceLocator()->get('dao_apartel_details');
         /** @var \DDD\Dao\Textline\Apartment $productTextlineDao */
         $productTextlineDao = $this->getServiceLocator()->get('dao_textline_apartment');
         /** @var \DDD\Service\Website\Cache $cache */
         $cache = $this->getServiceLocator()->get('service_website_cache');
         $apartelGeneralData = $apartelGeneralDao->getApartelById($data['id'], false);
         if ($apartelGeneralData === false) {
             throw new \Exception('Cannot find Apartel by Id');
         }
         $apartelDetailsData = $apartelDetailsDao->getApartelDetailsById($data['id']);
         $productTextlineDao->update(['en' => $data['content_textline'], 'en_html_clean' => Translation::cleanTextline($data['content_textline'])], ['id' => $apartelDetailsData->getContentTextlineId()]);
         $cache->set('prod-' . $apartelDetailsData->getContentTextlineId() . '-en', $data['content_textline']);
         $productTextlineDao->update(['en' => $data['meta_description_textline'], 'en_html_clean' => Translation::cleanTextline($data['meta_description_textline'])], ['id' => $apartelDetailsData->getMetaDescriptionTextlineId()]);
         $cache->set('prod-' . $apartelDetailsData->getMetaDescriptionTextlineId() . '-en', $data['meta_description_textline']);
         $productTextlineDao->update(['en' => $data['moto_textline'], 'en_html_clean' => Translation::cleanTextline($data['moto_textline'])], ['id' => $apartelDetailsData->getMotoTextlineId()]);
         $cache->set('prod-' . $apartelDetailsData->getMotoTextlineId() . '-en', $data['moto_textline']);
         if (!empty($file)) {
             try {
                 $image = new Images($file);
                 if ($image && $image->errors) {
                     return false;
                 }
                 $image->resizeToWidth([1920]);
             } catch (\Exception $e) {
                 throw new \Exception($e->getMessage());
             }
             $apartelImagesPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_APARTEL_BG_IMAGE . $data['id'] . '/';
             array_map('unlink', glob($apartelImagesPath . '*'));
             $originalImagePath = $image->saveImage($apartelImagesPath, 80);
             $originalImage = explode('/', $originalImagePath);
             $originalImageName = $originalImage[count($originalImage) - 1];
             $originalImageNameParsed = explode('_', $originalImageName);
             $newImageName = $originalImageNameParsed[0] . '_0_1920.png';
             $apartelDetailsDao->update(['bg_image' => $newImageName], ['apartel_id' => $data['id']]);
         }
         if (isset($newImageName) && !empty($newImageName)) {
             return $newImageName;
         } else {
             return true;
         }
     } catch (\Exception $e) {
         $this->gr2logException($e, 'Cannot save Apartel general data', $data);
     }
     return false;
 }
Beispiel #2
0
 public function blogSave($data, $id)
 {
     $blogDao = $this->getBlogDao();
     $data = (array) $data;
     $saveData = array('content' => $data['body'], 'en_status' => 3, 'title' => $data['title'], 'date' => $data['date'] ? date('Y-m-d', strtotime($data['date'])) : '', 'en_title_status' => 3, 'slug' => str_replace(' ', '-', strtolower(preg_replace('/[^a-zA-Z0-9 -]/', '', $data['title']))));
     $insert_id = $id;
     $location_id = 0;
     if ($id > 0) {
         $blogDao->save($saveData, array('id' => (int) $id));
     } else {
         if (!$data['date']) {
             $saveData['date'] = date('Y-m-d');
         }
         $insert_id = $blogDao->save($saveData);
     }
     if ($data['img_post'] !== '' and file_exists($data['img_post'])) {
         $filePathArray = explode('/', $data['img_post']);
         $fileInfo[0]['name'] = end($filePathArray);
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $fileInfo[0]['type'] = finfo_file($finfo, $data['img_post']);
         finfo_close($finfo);
         $fileInfo[0]['tmp_name'] = $data['img_post'];
         $fileInfo[0]['error'] = 0;
         $fileInfo[0]['size'] = filesize($data['img_post']);
         $image = new Images($fileInfo);
         $img_size = 300;
         $image->resizeToWidth(array($img_size));
         $blogImagesPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_BLOG_PATH;
         $newImg = str_replace(array('/ginosi/images', '_original', 'jpeg', 'jpg', 'gif'), array('', '_300', 'png', 'png', 'png'), $image->saveImage($blogImagesPath . $insert_id . '/'));
         if ($newImg) {
             $row = $blogDao->fetchOne(['id' => $insert_id]);
             if ($row->getImg() != '') {
                 if (strstr($row->getImg(), '_300')) {
                     $imagePathParts = explode('_300', $row->getImg());
                 } elseif (strstr($row->getImg(), '_orig')) {
                     $imagePathParts = explode('_orig', $row->getImg());
                 }
                 $imagePathMask = '/ginosi/images' . $imagePathParts[0] . '*';
                 array_map('unlink', glob($imagePathMask));
             }
             $blogDao->save(array('img' => $newImg), array('id' => $insert_id));
         }
     }
     return array($insert_id, $location_id);
 }
Beispiel #3
0
 public function uploadImages($ownerId, array $files, $ownerFileName = null, $imagesOwner = null)
 {
     $myTime = time();
     $cropImages = new Images($files);
     if ($cropImages->errors) {
         return ['error' => true, "msg" => $cropImages->errors];
     }
     $cropImages->cropImages([['h' => 300, 'w' => 445], ['h' => 520, 'w' => 780], ['h' => 64, 'w' => 96], ['h' => 370, 'w' => 555]]);
     $imagePath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_APARTMENT . $ownerId . '/';
     $cropImages->saveImage($imagePath, 75, false, true, 'orig', 'jpg', $myTime, true, $ownerFileName, $imagesOwner);
     return $cropImages->filenames;
 }
Beispiel #4
0
 public function locationSave($data, $id, $locationType, $slugRegenerate = FALSE)
 {
     $locationDetailsDao = $this->getLocationDetailsDao();
     $data = (array) $data;
     $informationText = isset($data['information']) ? $data['information'] : Null;
     if (!is_null($informationText)) {
         $withoutHtml = strip_tags($informationText);
         $without2nbsp = str_replace('  ', ' ', $withoutHtml);
         $without1nbsp = str_replace(' ', ' ', $without2nbsp);
         $informationTextHtmlClean = $without1nbsp;
     } else {
         $informationTextHtmlClean = Null;
     }
     $saveData = ['name' => $data['name'], 'information_text' => $informationText, 'information_text_html_clean' => $informationTextHtmlClean, 'is_selling' => (int) $data['is_selling'] > 0 ? (int) $data['is_selling'] : 0, 'latitude' => isset($data['latitude']) ? $data['latitude'] : Null, 'longitude' => isset($data['longitude']) ? $data['longitude'] : Null];
     $parentData = [];
     $parentID = $data['autocomplete_id'];
     switch ($locationType) {
         case self::LOCATION_TYPE_COUNTRY:
             $saveData['iso'] = $data['iso'];
             $saveData['is_searchable'] = (int) $data['is_searchable'] > 0 ? (int) $data['is_searchable'] : 0;
             $parentData['currency_id'] = !empty($data['currency']) ? $data['currency'] : null;
             $parentData['contact_phone'] = $data['contact_phone'];
             $parentData['required_postal_code'] = $data['required_postal_code'];
             $parentField = 'continent_id';
             break;
         case self::LOCATION_TYPE_PROVINCE:
             $parentData['short_name'] = $data['province_short_name'];
             $parentField = 'country_id';
             break;
         case self::LOCATION_TYPE_CITY:
             $saveData['is_searchable'] = (int) $data['is_searchable'] > 0 ? (int) $data['is_searchable'] : 0;
             $saveData['tot_included'] = (int) $data['tot_included'] > 0 ? (int) $data['tot_included'] : 0;
             $saveData['tot_max_duration'] = (int) $data['tot_max_duration'] > 0 ? (int) $data['tot_max_duration'] : 0;
             $saveData['vat_included'] = (int) $data['vat_included'] > 0 ? (int) $data['vat_included'] : 0;
             $saveData['vat_max_duration'] = (int) $data['vat_max_duration'] > 0 ? (int) $data['vat_max_duration'] : 0;
             $saveData['city_tax_included'] = (int) $data['city_tax_included'] > 0 ? (int) $data['city_tax_included'] : 0;
             $saveData['city_tax_max_duration'] = (int) $data['city_tax_max_duration'] > 0 ? (int) $data['city_tax_max_duration'] : 0;
             $saveData['sales_tax_included'] = (int) $data['sales_tax_included'] > 0 ? (int) $data['sales_tax_included'] : 0;
             $saveData['sales_tax_max_duration'] = (int) $data['sales_tax_max_duration'] > 0 ? (int) $data['sales_tax_max_duration'] : 0;
             if ($data['tot_type'] > 0 && $data['tot'] > 0) {
                 $saveData['tot_type'] = $data['tot_type'];
                 $saveData['tot'] = $data['tot'];
                 $saveData['tot_additional'] = $data['tot_additional'];
             } else {
                 $saveData['tot_type'] = 0;
                 $saveData['tot'] = 0;
                 $saveData['tot_additional'] = 0;
             }
             if ($data['vat_type'] > 0 && $data['vat'] > 0) {
                 $saveData['vat_type'] = $data['vat_type'];
                 $saveData['vat'] = $data['vat'];
                 $saveData['vat_additional'] = $data['vat_additional'];
             } else {
                 $saveData['vat_type'] = 0;
                 $saveData['vat'] = 0;
                 $saveData['vat_additional'] = 0;
             }
             if ($data['sales_tax_type'] > 0 && $data['sales_tax'] > 0) {
                 $saveData['sales_tax_type'] = $data['sales_tax_type'];
                 $saveData['sales_tax'] = $data['sales_tax'];
                 $saveData['sales_tax_additional'] = $data['sales_tax_additional'];
             } else {
                 $saveData['sales_tax_type'] = 0;
                 $saveData['sales_tax'] = 0;
                 $saveData['sales_tax_additional'] = 0;
             }
             if ($data['city_tax_type'] > 0 && $data['city_tax'] > 0) {
                 $saveData['city_tax_type'] = $data['city_tax_type'];
                 $saveData['city_tax'] = $data['city_tax'];
                 $saveData['city_tax_additional'] = $data['city_tax_additional'];
             } else {
                 $saveData['city_tax_type'] = 0;
                 $saveData['city_tax'] = 0;
                 $saveData['city_tax_additional'] = 0;
             }
             $parentData['timezone'] = $data['timezone'];
             $parentField = 'province_id';
             break;
         case self::LOCATION_TYPE_POI:
             $saveData['is_searchable'] = self::IS_SEARCHABLE;
             $parentData['ws_show_right_column'] = $data['ws_show_right_column'];
             $parentData['type_id'] = $data['poi_type'];
             $parentField = 'city_id';
             break;
     }
     $insert_id = $id;
     $location_id = 0;
     if ($id > 0) {
         /**
          * @var \Library\ActionLogger\Logger $actionLogger
          */
         $actionLogger = $this->getServiceLocator()->get('ActionLogger');
         if ($slugRegenerate) {
             $saveData['slug'] = $this->generateSlug($saveData['name']);
             $checkDuplicateSlug = $this->checkDuplicateSlug($saveData['slug'], $locationType, $id);
             if ($checkDuplicateSlug) {
                 // we found duplicate slug = error
                 return $checkDuplicateSlug;
             }
         }
         $locationCurrentData = $locationDetailsDao->getDetailsById($id);
         if ($locationType == self::LOCATION_TYPE_CITY && $saveData['is_searchable'] != $locationCurrentData->getIs_searchable()) {
             $value = $saveData['is_searchable'] ? '' : ' non';
             $actionLogger->save(ActionLogger::MODULE_LOCATIONS, $id, ActionLogger::ACTION_LOCATION_SEARCHABLE, 'Location is set as' . $value . ' searchable');
         }
         if ($saveData['name'] != $locationCurrentData->getName()) {
             $actionLogger->save(ActionLogger::MODULE_LOCATIONS, $id, ActionLogger::ACTION_LOCATION_NAME, 'Location name change from "' . $locationCurrentData->getName() . '" to "' . $saveData['name'] . '"');
         }
         if ($saveData['information_text'] != $locationCurrentData->getInformation_text()) {
             $actionLogger->save(ActionLogger::MODULE_LOCATIONS, $id, ActionLogger::ACTION_LOCATION_INFORMATION, 'The location\'s information text was updated');
         }
         $preLocationInfo = $locationDetailsDao->fetchOne(['id' => (int) $id]);
         $locationDetailsDao->save($saveData, ['id' => (int) $id]);
         $locatinInfo = $locationDetailsDao->fetchOne(['id' => (int) $id]);
         $casheService = $this->getServiceLocator()->get('service_website_cache');
         if ($preLocationInfo->getName() != $saveData['name']) {
             if ($locationType == self::LOCATION_TYPE_CITY) {
                 $cityDao = $this->getCityDao();
                 $cityInfo = $cityDao->fetchOne(['detail_id' => (int) $id]);
                 if ($casheService->get('city-' . $cityInfo->getId() . '-en') != null && $casheService->get('city-' . $cityInfo->getId() . '-en') != $saveData['name']) {
                     $casheService->set('city-' . $cityInfo->getId() . '-en', $saveData['name']);
                 }
             } elseif ($locationType == self::LOCATION_TYPE_COUNTRY) {
                 /**
                  * @var \DDD\Dao\Geolocation\Countries $geolocationCountryDao
                  */
                 $geolocationCountryDao = $this->getServiceLocator()->get('dao_geolocation_countries');
                 $countryInfo = $geolocationCountryDao->fetchOne(['detail_id' => (int) $id]);
                 if ($casheService->get('country-' . $countryInfo->getId() . '-en') != null && $casheService->get('country-' . $countryInfo->getId() . '-en') != $saveData['name']) {
                     $casheService->set('country-' . $countryInfo->getId() . '-en', $saveData['name']);
                 }
             }
         }
         if ($locationType == self::LOCATION_TYPE_POI) {
             $poiDao = $this->getPoiDao();
             $poiDao->save($parentData, ['detail_id' => (int) $id]);
         }
         if ($locationType == self::LOCATION_TYPE_CITY) {
             $cityDao = $this->getCityDao();
             $cityDao->save($parentData, ['detail_id' => (int) $id]);
         }
         if ($locationType == self::LOCATION_TYPE_COUNTRY) {
             /**
              * @var \DDD\Dao\Geolocation\Countries $geolocationCountryDao
              */
             $geolocationCountryDao = $this->getServiceLocator()->get('dao_geolocation_countries');
             $geolocationCountryDao->save($parentData, array('detail_id' => (int) $id));
         }
         if ($locationType == self::LOCATION_TYPE_PROVINCE) {
             $provinceDao = $this->getProvinceDao();
             $provinceDao->save($parentData, array('detail_id' => (int) $id));
         }
     } else {
         $saveData['slug'] = $this->generateSlug($saveData['name']);
         $checkDuplicateSlug = $this->checkDuplicateSlug($saveData['slug'], $locationType, $id);
         if ($checkDuplicateSlug) {
             // we found duplicate slug = error
             return $checkDuplicateSlug;
         }
         $insert_id = $locationDetailsDao->save($saveData);
         $parentDao = $this->getLocationDaoByType($locationType);
         $parentData['detail_id'] = $insert_id;
         $parentData[$parentField] = $parentID;
         $location_id = $parentDao->save($parentData);
     }
     for ($i = 1; $i <= 2; $i++) {
         if ($i == 1) {
             $saveImg = 'cover_image';
             $imageFieldName = 'cover_image_post';
         } elseif ($i == 2) {
             $saveImg = 'thumbnail';
             $imageFieldName = 'thumbnail_post';
         }
         if ($data[$imageFieldName] !== '' && file_exists($data[$imageFieldName])) {
             $filePathArray = explode('/', $data[$imageFieldName]);
             $fileInfo[0]['name'] = end($filePathArray);
             $finfo = finfo_open(FILEINFO_MIME_TYPE);
             $fileInfo[0]['type'] = finfo_file($finfo, $data[$imageFieldName]);
             finfo_close($finfo);
             $fileInfo[0]['tmp_name'] = $data[$imageFieldName];
             $fileInfo[0]['error'] = 0;
             $fileInfo[0]['size'] = filesize($data[$imageFieldName]);
             $image = new Images($fileInfo);
             $image->resizeToWidth([1920]);
             $image->resizeToWidth([500]);
             $image->resizeToWidth([360]);
             $image->resizeToWidth([140]);
             $newImg = str_replace(['/ginosi/images/locations/' . $insert_id . '/'], [''], $image->saveImage(DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_LOCATIONS_PATH . $insert_id . '/', 75, $i, TRUE, 'orig', 'jpg'));
             if ($newImg) {
                 $row = $locationDetailsDao->fetchOne(['id' => $insert_id]);
                 if ($i == 1) {
                     if ($row->getCover_image() != '') {
                         $imageMask = explode('_orig', $row->getCover_image());
                         @array_map("unlink", glob('/ginosi/images/locations/' . $insert_id . '/' . $imageMask[0] . '*'));
                     }
                 } else {
                     if ($row->getThumbnail() != '') {
                         $imageMask = explode('_orig', $row->getThumbnail());
                         @array_map("unlink", glob('/ginosi/images/locations/' . $insert_id . '/' . $imageMask[0] . '*'));
                     }
                 }
                 $locationDetailsDao->save([$saveImg => $newImg], ['id' => $insert_id]);
             }
         }
     }
     return array($insert_id, $location_id);
 }