public function get_customer_assignment()
 {
     if (Request::input('key') && Request::input('key') == '8855a5gp2C6577') {
         $customernr = Request::input('customernr');
         $list = Assignment::where('customer_id', $customernr)->get();
         if ($list->count()) {
             foreach ($list as $key => $value) {
                 $result[$key]['created_at'] = $value->created_at;
                 $result[$key]['minimum_wordcount'] = $value->minimum_wordcount;
                 $result[$key]['img_link'] = json_decode($value->img_link);
                 $result[$key]['status'] = $value->status;
                 $result[$key]['total_user'] = UserAssignment::where('assignment_id', $value->id)->count();
             }
             return $result;
         } else {
             return 'Assignments for this customer does not exist';
         }
     } else {
         return 'You do not have permission to view this page';
     }
 }
示例#2
0
 public function complete_assignment($id)
 {
     $u = UserAssignment::find($id);
     $u->status = 5;
     $u->save();
     return redirect('admin/user-assignments')->with('ok', 'Completed');
 }
 public function index()
 {
     $exportExcel = Request::input('exportExcel');
     $lang = Request::input('lang');
     $status = Request::input('status');
     $period = Request::input('period');
     $period_to = Request::input('period_to');
     $data = array();
     $data['langs'] = Language::all();
     $users = User::where('role', '<>', 1)->get(array('id', 'name', 'cpr', 'account_number'));
     $list_user_assigns = array();
     $list_users_lang = array();
     /// filter by langs
     if ($lang && $lang == 'all' || !$lang) {
         foreach ($users as $k => $u) {
             $num = UserBlog::where('user_id', $u->id)->first();
             if ($num) {
                 $list_users_lang[$k] = $u;
                 $list_users_lang[$k]['star'] = $num->star;
                 $list_users_lang[$k]['lang_code'] = $num->lang_code;
                 $star_value = Setting::where('lang_code', $num->lang_code)->where('name', 'star_value')->first()->value;
                 if (!$star_value) {
                     $star_value = Setting::where('lang_code', 'en')->where('name', 'star_value')->first()->value;
                 }
                 $list_users_lang[$k]['star_value'] = $star_value;
                 $list_users_lang[$k]['total_amount'] = 0;
             }
         }
     } elseif ($lang && $lang != 'all') {
         foreach ($users as $k => $u) {
             $num = UserBlog::where('user_id', $u->id)->where('lang_code', $lang)->first();
             if ($num) {
                 $list_users_lang[$k] = $u;
                 $list_users_lang[$k]['star'] = $num->star;
                 $list_users_lang[$k]['lang_code'] = $num->lang_code;
                 $star_value = Setting::where('lang_code', $num->lang_code)->where('name', 'star_value')->first()->value;
                 if (!$star_value) {
                     $star_value = Setting::where('lang_code', 'en')->where('name', 'star_value')->first()->value;
                 }
                 $list_users_lang[$k]['star_value'] = $star_value;
                 $list_users_lang[$k]['total_amount'] = 0;
             }
         }
     }
     /// filter by status
     /// if status == all or dont isset status
     if ($status && $status == 'all' || !$status) {
         foreach ($list_users_lang as $k_u_l => $v_u_l) {
             /// if period = null, dont query by date
             if ($period == '' || !$period) {
                 $ua = UserAssignment::where('user_id', $v_u_l->id)->whereIn('status', array(3, 5))->get(array('id', 'link', 'status', 'extra_star', 'approved_at', 'created_at'));
             } else {
                 // if isset period and period != null
                 $period = date('Y-m-d 00:00:00', strtotime($period));
                 $period_to = date('Y-m-d 23:59:59', strtotime($period_to));
                 $ua = UserAssignment::where('user_id', $v_u_l->id)->whereIn('status', array(3, 5))->where('approved_at', '>=', $period)->where('approved_at', '<=', $period_to)->get(array('id', 'link', 'status', 'extra_star', 'approved_at', 'created_at'));
             }
             if (count($ua)) {
                 $list_user_assigns[$k_u_l] = $v_u_l;
                 $list_user_assigns[$k_u_l]['user_assignment'] = $ua;
                 foreach ($ua as $key_ua => $value_ua) {
                     $list_user_assigns[$k_u_l]['user_assignment'][$key_ua]['amount'] = ($value_ua['extra_star'] + $v_u_l['star']) * $v_u_l['star_value'];
                     $list_users_lang[$k_u_l]['total_amount'] += $list_user_assigns[$k_u_l]['user_assignment'][$key_ua]['amount'];
                 }
             }
         }
     } elseif ($status && $status != 'all') {
         foreach ($list_users_lang as $k_u_l => $v_u_l) {
             if ($period == '' || !$period) {
                 $ua = UserAssignment::where('user_id', $v_u_l->id)->where('status', $status)->get(array('id', 'link', 'status', 'extra_star', 'approved_at', 'created_at'));
             } else {
                 $period = date('Y-m-d 00:00:00', strtotime($period));
                 $period_to = date('Y-m-d 23:59:59', strtotime($period_to));
                 $ua = UserAssignment::where('user_id', $v_u_l->id)->where('status', $status)->where('approved_at', '>=', $period)->where('approved_at', '<=', $period_to)->get(array('id', 'link', 'status', 'extra_star', 'approved_at', 'created_at'));
             }
             if (count($ua)) {
                 $list_user_assigns[$k_u_l] = $v_u_l;
                 $list_user_assigns[$k_u_l]['user_assignment'] = $ua;
                 foreach ($ua as $key_ua => $value_ua) {
                     $list_user_assigns[$k_u_l]['user_assignment'][$key_ua]['amount'] = ($value_ua['extra_star'] + $v_u_l['star']) * $v_u_l['star_value'];
                     $list_users_lang[$k_u_l]['total_amount'] += $list_user_assigns[$k_u_l]['user_assignment'][$key_ua]['amount'];
                 }
             }
         }
     }
     /// export excel
     if ($exportExcel) {
         return $this->exportExcel($list_user_assigns);
     }
     return view('admin.payment-list.index', array('users' => $list_user_assigns, 'langs' => $data['langs']));
 }
示例#4
0
 public function validate_user_assignment_link()
 {
     $link = Request::input('data');
     /// user report link
     $id = Request::input('user_assignment_id');
     $ua = UserAssignment::find($id);
     // user assignment
     /// used for (maybe) when user reached of max time to repost, then remove and return not exist to move
     if (!$ua) {
         return array('statusCode' => 500, 'content' => 'not_exist');
     }
     $current_allow = Setting::where('name', 'time_to_repost')->first()->value;
     /// reached of allow time to repost
     if ($ua->time_to_repost == 1) {
         //// remove current user assignment - return to available
         /// message to user this assignment is Canceled
         $ua->delete();
         return array('statusCode' => 500, 'content' => 'You have tried <strong>' . $current_allow . '</strong> times to repost but ' . $link . ' is not enough of quality. Your assignment is Canceled', 'overtime' => 'yes');
     }
     $ua->time_to_repost = $ua->time_to_repost - 1;
     $ua->save();
     /////*********************************
     $true_apply = UserAssignment::where('user_id', Auth::user()->id)->where('id', $id)->first();
     if (!$true_apply) {
         return array('statusCode' => 500, 'content' => 'not_exist');
     }
     $domain = strtolower($link);
     $domain = parse_url($domain, PHP_URL_HOST);
     $domain = preg_replace('/(?:https?:\\/\\/)?(?:www\\.)?(.*)\\/?$/i', '$1', $domain);
     $domain = preg_replace('/\\//i', '$1', $domain);
     /*
      *
      *	BEGIN TO VALIDATE AND MINUS TIME TO TRY AND PLUS MORE TIME IF FAILED
      *	If plus more time (minute_to_repost_time) , just get from Setting then plus with: created_at of this UA
      **/
     //// check link domain same with user blog domain
     if ($domain != Auth::user()->userblog->domain) {
         $this->plus_time_repost($ua);
         return array('statusCode' => 500, 'content' => '<strong>' . $link . '</strong> is not match with your blog domain you have registered. You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
     }
     /************************************************/
     /// ALL OK
     $assignment = Assignment::find($ua->assignment_id);
     $required_link = json_decode($assignment->img_link);
     $required_keyword = explode(',', $assignment->keyword);
     $wordcount = $assignment->minimum_wordcount;
     $curl = curl_init($link);
     curl_setopt($curl, CURLOPT_NOBODY, true);
     $result = curl_exec($curl);
     $headerStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     if ($headerStatusCode == '404') {
         $this->plus_time_repost($ua);
         return array('statusCode' => 500, 'content' => '<strong>' . $link . '</strong> does not exist. You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
     } elseif ($headerStatusCode == '301') {
         return array('statusCode' => 500, 'content' => '<strong>' . $link . '</strong> is redirected, please use direct link. You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
     } elseif ($headerStatusCode == '200') {
         $result_complete_validate = $this->complete_validate_blog($required_link, $link, $required_keyword, $wordcount);
         if (isset($result_complete_validate['error']) && $result_complete_validate['error'] == 'not-enough') {
             /// not enough link
             $this->plus_time_repost($ua);
             $list_notfollow = '';
             if (count($result_complete_validate['list_notfollow'])) {
                 $list_notfollow .= '<ul>';
                 foreach ($result_complete_validate['list_notfollow'] as $ln) {
                     $list_notfollow .= ' <li><strong> ' . $ln . '</strong> rel="nofollow" is not allowed</li> ';
                 }
                 $list_notfollow .= '</ul>';
             }
             return array('statusCode' => 500, 'content' => 'Number of links required: <strong>' . $result_complete_validate['num'] . '</strong><br>' . $list_notfollow . '  . You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
         }
         if (isset($result_complete_validate['error']) && $result_complete_validate['error'] == 'not-enough-keyword') {
             $this->plus_time_repost($ua);
             $list_notOK_keyword = '';
             if (count($result_complete_validate['list_notOK_keyword'])) {
                 $list_notOK_keyword .= '<ul>';
                 foreach ($result_complete_validate['list_notOK_keyword'] as $ln) {
                     $list_notOK_keyword .= ' <li>Keyword: <strong> ' . $ln . '</strong>  not found</li> ';
                 }
                 $list_notOK_keyword .= '</ul>';
             }
             return array('statusCode' => 500, 'content' => 'Number of keyword required: <strong>' . $result_complete_validate['num'] . '</strong><br>' . $list_notOK_keyword . '. You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
         }
         if (isset($result_complete_validate['error']) && $result_complete_validate['error'] == 'not-enough-wordcount') {
             $this->plus_time_repost($ua);
             return array('statusCode' => 500, 'content' => 'Number of words required: <strong>' . $result_complete_validate['num'] . '</strong>. You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
         }
         /// ALl OKKKKKKKKKKKKKKK. Count user_assignment by assignment_id, if full with status 3, close this assignment
         UserAssignment::where('user_id', Auth::user()->id)->where('id', $id)->update(array('status' => 3, 'link' => $link, 'approved_at' => date('Y-m-d H:i:s', time())));
         /// 2 is Written
         $total = UserAssignment::where('assignment_id', $ua->assignment_id)->where('status', 3)->count();
         if ($total == $assignment->max_blogger) {
             $assignment->status = 0;
             $assignment->save();
         }
         return array('statusCode' => 200);
     } else {
         $this->plus_time_repost($ua);
         return array('statusCode' => 500, 'content' => '<strong>' . $link . '</strong> is not valid. You have <strong>' . $ua->time_to_repost . '</strong> times to try again');
     }
 }