Jump to content

Search by comma separated values


Sradesign
 Share

Recommended Posts

Hi

I have another issue like always :D I have a field in my page details that contain comma separated values like this "ali,sradesign,nona" and now I want to get pages if $user->name is ali or sradesign or nona.

What do you think guys how can I achieve this?

Best Regards,

Ali.M

Link to comment
Share on other sites

ok I think I mentioned wrong I have a page name Task which contain different task and each task has field like this task_person = "ali,sradesign,nona"

the data for each task may vary then when I try to get all the tasks like this

$tasks = $pages->find("parent=/tasks/,include=hidden,sort=-created");

I want to have a filter here to check for it in one statement not to get all the tasks first then check for that.


just to get the tasks that their task_person is equal too $user->name either ali or sradesign or nona.

Link to comment
Share on other sites

Kixe that doesn't work I tried see now in one task I have task_person = "sradesigns,ali" and in the other one I have task_person = "ali,sradesign" both are shown for user serdesign but not for ali which is wrong first of all it should show for both of them second of all it shouldn't show it to sradesign when is "sradesigns,ali" cause is not exactly sradesign and is sradesigns :D

Link to comment
Share on other sites

May I ask why you're not using a PageField to reference users? *= does not support partial word matching and in this case there are no spaces, which is why it doesn't work. ~= would work, but only in db queries and not for runtime filtering.

  • Like 1
Link to comment
Share on other sites

I did it @LostKobrakai but when I try to add them with api I have again issue I use a multiple select and send the page ID's and in processing part I do it like this but as you can see I get error.

<?php
	$input = wire('input');
	$sanitizer = wire('sanitizer');
	$roles = wire('roles');
	$_POST = json_decode(file_get_contents('php://input'), true);

	if($_POST['title']){
		$task_title = $_POST['title'];
	} else {
		$task_title = '';
	}
	if($_POST['date']){
		$task_date = $_POST['date'];
	} else {
		$task_date = '';
	}
	if($_POST['description']){
		$task_description = $_POST['description'];
	} else {
		$task_description = '';
	}
	if($_POST['priority']){
		$task_priority = $_POST['priority'];
	} else {
		$task_priority = '';
	}
	if($_POST['due']){
		$task_due = $_POST['due'];
	} else {
		$task_due = '';
	}
	$task_person = $_POST['assigned'];
	if($_POST['progress']){
		$task_progress = $_POST['progress'];
	} else {
		$task_progress = '0';
	}
	
	if(!empty($_POST)){
		$task = new Page();
		$task->template = 'task';
		$task->parent = wire('pages')->get('/tasks/');
		$task->save();
		$task->title = $task_title;
		$task->task_date = $task_date;
		$task->task_description = $task_description;
		$task->task_priority = $task_priority;
		$task->task_due = $task_due;
		$task->task_person->add($task_person);
		$task->task_progress = $task_progress;
		$task->page_roles = 'superuser';
		$task->status = Page::statusHidden;
		$task->save();
		
		$session->message(__('A New Task Successfully Added'));
		$session->prevPage = $page;
	}
?>

test.jpg

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...