Jump to content
Vayu Robins

Compare two pagefields

Recommended Posts

Hi.

I need to compare two pagefields. I tried this:

$page->locations->has($user->locations)

But this doesn't work. I need to compare them and find out if the $page->locations has one or more of the same locations as the $user->locations. Hope it makes sense. :-)

Share this post


Link to post
Share on other sites

PageArray::has() only accepts a single object. You need a loop, here's an example:

$found = false;
foreach ($user->locations as $location) {
  if ($page->locations->has($location) {
    $found = true;
    break;
  }
}

  • Like 3

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ngrmm
      i have a event-page with a table.
      first column in this table is page-reference-field
      how can i find out if a urlSegment matches one of the rows having the same page-reference-field (page-id)?
      // all guests $allguests = new pageArray(); foreach($page->event_guests_table as $event_guests_table_row) { $allguests->prepend($event_table_row->guest); } // echo allguests would output: 1101|1102|1103|… // domain.tld/event/1101/ // show content if guest is in the table or redirect if($input->urlSegment1 ~= $allguests ) { // show content } else { // redirect }  
      which selector operator do i have to use? the one above does not work
    • By celfred
      Hello,
      I'm struggling with this : a 'group' field of 'Page' type.
      The parent of selectable pages is '/groups', the template is 'group', and a member can create some groups in the /groups tree. I would like this user to see only the groups he or she has created so in my 'Find selector' in the backend, I would like to use :

      template=group, created_users_id=$user->id But that doesn't seem to work... I still get the list of all available groups in the /groups tree.
      Any idea ?
      I had a feeling I had already seen that before (something like $user->id must be replaced by users_id or something, but I can't find anything in the Forums... and all my tests keep failing...
    • By Sanyaissues
      Hi, I have a page with a repeater called teams with two fields: team (a pageReference with a list of teams) and people (a pageReference with a list of people who likes this team).
      I'm trying to populate the people field in the repeater according to the value of the team field in the same repeater. So far. I'm able to get the pageArray that I want to assign to the people field, but i don't know how to "save" the value for each instance of the repeater.
      I hope somebody can give me a light. Thanks in advance.
       
      $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'people') { $repeaterField = $event->arguments('page')->teams; foreach ($repeaterField as $t) { // Is this the way to loop the instances of the repeater? $team = $t->team->id; $t->people = $event->pages->find("template=user, team={$team}"); var_dump($t->people); // This returns the values that i want to assign for each repeate instance $event->return = $t->people; // I hope this assign a custom pageArray for each repeater, but it assigns the same for all the instances of the repeater } } });  
    • By louisstephens
      So, I really don't know where to begin with this. I have the thought in my head (the basics), but not really sure how to set it up.
      The desired effect:
      The homepage is set up with a foreach loop that outputs all the child pages (basically just a bunch of pages with pdfs, docs etc stored in a file field). When A user is actually logged in, they can "star" an item or drag and drop (using Dragula) the page to a sidebar. Also, they would be able to reorder the pages in the sidebar.
      The question(s):
      I guess I have multiple questions regarding how to achieve this.
      Would it be best to create a page field in the user template to save the page(s)? How would you actually save the page state (sidebar output, reordering, etc) once the drag and drop has been used? Thanks in advance for any help! A lot of this was just what was in my head, so it might not make full sense. However, I will update this if I can actually wrap my head around everything.
    • By Vigilante
      I'm wondering about creating a query that involves looking across two different parent page trees.
      One parent is for blog posts and it has each post under that.
      Another parent is used for categories and subcategories for the blog.
      Then in the blogs there is a page field that can reference the categories. This is all pretty normal setup so far.
      I created a navigation that lists the current category and its children, but I want to not show categories that have no posts. For some reason I'm drawing a blank.
      So let's say a user clicks category1, and it shows a blog listing for that category. I query for all the child categories of the current one. Now I want to exclude any categories where NO blogs exist that make reference to the category (an unused category). How do I do this in a way that is performant? I don't want to have to query the blogs tree over and over to test for the presence of each category in the list!
      Here is the tree:
      blogs
       - article1  [pagefieldcat = "cat1"]
       - article2 [pagefieldcat = ""]
      categories
      - cat1
      - cat2
      Now when I get all children of categories, I want to exclude cat2 since it's not referenced from any blogs. Can I do this without having to loop and query every category against every blog one by one?
      Thanks
×
×
  • Create New...