Пример #1
0
 public function test_time()
 {
     $time = time();
     $theTime = \Morilog\Jalali\jDate::forge($time)->time();
     $this->assertTrue($time === $theTime);
     $theTime = \Morilog\Jalali\jDate::forge('now')->time();
     $this->assertTrue($theTime === strtotime('now'));
 }
Пример #2
0
 public function testTimezone()
 {
     date_default_timezone_set('Asia/Tehran');
     $tehranDate = jDate::forge();
     $tehranHour = $tehranDate->format('H');
     $tehranMin = $tehranDate->format('i');
     date_default_timezone_set('UTC');
     $utcDate = jDate::forge();
     $utcHour = $utcDate->format('H');
     $utcMin = $utcDate->format('i');
     $tzOffset = $this->getTimeZoneOffset('Asia/Tehran', 'UTC');
     $this->assertTrue(($utcHour * 60 + $utcMin) * 60 - ($tehranHour * 60 + $tehranMin) * 60 === $tzOffset);
 }
Пример #3
0
 /**
  * Created By Dara on 7/11/2015
  * get nearest settlement shamsi time and check if the user can settle now or not
  */
 public function settleTime()
 {
     $user = Auth::user();
     //check if the user has an settle with status 0 or not
     $count = $user->settles()->where('status', 0)->count();
     $event = Event::where('from_time', '<=', date('Y-m-d h-i-s'))->where('to_time', '>', date('Y-m-d h-i-s'))->where('name', '=', 'settle')->orWhere('to_time', '>', date('Y-m-d h-i-s'))->where('name', 'settle')->orderBy('from_time', 'Asc')->first();
     if (count($event)) {
         if ($event->from_time < date('Y-m-d h-i-s')) {
             //the current time is between the from and to
             if ($count > 0) {
                 return ['time' => jDate::forge(date('Y-m-d'))->format('Y/m/d'), 'canSettle' => false, 'message' => 'شما درخواست تسویه در حال بررسی دارید!'];
             }
             return ['time' => jDate::forge(date('Y-m-d'))->format('Y/m/d'), 'canSettle' => true, 'message' => 'هم اکنون می توانید تسویه کنید .'];
         } else {
             return ['time' => jDate::forge($event->from_time)->format('Y/m/d'), 'canSettle' => false, 'message' => 'زمان تسویه فرانرسیده است'];
         }
     } else {
         return ['time' => 'نا مشخص', 'canSettle' => false, 'message' => 'رویدادی برای تسویه حساب وجود ندارد.'];
     }
 }
Пример #4
0
 public function index(FriendRepository $friendRepository, ChatRepository $chatRepository, User $holder)
 {
     $user = Auth::user();
     if (!empty($holder->id)) {
         $histories = $chatRepository->historyCollection($holder->id)->get();
         Event::fire(new seenMessage($holder->id));
         MessageUser::where('parentable_type', 'App\\User')->where('parentable_id', $holder)->where('user_id', $user->id)->where('status', 0)->update(['status' => 1]);
     } else {
         $histories = [];
     }
     $friends = $friendRepository->myFriends();
     $chats = $chatRepository->myChats();
     $friends = $friends->each(function ($friend, $key) use($chatRepository) {
         $chatRepository->latest($friend->friend_info->id);
         $friend->latestMessage = $chatRepository->latestMessage();
         $friend->latestCreatedAt = $chatRepository->latestCreatedAt();
         $friend->latestHumanCreatedAt = jDate::forge($friend->latestCreatedAt)->ago();
         $friend->newMessagesCount = $chatRepository->newMessagesCount();
     });
     $friends = $friends->sortByDesc('latestCreatedAt');
     return view('chat.index', compact('user', 'friends', 'chatRepository', 'histories', 'holder', 'chats'))->with(['title' => 'گفتگو']);
 }
Пример #5
0
 public function myChats()
 {
     $user = Auth::user();
     $send = MessageUser::where('parentable_id', $user->id)->where('parentable_type', 'App\\User')->where('user_id', '!=', $user->id)->groupBy('user_id')->get();
     $receive = MessageUser::where('user_id', $user->id)->where('parentable_id', '!=', $user->id)->where('parentable_type', 'App\\User')->groupBy('parentable_id')->get();
     $histories = $receive->merge($send);
     $histories = $histories->each(function ($history, $key) use($user) {
         if ($history->user_id == $user->id) {
             $history->friend_info = $history->parentable;
         } elseif ($history->parentable_id == $user->id) {
             $history->friend_info = $history->user;
         }
         $this->latest($history->friend_info->id);
         $history->latestMessage = $this->latestMessage();
         $history->latestCreatedAt = $this->latestCreatedAt();
         $history->latestHumanCreatedAt = jDate::forge($history->latestCreatedAt)->ago();
         $history->newMessagesCount = $this->newMessagesCount();
     })->sortByDesc('latestCreatedAt');
     $histories = $histories->groupBy(function ($item, $key) {
         return $item->friend_info->id;
     });
     return $histories;
 }
Пример #6
0
 public function getShamsiCreatedAtAttribute()
 {
     return jDate::forge($this->attributes['created_at'])->format('Y/m/d');
 }
Пример #7
0
 private function advertiseAvailableList()
 {
     $advertises = Advertise::where('expired_at', '>', Carbon::now())->active()->get();
     $reservation_dates = [];
     $columns = Config::get('addonAdvertise.columns');
     for ($i = 1; $i <= 15; $i++) {
         $capacity = $columns;
         $start_date = Carbon::now()->addDays($i - 1);
         $expire_date = Carbon::now()->addDays($i);
         $selected_advertises = $advertises->filter(function ($advertise) use($start_date, $expire_date) {
             return $advertise->expired_at > $start_date and $advertise->expired_at < $expire_date;
         });
         foreach ($selected_advertises as $selected_advertise) {
             $weight = Config::get('addonAdvertise.attributes')[1]['values'][$selected_advertise->type]['weight'];
             $capacity = $capacity - $weight;
         }
         if ($capacity - Config::get('addonAdvertise.attributes')[1]['values'][1]['weight'] >= 0) {
             $gold_availability = 1;
         } else {
             $gold_availability = 0;
         }
         if ($capacity - Config::get('addonAdvertise.attributes')[1]['values'][2]['weight'] >= 0) {
             $silver_availability = 1;
         } else {
             $silver_availability = 0;
         }
         if ($capacity - Config::get('addonAdvertise.attributes')[1]['values'][3]['weight'] >= 0) {
             $bronze_availability = 1;
         } else {
             $bronze_availability = 0;
         }
         $selected_advertises = $selected_advertises->all();
         $expire_date = jDate::forge($expire_date)->format('Y/m/d H:i');
         $start_date = jDate::forge($start_date)->format('Y/m/d H:i');
         $reservation_dates[$i] = compact('start_date', 'expire_date', 'gold_availability', 'silver_availability', 'bronze_availability', 'selected_advertises');
     }
     return $reservation_dates;
 }
Пример #8
0
 public function getShamsiHumanCreatedAtAttribute()
 {
     return jDate::forge($this->attributes['created_at'])->ago();
 }
Пример #9
0
 public function getHumanUpdatedAtAttribute()
 {
     return jDate::forge($this->attributes['updated_at'])->ago();
 }
Пример #10
0
 public function sold(CouponUser $couponUser, Request $request)
 {
     $user = Auth::user();
     $input = $request->all();
     $trackingCode = $input['tracking_code'];
     $legalCode = $input['legal_code'];
     //check the information of the coupon
     if ($couponUser->tracking_code == $trackingCode && $couponUser->legal_code == $legalCode) {
         //the coupon info is correct
         //check if him/her is the owner of the coupon(offer)
         $coupon = $couponUser->coupon;
         if ($coupon->user_id == $user->id) {
             //the owner is correct and can continue
             $couponUser->update(['status' => 2]);
             //add to the credits table
             $description = "خرید کوپن";
             $user->credits()->create(['amount' => $couponUser->pay_amount, 'description' => $description]);
             return ['hasCallback' => 1, 'callback' => 'coupon_sold', 'hasMsg' => 0, 'msg' => '', 'msgType' => '', 'returns' => ['status' => 'done', 'date' => jDate::forge(Carbon::now())->format('Y/m/d')]];
         } else {
             //the owner is wrong
         }
     } else {
         //the coupon info is wrong
     }
 }
Пример #11
0
 /**
  * @param string $str
  * @return \Morilog\Jalali\jDate
  */
 function jdate($str = null)
 {
     return \Morilog\Jalali\jDate::forge($str);
 }
Пример #12
0
 public function getShamsiToTimeAttribute()
 {
     return jDate::forge($this->attributes['to_time'])->format('Y/m/d');
 }
Пример #13
0
 public function getExpiredAtAttribute()
 {
     return jDate::forge($this->attributes['expired_at'])->format('Y/m/d');
 }