How to use withType method of error class

Best Atoum code snippet using error.withType

LocalDevicesController.php

Source:LocalDevicesController.php Github

copy

Full Screen

...81 '_serialize' => array('status', 'user', 'token', 'mode')82 ));83 return $this->getResponse()84 ->withStatus(200)85 ->withType('application/json')86 ->withStringBody(json_encode(array(87 'status' => 'success',88 'user' => $users,89 'token' => $token,90 'mode' => $this->mode)));91 }else{92 return $this->getResponse()93 ->withStatus(200)94 ->withType('application/json')95 ->withStringBody(json_encode(array(96 'status' => 'error',97 'msg' => 'Invalid username or password',98 'mode' => $this->mode)));99 }100 }else{101 $this->set(array(102 'status' => 'error',103 'msg' => 'Invalid username or password',104 'mode' => $this->mode,105 '_serialize' => array('status', 'msg', 'mode')106 ));107 }108 }else{109 $this->set(array(110 'status' => 'error',111 'msg' => 'Invalid request method',112 'mode' => $this->mode,113 '_serialize' => array('status', 'msg', 'mode')114 ));115 }116 }117 public function getTokenByRefreshToken()118 {119 if($this->request->is('post')){120 $request_data = file_get_contents("php://input");121 $request_data = $this->json_decode($request_data, true);122 $this->log($request_data);123 $refresh_token = $request_data['refresh_token'];124 $this->log('refresh token request :');125 $this->log($request_data);126 $this->log('refresh token header request:');127 $this->log( $this->request->getHeader('Authorization'));128 if(isset($refresh_token) && !empty($refresh_token)){129 $result = $this->AccessToken->getTokenByRefreshToken($refresh_token);130 $this->UserLoginDetails = $this->getDbTable('UserLoginDetails');131 $data_log_entities = $this->UserLoginDetails->find()->where(['refresh_token' => $refresh_token])->first();132 $data_log['access_token'] = $result['access_token'];133 $data_log['refresh_token'] = $result['refresh_token'];134 $data_log_entities = $this->UserLoginDetails->patchEntity($data_log_entities, $data_log);135 $this->UserLoginDetails->save($data_log_entities);136 if(isset($result['error'])){137 return $this->getResponse()138 ->withStatus(200)139 ->withType('application/json')140 ->withStringBody(json_encode(array(141 'status' => 'error',142 'msg' => $result['message'],143 'mode' => $this->mode)));144 }else{145 return $this->getResponse()146 ->withStatus(200)147 ->withType('application/json')148 ->withStringBody(json_encode(array(149 'status' => 'success',150 'token' => array(151 'access_token'=> $result['access_token'],152 'token_type'=> $result['token_type'],153 'expires_in'=> $result['expires_in'],154 'refresh_token'=> $result['refresh_token']155 ),156 'mode' => $this->mode)));157 }158 }else{159 return $this->getResponse()160 ->withStatus(200)161 ->withType('application/json')162 ->withStringBody(json_encode(array(163 'status' => 'error',164 'msg' => 'The refresh token is invalid.',165 'mode' => $this->mode,166 $this->viewBuilder()->setOption('serialize', true))));167 }168 }else{169 return $this->getResponse()170 ->withStatus(200)171 ->withType('application/json')172 ->withStringBody(json_encode(array(173 'status' => 'error',174 'msg' => 'Invalid request method',175 'mode' => $this->mode)));176 }177 }178 public function createUser () {179 if($this->request->is('post')){180 $request_data = file_get_contents("php://input");181 $request_data = $this->json_decode($request_data, true);182 $this->log($request_data);183 if (!empty($request_data)) {184 $email = isset($request_data['User']['email']) ? $request_data['User']['email']:'';185 $displayName = isset($request_data['User']['display_name']) ? $request_data['User']['display_name']:'';186 $address = isset($request_data['User']['address']) ? $request_data['User']['address']:'';187 $phone = isset($request_data['User']['phone']) ? $request_data['User']['phone']:'';188 $password = isset($request_data['User']['password']) ? $request_data['User']['password']:'';189 $errorMessage = [];190 if (empty($displayName)) {191 $errorMessage[] = ['Required field display name is missing'];192 }193 if (empty($email)) {194 $errorMessage[] = ['Required field email is missing'];195 }196 if (empty($address)) {197 $errorMessage[] = ['Required field address is missing'];198 }199 if (empty($phone)) {200 $errorMessage[] = ['Required field phone is missing'];201 }202 if (empty($password)) {203 $errorMessage[] = ['Required field password is missing'];204 }205 if (count($errorMessage) == 0) {206 $getEmail = $this->Users->find()->where(['email' => $email])->first();207 if (empty($getEmail)) {208 $roles = $this->Roles->find()->all()->toArray();209 $users = $this->Users->newEmptyEntity();210 $userData['display_name'] = $displayName;211 $userData['email'] = $email;212 $userData['address'] = $address;213 $userData['phone_no'] = $phone;214 $userData['password'] = Security::hash($password, null, true);215 $userData['role_id'] = $roles[1]['id'];216 $userData['status'] = 1;217 $users = $this->Users->patchEntity($users, $userData);218 $user = $this->Users->save($users);219 if ($user->id) {220 try {221 $this->getComponent('EmailHandler')->emailSend($email, $displayName);222 } catch (Exception $e) {223 $this->log($e->getMessage());224 }225 return $this->getResponse()226 ->withStatus(200)227 ->withType('application/json')228 ->withStringBody(json_encode(array(229 'status' => 'success',230 'msg' => 'Account Create Successfully',231 'mode' => $this->mode)));232 } else{233 return $this->getResponse()234 ->withStatus(200)235 ->withType('application/json')236 ->withStringBody(json_encode(array(237 'status' => 'error',238 'msg' => 'Oops user create failed',239 'mode' => $this->mode)));240 }241 } else {242 return $this->getResponse()243 ->withStatus(404)244 ->withType('application/json')245 ->withStringBody(json_encode(array(246 'status' => 'error',247 'msg' => 'Email Already Exist!',248 'mode' => $this->mode)));249 }250 } else {251 return $this->getResponse()252 ->withStatus(404)253 ->withType('application/json')254 ->withStringBody(json_encode(array(255 'status' => 'error',256 'msg' => $errorMessage,257 'mode' => $this->mode)));258 }259 } else {260 return $this->getResponse()261 ->withStatus(200)262 ->withType('application/json')263 ->withStringBody(json_encode(array(264 'status' => 'error',265 'msg' => 'Invalid request method',266 'mode' => $this->mode)));267 }268 }else{269 return $this->getResponse()270 ->withStatus(200)271 ->withType('application/json')272 ->withStringBody(json_encode(array(273 'status' => 'error',274 'msg' => 'Invalid request method',275 'mode' => $this->mode)));276 }277 }278 public function getAllProductsByCategory() {279 if ($this->AccessToken->verify()) {280 if ($this->request->is('post')) {281 $fullUrl = Router::fullBaseUrl();282 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1])->orderDesc('id')->toArray();283 $getUser = $this->getComponent('CommonFunction')->getUserInfo();284 if (!empty($products)) {285 foreach ($products as $product) {286 $getFavoriteProduct = $this->FavouritesProduct->find()->where(['product_id' => $product['id'], 'user_id' => $getUser['id']])->first();287 if (!empty($getFavoriteProduct)) {288 $product['favorite'] = true;289 } else {290 $product['favorite'] = false;291 }292 $images = $this->ProductImages->find()->where(['product_id' => $product['id']])->toArray();293 if (!empty($images)) {294 $imageArray = [];295 foreach ($images as $image) {296 $imageArray[] = $fullUrl . '/' . 'img' . DS . 'product_images' . DS . 'thumb' . DS . $image['image_path'];297 }298 $product['image'] = $imageArray;299 }300 }301 }302 if (!empty($products)) {303 return $this->getResponse()304 ->withStatus(200)305 ->withType('application/json')306 ->withStringBody(json_encode(array(307 'status' => 'success',308 'products' => $products,309 'mode' => $this->mode)));310 } else {311 return $this->getResponse()312 ->withStatus(200)313 ->withType('application/json')314 ->withStringBody(json_encode(array(315 'status' => 'success',316 'products' => array(),317 'mode' => $this->mode)));318 }319 } else {320 return $this->getResponse()321 ->withStatus(200)322 ->withType('application/json')323 ->withStringBody(json_encode(array(324 'status' => 'error',325 'msg' => 'Invalid request method',326 'mode' => $this->mode)));327 }328 } else {329 header('HTTP/1.1 401 Unauthorized', true, 401);330 return $this->getResponse()331 ->withStatus(401)332 ->withType('application/json')333 ->withStringBody(json_encode(array(334 'status' => 'error',335 'msg' => 'Invalid access token.',336 'mode' => $this->mode)));337 }338 }339 public function filterProducts(): Response {340 if ($this->AccessToken->verify()) {341 if ($this->request->is('post')) {342 $request_data = $this->request->getQueryParams();343 if (!empty($request_data)) {344 $action = isset($request_data['action']) ? $request_data['action']:'';345 $minPrice = isset($request_data['min_price']) ? $request_data['min_price']:'';346 $maxPrice = isset($request_data['max_price']) ? $request_data['max_price']:'';347 $search_product = isset($request_data['search_product']) ? $request_data['search_product']:'';348 if (!empty($action) && $action == 'lowToHigh') {349 if (!empty($minPrice) && !empty($maxPrice)) {350 if (!empty($search_product)) {351 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price >=' => $minPrice, 'price <=' => $maxPrice, 'display_name LIKE' => $search_product . '%'])->orderAsc('price')->toArray();352 } else {353 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price >=' => $minPrice, 'price <=' => $maxPrice])->orderAsc('price')->toArray();354 }355 } elseif (!empty($minPrice)) {356 if (!empty($search_product)) {357 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price >=' => $minPrice, 'display_name LIKE' => $search_product . '%'])->orderAsc('price')->toArray();358 } else {359 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price >=' => $minPrice])->orderAsc('price')->toArray();360 }361 } elseif (!empty($maxPrice)) {362 if (!empty($search_product)) {363 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price <=' => $maxPrice, 'display_name LIKE' => $search_product . '%'])->orderAsc('price')->toArray();364 } else {365 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price <=' => $maxPrice])->orderAsc('price')->toArray();366 }367 }else {368 if (!empty($search_product)) {369 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1,'display_name LIKE' => $search_product . '%'])->orderAsc('price')->toArray();370 } else {371 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1])->orderAsc('price')->toArray();372 }373 }374 } elseif (!empty($action) && $action == 'highToLow') {375 if (!empty($minPrice) && !empty($maxPrice)) {376 if (!empty($search_product)) {377 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price >=' => $minPrice, 'price <=' => $maxPrice, 'display_name LIKE' => $search_product . '%'])->orderDesc('price')->toArray();378 } else {379 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price >=' => $minPrice, 'price <=' => $maxPrice])->orderDesc('price')->toArray();380 }381 } elseif (!empty($minPrice)) {382 if (!empty($search_product)) {383 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price >=' => $minPrice, 'display_name LIKE' => $search_product . '%'])->orderDesc('price')->toArray();384 } else {385 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price >=' => $minPrice])->orderDesc('price')->toArray();386 }387 } elseif (!empty($maxPrice)) {388 if (!empty($search_product)) {389 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price <=' => $maxPrice, 'display_name LIKE' => $search_product . '%'])->orderDesc('price')->toArray();390 } else {391 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price <=' => $maxPrice])->orderDesc('price')->toArray();392 }393 } else {394 if (!empty($search_product)) {395 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'display_name LIKE' => $search_product . '%'])->orderDesc('price')->toArray();396 } else {397 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1])->orderDesc('price')->toArray();398 }399 }400 } elseif (!empty($action) && $action == 'bestMatch') {401 if (!empty($minPrice) && !empty($maxPrice)) {402 if (!empty($search_product)) {403 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price >=' => $minPrice, 'price <=' => $maxPrice, 'display_name LIKE' => $search_product . '%'])->orderAsc('price')->toArray();404 } else {405 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price >=' => $minPrice, 'price <=' => $maxPrice])->orderAsc('price')->toArray();406 }407 } elseif (!empty($minPrice)) {408 if (!empty($search_product)) {409 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price >=' => $minPrice, 'display_name LIKE' => $search_product . '%'])->orderAsc('price')->toArray();410 } else {411 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price >=' => $minPrice])->orderAsc('price')->toArray();412 }413 } elseif (!empty($maxPrice)) {414 if (!empty($search_product)) {415 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price <=' => $maxPrice, 'display_name LIKE' => $search_product . '%'])->orderAsc('price')->toArray();416 } else {417 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'price <=' => $maxPrice])->orderAsc('price')->toArray();418 }419 }else {420 if (!empty($search_product)) {421 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'display_name LIKE' => $search_product . '%'])->orderAsc('price')->toArray();422 } else {423 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1])->orderAsc('price')->toArray();424 }425 }426 } else {427 if (!empty($search_product)) {428 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1, 'display_name LIKE' => $search_product . '%'])->orderAsc('price')->toArray();429 } else {430 $products = $this->Products->find()->where(['category_id in (SELECT id FROM categories WHERE published = 1)', 'published' => 1])->orderAsc('price')->toArray();431 }432 }433 $getUser = $this->getComponent('CommonFunction')->getUserInfo();434 if (!empty($products)) {435 foreach ($products as $product) {436 $getFavoriteProduct = $this->FavouritesProduct->find()->where(['product_id' => $product['id'], 'user_id' => $getUser['id']])->first();437 if (!empty($getFavoriteProduct)) {438 $product['favorite'] = true;439 } else {440 $product['favorite'] = false;441 }442 $images = $this->ProductImages->find()->where(['product_id' => $product['id']])->toArray();443 if (!empty($images)) {444 $imageArray = [];445 $fullUrl = Router::fullBaseUrl();446 foreach ($images as $image) {447 $imageArray[] = $fullUrl . '/' . $image['image_path'];448 }449 $product['image'] = $imageArray;450 }451 }452 }453 if (!empty($products)) {454 return $this->getResponse()455 ->withStatus(200)456 ->withType('application/json')457 ->withStringBody(json_encode(array(458 'status' => 'success',459 'products' => $products,460 'mode' => $this->mode)));461 } else {462 return $this->getResponse()463 ->withStatus(200)464 ->withType('application/json')465 ->withStringBody(json_encode(array(466 'status' => 'success',467 'products' => array(),468 'mode' => $this->mode)));469 }470 } else {471 return $this->getResponse()472 ->withStatus(200)473 ->withType('application/json')474 ->withStringBody(json_encode(array(475 'status' => 'error',476 'msg' => 'Invalid request method',477 'mode' => $this->mode)));478 }479 } else {480 return $this->getResponse()481 ->withStatus(200)482 ->withType('application/json')483 ->withStringBody(json_encode(array(484 'status' => 'error',485 'msg' => 'Invalid request method',486 'mode' => $this->mode)));487 }488 } else {489 header('HTTP/1.1 401 Unauthorized', true, 401);490 return $this->getResponse()491 ->withStatus(401)492 ->withType('application/json')493 ->withStringBody(json_encode(array(494 'status' => 'error',495 'msg' => 'Invalid access token.',496 'mode' => $this->mode)));497 }498 }499 public function getProduct() {500 if ($this->AccessToken->verify()) {501 if ($this->request->is('post')) {502 $request_data = $this->request->getQueryParams();503 if (!empty($request_data)) {504 $product_id = isset($request_data['product_id']) ? $request_data['product_id']:'';505 $user_id = isset($request_data['user_id']) ? $request_data['user_id']:'';506 $fullUrl = Router::fullBaseUrl();507 $product = $this->Products->find()->where(['id' => $product_id, 'published' => 1])->first();508 $getUser = $this->getComponent('CommonFunction')->getUserInfo();509 $getFavoriteProduct = $this->FavouritesProduct->find()->where(['product_id' => $product['id'], 'user_id' => $getUser['id']])->first();510 if (!empty($getFavoriteProduct)) {511 $product['favorite'] = true;512 } else {513 $product['favorite'] = false;514 }515 if (!empty($product)) {516 $images = $this->ProductImages->find()->where(['product_id' => $product['id']])->toArray();517 if (!empty($images)) {518 $imageArray = [];519 foreach ($images as $image) {520 $imageArray[] = $fullUrl . '/' . 'img' . DS . 'product_images' . DS . $image['image_path'];521 }522 $product['image'] = $imageArray;523 }524 }525 $this->getComponent('Product')->recentlyViewSave($product_id, $getUser['id']);526 if (!empty($product)) {527 return $this->getResponse()528 ->withStatus(200)529 ->withType('application/json')530 ->withStringBody(json_encode(array(531 'status' => 'success',532 'products' => $product,533 'mode' => $this->mode)));534 } else {535 return $this->getResponse()536 ->withStatus(200)537 ->withType('application/json')538 ->withStringBody(json_encode(array(539 'status' => 'success',540 'products' => array(),541 'mode' => $this->mode)));542 }543 } else {544 return $this->getResponse()545 ->withStatus(200)546 ->withType('application/json')547 ->withStringBody(json_encode(array(548 'status' => 'error',549 'msg' => 'Missing Input Data!',550 'mode' => $this->mode)));551 }552 } else {553 return $this->getResponse()554 ->withStatus(200)555 ->withType('application/json')556 ->withStringBody(json_encode(array(557 'status' => 'error',558 'msg' => 'Invalid request method',559 'mode' => $this->mode)));560 }561 } else {562 header('HTTP/1.1 401 Unauthorized', true, 401);563 return $this->getResponse()564 ->withStatus(401)565 ->withType('application/json')566 ->withStringBody(json_encode(array(567 'status' => 'error',568 'msg' => 'Invalid access token.',569 'mode' => $this->mode)));570 }571 }572 public function getAddress(): Response {573 if ($this->AccessToken->verify()) {574 if ($this->request->is('post')) {575 $getUser = $this->getComponent('CommonFunction')->getUserInfo();576 $productDeliveryAddress = $this->ProductDeliveryAddress->find()->where(['user_id="' . $getUser['id'].'" OR user_id IS NULL'])->toArray();577 if (!empty($productDeliveryAddress)) {578 return $this->getResponse()579 ->withStatus(200)580 ->withType('application/json')581 ->withStringBody(json_encode(array(582 'status' => 'success',583 'address_list' => $productDeliveryAddress,584 'mode' => $this->mode)));585 } else {586 return $this->getResponse()587 ->withStatus(200)588 ->withType('application/json')589 ->withStringBody(json_encode(array(590 'status' => 'success',591 'address_list' => array(),592 'mode' => $this->mode)));593 }594 } else {595 return $this->getResponse()596 ->withStatus(200)597 ->withType('application/json')598 ->withStringBody(json_encode(array(599 'status' => 'error',600 'msg' => 'Invalid request method',601 'mode' => $this->mode)));602 }603 } else {604 header('HTTP/1.1 401 Unauthorized', true, 401);605 return $this->getResponse()606 ->withStatus(401)607 ->withType('application/json')608 ->withStringBody(json_encode(array(609 'status' => 'error',610 'msg' => 'Invalid access token.',611 'mode' => $this->mode)));612 }613 }614 public function addToFavouriteProduct(): Response {615 if ($this->AccessToken->verify()) {616 if ($this->request->is('post')) {617 $request_data = file_get_contents("php://input");618 $request_data = $this->json_decode($request_data, true);619 $this->log($request_data);620 if (!empty($request_data)) {621 $product_id = isset($request_data['Product']['product_id']) ? $request_data['Product']['product_id'] : '';622 $user_id = isset($request_data['Product']['user_id']) ? $request_data['Product']['user_id'] : '';623 $favourite = isset($request_data['Product']['favourite']) ? $request_data['Product']['favourite'] : '';624 $errorMessage = [];625 if (empty($product_id)) {626 $errorMessage[] = ['Required field product id is missing'];627 }628 if (empty($user_id)) {629 $errorMessage[] = ['Required field user id is missing'];630 }631 if (empty($favourite)) {632 $errorMessage[] = ['Required favourite is missing'];633 }634 if (empty($user_id)) {635 $getUser = $this->getComponent('CommonFunction')->getUserInfo();636 $user_id = $getUser['id'];637 }638 $getFavoriteProduct = $this->FavouritesProduct->find()->where(['product_id' => $product_id, 'user_id' => $user_id])->first();639 if (!empty($getFavoriteProduct)) {640 if ($this->FavouritesProduct->delete($getFavoriteProduct)) {641 return $this->getResponse()642 ->withStatus(200)643 ->withType('application/json')644 ->withStringBody(json_encode(array(645 'status' => 'success',646 'msg' => true,647 'mode' => $this->mode)));648 }649 }650 $getFavourite = $this->getComponent('Product')->saveFavouritesProduct($product_id, $user_id, $favourite);651 if (!empty($getFavourite)) {652 return $this->getResponse()653 ->withStatus(200)654 ->withType('application/json')655 ->withStringBody(json_encode(array(656 'status' => 'success',657 'msg' => true,658 'mode' => $this->mode)));659 } else {660 return $this->getResponse()661 ->withStatus(404)662 ->withType('application/json')663 ->withStringBody(json_encode(array(664 'status' => 'error',665 'msg' => $errorMessage,666 'mode' => $this->mode)));667 }668 } else {669 return $this->getResponse()670 ->withStatus(200)671 ->withType('application/json')672 ->withStringBody(json_encode(array(673 'status' => 'error',674 'msg' => 'Invalid request method',675 'mode' => $this->mode)));676 }677 } else {678 return $this->getResponse()679 ->withStatus(200)680 ->withType('application/json')681 ->withStringBody(json_encode(array(682 'status' => 'error',683 'msg' => 'Invalid request method',684 'mode' => $this->mode)));685 }686 } else {687 header('HTTP/1.1 401 Unauthorized', true, 401);688 return $this->getResponse()689 ->withStatus(401)690 ->withType('application/json')691 ->withStringBody(json_encode(array(692 'status' => 'error',693 'msg' => 'Invalid access token.',694 'mode' => $this->mode)));695 }696 }697 public function getFavouriteProducts(): Response {698 if ($this->AccessToken->verify()) {699 if ($this->request->is('post')) {700 $request_data = $this->request->getQueryParams();701 if (!empty($request_data)) {702 $user_id = isset($request_data['user_id']) ? $request_data['user_id']:'';703 $getUser = $this->getComponent('CommonFunction')->getUserInfo();704 $products = $this->Products->find()->where(['id in (SELECT product_id FROM favourites_product WHERE user_id = '.$getUser['id'].')', 'published' => 1])->orderDesc('id')->toArray();705 $fullUrl = Router::fullBaseUrl();706 foreach ($products as $product) {707 $images = $this->ProductImages->find()->where(['product_id' => $product['id']])->toArray();708 if (!empty($images)) {709 $imageArray = [];710 foreach ($images as $image) {711 $imageArray[] = $fullUrl . '/' . 'img' . DS . 'product_images' . DS . 'thumb'. DS . $image['image_path'];712 break;713 }714 $product['image'] = $imageArray;715 }716 $product['favorite'] = true;717 }718 if (!empty($products)) {719 return $this->getResponse()720 ->withStatus(200)721 ->withType('application/json')722 ->withStringBody(json_encode(array(723 'status' => 'success',724 'products' => $products,725 'mode' => $this->mode)));726 } else {727 return $this->getResponse()728 ->withStatus(200)729 ->withType('application/json')730 ->withStringBody(json_encode(array(731 'status' => 'success',732 'products' => array(),733 'mode' => $this->mode)));734 }735 } else {736 return $this->getResponse()737 ->withStatus(200)738 ->withType('application/json')739 ->withStringBody(json_encode(array(740 'status' => 'error',741 'msg' => 'Missing Input Data!',742 'mode' => $this->mode)));743 }744 } else {745 return $this->getResponse()746 ->withStatus(200)747 ->withType('application/json')748 ->withStringBody(json_encode(array(749 'status' => 'error',750 'msg' => 'Invalid request method',751 'mode' => $this->mode)));752 }753 } else {754 header('HTTP/1.1 401 Unauthorized', true, 401);755 return $this->getResponse()756 ->withStatus(401)757 ->withType('application/json')758 ->withStringBody(json_encode(array(759 'status' => 'error',760 'msg' => 'Invalid access token.',761 'mode' => $this->mode)));762 }763 }764 public function getRecentlyView(): Response {765 if ($this->AccessToken->verify()) {766 if ($this->request->is('post')) {767 $request_data = $this->request->getQueryParams();768 if (!empty($request_data)) {769 $user_id = isset($request_data['user_id']) ? $request_data['user_id'] : '';770 $getUser = $this->getComponent('CommonFunction')->getUserInfo();771// $products = $this->Products->find()->where(['id in (SELECT product_id FROM product_recently_view WHERE user_id = ' . $getUser['id'] . ' order by date_time asc)', 'published' => 1])->limit(20)->toArray();772// $products = $this->ProductRecentlyView->find()->where(['id in (SELECT id FROM products WHERE id in (SELECT product_id FROM product_recently_view WHERE user_id = ' . $getUser['id'] . ' order by date_time asc))', 'published' => 1])->orderDesc('date_time')->limit(20)->toArray();773// $join = array(774// 'table' => $this->ProductRecentlyView,775// 'alias' => 'ProductRecentlyView',776// 'type' => 'LEFT',777// 'confitions' => array('Products.id = ProductRecentlyView.product_id')778// );779 $connection = ConnectionManager::get('default');780 $sql = 'SELECT Products.id, Products.category_id, Products.title title, Products.display_name, Products.image, Products.slug, Products.description, Products.price, Products.published781 FROM products Products782 LEFT JOIN product_recently_view recentlyView783 ON Products.id = recentlyView.product_id784 WHERE785 recentlyView.user_id = ' . $getUser['id'] . ' ORDER BY recentlyView.date_time desc ;';786 $products = $connection->execute($sql)->fetchAll('assoc');787 $fullUrl = Router::fullBaseUrl();788 foreach ($products as $key => $product) {789 $getFavoriteProduct = $this->FavouritesProduct->find()->where(['product_id' => $product['id'], 'user_id' => $getUser['id']])->first();790 if (!empty($getFavoriteProduct)) {791 $product['favorite'] = true;792 } else {793 $product['favorite'] = false;794 }795 $images = $this->ProductImages->find()->where(['product_id' => $product['id']])->toArray();796 if (!empty($images)) {797 $imageArray = [];798 foreach ($images as $image) {799 $imageArray[] = $fullUrl . '/' . 'img' . DS . 'product_images' . DS . 'thumb'. DS . $image['image_path'];800 break;801 }802 $product['image'] = $imageArray;803 }804 $products[$key] = $product;805 }806 if (!empty($products)) {807 return $this->getResponse()808 ->withStatus(200)809 ->withType('application/json')810 ->withStringBody(json_encode(array(811 'status' => 'success',812 'products' => $products,813 'mode' => $this->mode)));814 } else {815 return $this->getResponse()816 ->withStatus(200)817 ->withType('application/json')818 ->withStringBody(json_encode(array(819 'status' => 'success',820 'products' => array(),821 'mode' => $this->mode)));822 }823 } else {824 return $this->getResponse()825 ->withStatus(200)826 ->withType('application/json')827 ->withStringBody(json_encode(array(828 'status' => 'error',829 'msg' => 'Missing Input Data!',830 'mode' => $this->mode)));831 }832 } else {833 return $this->getResponse()834 ->withStatus(200)835 ->withType('application/json')836 ->withStringBody(json_encode(array(837 'status' => 'error',838 'msg' => 'Invalid request method',839 'mode' => $this->mode)));840 }841 } else {842 header('HTTP/1.1 401 Unauthorized', true, 401);843 return $this->getResponse()844 ->withStatus(401)845 ->withType('application/json')846 ->withStringBody(json_encode(array(847 'status' => 'error',848 'msg' => 'Invalid access token.',849 'mode' => $this->mode)));850 }851 }852 public function profileImageChange () {853 if ($this->AccessToken->verify()) {854 if ($this->request->is('post')) {855 $request_data = $this->request->getData();856 $this->log($request_data);857 if (!empty($request_data)) {858 $image = isset($request_data['image']) ? $request_data['image'] : '';859 $user_id = isset($request_data['user_id']) ? $request_data['user_id'] : '';860 $errorMessage = [];861 if (empty($image)) {862 $errorMessage[] = ['Required field image is missing'];863 }864 if (empty($user_id)) {865 $errorMessage[] = ['Required field user id is missing'];866 }867 if (count($errorMessage) == 0) {868 $fullUrl = Router::fullBaseUrl();869 $getUser = $this->getComponent('CommonFunction')->getUserInfo();870 $users = $this->Users->find()->where(['id' => $getUser['id']])->first();871 if (!empty($users['image'])) {872 if (is_file(WWW_ROOT . $users['image'])) {873 unlink(WWW_ROOT . $users['image']);874 }875 }876 $extension=array("jpeg","jpg","png");877 $file_name= $image->getClientFilename();878 $ext = pathinfo($file_name,PATHINFO_EXTENSION);879 $image_name = $users['id'] . '-main-image-' . strtotime(date('Y-m-d H:i:s'));880 $targetPath = WWW_ROOT . 'img' . DS . 'profile_images' . DS . $image_name . '.' . strtolower($ext);881 if(in_array(strtolower($ext),$extension)) {882 if(!file_exists($targetPath)) {883 $image->moveTo($targetPath);884 $saveImage['image'] = 'img' . DS . 'profile_images' . DS . $image_name . '.' . strtolower($ext);885 $users = $this->Users->patchEntity($users, $saveImage);886 $getUserInfo = $this->Users->save($users);887 if ($getUserInfo->id) {888 $getUserInfo['image'] = $fullUrl . '/' . $getUserInfo['image'];889 return $this->getResponse()890 ->withStatus(200)891 ->withType('application/json')892 ->withStringBody(json_encode(array(893 'status' => 'success',894 'user' => $getUserInfo,895 'mode' => $this->mode)));896 } else {897 return $this->getResponse()898 ->withStatus(404)899 ->withType('application/json')900 ->withStringBody(json_encode(array(901 'status' => 'error',902 'msg' => 'Not Save!',903 'mode' => $this->mode)));904 }905 }906 }907 } else {908 return $this->getResponse()909 ->withStatus(404)910 ->withType('application/json')911 ->withStringBody(json_encode(array(912 'status' => 'error',913 'msg' => $errorMessage,914 'mode' => $this->mode)));915 }916 } else {917 return $this->getResponse()918 ->withStatus(200)919 ->withType('application/json')920 ->withStringBody(json_encode(array(921 'status' => 'error',922 'msg' => 'Invalid request method',923 'mode' => $this->mode)));924 }925 } else {926 return $this->getResponse()927 ->withStatus(200)928 ->withType('application/json')929 ->withStringBody(json_encode(array(930 'status' => 'error',931 'msg' => 'Invalid request method',932 'mode' => $this->mode)));933 }934 } else {935 header('HTTP/1.1 401 Unauthorized', true, 401);936 return $this->getResponse()937 ->withStatus(401)938 ->withType('application/json')939 ->withStringBody(json_encode(array(940 'status' => 'error',941 'msg' => 'Invalid access token.',942 'mode' => $this->mode)));943 }944 }945 public function updateProfileInfo () {946 if ($this->AccessToken->verify()) {947 if ($this->request->is('post')) {948 $request_data = file_get_contents("php://input");949 $request_data = $this->json_decode($request_data, true);950 $this->log($request_data);951 if (!empty($request_data)) {952 $user_id = isset($request_data['User']['user_id']) ? $request_data['User']['user_id'] : '';953 $display_name = isset($request_data['User']['display_name']) ? $request_data['User']['display_name'] : '';954 $phone_no = isset($request_data['User']['phone_no']) ? $request_data['User']['phone_no'] : '';955 $address = isset($request_data['User']['address']) ? $request_data['User']['address'] : '';956 $bio = isset($request_data['User']['bio']) ? $request_data['User']['bio'] : '';957 $fullUrl = Router::fullBaseUrl();958 $getUser = $this->getComponent('CommonFunction')->getUserInfo();959 $users = $this->Users->find()->where(['id' => $getUser['id']])->first();960 if (!empty($users)) {961 $updateUserinfo['display_name'] = $display_name ?? '';962 $updateUserinfo['phone_no'] = $phone_no ?? '';963 $updateUserinfo['address'] = $address ?? '';964 $updateUserinfo['bio'] = $bio ?? '';965 $users = $this->Users->patchEntity($users, $updateUserinfo);966 $getUserInfo = $this->Users->save($users);967 if ($getUserInfo->id) {968 $getUserInfo['image'] = $fullUrl . '/' . $getUserInfo['image'] ?? '';969 return $this->getResponse()970 ->withStatus(200)971 ->withType('application/json')972 ->withStringBody(json_encode(array(973 'status' => 'success',974 'user' => $getUserInfo,975 'mode' => $this->mode)));976 }977 } else {978 return $this->getResponse()979 ->withStatus(200)980 ->withType('application/json')981 ->withStringBody(json_encode(array(982 'status' => 'error',983 'msg' => 'User Not Exist!',984 'mode' => $this->mode)));985 }986 } else {987 return $this->getResponse()988 ->withStatus(200)989 ->withType('application/json')990 ->withStringBody(json_encode(array(991 'status' => 'error',992 'msg' => 'Invalid request method',993 'mode' => $this->mode)));994 }995 } else {996 return $this->getResponse()997 ->withStatus(200)998 ->withType('application/json')999 ->withStringBody(json_encode(array(1000 'status' => 'error',1001 'msg' => 'Invalid request method',1002 'mode' => $this->mode)));1003 }1004 } else {1005 header('HTTP/1.1 401 Unauthorized', true, 401);1006 return $this->getResponse()1007 ->withStatus(401)1008 ->withType('application/json')1009 ->withStringBody(json_encode(array(1010 'status' => 'error',1011 'msg' => 'Invalid access token.',1012 'mode' => $this->mode)));1013 }1014 }1015 public function saveAddress() {1016 if ($this->AccessToken->verify()) {1017 if ($this->request->is('post')) {1018 $request_data = file_get_contents("php://input");1019 $request_data = $this->json_decode($request_data, true);1020 $this->log($request_data);1021 if (!empty($request_data)) {1022 $user_id = isset($request_data['Address']['user_id']) ? $request_data['Address']['user_id'] : '';1023 $address_name = isset($request_data['Address']['name']) ? $request_data['Address']['name'] : '';1024 $errorMessage = [];1025 if (empty($user_id)) {1026 $errorMessage[] = ['Required field user id is missing'];1027 }1028 if (empty($address_name)) {1029 $errorMessage[] = ['Required field address name is missing'];1030 }1031 if (count($errorMessage) == 0) {1032 $getUser = $this->getComponent('CommonFunction')->getUserInfo();1033 $productDeliveryAddress = $this->ProductDeliveryAddress->find()->where(['user_id' => $getUser['id'], 'address_line' => $address_name])->first();1034 if (empty($productDeliveryAddress)) {1035 $productDeliveryAddress = $this->ProductDeliveryAddress->newEmptyEntity();1036 $newAddress['user_id'] = $getUser['id'];1037 $newAddress['address_line'] = $address_name;1038 $productDeliveryAddress = $this->ProductDeliveryAddress->patchEntity($productDeliveryAddress, $newAddress);1039 $getProductDeliveryAddress = $this->ProductDeliveryAddress->save($productDeliveryAddress);1040 if ($getProductDeliveryAddress->id) {1041 return $this->getResponse()1042 ->withStatus(200)1043 ->withType('application/json')1044 ->withStringBody(json_encode(array(1045 'status' => 'success',1046 'address' => $getProductDeliveryAddress,1047 'mode' => $this->mode)));1048 }1049 } else {1050 return $this->getResponse()1051 ->withStatus(200)1052 ->withType('application/json')1053 ->withStringBody(json_encode(array(1054 'status' => 'error',1055 'msg' => 'Address Already Exist!',1056 'mode' => $this->mode)));1057 }1058 } else {1059 return $this->getResponse()1060 ->withStatus(404)1061 ->withType('application/json')1062 ->withStringBody(json_encode(array(1063 'status' => 'error',1064 'msg' => $errorMessage,1065 'mode' => $this->mode)));1066 }1067 } else {1068 return $this->getResponse()1069 ->withStatus(200)1070 ->withType('application/json')1071 ->withStringBody(json_encode(array(1072 'status' => 'error',1073 'msg' => 'Invalid request method',1074 'mode' => $this->mode)));1075 }1076 } else {1077 return $this->getResponse()1078 ->withStatus(200)1079 ->withType('application/json')1080 ->withStringBody(json_encode(array(1081 'status' => 'error',1082 'msg' => 'Invalid request method',1083 'mode' => $this->mode)));1084 }1085 } else {1086 header('HTTP/1.1 401 Unauthorized', true, 401);1087 return $this->getResponse()1088 ->withStatus(401)1089 ->withType('application/json')1090 ->withStringBody(json_encode(array(1091 'status' => 'error',1092 'msg' => 'Invalid access token.',1093 'mode' => $this->mode)));1094 }1095 }1096 public function getUserInfo() {1097 if ($this->AccessToken->verify()) {1098 if ($this->request->is('post')) {1099 $getUser = $this->getComponent('CommonFunction')->getUserInfo();1100 if (!empty($getUser)) {1101 $fullUrl = Router::fullBaseUrl();1102 if (!empty($getUser['image'])) {1103 $getUser['image'] = $fullUrl . DS . $getUser['image'];1104 }1105 $getOrder = $this->Orders->find()->where(['order_stage' => OrderStage::PROCESSING, 'user_id' => $getUser['id']])->enableHydration(false)->count();1106 if (!empty($getOrder)) {1107 $getUser['tree_planted'] = $getOrder;1108 } else {1109 $getUser['tree_planted'] = 0;1110 }1111 $getFavorites = $this->FavouritesProduct->find()->where(['user_id' => $getUser['id']])->enableHydration(false)->count();1112 if (!empty($getFavorites)) {1113 $getUser['favorites'] = $getFavorites;1114 } else {1115 $getUser['favorites'] = 0;1116 }1117 return $this->getResponse()1118 ->withStatus(200)1119 ->withType('application/json')1120 ->withStringBody(json_encode(array(1121 'status' => 'success',1122 'user' => $getUser,1123 'mode' => $this->mode)));1124 } else {1125 return $this->getResponse()1126 ->withStatus(200)1127 ->withType('application/json')1128 ->withStringBody(json_encode(array(1129 'status' => 'success',1130 'user' => array(),1131 'mode' => $this->mode)));1132 }1133 } else {1134 return $this->getResponse()1135 ->withStatus(200)1136 ->withType('application/json')1137 ->withStringBody(json_encode(array(1138 'status' => 'error',1139 'msg' => 'Invalid request method',1140 'mode' => $this->mode)));1141 }1142 } else {1143 header('HTTP/1.1 401 Unauthorized', true, 401);1144 return $this->getResponse()1145 ->withStatus(401)1146 ->withType('application/json')1147 ->withStringBody(json_encode(array(1148 'status' => 'error',1149 'msg' => 'Invalid access token.',1150 'mode' => $this->mode)));1151 }1152 }1153 public function changePassword() {1154 if ($this->AccessToken->verify()) {1155 if ($this->request->is('post')) {1156 $request_data = file_get_contents("php://input");1157 $request_data = $this->json_decode($request_data, true);1158 $this->log($request_data);1159 if (!empty($request_data)) {1160 $current_password = isset($request_data['User']['current_password']) ? $request_data['User']['current_password'] : '';1161 $new_password = isset($request_data['User']['new_password']) ? $request_data['User']['new_password'] : '';1162 $errorMessage = [];1163 if (empty($current_password)) {1164 $errorMessage[] = ['Required field current password is missing'];1165 }1166 if (empty($new_password)) {1167 $errorMessage[] = ['Required field new password is missing'];1168 }1169 if (count($errorMessage) == 0) {1170 $getUser = $this->getComponent('CommonFunction')->getUserInfo();1171 $users = $this->Users->find()->where(['id' => $getUser['id'], 'password' => Security::hash($current_password, null, true)])->first();1172 if (!empty($users)) {1173 $user['password'] = Security::hash($new_password, null, true);1174 $users = $this->Users->patchEntity($users, $user);1175 $users = $this->Users->save($users);1176 if (!empty($users)) {1177 $fullUrl = Router::fullBaseUrl();1178 if (!empty($users['image'])) {1179 $users['image'] = $fullUrl . DS . $users['image'];1180 }1181 return $this->getResponse()1182 ->withStatus(200)1183 ->withType('application/json')1184 ->withStringBody(json_encode(array(1185 'status' => 'success',1186 'user' => $users,1187 'mode' => $this->mode)));1188 }1189 }1190 else {1191 return $this->getResponse()1192 ->withStatus(200)1193 ->withType('application/json')1194 ->withStringBody(json_encode(array(1195 'status' => 'success',1196 'user' => 'Current Password Not Match!',1197 'mode' => $this->mode)));1198 }1199 } else {1200 return $this->getResponse()1201 ->withStatus(404)1202 ->withType('application/json')1203 ->withStringBody(json_encode(array(1204 'status' => 'error',1205 'msg' => $errorMessage,1206 'mode' => $this->mode)));1207 }1208 } else {1209 return $this->getResponse()1210 ->withStatus(200)1211 ->withType('application/json')1212 ->withStringBody(json_encode(array(1213 'status' => 'error',1214 'msg' => 'Invalid request method',1215 'mode' => $this->mode)));1216 }1217 } else {1218 return $this->getResponse()1219 ->withStatus(200)1220 ->withType('application/json')1221 ->withStringBody(json_encode(array(1222 'status' => 'error',1223 'msg' => 'Invalid request method',1224 'mode' => $this->mode)));1225 }1226 } else {1227 header('HTTP/1.1 401 Unauthorized', true, 401);1228 return $this->getResponse()1229 ->withStatus(401)1230 ->withType('application/json')1231 ->withStringBody(json_encode(array(1232 'status' => 'error',1233 'msg' => 'Invalid access token.',1234 'mode' => $this->mode)));1235 }1236 }1237}...

Full Screen

Full Screen

AttendanceController.php

Source:AttendanceController.php Github

copy

Full Screen

...60 ))61 ->orderBy('time_shift')62 ->get();63 if (count($batch) <= 0) {64 return redirect()->back()->withFlashMessage('You are not in charge of any Batches to mark attendance!!')->withType('danger');65 }66 } else {67 $batch = $this->batch68 ->select('id', 'batch', 'time_shift')69 ->where('year', $year)70 ->get();71 if (count($batch) <= 0) {72 return redirect()->back()->withFlashMessage('No batch found!!')->withType('danger');73 }74 }75 } catch (Exception $e) {76 return redirect()->back()->withFlashMessage('Error Selecting batch!!')->withType('danger');77 }78 foreach ($batch as $each_batch) {79 $each_batch['enc_id'] = Encrypt::encrypt($each_batch['id']);80 $each_batch['status'] = (in_array($each_batch['id'], $marked_batches)) ? 'marked' : 'unmarked';81 switch ($each_batch['time_shift']) {82 case 1:83 $each_batch['time_shift'] = 'morning';84 break;85 case 2:86 $each_batch['time_shift'] = 'afternoon';87 break;88 case 3:89 $each_batch['time_shift'] = 'evening';90 break;91 default:92 return redirect()->back()->withFlashMessage('Error Selecting batch With Time Shift!!')->withType('danger');93 }94 }95 $batch = $batch->toArray();96 return view('attendance.attendance_in_charge', ['time_shift' => $time_shift, 'batch' => $batch]);97 }98 }99 /**100 * Show page for entering attendance.101 *102 * @param $id103 * @return Response104 */105 public function mark($id)106 {107 $enc_id = $id;108 $id = Encrypt::decrypt($id);109 if (!is_numeric($id)) {110 return redirect()->back()->withFlashMessage('Invalid Token!')->withType('danger');111 }112 $data = array();113 try {114 $students = $this->student_details115 ->join('users', 'users.id', '=', 'student_details.user_id')116 ->select('users.id', 'users.first_name', 'users.last_name')117 ->where(array(118 'student_details.batch_id' => $id,119 'users.deleted_at' => null120 ))121 ->get();122 if (count($students) <= 0) {123 return redirect()->back()->withFlashMessage('No students found for this Batch!')->withType('danger');124 }125 foreach ($students as $each_student) {126 $data[Encrypt::encrypt($each_student['id'])]['name'] = $each_student['first_name'] . ' ' . $each_student['last_name'];127 }128 } catch (Exception $e) {129 return redirect()->back()->withFlashMessage('Error Selecting Students!')->withType('danger');130 }131 return view('attendance.attendance_create', ['id' => $enc_id, 'students' => $data]);132 }133 /**134 * Save attendance135 *136 * @param $request137 * @return Response138 */139 public function store(AjaxAttendanceRequest $request)140 {141 if ($request->ajax()) {142 $attendance = array();143 $id = Encrypt::decrypt($request['id']);144 $count = sizeof($request['present']);145 if (empty($request['present'])) {146 $present = '';147 } else {148 foreach ($request['present'] as $each) {149 $attendance [] = (int)Encrypt::decrypt($each);150 }151 $present = json_encode($attendance);152 }153 try {154 $this->attendance->insert(array(155 'batch_id' => $id,156 'present_count' => $count,157 'attendance' => $present158 ));159 } catch (Exception $e) {160 return 'error';161 }162 return 'success';163 } else {164 return '<h1>Invalid Request!! Access Denied</h1>';165 }166 }167 /**168 * Display Batch to select.169 *170 * @return Response171 */172 public function selectBatch()173 {174 $year = 2016;175 $time_shifts = array('morning', 'afternoon', 'evening');176 try {177 $batch = $this->batch178 ->select('id', 'batch', 'time_shift')179 ->where('year', $year)180 ->orderBy('time_shift')181 ->get();182 } catch (Exception $e) {183 return redirect('attendance/batch')->withFlashMessage('Error Selecting batch')->withType('danger');184 }185 foreach ($batch as $each_batch) {186 $each_batch['enc_id'] = Encrypt::encrypt($each_batch['id']);187 $each_batch['time_shift'] = $time_shifts[$each_batch['time_shift'] - 1];188 }189 $batch = $batch->toArray();190 return view('attendance.attendance_select_batch', ['time_shift' => $time_shifts, 'batch' => $batch]);191 }192 /**193 * Display Students to select :- First time.194 *195 * @return Response196 */197 public function selectStudentGet()198 {199 return $this->selectStudentCore('first');200 }201 /**202 * Display Students to select :- Filtered.203 *204 * @param $request205 * @return Response206 */207 public function selectStudentPost(SelectBatchRequest $request)208 {209 return $this->selectStudentCore(Encrypt::decrypt($request['batch']));210 }211 /**212 * Core to Display Students to select.213 *214 * @param $id215 * @return Response216 */217 private function selectStudentCore($id)218 {219 $flag = false;220 $year = 2016;221 $time_shifts = array('morning', 'afternoon', 'evening');222 $data = array();223 $data['batch'] = array();224 $data['students'] = array();225 if ($id == 'first') {226 $flag = true;227 } else {228 $data['selected']['batch'] = Encrypt::encrypt($id);229 }230 try {231 $batch = $this->batch232 ->select('id', 'batch', 'time_shift')233 ->where('year', $year)234 ->get();235 if (count($batch) <= 0) {236 return redirect()->back()->withFlashMessage('No batches available to display!')->withType('danger');237 }238 } catch (Exception $e) {239 return redirect('attendance/batch')->withFlashMessage('Error Selecting batch')->withType('danger');240 }241 foreach ($batch as $each_batch) {242 if ($flag) {243 $id = $each_batch['id'];244 $data['selected']['batch'] = Encrypt::encrypt($each_batch['id']);245 $flag = false;246 }247 $data['batch'][Encrypt::encrypt($each_batch['id'])] = $each_batch['batch'] . ' - ' . $time_shifts[$each_batch['time_shift'] - 1];248 }249 try {250 $students = $this->student_details251 ->join('users', 'users.id', '=', 'student_details.user_id')252 ->select('users.id', 'users.first_name', 'users.last_name')253 ->where(array(254 'student_details.batch_id' => $id,255 'users.deleted_at' => null256 ))257 ->get();258 if (count($students) <= 0) {259 return redirect()->back()->withFlashMessage('No students available to display!')->withType('danger');260 }261 foreach ($students as $each_student) {262 $data['students'][Encrypt::encrypt($each_student['id'])]['name'] = $each_student['first_name'] . ' ' . $each_student['last_name'];263 }264 } catch (Exception $e) {265 return redirect()->back()->withFlashMessage('Error Selecting Students!')->withType('danger');266 }267 return view('attendance.attendance_select_student', [268 'batch' => $data['batch'],269 'selected' => $data['selected'],270 'students' => $data['students']271 ]);272 }273 /**274 * Batch wise attendance275 *276 * @param int $id277 * @return Response278 */279 public function ofBatch($id)280 {281 $enc_id = $id;282 $id = Encrypt::decrypt($id);283 if (!$id) {284 return redirect()->back()->withFlashMessage('Invalid Token!')->withType('danger');285 }286 try {287 $data = $this->attendance288 ->where('batch_id', $id)289 ->get();290 if (count($data) <= 0) {291 return redirect()->back()->withFlashMessage('No attendance available for the batch!')->withType('danger');292 }293 } catch (Exception $e) {294 return redirect()->back()->withFlashMessage('Error Fetching attendance!')->withType('danger');295 }296 return view('attendance.attendance_batch', ['id' => $enc_id]);297 }298 /**299 * Batch wise attendance300 *301 * @param int $id302 * @param date $date303 * @return Response304 */305 public function ofBatchDate($id, $date)306 {307 $enc_id = $id;308 $data = array();309 $id = Encrypt::decrypt($id);310 $date = Encrypt::decrypt($date);311 if (!$id) {312 return redirect()->back()->withFlashMessage('Invalid Batch Token!')->withType('danger');313 }314 if (!$date) {315 return redirect()->back()->withFlashMessage('Invalid Date Token!')->withType('danger');316 }317 try {318 $attendance = $this->attendance319 ->select('attendance')320 ->whereRaw("batch_id = " . $id . " AND created_at = '" . $date . "'")321 ->first();322 if (count($attendance) <= 0) {323 return redirect()->back()->withFlashMessage('No attendance available for this date!')->withType('danger');324 }325 $attendance = json_decode($attendance->attendance);326 if (!is_array($attendance)) {327 $attendance = array();328 }329 } catch (Exception $e) {330 return redirect()->back()->withFlashMessage('Error Fetching attendance!')->withType('danger');331 }332 try {333 $students = $this->student_details334 ->join('users', 'users.id', '=', 'student_details.user_id')335 ->select('users.id', 'users.first_name', 'users.last_name')336 ->where(array(337 'student_details.batch_id' => $id,338 'users.deleted_at' => null339 ))340 ->get();341 if (count($students) <= 0) {342 return redirect()->back()->withFlashMessage('No students available to display!')->withType('danger');343 }344 foreach ($students as $each_student) {345 $enc_std_id = Encrypt::encrypt($each_student->id);346 $data[$enc_std_id] = new \stdClass();347 $data[$enc_std_id]->name = $each_student->first_name . ' ' . $each_student->last_name;348 $data[$enc_std_id]->status = (in_array($each_student->id, $attendance)) ? 'present' : 'absent';349 }350 } catch (Exception $e) {351 return redirect()->back()->withFlashMessage('Error Fetching Students!')->withType('danger');352 }353 return view('attendance.attendance_batch_date', ['data' => $data]);354 }355 /**356 * Attendance in the range357 *358 * @param $request359 * @return Response360 */361 public function rangeAttendance(RangeAttendanceRequest $request)362 {363 if ($request->ajax()) {364 $enc_id = $request['id'];365 $id = Encrypt::decrypt($request['id']);366 if (!$id) {367 return 'Invalid Token!';368 }369 $start_date = $request['start_date'] . ' 00:00:00';370 $end_date = $request['end_date'] . ' 23:59:59';371 try {372 $data = $this->attendance373 ->whereRaw('batch_id = ' . $id . ' AND created_at > "' . $start_date . '" AND created_at < "' . $end_date . '"')374 ->orderBy('created_at', 'ASC')375 ->get();376 if (count($data) <= 0) {377 return 'No attendance Available!';378 }379 } catch (Exception $e) {380 return 'Error Fetching attendance!';381 }382 $chartObject = new \stdClass();383 $chartObject->element = 'attendance-chart';384 $chartObject->resize = true;385 $chartObject->data = array();386 $chartObject->xkey = 'date';387 $chartObject->ykeys = array('present');388 $chartObject->labels = array('Present');389 $chartObject->lineColors = array('#3c8dbc');390 $chartObject->hideHover = 'auto';391 $chartObject->parseTime = false;392 $chartObject->xLabelAngle = 60;393 $chartObject->stacked = true;394 $max = 0;395 foreach ($data as $each_data) {396 $date = date_create($each_data->created_at);397 $enc_date = Encrypt::encrypt($each_data->created_at);398 $temp = new \stdClass();399 $temp->date = '<a href="' . url('attendance/batch/' . $enc_id . '/' . $enc_date) . '">' . date_format($date, 'M d - D') . '</a>';400 //$temp->date = date_format($date, 'd/m/Y');401 $temp->present = $each_data->present_count;402 if ($max < $each_data->present_count + 3) {403 $max = $each_data->present_count + 3;404 }405 $chartObject->data [] = $temp;406 }407 $chartObject->ymax = $max;408 return json_encode($chartObject);409 } else {410 return '<h1>Invalid Request!! Access Denied!</h1>';411 }412 }413 /**414 * Student wise Attendance415 *416 * @param int $id417 * @return Response418 */419 public function ofStudent($id)420 {421 $id = Encrypt::decrypt($id);422 $data = array();423 if (!is_numeric($id)) {424 if (Sentinel::getUser()->inRole('users')) {425 return redirect()->back();426 }427 return redirect()->back()->withFlashMessage('Invalid Token!')->withType('danger');428 }429 try {430 $user = Sentinel::findById($id);431 if ($user == null) {432 return redirect()->back()->withFlashMessage('Oops Looks like the User doesn\'t exist!')->withType('danger');433 }434 } catch (Exception $e) {435 return redirect()->back()->withFlashMessage('Invalid Token!')->withType('danger');436 }437 if (!$user->inRole('users')) {438 return redirect()->back()->withFlashMessage('Invalid Reference Token!')->withType('danger');439 }440 try {441 $last_month = date('F - Y');442 $working_days = array();443 $absent = array();444 $batch_id = $this->student_details445 ->select('batch_id')446 ->where('user_id', $id)447 ->first();448 $months = $this->attendance449 ->select('created_at')450 ->where('batch_id', $batch_id['batch_id'])451 ->get()452 ->toArray();453 if (count($months) <= 0) {454 return redirect()->back()->withFlashMessage('No attendance available!')->withType('danger');455 }456 foreach ($months as $month) {457 $date = date_create($month['created_at']);458 if (!in_array(date_format($date, 'F-Y'), $data)) {459 $data [] = date_format($date, 'F-Y');460 $last_month = date_format($date, 'F-Y');461 }462 $working_days[date_format($date, 'F-Y')][] = date_format($date, 'd');463 }464 $months = $data;465 $attendance = $this->attendance466 ->select('created_at')467 ->where('attendance', 'like', '%[' . $id . ',%')468 ->orWhere('attendance', 'like', '%,' . $id . ']%')469 ->orWhere('attendance', 'like', '%,' . $id . ',%')470 ->orWhere('attendance', 'like', '%[' . $id . ']%')471 ->get()472 ->toArray();473 if (count($months) <= 0) {474 return redirect()->back()->withFlashMessage('No attendance available!')->withType('danger');475 }476 $data = '';477 foreach ($attendance as $each_attendance) {478 $date = date_create($each_attendance['created_at']);479 $data[date_format($date, 'F-Y')][] = date_format($date, 'd');480 }481 $present = $data;482 foreach ($months as $month) {483 if (isset($present[$month])) {484 $absent[$month] = array_diff($working_days[$month], $present[$month]);485 } else {486 $absent[$month] = $working_days[$month];487 }488 }489 } catch (Exception $e) {490 return redirect()->back()->withFlashMessage('Error Fetching attendance!')->withType('danger');491 }492 return view('attendance.attendance_student', [493 'months' => $months,494 'last_month' => $last_month,495 'present' => $present,496 'absent' => $absent,497 'working_days' => $working_days498 ]);499 }500 /**501 * Select batch to Edit.502 *503 * @return Response504 */505 public function edit()506 {507 $year = 2016;508 $marked_batches = array();509 $time_shift = array('morning', 'afternoon', 'evening');510 try {511 $batch = $this->batch512 ->select('id', 'batch', 'time_shift')513 ->where('year', $year)514 ->get();515 } catch (Exception $e) {516 return redirect()->back()->withFlashMessage('Error Selecting batch!!')->withType('danger');517 }518 foreach ($batch as $each_batch) {519 $each_batch['enc_id'] = Encrypt::encrypt($each_batch['id']);520 $each_batch['status'] = (in_array($each_batch['id'], $marked_batches)) ? 'marked' : 'unmarked';521 switch ($each_batch['time_shift']) {522 case 1:523 $each_batch['time_shift'] = 'morning';524 break;525 case 2:526 $each_batch['time_shift'] = 'afternoon';527 break;528 case 3:529 $each_batch['time_shift'] = 'evening';530 break;531 default:532 return redirect()->back()->withFlashMessage('Error Selecting batch With Time Shift!!')->withType('danger');533 }534 }535 $batch = $batch->toArray();536 return view('attendance.attendance_edit_select_batch', ['time_shift' => $time_shift, 'batch' => $batch]);537 }538 /**539 * List dates of selected batch to Edit attendance.540 *541 * @param int $id542 * @return Response543 */544 public function selectDate($id)545 {546 $enc_id = $id;547 $id = Encrypt::decrypt($id);548 $data = array();549 if (!is_numeric($id)) {550 return redirect()->back()->withFlashMessage('Invalid Token!')->withType('danger');551 }552 try {553 $dates = $this->attendance554 ->select('created_at')555 ->where('batch_id', $id)556 ->orderBy('created_at', 'DESC')557 ->get()->toArray();558 if (count($dates) <= 0) {559 return redirect()->back()->withFlashMessage('No attendance available for this batch!!')->withType('danger');560 }561 foreach ($dates as $each_date) {562 $date = date_create($each_date['created_at']);563 $enc_date = Encrypt::encrypt(date_format($date, 'Y-m-d'));564 $data [$enc_date] = date_format($date, 'd/m/Y - D');565 }566 $dates = $data;567 } catch (Exception $e) {568 return redirect()->back()->withFlashMessage('Error Selecting date!!')->withType('danger');569 }570 return view('attendance.attendance_select_date', ['dates' => $dates, 'id' => $enc_id]);571 }572 /**573 * Page to edit Attendance574 *575 * @param int $id576 * @param int $date577 * @return Response578 */579 public function editBatch($id, $date)580 {581 $enc_id = $id;582 $enc_date = $date;583 $id = Encrypt::decrypt($id);584 $date = Encrypt::decrypt($date);585 if (!is_numeric($id)) {586 return redirect()->back()->withFlashMessage('Invalid Batch Token!')->withType('danger');587 }588 if ($date === false) {589 return redirect()->back()->withFlashMessage('Invalid Date Token!')->withType('danger');590 }591 $data = array();592 try {593 $students = $this->student_details594 ->join('users', 'users.id', '=', 'student_details.user_id')595 ->select('users.id', 'users.first_name', 'users.last_name')596 ->where(array(597 'student_details.batch_id' => $id,598 'users.deleted_at' => null599 ))600 ->get();601 if (count($students) <= 0) {602 return redirect()->back()->withFlashMessage('No students found for this Batch!')->withType('danger');603 }604 foreach ($students as $each_student) {605 $data[Encrypt::encrypt($each_student['id'])]['name'] = $each_student['first_name'] . ' ' . $each_student['last_name'];606 }607 $students = $data;608 } catch (Exception $e) {609 return redirect()->back()->withFlashMessage('Error Selecting Students!')->withType('danger');610 }611 try {612 $attendance = $this->attendance613 ->select('attendance')614 ->whereRaw("batch_id = " . $id . " AND created_at LIKE '" . $date . "%'")615 ->first()->toArray();616 $data = [];617 $attendance = json_decode($attendance['attendance']);618 if (!is_array($attendance)) {619 return redirect()->back()->withFlashMessage('Attendance Data Corrupted!')->withType('danger');620 }621 foreach ($attendance as $each_attendance) {622 $data [] = Encrypt::encrypt($each_attendance);623 }624 $attendance = $data;625 } catch (Exception $e) {626 return redirect()->back()->withFlashMessage('Error Fetching Attendance!')->withType('danger');627 }628 return view('attendance.attendance_edit', ['id' => $enc_id, 'students' => $students, 'attendance' => $attendance, 'created_at' => $enc_date]);629 }630 /**631 * Update attendance.632 *633 * @param AjaxAttendanceRequest $request634 * @return Response635 */636 public function update(AjaxAttendanceRequest $request)637 {638 if ($request->ajax()) {639 $attendance = array();640 $id = Encrypt::decrypt($request['id']);...

Full Screen

Full Screen

MarkDetailsController.php

Source:MarkDetailsController.php Github

copy

Full Screen

...102 $data['batch'][Encrypt::encrypt($each_batch['id'])] = $each_batch['batch'] . ' - ' . $time_shifts[$each_batch['time_shift'] - 1];103 }104 $batch = $data['batch'];105 } catch (Exception $e) {106 return back()->withFlashMessage('Error Selecting batch')->withType('danger');107 }108 try {109 $exams = $this->exam_details110 ->limit(10)111 ->get();112 foreach ($exams as $exam) {113 $date = date_create($exam['exam_date']);114 $name = DB::table('Exam_type')115 ->select('name')116 ->where('id',$exam['type_id'])117 ->first();118 if(count($name)<=0){119 return back()->withFlashMessage('Exam data Corrupted..!')->withType('danger');120 }121 $data['exams'][Encrypt::encrypt($exam['id'])] = $name->name . ' - ' . date_format($date, 'd/m/Y');122 }123 $exams = $data['exams'];124 } catch (Exception $e) {125 return back()->withFlashMessage('Error Selecting Exam Details')->withType('error');126 }127 return view('mark.register_mark', ['batch' => $batch, 'exam' => $exams]);128 }129 /**130 * Store a newly created resource in storage.131 *132 * @param $request133 * @return Response134 */135 public function store(StoreMarkRequest $request)136 {137 try {138 $exam_id = Encrypt::decrypt($request['exam_id']);139 //$id = Encrypt::decrypt($request['batch_id']);140 //$count = count($request['markof']);141 if (!array_filter($request['markof'], 'is_numeric')) {142 return redirect('mark/create')->withFlashMessage('143 <h4>Error!</h4>144 <ol>145 <li>Enter only integers as Mark</li>146 <li>Enter marks of all students</li>147 </ol>148 ')->withType('danger');149 }150 foreach ($request['markof'] as $enc_id => $mark) {151 $id = Encrypt::decrypt($enc_id);152 $check = $this->mark_details153 ->where(array(154 'exam_id' => $exam_id,155 'user_id' => $id156 ))157 ->get();158 if (count($check) > 0) {159 return redirect('mark/create')->withFlashMessage('Mark already entered.')->withType('danger');160 }161 $this->mark_details162 ->insert([163 ['exam_id' => $exam_id, 'user_id' => $id, 'mark' => $mark]164 ]);165 }166 } catch (Exception $e) {167 return redirect('mark/create')->withFlashMessage('Error Adding mark to database')->withType('danger');168 }169 return redirect('mark/create')->withFlashMessage('Mark successfully added')->withType('success');170 }171 public function show($id){172 try {173 $id = Encrypt::decrypt($id);174 $marks = $this->mark_details175 ->select('exam_id', 'mark')176 ->where(array(177 'user_id' => $id178 ))179 ->get();180 if(count($marks)<=0){181 return redirect()->back()->withFlashMessage('No marks available to display!')->withType('danger');182 }183 foreach ($marks as $each) {184 $exam = $this->exam_details185 ->select('type_id','exam_date')186 ->where('id', $each->exam_id)187 ->orderBy('exam_date','DESC')188 ->first();189 if (count($exam) <= 0) {190 return redirect()->back()->withFlashMessage('No marks available to display!')->withType('danger');191 }192 $exam->exam_date = date_format(date_create($exam->exam_date),'d/m/Y');193 $exam_type = DB::table('Exam_type')194 ->select('name')195 ->where('id', $exam->type_id)196 ->first();197 if (count($exam_type) <= 0) {198 return redirect()->back()->withFlashMessage('Exam Type Mismatch!')->withType('danger');199 }200 unset($exam->type_id);201 unset($each->exam_id);202 $exam->type = $exam_type->name;203 $each->exam = $exam;204 }205 } catch (Exception $e) {206 return redirect()->back()->withFlashMessage('Error Fetching marks!')->withType('danger');207 }208 return view('protected.standardUser.mark',compact('marks'));209 }210 /**211 * Display the specified resource.212 *213 * @return Response214 */215 public function index()216 {217 $data = array();218 $year = 2016;219 $time_shifts = array('morning', 'afternoon', 'evening');220 try {221 $batch = $this->batch222 ->select('id', 'batch', 'time_shift')223 ->where('year', $year)224 ->get();225 $data['batch']['0'] = 'Select Batch';226 foreach ($batch as $each_batch) {227 $data['batch'][Encrypt::encrypt($each_batch['id'])] = $each_batch['batch'] . ' - ' . $time_shifts[$each_batch['time_shift'] - 1];228 }229 $batch = $data['batch'];230 } catch (Exception $e) {231 return back()->withFlashMessage('Error Selecting batch')->withType('error');232 }233 try {234 $exams = $this->exam_details235 ->get();236 foreach ($exams as $exam) {237 $date = date_create($exam['exam_date']);238 $name = DB::table('Exam_type')239 ->select('name')240 ->where('id',$exam['type_id'])241 ->first();242 if(count($name)<=0){243 return back()->withFlashMessage('Exam data Corrupted..!')->withType('danger');244 }245 $data['exams'][Encrypt::encrypt($exam['id'])] = $name->name . ' - ' . date_format($date, 'd/m/Y');246 }247 $exams = $data['exams'];248 } catch (Exception $e) {249 return back()->withFlashMessage('Error Selecting Exam Details')->withType('error');250 }251 return view('mark.view_mark', ['batch' => $batch, 'exam' => $exams]);252 }253 /**254 * Fetch students of given Batch Id255 *256 * @param $request257 * @return Response258 */259 public function fetchMark(FetchStudentsRequest $request)260 {261 if ($request->ajax()) {262 $batch_id = $request['id'];263 $exam_id = $request['exam_id'];264 if ($request['id'] == '0') {265 return '<h4>Select a Batch to View students</h4>';266 }267 $id = Encrypt::decrypt($request['id']);268 if (!is_numeric($id)) {269 return 'Invalid Token!';270 }271 $exam_id = Encrypt::decrypt($exam_id);272 if (!$exam_id) {273 return 'Invalid Token!';274 }275 $data = array();276 try {277 $students = $this->student_details278 ->join('users', 'users.id', '=', 'student_details.user_id')279 ->select('users.id', 'users.first_name', 'users.last_name')280 ->where(array(281 'student_details.batch_id'=> $id,282 'users.deleted_at' => null283 ))284 ->get();285 if (count($students) <= 0) {286 return '<h4>No students Available to display</h4>';287 }288 foreach ($students as $each_student) {289 $check = $this->mark_details290 ->where(array(291 'exam_id' => $exam_id,292 'user_id' => $each_student->id293 ))294 ->first();295 if (count($check) <= 0) {296 return '<h4>No marks available!</h4>';297 }298 $check = $check->toArray();299 $data[Encrypt::encrypt($each_student['id'])]['name'] = $each_student['first_name'] . ' ' . $each_student['last_name'];300 $data[Encrypt::encrypt($each_student['id'])]['mark'] = $check['mark'];301 }302 $students = $data;303 } catch (Exception $e) {304 return 'Error Selecting Students!';305 }306 return view('mark.mark_section', ['students' => $students, 'batch_id' => $batch_id]);307 } else {308 return '<h1>Invalid Request!! Access Denied</h1>';309 }310 }311 /**312 * Update the specified resource in storage.313 *314 * @param $request315 * @return Response316 */317 public function update(StoreMarkRequest $request)318 {319 try {320 $exam_id = Encrypt::decrypt($request['exam_id']);321 //$id = Encrypt::decrypt($request['batch_id']);322 //$count = count($request['markof']);323 if (!array_filter($request['markof'], 'is_numeric')) {324 return redirect('mark/create')->withFlashMessage('325 <h4>Error!</h4>326 <ol>327 <li>Enter only integers as Mark</li>328 <li>Enter marks of all students</li>329 </ol>330 ')->withType('danger');331 }332 foreach ($request['markof'] as $enc_id => $mark) {333 $id = Encrypt::decrypt($enc_id);334 $check = $this->mark_details335 ->where(array(336 'exam_id' => $exam_id,337 'user_id' => $id338 ))339 ->get();340 if (count($check) <= 0) {341 return redirect('mark')->withFlashMessage('Mark doesn\'t Exist.')->withType('danger');342 }343 $this->mark_details344 ->where(array(345 'exam_id' => $exam_id,346 'user_id' => $id347 ))348 ->update(['mark' => $mark]);349 }350 } catch (Exception $e) {351 return redirect('mark')->withFlashMessage('Error Updating mark to database')->withType('danger');352 }353 return redirect('mark')->withFlashMessage('Mark successfully Updated')->withType('success');354 }355 /**356 * Remove the specified resource from storage.357 *358 * @param $request359 * @return Response360 */361 public function destroy(DeleteMarkRequest $request)362 {363 $batch_id = Encrypt::decrypt($request['batch_id']);364 $exam_id = Encrypt::decrypt($request['exam_id']);365 try {366 $students = $this->student_details367 ->join('users', 'users.id', '=', 'student_details.user_id')368 ->select('users.id', 'users.first_name', 'users.last_name')369 ->where('student_details.batch_id', $batch_id)370 ->get();371 if (count($students) <= 0) {372 return redirect('mark')->withFlashMessage('No students Found!')->withType('danger');373 }374 foreach ($students as $each_student) {375 $this->mark_details376 ->where(array(377 'exam_id' => $exam_id,378 'user_id' => $each_student->id379 ))380 ->delete();381 }382 } catch (Exception $e) {383 return redirect('mark')->withFlashMessage('Error Deleting Mark!')->withType('danger');384 }385 return redirect('mark')->withFlashMessage('Mark Successfully Deleted!')->withType('success');386 }387 public function getMark()388 {389 $user = Sentinel::getUser();390 if ($user->inRole('users')) {391 try {392 $id = $user->id;393 $marks = $this->mark_details394 ->select('exam_id', 'mark')395 ->where(array(396 'user_id' => $id397 ))398 ->get();399 foreach ($marks as $each) {400 $exam = $this->exam_details401 ->select('type_id','exam_date')402 ->where('id', $each->exam_id)403 ->orderBy('exam_date','DESC')404 ->first();405 if (count($exam) <= 0) {406 return redirect()->back()->withFlashMessage('No marks available to display!')->withType('danger');407 }408 $exam->exam_date = date_format(date_create($exam->exam_date),'d/m/Y');409 $exam_type = DB::table('Exam_type')410 ->select('name')411 ->where('id', $exam->type_id)412 ->first();413 if (count($exam_type) <= 0) {414 return redirect()->back()->withFlashMessage('Exam Type Mismatch!')->withType('danger');415 }416 unset($exam->type_id);417 unset($each->exam_id);418 $exam->type = $exam_type->name;419 $each->exam = $exam;420 }421 } catch (Exception $e) {422 return redirect()->back()->withFlashMessage('Error Fetching marks!')->withType('danger');423 }424 return view('protected.standardUser.mark',compact('marks'));425 } else {426 return redirect()->back()->withFlashMessage('Access restricted!')->withType('danger');427 }428 }429}...

Full Screen

Full Screen

withType

Using AI Code Generation

copy

Full Screen

1$err = new Error();2$err->withType(1);3$err->withMessage("Error");4$err->withCode(100);5echo $err->getErrorMessage();6$err = new Error();7$err->withMessage("Error");8$err->withCode(100);9echo $err->getErrorMessage();10$err = new Error();11$err->withCode(100);12echo $err->getErrorMessage();13$err = new Error();14$err->withMessage("Error");15$err->withCode(100);16echo $err->getErrorMessage();17$err = new Error();18$err->withType(1);19$err->withMessage("Error");20$err->withCode(100);21echo $err->getErrorMessage();22$err = new Error();23$err->withType(1);24$err->withMessage("Error");25$err->withCode(100);26echo $err->getErrorMessage();27$err = new Error();28$err->withType(1);29$err->withMessage("Error");30$err->withCode(100);31echo $err->getErrorMessage();32$err = new Error();33$err->withType(1);34$err->withMessage("Error");35$err->withCode(100);36echo $err->getErrorMessage();37$err = new Error();38$err->withType(1);39$err->withMessage("Error");40$err->withCode(100);41echo $err->getErrorMessage();42$err = new Error();43$err->withType(1);44$err->withMessage("Error");45$err->withCode(100);46echo $err->getErrorMessage();

Full Screen

Full Screen

withType

Using AI Code Generation

copy

Full Screen

1{2public function __construct()3{4}5public function myMethod()6{7error::withType('myType');8}9}10$obj = new myClass();11$obj->myMethod();12$obj = new myClass();13$obj->myMethod();14$obj = new myClass();15$obj->myMethod();16{17public function __construct()18{19}20public function myMethod()21{22error::withType('myType');23}24}25$obj = new myClass();26$obj->myMethod();27$obj = new myClass();28$obj->myMethod();29$obj = new myClass();30$obj->myMethod();31{32public function __construct()33{34}35public function myMethod()36{37error::withType('myType');38}39}40$obj = new myClass();41$obj->myMethod();42$obj = new myClass();43$obj->myMethod();44$obj = new myClass();45$obj->myMethod();46{47public function __construct()48{49}50public function myMethod()51{52error::withType('myType');53}54}55$obj = new myClass();56$obj->myMethod();57$obj = new myClass();58$obj->myMethod();59$obj = new myClass();60$obj->myMethod();61{62public function __construct()63{64}65public function myMethod()66{67error::withType('myType');68}69}70$obj = new myClass();71$obj->myMethod();

Full Screen

Full Screen

withType

Using AI Code Generation

copy

Full Screen

1$error = new Error();2$error->withType(1);3echo $error->getType();4$error = new Error();5$error->withType(2);6echo $error->getType();7$error = new Error();8$error->withType(3);9echo $error->getType();10$error = new Error();11$error->withType(4);12echo $error->getType();13$error = new Error();14$error->withType(5);15echo $error->getType();16$error = new Error();17$error->withType(6);18echo $error->getType();19$error = new Error();20$error->withType(7);21echo $error->getType();22$error = new Error();23$error->withType(8);24echo $error->getType();25$error = new Error();26$error->withType(9);27echo $error->getType();28$error = new Error();29$error->withType(10);30echo $error->getType();31$error = new Error();32$error->withType(11);33echo $error->getType();34$error = new Error();

Full Screen

Full Screen

withType

Using AI Code Generation

copy

Full Screen

1require_once('error.php');2class foo {3 public function bar() {4 $error = new error();5 $error->withType('foo');6 }7}8$foo = new foo();9$foo->bar();10require_once('error.php');11class foo {12 public function bar() {13 $error = new error();14 $error->withType('foo');15 }16}17$foo = new foo();18$foo->bar();19class error {20 public function withType($type) {21 echo 'Error from '.$type;22 }23}24require_once('error.php');25class foo {26 public function bar() {27 $error = new error();28 $error->withType('foo');29 }30}31$foo = new foo();32$foo->bar();33require_once('error.php');34class foo {35 public function bar() {36 $error = new error();37 $error->withType('foo');38 }39}40$foo = new foo();41$foo->bar();42class error {43 public function withType($type) {44 echo 'Error from '.$type;45 }46}47require_once('error.php');48class foo {49 public function bar() {50 $error = new error();51 $error->withType('foo');52 }53}54$foo = new foo();55$foo->bar();

Full Screen

Full Screen

withType

Using AI Code Generation

copy

Full Screen

1$err = new Error();2$err->withType('1');3echo $err->getErrorMessage();4public function withType($type) {5 $this->type = $type;6 return $this;7}

Full Screen

Full Screen

withType

Using AI Code Generation

copy

Full Screen

1echo $err->withType(E_NOTICE);2echo $err->withMessage(E_NOTICE);3echo $err->withFile(E_NOTICE);4echo $err->withLine(E_NOTICE);5echo $err->withTrace(E_NOTICE);6echo $err->withAll(E_NOTICE);7echo $err->withAll(E_NOTICE);8echo $err->withAll(E_NOTICE);9echo $err->withAll(E_NOTICE);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger withType code on LambdaTest Cloud Grid

Execute automation tests with withType on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful