作者:utrenkne
项目:YAWI
/**
* @param Parameters $params
* @param Builder $queryBuilder
*
* @return Builder
*/
public function createQuery($params, $queryBuilder)
{
$this->value = $params->toArray();
/*
* search jobs by keywords
*/
if (isset($this->value['params']['search']) && !empty($this->value['params']['search'])) {
$search = strtolower($this->value['params']['search']);
$expression = $queryBuilder->expr()->operator('$text', ['$search' => $search]);
$queryBuilder->field(null)->equals($expression->getQuery());
}
if (isset($this->value['params']['status']) && !empty($this->value['params']['status'])) {
if ($this->value['params']['status'] != 'all') {
$queryBuilder->field('status.name')->equals($this->value['params']['status']);
}
} else {
$queryBuilder->field('status.name')->equals(Status::CREATED);
}
if (isset($this->value['params']['companyId']) && !empty($this->value['params']['companyId'])) {
$queryBuilder->field('organization')->equals(new \MongoId($this->value['params']['companyId']));
}
if (isset($this->value['sort'])) {
foreach (explode(",", $this->value['sort']) as $sort) {
$queryBuilder->sort($this->filterSort($sort));
}
}
return $queryBuilder;
}
作者:no-repl
项目:cbpl-vufin
/**
* getSuggestions
*
* This returns an array of suggestions based on current request parameters.
* This logic is present in the factory class so that it can be easily shared
* by multiple AJAX handlers.
*
* @param \Zend\Stdlib\Parameters $request The user request
* @param string $typeParam Request parameter containing search
* type
* @param string $queryParam Request parameter containing query
* string
*
* @return array
*/
public function getSuggestions($request, $typeParam = 'type', $queryParam = 'q')
{
// Process incoming parameters:
$type = $request->get($typeParam, '');
$query = $request->get($queryParam, '');
// get Autocomplete_Type config
$searcher = $request->get('searcher', 'Solr');
$options = $this->getServiceLocator()->get('SearchManager')->setSearchClassId($searcher)->getOptionsInstance();
$config = ConfigReader::getConfig($options->getSearchIni());
$types = isset($config->Autocomplete_Types) ? $config->Autocomplete_Types->toArray() : array();
// Figure out which handler to use:
if (!empty($type) && isset($types[$type])) {
$module = $types[$type];
} else {
if (isset($config->Autocomplete->default_handler)) {
$module = $config->Autocomplete->default_handler;
} else {
$module = false;
}
}
// Get suggestions:
if ($module) {
if (strpos($module, ':') === false) {
$module .= ':';
// force colon to avoid warning in explode below
}
list($name, $params) = explode(':', $module, 2);
$handler = $this->get($name);
$handler->setConfig($params);
}
return isset($handler) && is_object($handler) ? array_values($handler->getSuggestions($query)) : array();
}
作者:bbeckma
项目:NDL-VuFind
/**
* Initialize the object's search settings from a request object.
*
* @param \Zend\StdLib\Parameters $request Parameter object representing user
* request.
*
* @return void
*/
protected function initSearch($request)
{
// Convert special 'id' parameter into a standard hidden filter:
$idParam = $request->get('id', []);
if (!empty($idParam)) {
$this->addHiddenFilter('ids:' . implode("\t", $idParam));
}
}
作者:grharr
项目:vufin
/**
* Add filters to the object based on values found in the request object.
*
* @param \Zend\StdLib\Parameters $request Parameter object representing user
* request.
*
* @return void
*/
protected function initFilters($request)
{
// Special filter -- if the "id" parameter is set, limit to a specific list:
$id = $request->get('id');
if (!empty($id)) {
$this->addFilter("lists:{$id}");
}
// Otherwise use standard parent behavior:
return parent::initFilters($request);
}
作者:javierdlaho
项目:SS-zen
/**
* @param $request
* @return array|mixed|User
* @throws \Exception
*/
public function login($request)
{
$adapter = $this->getAuthPlugin()->getAuthAdapter();
$pin = $request->get('pin');
$accountId = $request->get('accountId');
if (!empty($pin)) {
$user = $this->getUserByPin($pin, $accountId);
$credentials = array('username' => $user->getUsername(), 'password' => $user->getPassword());
} else {
$credentials = array('username' => $request->get('username'), 'password' => $request->get('password'));
}
$params = new Parameters();
$params->set('identity', $credentials['username']);
$params->set('credential', $credentials['password']);
$emulatedRequest = new Request();
$emulatedRequest->setPost($params);
$result = $adapter->prepareForAuthentication($emulatedRequest);
if ($result instanceof Response) {
return $result;
}
$auth = $this->getAuthPlugin()->getAuthService()->authenticate($adapter);
if (!$auth->isValid()) {
$isRegistered = $this->isRegistered($credentials);
$accountUser = $this->getAccountUsersByParams($params);
if ($accountUser != null && !$isRegistered) {
if ($this->getAgencyIsDeleted($accountUser->getAccountId())) {
throw new \Exception(self::AGENCY_DELETED_MESSAGE);
}
return $this->createUserFromAccountUsers($accountUser);
}
$account = $this->getAccountByParams($params);
if ($account != null && !$isRegistered) {
return $this->createUserFromAccount($account);
}
if ($accountUser != null && $isRegistered) {
return $this->updateUser($accountUser);
}
$result = $auth->getMessages();
$message = "Bad request.";
if (isset($result[0])) {
$message = $result[0];
}
throw new \Exception($message);
}
$accountUser = $this->getAccountUsersByParams($params);
if ($this->getAgencyIsDeleted($accountUser->getAccountId())) {
throw new \Exception(self::AGENCY_DELETED_MESSAGE);
}
if ($this->getUserIsDeleted($credentials['username'])) {
throw new \Exception(self::USER_DELETED_MESSAGE);
}
$user = $this->getAuthPlugin()->getIdentity();
return $user;
}
作者:no-repl
项目:cbpl-vufin
/**
* Support method for _initSearch() -- handle basic settings.
*
* @param \Zend\StdLib\Parameters $request Parameter object representing user
* request.
*
* @return boolean True if search settings were found, false if not.
*/
protected function initBasicSearch($request)
{
// If no lookfor parameter was found, we have no search terms to
// add to our array!
if (is_null($lookfor = $request->get('lookfor'))) {
return false;
}
// Set the search (handler is always Author for this module):
$this->setBasicSearch($lookfor, 'Author');
return true;
}
作者:no-repl
项目:cbpl-vufin
/**
* init
*
* Called at the end of the Search Params objects' initFromRequest() method.
* This method is responsible for setting search parameters needed by the
* recommendation module and for reading any existing search parameters that may
* be needed.
*
* @param \VuFind\Search\Base\Params $params Search parameter object
* @param \Zend\StdLib\Parameters $request Parameter object representing user
* request.
*
* @return void
*/
public function init($params, $request)
{
// Build a search parameters object:
$sm = $this->getSearchManager()->setSearchClassId($this->getSearchClassId());
$params = $sm->getParams();
$params->setLimit($this->limit);
$params->setBasicSearch($request->get($this->requestParam));
// Perform the search:
$this->results = $sm->setSearchClassId($this->getSearchClassId())->getResults($params);
$this->results->performAndProcessSearch();
}
作者:opswa
项目:tocat-opsdesk-platfor
public function testPagesActionCanBeAccessedByPost()
{
$this->routeMatch->setParam('action', 'pages');
$this->request->setMethod('POST');
$p = new Parameters();
$p->set('role_id', '1');
$this->request->setPost($p);
$result = $this->controller->dispatch($this->request);
$response = $this->controller->getResponse();
$this->assertInstanceOf('Zend\\Http\\Response', $result);
$this->assertEquals(302, $response->getStatusCode());
}
作者:grharr
项目:vufin
/**
* Support method for _initSearch() -- handle basic settings.
*
* @param \Zend\StdLib\Parameters $request Parameter object representing user
* request.
*
* @return boolean True if search settings were found, false if not.
*/
protected function initBasicSearch($request)
{
// If no lookfor parameter was found, we have no search terms to
// add to our array!
if (is_null($lookfor = $request->get('author'))) {
return false;
}
// Force the search to be a phrase:
$lookfor = '"' . str_replace('"', '\\"', $lookfor) . '"';
// Set the search (handler is always Author for this module):
$this->setBasicSearch($lookfor, 'Author');
return true;
}
作者:aromati
项目:HumusPHPUnitModul
public function testRunActionWithParams()
{
$params = array('strict' => true, 'verbose' => true, 'debug' => true);
$runner = $this->getMockForAbstractClass('HumusPHPUnitModule\\RunnerInterface');
$runner->expects($this->once())->method('setParams')->with($params);
$runner->expects($this->once())->method('run');
$params = new Parameters();
$params->set('strict', true);
$params->set('verbose', true);
$params->set('debug', true);
$this->request->setParams($params);
$this->controller->setRunner($runner);
$response = new Response();
$this->controller->dispatch($this->request, $response);
}
作者:wizard201
项目:ze-album.de
/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
*
* @return HtmlResponse|RedirectResponse
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
{
try {
$album = (array) $this->albumService->getAlbum($request->getAttribute('id'));
} catch (\Exception $e) {
return new HtmlResponse($this->template->render('error::404'), 404);
}
if ($request->getMethod() === 'POST') {
$body = new Parameters($request->getParsedBody());
$del = $body->get('del', 'No');
if (strtolower($del) === 'yes') {
$this->albumService->deleteAlbum($album);
}
return new RedirectResponse($this->router->generateUri('album.index'));
}
return new HtmlResponse($this->template->render('album::delete', ['album' => $album]));
}
作者:spala
项目:ua-webchalange-instagram-collag
/**
* @param Parameters $params
*
* @return Parameters
*/
protected function initDefaults(Parameters $params)
{
if (is_null($params->get('quality')) || !strlen(trim($params->get('quality')))) {
$params->set('quality', QualityInterface::QUALITY_THUMBNAIL);
}
if (is_null($params->get('source')) || !strlen(trim($params->get('source')))) {
$params->set('source', SourceNameInterface::SOURCE_USER);
}
return $params;
}
作者:bbeckma
项目:NDL-VuFind
/**
* This returns an array of suggestions based on current request parameters.
* This logic is present in the factory class so that it can be easily shared
* by multiple AJAX handlers.
*
* @param \Zend\Stdlib\Parameters $request The user request
* @param string $typeParam Request parameter containing search
* type
* @param string $queryParam Request parameter containing query
* string
*
* @return array
*/
public function getSuggestions($request, $typeParam = 'type', $queryParam = 'q')
{
// Process incoming parameters:
$type = $request->get($typeParam, '');
$query = $request->get($queryParam, '');
$searcher = $request->get('searcher', 'Solr');
$hiddenFilters = $request->get('hiddenFilters', []);
// If we're using a combined search box, we need to override the searcher
// and type settings.
if (substr($type, 0, 7) == 'VuFind:') {
list(, $tmp) = explode(':', $type, 2);
list($searcher, $type) = explode('|', $tmp, 2);
}
// get Autocomplete_Type config
$options = $this->getServiceLocator()->get('VuFind\\SearchOptionsPluginManager')->get($searcher);
$config = $this->getServiceLocator()->get('VuFind\\Config')->get($options->getSearchIni());
$types = isset($config->Autocomplete_Types) ? $config->Autocomplete_Types->toArray() : [];
// Figure out which handler to use:
if (!empty($type) && isset($types[$type])) {
$module = $types[$type];
} else {
if (isset($config->Autocomplete->default_handler)) {
$module = $config->Autocomplete->default_handler;
} else {
$module = false;
}
}
// Get suggestions:
if ($module) {
if (strpos($module, ':') === false) {
$module .= ':';
// force colon to avoid warning in explode below
}
list($name, $params) = explode(':', $module, 2);
$handler = $this->get($name);
$handler->setConfig($params);
}
if (is_callable([$handler, 'addFilters'])) {
$handler->addFilters($hiddenFilters);
}
return isset($handler) && is_object($handler) ? array_values($handler->getSuggestions($query)) : [];
}
作者:till
项目:vufin
/**
* Process renewal requests.
*
* @param \Zend\Stdlib\Parameters $request Request object
* @param \VuFind\ILS\Connection $catalog ILS connection object
* @param array $patron Current logged in patron
*
* @return array The result of the renewal, an
* associative array keyed by item ID (empty if no renewals performed)
*/
public function processRenewals($request, $catalog, $patron)
{
// Pick IDs to renew based on which button was pressed:
$all = $request->get('renewAll');
$selected = $request->get('renewSelected');
if (!empty($all)) {
$ids = $request->get('renewAllIDS');
} else {
if (!empty($selected)) {
$ids = $request->get('renewSelectedIDS');
} else {
$ids = [];
}
}
// Retrieve the flashMessenger helper:
$flashMsg = $this->getController()->flashMessenger();
// If there is actually something to renew, attempt the renewal action:
if (is_array($ids) && !empty($ids)) {
$renewResult = $catalog->renewMyItems(['details' => $ids, 'patron' => $patron]);
if ($renewResult !== false) {
// Assign Blocks to the Template
if (isset($renewResult['blocks']) && is_array($renewResult['blocks'])) {
foreach ($renewResult['blocks'] as $block) {
$flashMsg->setNamespace('info')->addMessage($block);
}
}
// Send back result details:
return $renewResult['details'];
} else {
// System failure:
$flashMsg->setNamespace('error')->addMessage('renew_error');
}
} else {
if (!empty($all) || !empty($selected)) {
// Button was clicked but no items were selected:
$flashMsg->setNamespace('error')->addMessage('renew_empty_selection');
}
}
return [];
}
作者:CUSA
项目:vufin
public function handleSort(Manager $manager, Parameters $request, $defaultSort, $target)
{
$user = $manager->isLoggedIn();
$requestParams = $request->toArray();
if ($user) {
//in case user changed the the sort settings on the result list with a specialized UI control
//we want to serialize the new value in database
if (array_key_exists('sortControlElement', $requestParams)) {
if (array_key_exists('sort', $requestParams)) {
$sort = $requestParams['sort'];
$dbSort = unserialize($user->default_sort);
$dbSort[$target] = $requestParams['sort'];
$user->default_sort = serialize($dbSort);
$user->save();
} else {
$tSort = $request->get('sort');
$sort = !empty($tSort) ? $tSort : $defaultSort;
}
} else {
$tSort = $request->get('sort');
$sort = !empty($tSort) ? $tSort : $defaultSort;
//overwrite sort if value is set in database
if ($user->default_sort) {
$userDefaultSort = unserialize($user->default_sort);
if (isset($userDefaultSort[$target])) {
$sort = $userDefaultSort[$target];
}
}
}
} else {
$sort = $request->get('sort');
}
// Check for special parameter only relevant in RSS mode:
if ($request->get('skip_rss_sort', 'unset') != 'unset') {
$this->skipRssSort = true;
}
return $sort;
}
作者:twyst
项目:expressive-albu
/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
{
try {
$album = $this->albumService->getAlbum($request->getAttribute('id'));
if ($request->getMethod() === 'POST') {
$body = new Parameters($request->getParsedBody());
$del = $body->get('del', 'No');
if (strtolower($del) === 'yes') {
$this->albumService->deleteAlbum($album);
/**
* @var Session $session
*/
$session = $request->getAttribute('session');
$session->getSegment('App\\Album')->setFlash('flash', ['type' => 'success', 'message' => sprintf('Successfully deleted album %s (%s)', $album->getTitle(), $album->getArtist())]);
}
// Redirect to list of albums
return new RedirectResponse($this->router->generateUri('album.index'));
}
} catch (\Exception $e) {
// do something useful
}
return new HtmlResponse($this->template->render('album::delete', compact('album')));
}
作者:pji
项目:zf2rapi
/**
* Test with project path set
*/
public function testWithProjectPathSet()
{
$this->console->expects($this->never())->method('writeFailLine')->with($this->equalTo('task_check_working_path_mandatory'));
$this->parameters->set('workingPath', '/path/to/project/');
$task = new ProjectPathMandatory();
$result = $task($this->route, $this->console, $this->parameters);
$this->assertEquals(0, $result);
}
作者:spala
项目:zf2-file-uploade
/**
* @param UploaderModelInterface $model
* @param null $values
* @return string
* @throws InvalidArgumentException
*/
public function render($model, $values = null)
{
if (!$model instanceof UploaderModelInterface) {
throw new InvalidArgumentException("Unsupportable type of model, required type UploaderModelInterface");
}
$resources = $model->getResourcePaths();
$url = array_pop($resources);
$funcNum = $this->params->get('CKEditorFuncNum', 0);
return "<script type='text/javascript'>\n window.parent.CKEDITOR.tools.callFunction({$funcNum}, '" . $url . "', '');\n </script>";
}
作者:pgiacomett
项目:zf2rapi
/**
* Test with controller existing
*/
public function testWithKnownHydrators()
{
$this->console->expects($this->never())->method('writeFailLine')->with($this->equalTo('task_check_base_hydrator_param_unknown'));
$this->console->expects($this->never())->method('colorize');
$knownHydrators = ['ArraySerializable', 'ClassMethods', 'ObjectProperty', 'Reflection'];
foreach ($knownHydrators as $hydrator) {
$this->parameters->set('paramBaseHydrator', $hydrator);
$task = new BaseHydratorParam();
$result = $task($this->route, $this->console, $this->parameters);
$this->assertEquals(0, $result);
}
}
作者:publicitas-deploymen
项目:php-openid-connect-clien
/**
* @return Http\Client
*/
public function getHttpClient()
{
if (!$this->httpClient instanceof Http\Client) {
$this->httpClient = $this->getHttpClientFactory()->createHttpClient($this->options->get(self::OPT_HTTP_CLIENT, array()));
}
return $this->httpClient;
}