diff --git a/addons/default/visiosoft/advs-module/resources/config/settings/sections.php b/addons/default/visiosoft/advs-module/resources/config/settings/sections.php index b5c4f64a3..6c3a9af6c 100644 --- a/addons/default/visiosoft/advs-module/resources/config/settings/sections.php +++ b/addons/default/visiosoft/advs-module/resources/config/settings/sections.php @@ -21,6 +21,7 @@ return [ 'title' => 'visiosoft.module.advs::section.ads', 'fields' => [ 'latest-limit', + 'popular_ads_limit', 'default_view_type', 'hide_zero_price', 'auto_approve', diff --git a/addons/default/visiosoft/advs-module/resources/config/settings/settings.php b/addons/default/visiosoft/advs-module/resources/config/settings/settings.php index 686ef580b..1c096479f 100644 --- a/addons/default/visiosoft/advs-module/resources/config/settings/settings.php +++ b/addons/default/visiosoft/advs-module/resources/config/settings/settings.php @@ -248,4 +248,11 @@ return [ 'default_value' => false, ] ], + + 'popular_ads_limit' => [ + 'type' => 'anomaly.field_type.integer', + 'config' => [ + 'default_value' => 15, + ], + ], ]; diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/section.php b/addons/default/visiosoft/advs-module/resources/lang/en/section.php index 926f1c534..af04042cc 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/section.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/section.php @@ -44,4 +44,7 @@ return [ 'options' => [ 'title' => 'Options', ], + 'theme_settings' => [ + 'name' => 'Theme Settings' + ], ]; diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/setting.php b/addons/default/visiosoft/advs-module/resources/lang/en/setting.php index 5dfc18925..458a81617 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/setting.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/setting.php @@ -155,4 +155,7 @@ return [ 'tcmb_exchange_url' => [ 'name' => 'TCMB Exchange URL', ], + 'popular_ads_limit' => [ + 'name' => 'Popular Ads Limit', + ], ]; diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php index ae6dd403b..d20583319 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php @@ -477,4 +477,14 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface ->where('advs_advs.status', 'approved') ->where('advs_advs.finish_at', '>', date('Y-m-d H:i:s')); } + + public function getPopular() + { + return $this->newQuery() + ->whereDate('finish_at', '>=', date("Y-m-d H:i:s")) + ->where('status', '=', 'approved') + ->where('slug', '!=', '') + ->orderBy('count_show_ad', 'desc') + ->paginate(setting_value('visiosoft.module.advs::popular_ads_limit', setting_value('streams::per_page'))); + } } diff --git a/addons/default/visiosoft/advs-module/src/Adv/Command/getPopular.php b/addons/default/visiosoft/advs-module/src/Adv/Command/getPopular.php new file mode 100644 index 000000000..672aa3868 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/Adv/Command/getPopular.php @@ -0,0 +1,20 @@ +getPopular(); + + $ads = $repository->getModel()->getLocationNames($ads); + + foreach ($ads as $index => $ad) { + $ads[$index]->detail_url = $repository->getModel()->getAdvDetailLinkByModel($ad, 'list'); + $ads[$index] = $repository->getModel()->AddAdsDefaultCoverImage($ad); + } + + return $ads; + } +} diff --git a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php index be75176c9..110673937 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php @@ -39,4 +39,6 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface public function extendAds($allAds, $isAdmin = false); public function getByUsersIDs($usersIDs); + + public function getPopular(); } diff --git a/addons/default/visiosoft/advs-module/src/AdvsModulePlugin.php b/addons/default/visiosoft/advs-module/src/AdvsModulePlugin.php index 64d8e466b..e060a3a09 100644 --- a/addons/default/visiosoft/advs-module/src/AdvsModulePlugin.php +++ b/addons/default/visiosoft/advs-module/src/AdvsModulePlugin.php @@ -6,13 +6,21 @@ use Visiosoft\AdvsModule\Adv\AdvModel; use Visiosoft\AdvsModule\Adv\Command\appendRequestURL; use Visiosoft\AdvsModule\Adv\Command\GetAd; use Visiosoft\AdvsModule\Adv\Command\getExchange; +use Visiosoft\AdvsModule\Adv\Command\getPopular; use Visiosoft\AdvsModule\Adv\Command\isActive; use Visiosoft\AdvsModule\Adv\Command\LatestAds; +use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface; use Visiosoft\AdvsModule\Currency\Currency; use Visiosoft\AdvsModule\Currency\CurrencyFormat; class AdvsModulePlugin extends Plugin { + public $repository; + + public function __construct(AdvRepositoryInterface $repository) + { + $this->repository = $repository; + } /** * @return array @@ -109,7 +117,15 @@ class AdvsModulePlugin extends Plugin } return $exchange; } - ) + ), new \Twig_SimpleFunction( + 'getPopular', + function () { + if (!$popular = $this->dispatch(new getPopular())) { + return null; + } + return $popular; + } + ), ]; } } diff --git a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php index b1eedcb8d..44c10eaf8 100644 --- a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php +++ b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php @@ -365,18 +365,24 @@ class AdvsModuleServiceProvider extends AddonServiceProvider { // Run extra post-boot registration logic here. // Use method injection or commands to bring in services. - $slug = 'general_settings'; - $section = [ - 'title' => 'visiosoft.module.advs::button.general_settings', - 'href' => '/admin/settings/modules/visiosoft.module.advs', + $settings_url = [ + 'general_settings' => [ + 'title' => 'visiosoft.module.advs::button.general_settings', + 'href' => '/admin/settings/modules/visiosoft.module.advs', + ], + 'theme_settings' => [ + 'title' => 'visiosoft.module.advs::section.theme_settings.name', + 'href' => url('admin/settings/themes/' . setting_value('streams::standard_theme')), + ], + 'assets_clear' => [ + 'title' => 'visiosoft.module.advs::section.assets_clear.name', + 'href' => '/admin/assets/clear', + ], ]; - $slug2 = 'assets_clear'; - $section2 = [ - 'title' => 'visiosoft.module.advs::section.assets_clear.name', - 'href' => '/admin/assets/clear', - ]; - $addonCollection->get('anomaly.module.settings')->addSection($slug, $section); - $addonCollection->get('anomaly.module.settings')->addSection($slug2, $section2); + + foreach ($settings_url as $key => $value) { + $addonCollection->get('anomaly.module.settings')->addSection($key, $value); + } // Disable file versioning $fileModel->disableVersioning();