示例#1
0
 /**
  * Display a listing of the resource
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $filters = $request->all();
     $limit = $request->input('limit', 50);
     $offset = $request->input('offset', 0);
     $order = $request->input('order', null);
     $order_flow = 'ASC';
     $order_by = 'findDate';
     if (!empty($order)) {
         $first_char = substr($order, 0, 1);
         if ($first_char == '-') {
             $order_flow = 'DESC';
             $order_by = substr($order, 1, strlen($order));
         }
     }
     $validated_status = $request->input('status', 'gevalideerd');
     if (empty($request->user())) {
         $validated_status = 'gevalideerd';
     }
     // Check if personal finds are set
     if ($request->has('myfinds') && !empty($request->user())) {
         $filters['myfinds'] = $request->user()->email;
         $validated_status = '*';
     }
     $result = $this->finds->getAllWithFilter($filters, $limit, $offset, $order_by, $order_flow, $validated_status);
     $finds = $result['data'];
     $count = $result['count'];
     $pages = Pager::calculatePagingInfo($limit, $offset, $count);
     $linkHeader = '';
     $query_string = $this->buildQueryString($request);
     foreach ($pages as $rel => $page_info) {
         if (!empty($query_string)) {
             $linkHeader .= $request->url() . '?offset=' . $page_info[0] . '&limit=' . $page_info[1] . '&' . $query_string . ';rel=' . $rel . ';';
         } else {
             $linkHeader .= $request->url() . '?offset=' . $page_info[0] . '&limit=' . $page_info[1] . ';rel=' . $rel . ';';
         }
     }
     $linkHeader = rtrim($linkHeader, ';');
     // If a user is a researcher or personal finds have been set, return the exact
     // find location, if not, round up to 2 digits, which lowers the accuracy to 1km
     if (empty($filters['myfinds'])) {
         $adjusted_finds = [];
         $user = $request->user();
         foreach ($finds as $find) {
             if (empty($user) || !empty($find['person']['identifier']) && $find['person']['identifier'] != $user->id && !in_array('onderzoeker', $user->getRoles())) {
                 if (!empty($find['findSpot']['location']['lat'])) {
                     $find['findSpot']['location']['lat'] = round($find['findSpot']['location']['lat'] / 2, 2) * 2;
                     $find['findSpot']['location']['lng'] = round($find['findSpot']['location']['lng'] / 2, 2) * 2;
                     $accuracy = isset($find['findSpot']['location']['accuracy']) ? $find['findSpot']['location']['accuracy'] : 1;
                     $find['findSpot']['location']['accuracy'] = max(2000, $accuracy);
                 }
             }
             $adjusted_finds[] = $find;
         }
         $finds = $adjusted_finds;
     }
     return response()->view('pages.finds-list', ['finds' => $finds, 'filterState' => ['query' => '', 'order' => $order, 'myfinds' => @$filters['myfinds'], 'category' => $request->input('category', '*'), 'period' => $request->input('period', '*'), 'technique' => $request->input('technique', '*'), 'objectMaterial' => $request->input('objectMaterial', '*'), 'status' => $validated_status, 'showmap' => $request->input('showmap', null)], 'fields' => $this->list_values->getFindTemplate(), 'link' => $linkHeader])->header('Link', $linkHeader);
 }
示例#2
0
 private function makeApiFindsResponse($request)
 {
     extract($this->processQueryParts($request));
     $result = $this->finds->getAllWithFilter($filters, $limit, $offset, $order_by, $order_flow, $validatedStatus);
     $finds = $result['data'];
     $count = $result['count'];
     // If a user is a researcher or personal finds have been set, return the exact
     // find location, if not, round up to 2 digits, which lowers the accuracy to 1km
     if (empty($filters['myfinds'])) {
         $adjustedFinds = [];
         $user = $request->user();
         foreach ($finds as $find) {
             if (empty($user) || !empty($find['person']['identifier']) && $find['person']['identifier'] != $user->id && !in_array('onderzoeker', $user->getRoles())) {
                 if (!empty($find['findSpot']['location']['lat'])) {
                     $find['findSpot']['location']['lat'] = round($find['findSpot']['location']['lat'] / 2, 2) * 2;
                     $find['findSpot']['location']['lng'] = round($find['findSpot']['location']['lng'] / 2, 2) * 2;
                     $accuracy = isset($find['findSpot']['location']['accuracy']) ? $find['findSpot']['location']['accuracy'] : 1;
                     $find['findSpot']['location']['accuracy'] = max(2000, $accuracy);
                 }
             }
             $adjustedFinds[] = $find;
         }
         $finds = $adjustedFinds;
     }
     $pages = Pager::calculatePagingInfo($limit, $offset, $count);
     $linkHeader = '';
     $queryString = $this->buildQueryString($request);
     foreach ($pages as $rel => $page_info) {
         if (!empty($queryString)) {
             $linkHeader .= $request->url() . '?offset=' . $page_info[0] . '&limit=' . $page_info[1] . '&' . $queryString . ';rel=' . $rel . ';';
         } else {
             $linkHeader .= $request->url() . '?offset=' . $page_info[0] . '&limit=' . $page_info[1] . ';rel=' . $rel . ';';
         }
     }
     $linkHeader = rtrim($linkHeader, ';');
     return response()->json($finds)->header('Link', $linkHeader);
 }
示例#3
0
    array_push($rules, $rule);
}
// Base URL without schema
$baseUrl = UrlHelper::removeScheme(Url::home(true));
// PHP options required by embed.js
$options = array("id" => $formModel->id, "app" => $baseUrl . "app", "tracker" => $baseUrl . "/static_files/js/form.tracker.js", "name" => "#form-app", "actionUrl" => Url::to(['app/a', 'id' => $formModel->id], true), "validationUrl" => Url::to(['app/check', 'id' => $formModel->id], true), "_csrf" => Yii::$app->request->getCsrfToken(), "resume" => $formModel->resume, "autocomplete" => $formModel->autocomplete, "analytics" => $formModel->analytics && $record, "confirmationType" => $formConfirmationModel->type, "confirmationMessage" => $formConfirmationModel->message, "confirmationUrl" => $formConfirmationModel->url, "showOnlyMessage" => $formConfirmationModel::CONFIRM_WITH_ONLY_MESSAGE, "redirectToUrl" => $formConfirmationModel::CONFIRM_WITH_REDIRECTION, "rules" => $rules, "fieldIds" => $formDataModel->getFieldIds(), "submitted" => false, "runOppositeActions" => true, "i18n" => ['complete' => Yii::t('app', 'Complete'), 'unexpectedError' => Yii::t('app', 'An unexpected error has occurred. Please retry later.')]);
// Pass php options to javascript
$this->registerJs("var options = " . json_encode($options) . ";", View::POS_BEGIN, 'form-options');
// Load reCAPTCHA JS Api
// Only if Form has reCaptcha component and was not passed in this session
if ($formModel->recaptcha === $formModel::RECAPTCHA_ACTIVE && !Yii::$app->session['reCaptcha']) {
    $this->registerJsFile('https://www.google.com/recaptcha/api.js', ['position' => View::POS_HEAD]);
    $this->registerCss(".g-recaptcha { height: 78px; }");
}
// Pager
$pager = new Pager(Html::decode($formDataModel->html));
// Utilities required for javascript files
$this->registerJsFile('@web/static_files/js/form.utils.min.js', ['depends' => JqueryAsset::className()]);
// If form has multiple pages
if ($pager->getNumberOfPages() > 1) {
    // Animations
    $this->registerJsFile('@web/static_files/js/libs/jquery.easing.min.js', ['depends' => JqueryAsset::className()]);
}
// If resume later is enabled
if ($formModel->resume) {
    $this->registerJsFile('@web/static_files/js/form.resume.min.js', ['depends' => JqueryAsset::className()]);
}
// If form has rules
if (count($rules) > 0) {
    // Load rules engine and run
    $this->registerJsFile('@web/static_files/js/rules.engine.min.js', ['depends' => JqueryAsset::className()]);