Sradesign Posted April 18, 2016 Share Posted April 18, 2016 Hi I have another issue like always 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 More sharing options...
LostKobrakai Posted April 18, 2016 Share Posted April 18, 2016 $names = explode(',', $names); $names = array_map('trim', $names); $names = implode('|', $names); $users->find("name=$names"); 1 Link to comment Share on other sites More sharing options...
kixe Posted April 18, 2016 Share Posted April 18, 2016 (edited) $names = "ali,sradesign,nona"; $names = strtr($names, ',','|'); $users = $users->find("name=".$names); @LostKobrakai Always quick Edited April 18, 2016 by kixe 2 Link to comment Share on other sites More sharing options...
Sradesign Posted April 18, 2016 Author Share Posted April 18, 2016 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 More sharing options...
kixe Posted April 18, 2016 Share Posted April 18, 2016 $tasks = $pages->find("task_person*=$user->name,parent=/tasks/,include=hidden,sort=-created"); 2 Link to comment Share on other sites More sharing options...
Sradesign Posted April 18, 2016 Author Share Posted April 18, 2016 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 Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 18, 2016 Share Posted April 18, 2016 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. 1 Link to comment Share on other sites More sharing options...
Sradesign Posted April 18, 2016 Author Share Posted April 18, 2016 Simply because I just found out about them I'll do that. Link to comment Share on other sites More sharing options...
Sradesign Posted April 18, 2016 Author Share Posted April 18, 2016 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; } ?> Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 18, 2016 Share Posted April 18, 2016 ->add() does afaik only allow for a single item. Either use ->import() or just $task->task_person = $task_person; 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now