diff --git a/plugins/tps/tps/controllers/api/AdvertisementsController.php b/plugins/tps/tps/controllers/api/AdvertisementsController.php index c9e91e0bb..35d4ba815 100644 --- a/plugins/tps/tps/controllers/api/AdvertisementsController.php +++ b/plugins/tps/tps/controllers/api/AdvertisementsController.php @@ -73,4 +73,10 @@ class AdvertisementsController extends BaseApiController } } + public function home(){ + //top + //mid + //right + //footer + } } diff --git a/plugins/tps/tps/controllers/api/BaseApiController.php b/plugins/tps/tps/controllers/api/BaseApiController.php index edca264c4..1bf85050e 100644 --- a/plugins/tps/tps/controllers/api/BaseApiController.php +++ b/plugins/tps/tps/controllers/api/BaseApiController.php @@ -3,7 +3,7 @@ use Cms\Classes\Controller; class BaseApiController extends Controller{ - private function apiArrayResponseBuilder($statusCode = null, $message = null, $data = []) + protected function apiArrayResponseBuilder($statusCode = null, $message = null, $data = []) { $arr = [ 'status_code' => (isset($statusCode)) ? $statusCode : 500, diff --git a/plugins/tps/tps/controllers/api/CmsController.php b/plugins/tps/tps/controllers/api/CmsController.php new file mode 100644 index 000000000..d6b4fbe9c --- /dev/null +++ b/plugins/tps/tps/controllers/api/CmsController.php @@ -0,0 +1,40 @@ +menuItems !== null) { + return $this->menuItems; + } + + $theme = Theme::getActiveTheme(); + $data['customData'] = $theme->getCustomData(); + $menu = Menu::load($theme, 'new-top-menui'); + $data['menuItems'] = $menu['settings']['items']; + + + if ($menu) { + return $this->apiArrayResponseBuilder(200, 'success', $data); + } + + return $this->apiArrayResponseBuilder(404, 'not found'); + + } + + + +} \ No newline at end of file diff --git a/plugins/tps/tps/controllers/api/MediaController.php b/plugins/tps/tps/controllers/api/MediaController.php index cf24abb84..9a932a8e4 100644 --- a/plugins/tps/tps/controllers/api/MediaController.php +++ b/plugins/tps/tps/controllers/api/MediaController.php @@ -1,6 +1,7 @@ where('row_num', '<=', 4) + ->orderBy('published_at','desc') + ->get(); + + if($data){ + $data = Media::hydrate($data->toArray()); + $data->transform(function ($value) use ($path) { + $value->poster_file = $path.$value->poster_file; + $mediaArray = []; + for($i=0; $i < count($value->media_file); $i++){ + $mediaArray[$i] = $value->media_file[$i]; + $mediaArray[$i]['media']=$path.$value->media_file[$i]['media']; + } + $value->media_file = $mediaArray; + return $value; + }); + + return $this->apiArrayResponseBuilder(200, 'success', $data->groupBy('type')); + } + + } + } diff --git a/plugins/tps/tps/controllers/api/PostController.php b/plugins/tps/tps/controllers/api/PostController.php new file mode 100644 index 000000000..b608b30d0 --- /dev/null +++ b/plugins/tps/tps/controllers/api/PostController.php @@ -0,0 +1,207 @@ + input('page'), + 'sort' => input('sort') ??'published_at desc', + 'perPage' => input('count'), + 'search' => trim(input('search')), + 'category' => input('category'), + 'date' => input('date'), + 'typePost' => input('typePost'), + 'postGroup' => input('group'), + 'published' => true, + 'select' => ['id','title','slug', 'featured', 'published_at', 'more_photo','afisha_phone', 'afisha_address', 'afisha_phone_new', DB::raw("IF(featured_image<>'',concat('$path',featured_image),featured_image) as main_image")] + ]; + + if(request()->has('featured')){ + $filter['featured'] = true; + } + + $data = Post::with(['categories:id,name'])->listFrontEnd($filter); + + if($data){ + $data->each(function ($item, $key) { + $item->url = $this->pageUrl('new/newPost',['id'=>$item->id,'slug'=>$item->slug]); + }); + } + + return $this->apiArrayResponseBuilder(200, 'success', $data); + } + + //posts item + public function show($locale,$id){ + $path = Config::get('app.cdn').Config::get('cms.storage.media.path'); + //$post = $this->Post::find($id,['id','content_html','author','slug', 'afisha_phone', 'afisha_address', 'afisha_phone_new']); + $post = Post::where('id', $id) + ->select('id', 'content_html', 'author', 'title','slug','published_at', 'more_photo','afisha_phone', 'afisha_address', 'afisha_phone_new', DB::raw("IF(featured_image<>'',concat('$path',featured_image),featured_image) as main_image")) + ->with(['categories:id,name']) + ->first(); + + if(!is_null($post)) { + + $post->url = $this->pageUrl('new/newPost',['id'=>$post->id,'slug'=>$post->slug]); + + $obj = Db::table('vdomah_blogviews_views') + ->where('post_id', $post->getKey()); + + if ($obj->count() > 0) { + $row = $obj->first(); + + $views = $row->views + rand(1,10);; + + $obj->update(['views' => $views]); + $post['views'] = $row->views; + } + else { + + Db::table('vdomah_blogviews_views')->insert([ + 'post_id' => $post->getKey(), + 'views' => rand(1,10) + ]); + } + return $this->apiArrayResponseBuilder(200, 'success', [$post]); + } + else { + return $this->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']); + } + + } + + public function lenta(){ + $now = Carbon::now(); + $locale = App::getLocale(); + + $posts = DB::table(DB::raw("( + SELECT id, title, slug, published_at, type_post, + ROW_NUMBER() OVER (PARTITION BY type_post ORDER BY published_at) as row_num + FROM rainlab_blog_posts + WHERE published IS NOT NULL + AND published = 1 + AND published_at IS NOT NULL + AND type_post IS NOT NULL + AND type_post <> '' + AND published_at < '{$now}' + AND locale = '{$locale}' + ) as ranked_posts")) + ->where('row_num', '<=', 7) + ->orderBy('published_at','desc') + ->get(); + + + if($posts){ + $posts = Post::hydrate($posts->toArray()); + + $posts->each(function ($item, $key) { + $item->url = $this->pageUrl('new/newPost',['id'=>$item->id,'slug'=>$item->slug]); + }); + return $this->apiArrayResponseBuilder(200, 'success', $posts->groupBy('type_post')); + } + + return $this->apiArrayResponseBuilder(200, 'no records found'); + } + + public function homeTop(){ + $path = Config::get('app.cdn').Config::get('cms.storage.media.path'); + + $featured = Post::isPublished() + ->select('id', 'title', 'slug', 'published_at', DB::raw("IF(featured_image<>'', concat('$path', featured_image), featured_image) as main_image, 'featured' as type")) + ->where('featured', true) + ->orderByDesc('published_at') + ->limit(4); + + // Second query + $morque = Post::isPublished() + ->select('id', 'title', 'slug', 'published_at', DB::raw("featured_image as main_image, 'marquee' as type")) + ->where('on_morque', true) + ->where('featured', false) + ->orderByDesc('published_at') + ->limit(5); + + $turkmenposts = Post::isPublished() + ->select('id', 'title', 'slug', 'published_at', DB::raw("featured_image as main_image, 'lenta' as type")) + ->where('on_morque', false) + ->where('featured', false) + ->where('type_post','turkmenistan') + ->orderByDesc('published_at') + ->limit(7); + + // Union + $posts = $morque->unionAll($featured)->unionAll($turkmenposts)->get(); + + if($posts){ + $posts = Post::hydrate($posts->toArray()); + + $posts->each(function ($item, $key) { + $item->url = $this->pageUrl('new/newPost',['id'=>$item->id,'slug'=>$item->slug]); + }); + return $this->apiArrayResponseBuilder(200, 'success', $posts->groupBy('type')); + } + + return $this->apiArrayResponseBuilder(200, 'no records found'); + } + + public function homeMid(){ + $path = Config::get('app.cdn').Config::get('cms.storage.media.path'); + + $world = Post::isPublished() + ->select('id', 'title', 'slug', 'published_at','type_post', 'excerpt', DB::raw("IF(featured_image<>'', concat('$path', featured_image), featured_image) as main_image, 'world' as type")) + ->where('on_morque', false) + ->where('featured', false) + ->where('type_post','world') + ->orderByDesc('published_at') + ->with(['categories:name']) + ->limit(5); + + $popular = Post::isPublished() + ->select('id', 'title', 'slug', 'published_at', 'type_post', 'excerpt', DB::raw("IF(featured_image<>'', concat('$path', featured_image), featured_image) as main_image, 'popular' as type")) + ->leftJoin('vdomah_blogviews_views as pv', 'pv.post_id', '=', 'rainlab_blog_posts.id') + // ->where('published_at','>=',Carbon::now()->addMonth(-1)) + ->orderByDesc('views', 'DESC') + ->with(['categories:name']) + ->limit(5); + + $redaktors = Post::isPublished() + ->select('id', 'title', 'slug', 'published_at','type_post', 'excerpt', DB::raw("IF(featured_image<>'', concat('$path', featured_image), featured_image) as main_image, 'redaktor' as type")) + ->orderByDesc('published_at') + ->with(['categories:name']) + ->where('on_morque', false) + ->where('featured', false) + ->whereHas('categories', function($q) { + $q->where('slug', 'ot-redaktora'); + }) + ->limit(5); + + $publications = Post::isPublished() + ->select('id', 'title', 'slug', 'published_at','type_post', 'excerpt', DB::raw("IF(featured_image<>'', concat('$path', featured_image), featured_image) as main_image, 'redaktor' as type")) + ->orderByDesc('published_at') + ->where('on_morque', false) + ->where('featured', false) + ->whereHas('category_groups', function($q) { + $q->where('slug', 'stati'); + }) + ->limit(4); + // Union + $posts = $world->unionAll($popular)->unionAll($redaktors)->get(); + + if($posts){ + $posts = Post::hydrate($posts->toArray()); + + $posts->each(function ($item, $key) { + $item->url = $this->pageUrl('new/newPost',['id'=>$item->id,'slug'=>$item->slug]); + }); + return $this->apiArrayResponseBuilder(200, 'success', $posts->groupBy('type')); + } + + return $this->apiArrayResponseBuilder(200, 'no records found'); + } +} diff --git a/plugins/tps/tps/controllers/api/PostsController.php b/plugins/tps/tps/controllers/api/PostsController.php deleted file mode 100644 index 4c9b457d2..000000000 --- a/plugins/tps/tps/controllers/api/PostsController.php +++ /dev/null @@ -1,78 +0,0 @@ - input('page'), - 'sort' => input('sort') ??'published_at desc', - 'perPage' => input('count'), - 'search' => trim(input('search')), - 'category' => input('category'), - 'date' => input('date'), - 'typePost' => input('typePost'), - 'postGroup' => input('group'), - 'published' => true, - 'select' => ['id','title','slug', 'featured', 'published_at', 'more_photo','afisha_phone', 'afisha_address', 'afisha_phone_new', DB::raw("IF(featured_image<>'',concat('$path',featured_image),featured_image) as main_image")] - ]; - - if(request()->has('featured')){ - $filter['featured'] = true; - } - - $data = Post::with(['categories:id,name'])->listFrontEnd($filter); - - if($data){ - $data->each(function ($item, $key) { - $item->url = $this->pageUrl('new/newPost',['id'=>$item->id,'slug'=>$item->slug]); - }); - } - - return $this->apiArrayResponseBuilder(200, 'success', $data); - } - - //posts item - public function show($locale,$id){ - $path = Config::get('app.cdn').Config::get('cms.storage.media.path'); - //$post = $this->Post::find($id,['id','content_html','author','slug', 'afisha_phone', 'afisha_address', 'afisha_phone_new']); - $post = Post::where('id', $id) - ->select('id', 'content_html', 'author', 'title','slug','published_at', 'more_photo','afisha_phone', 'afisha_address', 'afisha_phone_new', DB::raw("IF(featured_image<>'',concat('$path',featured_image),featured_image) as main_image")) - ->with(['categories:id,name']) - ->first(); - - if(!is_null($post)) { - - $post->url = $this->pageUrl('new/newPost',['id'=>$post->id,'slug'=>$post->slug]); - - $obj = Db::table('vdomah_blogviews_views') - ->where('post_id', $post->getKey()); - - if ($obj->count() > 0) { - $row = $obj->first(); - - $views = $row->views + rand(1,10);; - - $obj->update(['views' => $views]); - $post['views'] = $row->views; - } - else { - - Db::table('vdomah_blogviews_views')->insert([ - 'post_id' => $post->getKey(), - 'views' => rand(1,10) - ]); - } - return $this->apiArrayResponseBuilder(200, 'success', [$post]); - } - else { - return $this->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']); - } - - } - -} diff --git a/plugins/tps/tps/routes.php b/plugins/tps/tps/routes.php index d78102287..6266480ac 100644 --- a/plugins/tps/tps/routes.php +++ b/plugins/tps/tps/routes.php @@ -2,24 +2,23 @@ use Tps\Tps\Controllers\TestQuestion; - -// Custom Routes -Route::get('{locale}/test/questions/{id}', 'Tps\Tps\Controllers\TestQuestion@getQuestions'); -Route::post('fatoni/generate/api', array('as' => 'fatoni.generate.api', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\ApiGeneratorController@generateApi')); -Route::post('fatoni/update/api/{id}', array('as' => 'fatoni.update.api', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\ApiGeneratorController@updateApi')); -Route::get('fatoni/delete/api/{id}', array('as' => 'fatoni.delete.api', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\ApiGeneratorController@deleteApi')); //postlar bilen categorialar -Route::resource('api/categories', 'AhmadFatoni\ApiGenerator\Controllers\API\CategoriesController', ['except' => ['destroy', 'create', 'edit']]); -Route::resource('api/advetisements', 'AhmadFatoni\ApiGenerator\Controllers\API\AdvertisementsController', ['except' => ['destroy', 'create', 'edit']]); -Route::get('api/group/advertisements', 'AhmadFatoni\ApiGenerator\Controllers\API\AdvertisementsController@getByGroup'); +Route::resource('api/categories', 'Tps\Tps\Controllers\API\CategoriesController', ['except' => ['destroy', 'create', 'edit']]); +Route::resource('api/advetisements', 'Tps\Tps\Controllers\API\AdvertisementsController', ['except' => ['destroy', 'create', 'edit']]); +Route::get('api/group/advertisements', 'Tps\Tps\Controllers\API\AdvertisementsController@getByGroup'); -Route::resource('{locale}/api/posts', 'AhmadFatoni\ApiGenerator\Controllers\API\postsController', ['except' => ['destroy', 'create', 'edit']]); +Route::resource('{locale}/api/posts', 'Tps\Tps\Controllers\API\PostController', ['except' => ['destroy', 'create', 'edit']]); - -Route::get('api/v2/categories', 'AhmadFatoni\ApiGenerator\Controllers\API\CategoriesV2Controller@index'); -Route::get('api/v2/media', 'AhmadFatoni\ApiGenerator\Controllers\API\MediaController@index'); -//Route::get('api/v2/afisha', 'AhmadFatoni\ApiGenerator\Controllers\API\AfishaController@index'); -Route::resource('api/v2/afisha', 'AhmadFatoni\ApiGenerator\Controllers\API\AfishaController', ['except' => ['destroy', 'create', 'edit']]); +//header +Route::get('api/v2/header','Tps\Tps\Controllers\API\CmsController@headerInfo'); +//lenta +Route::get('{locale}/api/v2/lenta','Tps\Tps\Controllers\API\PostController@lenta'); +Route::get('{locale}/api/v2/home-top','Tps\Tps\Controllers\API\PostController@homeTop'); +Route::get('{locale}/api/v2/home-mid','Tps\Tps\Controllers\API\PostController@homeMid'); +Route::get('{locale}/api/v2/home-footer','Tps\Tps\Controllers\API\MediaController@home'); +Route::get('api/v2/categories', 'Tps\Tps\Controllers\API\CategoriesV2Controller@index'); +Route::get('api/v2/media', 'Tps\Tps\Controllers\API\MediaController@index'); +Route::resource('api/v2/afisha', 'Tps\Tps\Controllers\API\AfishaController', ['except' => ['destroy', 'create', 'edit']]); Route::get('api/version',function (){ return '2.0.8'; diff --git a/themes/modern2/meta/menus/new-top-menui.yaml b/themes/modern2/meta/menus/new-top-menui.yaml index 647386b42..ddecbeafd 100644 --- a/themes/modern2/meta/menus/new-top-menui.yaml +++ b/themes/modern2/meta/menus/new-top-menui.yaml @@ -1,9 +1,13 @@ items: - title: Новости + nesting: null type: url url: /ru/posts/news code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -18,9 +22,13 @@ items: items: - title: События + nesting: null type: url url: /ru/posts/news/events code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -41,7 +49,7 @@ items: locale: en: title: Economy - url: '' + url: /en/posts/news/economy tm: title: Ykdysadyýet url: /tm/posts/news/ykdysadyyet @@ -50,9 +58,13 @@ items: isExternal: '0' - title: Общество + nesting: null type: url url: /ru/posts/news/society code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -66,9 +78,13 @@ items: isExternal: '0' - title: Культура + nesting: null type: url url: /ru/posts/news/culture code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -82,9 +98,13 @@ items: isExternal: '0' - title: 'Новости бизнеса' + nesting: null type: url url: /ru/posts/news/novosti-biznesa code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -98,9 +118,13 @@ items: isExternal: '0' - title: Спорт + nesting: null type: url url: /ru/posts/news/sport code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -114,9 +138,13 @@ items: isExternal: '0' - title: Наука + nesting: null type: url url: /ru/posts/news/nauka code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -130,9 +158,13 @@ items: isExternal: '0' - title: Экомир + nesting: null type: url url: /ru/posts/news/eco-world code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -146,9 +178,13 @@ items: isExternal: '0' - title: Технологии + nesting: null type: url url: /ru/posts/news/technology code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -162,9 +198,13 @@ items: isExternal: '0' - title: 'Новости партнеров' + nesting: null type: url url: /ru/posts/news/novosti-partnerov code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -178,9 +218,13 @@ items: isExternal: '0' - title: Статьи + nesting: null type: url url: /ru/posts/stati code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -195,9 +239,13 @@ items: items: - title: События + nesting: null type: url url: /ru/posts/stati/events code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -211,9 +259,13 @@ items: isExternal: '0' - title: Экономика + nesting: null type: url url: /ru/posts/stati/economy code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -227,9 +279,13 @@ items: isExternal: '0' - title: Общество + nesting: null type: url url: /ru/posts/stati/society code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -243,9 +299,13 @@ items: isExternal: '0' - title: 'От редактора' + nesting: null type: url url: /ru/posts/stati/ot-redaktora code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -259,9 +319,13 @@ items: isExternal: '0' - title: Культура + nesting: null type: url url: /ru/posts/stati/culture code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -275,9 +339,13 @@ items: isExternal: '0' - title: Полезное + nesting: null type: url url: /ru/posts/stati/poleznoe code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -291,9 +359,13 @@ items: isExternal: '0' - title: Спорт + nesting: null type: url url: /ru/posts/stati/sport code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -307,9 +379,13 @@ items: isExternal: '0' - title: Экомир + nesting: null type: url url: /ru/posts/stati/eco-world code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -323,9 +399,13 @@ items: isExternal: '0' - title: Технологии + nesting: null type: url url: /ru/posts/stati/technology code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -339,9 +419,13 @@ items: isExternal: '0' - title: Медиа + nesting: null type: url url: /ru/posts/media code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -396,9 +480,13 @@ items: isExternal: '0' - title: Афиша + nesting: null type: url url: /ru/posts/poster code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -413,9 +501,13 @@ items: items: - title: Концерты + nesting: null type: url url: /ru/posts/poster/koncerty code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -429,9 +521,13 @@ items: isExternal: '0' - title: Кинотеатры + nesting: null type: url url: /ru/posts/poster/kinoteatry code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -445,9 +541,13 @@ items: isExternal: '0' - title: Театры + nesting: null type: url url: /ru/posts/poster/teatry code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -461,9 +561,13 @@ items: isExternal: '0' - title: Выставки + nesting: null type: url url: /ru/posts/poster/vystavki code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -477,9 +581,13 @@ items: isExternal: '0' - title: Спорт + nesting: null type: url url: /ru/posts/poster/sportt code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: @@ -493,9 +601,13 @@ items: isExternal: '0' - title: Объявления + nesting: null type: url url: /ru/posts/poster/obyavleniya code: '' + reference: null + cmsPage: null + replace: null viewBag: locale: en: