/** * Makers list */ public function indexAction() { $request = $this->request; $persistent = $this->persistent; // Reset $reset = $this->request->getQuery('reset', 'int'); if (isset($reset)) { $persistent->makersParams = null; } // Persistent parameters if (!is_array($persistent->makersParams)) { $persistent->makersParams = ['qry' => ['conditions' => "id IS NOT NULL", 'order' => 'updated DESC'], 'sort' => ['page' => 1, 'perpage' => 50]]; } $parameters = $persistent->makersParams; $parameters['sort']['perpage'] = isset($parameters['sort']['perpage']) ? $parameters['sort']['perpage'] : 50; $parameters['sort']['page'] = isset($parameters['sort']['page']) ? $parameters['sort']['page'] : 1; if ($request->getQuery('page', 'int')) { $parameters['sort']['page'] = $request->getQuery('page', 'int'); } if ($request->getQuery('perpage', 'int')) { $parameters['sort']['perpage'] = $request->getQuery('perpage', 'int'); } // Search if ($request->isPost()) { $parameters['search_region'] = null; $parameters['search_approved'] = null; // Placer if (!empty($_POST['search_region'])) { $search_region_get = $request->getPost('search_region', 'int'); $parameters['search_region'] = $search_region_get; $search_region = " AND geo_id = {$search_region_get}"; } else { $search_region = null; } // Name or ID if (!empty($_POST['search_name'])) { $search_name_get = $request->getPost('search_name', 'string'); if (preg_match('/^[0-9,\\s]+$/', $request->getPost('search_name', 'string'))) { $search_split = preg_split('/[,\\s]/', $search_name_get, 0, PREG_SPLIT_NO_EMPTY); $search_name = implode(', ', $search_split); $search_name = " AND id IN ({$search_name})"; } else { $search_name = " AND name LIKE '%{$search_name_get}%'"; } } else { $search_name_get = null; $search_name = null; } // Email if (!empty($_POST['search_email'])) { $search_email_get = $request->getPost('search_email', 'string'); $search_email = " AND email LIKE '%{$search_email_get}%'"; } else { $search_email_get = null; $search_email = null; } // Phone if (!empty($_POST['search_phone'])) { $search_phone_get = $request->getPost('search_phone', 'string'); $search_phone = " AND phone LIKE '%{$search_phone_get}%' OR phone2 LIKE '%{$search_phone_get}%'"; } else { $search_phone_get = null; $search_phone = null; } // Approved status if (!empty($_POST['search_approved'])) { $search_approved_get = $request->getPost('search_approved', 'int'); $parameters['search_approved'] = $search_approved_get; $search_approved = " AND approved = {$search_approved_get}"; } else { $search_approved = null; } // Search parameters $parameters['qry'] = ['conditions' => "id IS NOT NULL\n {$search_region}\n {$search_name}\n {$search_email}\n {$search_phone}\n {$search_approved}"]; } // Other parameters $parameters['count'] = PMaker::count($parameters['qry']); $parameters['qry']['order'] = "updated DESC"; $parameters['qry']['limit'] = 10000; $persistent->makersParams = $parameters; // var_dump($parameters); $makers = PMaker::find($parameters['qry']); // Paginator $paginator = new Paginator(["data" => $makers, "limit" => $parameters['sort']['perpage'], "page" => $parameters['sort']['page']]); $this->view->page = $paginator->getPaginate(); // Set selected search values $this->view->selected_region = isset($parameters['search_region']) && !empty($parameters['search_region']) ? $parameters['search_region'] : null; $this->view->selected_approved = isset($parameters['search_approved']) && !empty($parameters['search_approved']) ? $parameters['search_approved'] : null; $this->view->makers_count = $parameters['count']; // All regions $this->view->regions_list = array_column(Geo::find(['order' => 'title ASC'])->toArray(), 'title', 'id'); // Currencies $currencies_array = array_column(PCrosscurrency::find()->toArray(), 'title', 'title'); $this->view->currencies_list = ['UAH' => $currencies_array['UAH']] + $currencies_array; // Countries $countries_array = array_column(Countries::find("active=1")->toArray(), 'title', 'id'); $ukraine = array_search('Украина', $countries_array); $this->view->countries_list = [$ukraine => $countries_array[$ukraine]] + $countries_array; $this->view->users_list = Accounts::getUsersByRole(['researcher', 'mobilegroup'], false, 'name ASC'); $this->view->can_edit = AccRoles::findFirst("user_id={$this->auth->id} AND (role_id=991 OR role_id=5)"); }