Last active
August 29, 2015 14:01
-
-
Save mockiemockiz/3f3e47b3f6faf86d5967 to your computer and use it in GitHub Desktop.
moduile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace RealEstate; | |
use RealEstate\View\Helper\RealEstateHeadTitleHelper; | |
class Module | |
{ | |
public function getAutoloaderConfig() | |
{ | |
return array( | |
'Zend\Loader\ClassMapAutoloader' => array( | |
__DIR__ . '/autoload_classmap.php', | |
), | |
'Zend\Loader\StandardAutoloader' => array( | |
'namespaces' => array( | |
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, | |
), | |
), | |
); | |
} | |
public function getConfig() | |
{ | |
return include __DIR__ . '/config/module.config.php'; | |
} | |
public function getServiceConfig() { | |
return array( | |
'factories' => array( | |
'RealEstate\Model\RealEstateCompanyTable' => function($sm) { | |
$table = new \RealEstate\Model\RealEstateCompanyTable($sm); | |
return $table; | |
}, | |
'RealEstate\Model\RealEstatePropertyTable' => function($sm) { | |
$table = new \RealEstate\Model\RealEstatePropertyTable($sm); | |
return $table; | |
}, | |
'RealEstate\Model\RealEstatePropertyImageTable' => function($sm) { | |
$table = new \RealEstate\Model\RealEstatePropertyImageTable($sm); | |
return $table; | |
}, | |
), | |
); | |
} | |
public function getControllerPluginConfig() | |
{ | |
return array( | |
'factories' => array( | |
'realEstatePlugin' => function ($sm) { | |
$plugin = new Controller\Plugin\RealEstatePlugin($sm); | |
return $plugin; | |
}, | |
'fourSquarePlugin' => function ($sm) { | |
$plugin = new Controller\Plugin\FourSquarePlugin($sm); | |
return $plugin; | |
}, | |
), | |
); | |
} | |
public function getViewHelperConfig() | |
{ | |
return array( | |
'factories' => array( | |
'realEstateHelper' => function ($sm) { | |
$plugin = new View\Helper\RealEstateHelper($sm); | |
return $plugin; | |
}, | |
'realEstateHeadTitleHelper' => function($sm){ | |
$helper = new RealEstateHeadTitleHelper($sm); | |
return $helper; | |
}, | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: mockie | |
* Date: 4/10/14 | |
* Time: 3:13 PM | |
*/ | |
namespace RealEstate\Controller\Plugin; | |
use Zend\Debug\Debug; | |
use Zend\Mvc\Controller\Plugin\AbstractPlugin; | |
class RealEstatePlugin extends AbstractPlugin | |
{ | |
protected $sl; | |
protected $config; | |
protected $propertyTable; | |
protected $propertyImageTable; | |
protected function getPropertyTable() | |
{ | |
if (!$this->propertyTable) { | |
$this->propertyTable = $this->sl->get('RealEstate\Model\RealEstatePropertyTable'); | |
} | |
return $this->propertyTable; | |
} | |
protected function getPropertyImageTable() | |
{ | |
if (!$this->propertyImageTable) { | |
$this->propertyImageTable = $this->sl->get('RealEstate\Model\RealEstatePropertyImageTable'); | |
} | |
return $this->propertyImageTable; | |
} | |
function __construct($sm) | |
{ | |
$this->sl = $sm->getServiceLocator(); | |
$this->config = $this->sl->get('Config'); | |
} | |
function __invoke() | |
{ | |
return $this; | |
} | |
/** | |
* Get Property types house,apart,villa | |
* @return array | |
*/ | |
public function getTypeList() | |
{ | |
return array(1 => _('Land'), 2 => _('House'), 3 => _('Apartment'), 4 => _('Villa'), 5 => _('Residential')); | |
} | |
/** | |
* Get purpose list sell or rent | |
* @return array | |
*/ | |
public function getPurposeList() | |
{ | |
return array(1 => _('Sell'), 2 => _('Rent')); | |
} | |
/** | |
* Get period list daily,weekly,etc | |
* @return array | |
*/ | |
public function getPeriodList() | |
{ | |
return array(1 => _('Daily'), 2 => _('Weekly'), 3 => _('Monthly'), 4 => _('Yearly')); | |
} | |
/** | |
* Create upload directory if doesn't exist | |
*/ | |
function checkUploadDir() | |
{ | |
if (!is_dir($this->config['property_image_path'])) { | |
mkdir($this->config['property_image_path']); | |
} | |
$category_dir = $this->config['property_image_path'] . '/'; | |
$year = $category_dir . date('Y'); | |
$month = $year . '/' . date('m'); | |
if (!is_dir($year)) { | |
mkdir($year); | |
} | |
if (!is_dir($month)) { | |
mkdir($month); | |
} | |
} | |
/** | |
* Upload property images and create the thumbnails | |
* @param $data | |
* @return array | |
*/ | |
function uploadPropertyPictures($data) | |
{ | |
$this->checkUploadDir(); | |
$files = array(); | |
$thumbs = array( | |
'large' => array(800, 800), // W x H | |
'thumbnail' => array(180, 180), | |
'small' => array(80, 80), | |
); | |
if ($data['image-file']) { | |
foreach ($data['image-file'] as $key => $val) { | |
$tmp = explode('\\', $val['tmp_name']); | |
$filename = explode('.', end($tmp)); | |
$filename[0] = md5($filename[0] . time()) . '.jpg'; | |
foreach ($thumbs as $key => $val2) { | |
$thumb = \PhpThumbFactory::create($val['tmp_name']); | |
$thumb->adaptiveResize($val2[0], $val2[1]); | |
$thumb->save($this->config['property_image_path'] . '/' . date('Y') . '/' . date('m') . '/' . $key . '_' . $filename[0]); | |
} | |
unlink($val['tmp_name']); | |
$files[] = date('Y') . '/' . date('m') . '/' . $filename[0]; | |
} | |
} | |
return $files; | |
} | |
/** | |
* Create year and month directory if doesn't exist | |
*/ | |
public function prepareCompanyProfilePictureUploadDir() | |
{ | |
$dir = $this->config['company_profile_picture_path'] . '/' . date('Y'); | |
if (!is_dir($dir)) { | |
mkdir($dir); | |
} | |
$dir = $this->config['company_profile_picture_path'] . '/' . date('Y') . '/' . date('m'); | |
if (!is_dir($dir)) { | |
mkdir($dir); | |
} | |
} | |
/** | |
* @param object $data | |
* @param string $oldProfilePicture | |
* @return string path to profile picture | |
*/ | |
function uploadCompanyProfilePicture($data, $oldProfilePicture = '') | |
{ | |
$this->prepareCompanyProfilePictureUploadDir(); | |
$thumbs = array( | |
'large' => array(180, 180), // W x H | |
'small' => array(50, 50), | |
); | |
if ($data->profilePicture['tmp_name']) { | |
$tmp = explode('\\', $data->profilePicture['tmp_name']); | |
$filename = explode('.', end($tmp)); | |
$filename[0] = md5($filename[0] . time()) . '.jpg'; | |
$oldPict = (!empty($oldProfilePicture)) ? explode('/', $oldProfilePicture) : array(); | |
$oldPictYear = isset($oldPict[0]) ? $oldPict[0] : ''; | |
$oldPictMonth = isset($oldPict[1]) ? $oldPict[1] : ''; | |
foreach ($thumbs as $key => $val) { | |
$thumb = \PhpThumbFactory::create($data->profilePicture['tmp_name']); | |
$thumb->adaptiveResize($val[0], $val[1]); | |
$thumb->save($this->config['company_profile_picture_path'] . '/' . date('Y') . '/' . date('m') . '/' . $key . '_' . $filename[0]); | |
$profpict = $this->config['company_profile_picture_path'] . '/' . $oldPictYear . '/' . $oldPictMonth . '/' . $key . '_' . end($oldPict); | |
if (is_file($profpict)) { | |
unlink($profpict); | |
} | |
} | |
unlink($data->profilePicture['tmp_name']); | |
return date('Y') . '/' . date('m') . '/' . $filename[0]; | |
} | |
return $oldProfilePicture; | |
} | |
/** | |
* Delete property images and all its thumbnails | |
* @param $path | |
*/ | |
function deletePropertyImage($path) | |
{ | |
$exp = explode('/', $path); // [0] = year , [1] = month , [2] = filename | |
$filename = end($exp); | |
$large = $this->config['property_image_path'] . '/' . $exp[0] . '/' . $exp[1] . '/' . 'large_' . $filename; | |
if (file_exists($large)) { | |
unlink($large); | |
} | |
$small = $this->config['property_image_path'] . '/' . $exp[0] . '/' . $exp[1] . '/' . 'small_' . $filename; | |
if (file_exists($small)) { | |
unlink($small); | |
} | |
$thumbnail = $this->config['property_image_path'] . '/' . $exp[0] . '/' . $exp[1] . '/' . 'thumbnail_' . $filename; | |
if (file_exists($thumbnail)) { | |
unlink($thumbnail); | |
} | |
} | |
public function getDefaultThumbnail( $propertyId ){ | |
$default = $this->getPropertyImageTable()->getDefaultThumbnail( $propertyId ); | |
if($default){ | |
return $default->path; | |
} | |
$default = $this->getPropertyImageTable()->getImageByPropertyId( $propertyId ); | |
Debug::dump($default); | |
if($default){ | |
return $default['path']; | |
} | |
return $this->config['default_property_image_url']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment