ziu

how pages that logged user has created in admin panel

Recommended Posts

Hi i created a custom admin page and i  just want to know is there a module  or any way to show a user only those pages under subpages of a page in tree which he has created. please help.

Share this post


Link to post
Share on other sites

i used that module but its not what i was looking for, i have below mentioned pages.

Properties (parent template)
---Property 1   created by admin
---Property 2   created by user1
---Property 3   created by user1
---Property 4   created by admin
---Property 5   created by user1

But i when 'User1' login to his account-- i want to show only those pages which he has created. like below

Properties (parent template)
---Property 2   created by user1
---Property 3   created by user1
---Property 5   created by user1

 

 

Thank you, any help will be appreciated.

 

Share this post


Link to post
Share on other sites

It sounds like easiest approach would be to change it to look like this:

Properties
---User 1
-------Property 1
-------Property 3
---User 2
-------Property 2
-------Property 4

I understand that might be an issue for the url structure on your site. There are ways around this though.

The other option is https://processwire.com/talk/topic/1176-hiding-uneditable-pages-from-users/?do=findComment&comment=84916 - read that post and the post that it links to and the rest of both threads. There are ways to do this that should work fine and in your scenario I don't think the mentioned problems will be an issue. Let us know if you need help with any of the linked scripts.

  • Like 2

Share this post


Link to post
Share on other sites

Thank you adrian, you are so quick, thanks alot, i guess the links you shared can possibly solve my problem and i am  also thinking about the way you presented the paging approach. thank you. will update you  soon. 

  • Like 1

Share this post


Link to post
Share on other sites

@adrian hi , can you show me the right way to use 'createdUser' api , i  want to match this with the logged in user so that i can display those pages only which has been created by the same user who is loggedin. 

 

thank you 

Share this post


Link to post
Share on other sites
2 hours ago, ziu said:

@adrian hi , can you show me the right way to use 'createdUser' api , i  want to match this with the logged in user so that i can display those pages only which has been created by the same user who is loggedin. 

Well, it's pretty much just like this. If the createdUser property for the given page matches the current user, it will return true, otherwise false. If that doesn't make sense, maybe post some code so we can debug for you.

5a0db11184acd_ScreenShot2017-11-16at7_38_39AM.png.0c07f1c773e2db0572589c269795f202.png

  • Like 2

Share this post


Link to post
Share on other sites

i have created a custom admin  page which shows pages of a template only... below is the code, but i want to show only those pages that are created by the login user. as i already tried other solutions you mentioned above, but i am totally confused that, how can display those pages.

 


<?php


$u=$user->id;
$this->modules->get('JqueryMagnific');

//render PageListtree with setting the parent page
$formImages = $this->modules->get('InputfieldForm'); // prep the form
$wrapperImages = new InputfieldWrapper; // a wrapper
$wrapperImages->attr('value', '<h2>Artist Registration Page</h2>');

$i = $this->modules->get('ProcessPageList'); // here i want to display only those subpages which matches to the user logged in
$i->set('id', 5845); // setting the parent page

$pageTreeImages = new InputfieldMarkup; // the placeholder
$pageTreeImages->value = $i->execute(); // fill the InputfieldMarkup form field...

$wrapperImages->add($pageTreeImages); // put inside the wrapper...
$formImages->append($wrapperImages); // append the wrapper

 


?>

Share this post


Link to post
Share on other sites

To hide pages from ProcessPageList for non-superusers (doesn't apply for superusers) you can hook Page::listable().

$page->listable()
bool Returns true if the page is listable by the current user, false if not. 
Can also be used as property: $page->listable

 

So to hide pages that the user cannot edit you can add this to /site/ready.php:

$wire->addHookAfter('Page::listable', function(HookEvent $event) {
    $page = $event->object;
    if(!$page->editable) $event->return = false;
});

 

  • Like 1

Share this post


Link to post
Share on other sites

hi @adrian that worked , now user can edit only those pages which he has created, but user still can see all other pages, can't we do anything to hide other pages that he has not created in list, i already tried to use higepagesuser module, but thats not working. 

Help

Share this post


Link to post
Share on other sites

@adrianyour hideotherpages and hideuneditable modules works like charm, but i used createdUser->id with User->id  to match and show only those pages which a user has created. 

Many thanks to adrian, i really appreciated the way he reponds.

  • Like 1

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 ziu
      hi, just created a parent page and under this i want a user who is logged in to create only one page, not more than that. how can i do this.
      thanks
    • By ziu
      I have created a website that has a login and register feature.
      i used ryan's login register module.
      but now i want the logged-in user to add a page e.g. Add Property this page will have custom fields which logged in user will fill. but user can add only single. and he/she can update/edit this page only.
      I need your help guys in achiveing this.
      Thanks in advance.
      Any help will be appreciated.