PageRenderTime 30ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/app/Http/Controllers/HomeController.php

https://bitbucket.org/coredeveloper2013/navipi-test
PHP | 533 lines | 278 code | 157 blank | 98 comment | 28 complexity | af7b7143709b01b30f79c4535105aade MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. use App\Package;
  6. use App\AllTropic;
  7. use App\Friend;
  8. use App\Chatmessage;
  9. use App\ContactMessages;
  10. use Illuminate\Support\Facades\Auth;
  11. use Illuminate\Support\Facades\Input;
  12. use Illuminate\Support\Facades\Mail;
  13. class HomeController extends Controller
  14. {
  15. /**
  16. * Display a listing of the resource.
  17. *
  18. * @return \Illuminate\Http\Response
  19. */
  20. public $chat_messsage_data = array();
  21. public $alpha_set = [
  22. ['start'=>'0','end'=>'3'],
  23. ['start'=>'4','end'=>'7'],
  24. ['start'=>'8','end'=>'11'],
  25. ['start'=>'12','end'=>'15'],
  26. ['start'=>'16','end'=>'19'],
  27. ['start'=>'20','end'=>'23'],
  28. ['start'=>'24','end'=>'25']
  29. ];
  30. public $alphabets = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
  31. public function __construct()
  32. {
  33. $unread_msg = [];
  34. $chat_users = [];
  35. $frnd_users = [];
  36. $chat_usersdta = [];
  37. $loguser = Auth::User();
  38. if(Auth::check())
  39. {
  40. $chat_usersdta = Friend::where(['to_user_id' => Auth::user()->id, 'status'=>'Y'])->orWhere(['from_user_id' => Auth::user()->id, 'status'=>'Y'])->orderBy('created_at', 'desc')->get();
  41. }
  42. if(count($chat_usersdta) > 0)
  43. {
  44. for($i = 0;$i < count($chat_usersdta); $i++)
  45. {
  46. if ($loguser->id == $chat_usersdta[$i]->from_user_id) $frnd_users[]=$chat_usersdta[$i]->to_user_id;
  47. else if ($loguser->id == $chat_usersdta[$i]->to_user_id) $frnd_users[]=$chat_usersdta[$i]->from_user_id;
  48. }
  49. }
  50. $frnd_users = array_unique($frnd_users);
  51. //
  52. $chat_users = Chatmessage::whereIn('from_user_id', $frnd_users)->orWhereIn('to_user_id', $frnd_users)->orderBy('created_at', 'desc')->get();
  53. //dd($chat_users);
  54. if(Auth::check())
  55. {
  56. $unread_msg = Chatmessage::where([
  57. ['to_user_id', '=', Auth::user()->id],
  58. ['to_user_view_status', '=', 'N']
  59. ])
  60. ->orderBy('created_at', 'desc')
  61. ->get();
  62. }
  63. //dd($chat_users->toArray());
  64. $this->chat_messsage_data = [
  65. 'chat_users' => $chat_users,
  66. 'unread_msg' => $unread_msg
  67. ];
  68. }
  69. public function index()
  70. {
  71. $data = [];
  72. $user = Auth::user();
  73. if (Auth::check()) {
  74. if ($user->status == 'E') {
  75. return redirect(url('/user/signup-step/'.$user->in_step));
  76. }else{
  77. return redirect(url('/user/account'));
  78. }
  79. }
  80. return view('index', $data);
  81. }
  82. public function registerAs()
  83. {
  84. $data = [];
  85. return view('register-as', $data);
  86. }
  87. public function tropicPage($id=0)
  88. {
  89. $tropic = array(); $userfollows = array();
  90. $tropic = AllTropic::find($id);
  91. $user = Auth::User();
  92. if(empty($tropic))
  93. {
  94. return redirect(url('topics'));
  95. }
  96. if($user)
  97. {
  98. if(!empty($user->question_follows))
  99. {
  100. foreach($user->question_follows as $val)
  101. {
  102. $userfollows[] = $val->question_id;
  103. }
  104. }
  105. }
  106. //$p_qs = \App\AskQuestion::where()
  107. $pinned_questions = \DB::table('ask_questions')
  108. ->join('tropic_questions', 'tropic_questions.question_id', '=', 'ask_questions.id')
  109. ->where('tropic_questions.tropic_id', '=', $tropic->id )
  110. ->where('ask_questions.is_pinned', '=', 1 )
  111. ->orderBy('ask_questions.pinned_time','DESC')
  112. ->limit(4 )
  113. ->get();
  114. //dd($pinned_questions);
  115. $data = [
  116. 'user' => $user,
  117. 'pinned_questions' => $pinned_questions,
  118. 'tropic' => $tropic,
  119. 'userfollows' => $userfollows,
  120. 'chat_messsage_data' => $this->chat_messsage_data
  121. ];
  122. return view('topic-page', $data);
  123. }
  124. public function topics()
  125. {
  126. if(Input::get('trpc'))
  127. {
  128. $trpc = Input::get('trpc');
  129. $all_data = \DB::select( \DB::raw("SELECT SUBSTR(title, 1, 1) AS first_alpha FROM all_tropics WHERE `title` LIKE '%".$trpc."%' GROUP BY first_alpha ") );
  130. }
  131. else{
  132. $all_data = \DB::select( \DB::raw("SELECT SUBSTR(title, 1, 1) AS first_alpha FROM all_tropics WHERE 1 GROUP BY first_alpha ") );
  133. }
  134. $noof_pages = ceil(count($all_data)/4);
  135. //echo "<pre>";print_r($all_data);exit;
  136. $page=1;
  137. if(Input::get('page'))
  138. {
  139. $page = Input::get('page');
  140. }
  141. $page_no=$page-1;
  142. $i = 0;
  143. $page_alpha_arr = array();
  144. $user_favs = array();
  145. if(Auth::check())
  146. {
  147. $user_favorites = Auth::user()->user_favorites;
  148. //dd($user_favorites->toArray());
  149. if(count($user_favorites)>0)
  150. {
  151. foreach($user_favorites as $val)
  152. {
  153. $user_favs[]=$val->tropic_id;
  154. }
  155. }
  156. }
  157. $topics = AllTropic::where('id', '<>', 0);
  158. $fav_topics = AllTropic::whereIn('id',$user_favs);
  159. if(Input::get('alph'))
  160. {
  161. $alph = Input::get('alph');
  162. $topics = $topics->where('title', 'like', $alph.'%');
  163. $fav_topics = $fav_topics->where('title', 'like', $alph.'%');
  164. }
  165. if(Input::get('trpc'))
  166. {
  167. $trpc = Input::get('trpc');
  168. $topics = $topics->where('title', 'like', '%'.$trpc.'%');
  169. $fav_topics = $fav_topics->where('title', 'like', '%'.$trpc.'%');
  170. } /* */
  171. $topics = $topics->orderBy('title')->get();
  172. $fav_topics = $fav_topics->orderBy('title')->get();
  173. $start_ky= $page_no*4;
  174. $end_ky= ($page*4)-1;
  175. $fav_alphabets = array();
  176. if(count($fav_topics)>0)
  177. {
  178. foreach($fav_topics as $fa)
  179. {
  180. if(!in_array($fa->title[0],$fav_alphabets)) $fav_alphabets[] = $fa->title[0];
  181. }
  182. }
  183. $all_tropics = AllTropic::all();
  184. //dd($fav_alphabets);
  185. $data = [
  186. 'topics' => $topics,
  187. 'all_data' => $all_data,
  188. 'alphabets' => $this->alphabets,
  189. 'noof_pages' => $noof_pages,
  190. 'start_ky' => $start_ky,
  191. 'end_ky' => $end_ky,
  192. 'user_favs' => $user_favs,
  193. 'fav_topics' => $fav_topics,
  194. 'fav_alphabets' => $fav_alphabets,
  195. 'all_tropics' => $all_tropics,
  196. 'chat_messsage_data'=>$this->chat_messsage_data,
  197. ];
  198. return view('topics', $data);
  199. }
  200. /**
  201. * Show the form for creating a new resource.
  202. *
  203. * @return \Illuminate\Http\Response
  204. */
  205. public function create()
  206. {
  207. //
  208. }
  209. /**
  210. * Store a newly created resource in storage.
  211. *
  212. * @param \Illuminate\Http\Request $request
  213. * @return \Illuminate\Http\Response
  214. */
  215. public function store(Request $request)
  216. {
  217. //
  218. }
  219. /**
  220. * Display the specified resource.
  221. *
  222. * @param int $id
  223. * @return \Illuminate\Http\Response
  224. */
  225. public function show($id)
  226. {
  227. //
  228. }
  229. /**
  230. * Show the form for editing the specified resource.
  231. *
  232. * @param int $id
  233. * @return \Illuminate\Http\Response
  234. */
  235. public function edit($id)
  236. {
  237. //
  238. }
  239. /**
  240. * Update the specified resource in storage.
  241. *
  242. * @param \Illuminate\Http\Request $request
  243. * @param int $id
  244. * @return \Illuminate\Http\Response
  245. */
  246. public function update(Request $request, $id)
  247. {
  248. //
  249. }
  250. /**
  251. * Remove the specified resource from storage.
  252. *
  253. * @param int $id
  254. * @return \Illuminate\Http\Response
  255. */
  256. public function destroy($id)
  257. {
  258. //
  259. }
  260. public function accountUpgrade(Request $request)
  261. {
  262. $packages= Package::all();
  263. $current_plan = array();
  264. if(Auth::check())
  265. {
  266. $user = Auth::user();
  267. if(!empty($user->current_package[0])){
  268. $current_plan = $user->current_package[0];
  269. }
  270. //dd($current_plan->plan);
  271. }
  272. //dd($user->toArray());
  273. $slug="pricing";
  274. $cmsdata = \App\PageTranslation::where('locale',app()->getLocale())->where('slug',$slug)->first();
  275. return view('user.upgrade-account',compact('current_plan','packages','cmsdata'));
  276. }
  277. public function contactUs()
  278. {
  279. $setting = app('settings');
  280. $slug="contact-us";
  281. $cmsdata = \App\PageTranslation::where('locale',app()->getLocale())->where('slug',$slug)->first();
  282. //dd($cmsdata->toArray());
  283. return view('contact-us',compact('setting','cmsdata'))->with('chat_messsage_data',$this->chat_messsage_data);
  284. }
  285. public function contactProcess(Request $request)
  286. {
  287. $input_data = $request->all();
  288. $this->validate($request, [
  289. 'name' => 'required',
  290. 'email' => 'required|email',
  291. 'subject' => 'required',
  292. // 'email_confirmation' => 'required|same:email',
  293. 'comments' => 'required',
  294. ]);
  295. $_files="";
  296. //dd($input_data);
  297. if($request->hasFile('file_attached')){
  298. $_files = $request->file('file_attached');
  299. }
  300. $mailcontent = $input_data['comments'];
  301. $to=[app('settings')->contact_email];
  302. $senderMail = $input_data['email'];
  303. $senderName = $input_data['name'];
  304. $headers ="From: ".$input_data['name']."<".$input_data['email'].">\n";
  305. $headers .= "MIME-Version: 1.0\n";
  306. $headers .= "Content-type: text/html; charset=UTF-8\n";
  307. $subject = $input_data['subject']!=''?$input_data['subject']:"Contact Mail Notification";
  308. $message ="<html><head></head><body>"."<style type=\"text/css\">
  309. <!--
  310. .style4 {font-size: x-small}
  311. -->
  312. </style>
  313. ".$mailcontent."
  314. </body></html>";
  315. //@mail($to,$subject, $message,$headers);
  316. //multi_attach_mail($to, $subject, $message, $senderMail, $senderName, $_files);
  317. Mail::send('emails.customer_query', ['content'=>$message], function($messg) use ($to,$senderMail,$subject,$_files)
  318. {
  319. $messg->to($to)->from($senderMail)->subject($subject);
  320. if($_files!='')
  321. {
  322. $messg->attach($_files);
  323. }
  324. });
  325. $contactMessage =new ContactMessages;
  326. $contactMessage->sender_name = $input_data['name'];
  327. $contactMessage->sender_email = $input_data['email'];
  328. //$contactMessage->phone = $input_data['phone'];
  329. $contactMessage->comments = $input_data['comments'];
  330. $contactMessage->save(); /* We will get back to you within 1 business day.*/
  331. return redirect(url('contact-us'))->with('success', 'Thank you for contacting us. ');
  332. }
  333. public function getPackage(Request $request)
  334. {
  335. $input_data = $request->all();
  336. //print_r($input_data);
  337. $package = Package::find($input_data['id']);
  338. if(!empty($package))
  339. echo json_encode($package);
  340. else echo "error";
  341. }
  342. }