Jump to content

Admin Custom Page and Registration


LukeCage
 Share

Recommended Posts

Hi! I have a big problem with a client of mine. I have to do something that i don't do very often with processwire, and i'm very afraid that i'm not gonna able to do it. So i write to search some help from you experts.

The website that i'm gonna create will have a database with infos about users. This users are not the actual registrered users, but possible users. I'll try my best to explain this. What i will have is a datasheet in the database with infos about all the users (name, surname, fiscal Code) that can register to the website. So during registration the website is confront with this database of people, and accept or not your registration to the website.

Now. The problems are: the client need a page in the CMS to insert this people in the first place (Custom Admin Page?) in the database. I read what i need to create it, but i don't understand what i need to do next. What i need to do for reading and writing to the database, with data, directly from a custom admin page in processwire?

The other thing is. I can do this control during registration? I Can extend fields in the user account?

I'm completely in your hands.

Link to comment
Share on other sites

2 hours ago, LukeCage said:

The problems are: the client need a page in the CMS to insert this people in the first place

  1. Is the client going to type in the data one by one or are you importing from a file, .e.g a CSV or JSON file?
  2. How many people potentially in the datasheet?
  3. Will this be done once or will the people be regularly updated?
  4. Can the people be saved as pages (hidden in admin) or you'd rather have them in a table external to ProcessWire?

Manage People Datasheet

You might need to create a simple Process Module, maybe even a one pager that lists the 'people'. You can include some simple actions like delete or edit people. To add people, a click on some button could open a modal window for you to add a person (depends on whether you are importing a file of people or typing manually).

There's also the module RockGrid that you can use for listing the 'people'. I don't know if it can do data imports though. I think it works with ProcessWire pages only, but am not sure.

User registration

Since creating users is a manual process, you have a lot of control here. How you check if a user is on the allowed people list depends on the approach you take above, i.e. whether people are pages or are in a custom database. If they are pages, you can use $pages API, e.g. $newUser = $pages->get("template=people, first_name=$firstName,last_name=$lastName"); Then check if that returned something. If yes, register this user. If you are using a custom table, you'd need to use SQL to fetch, insert, update, etc, people. ProcessWire has a $database API that you can use

Your other option is a custom Fieldtype but that is a bit more technical, going by how you've described your current skill set. 

2 hours ago, LukeCage said:

i'm very afraid that i'm not gonna able to do it. So i write to search some help from you experts.

Depending on your timescales, you might be able to get some help in the forums. If this is needed fairly soon, you might want to consider hiring an experienced ProcessWire developer to carry out the work for you.

  • Like 2
Link to comment
Share on other sites

6 hours ago, kongondo said:
  1. Is the client going to type in the data one by one or are you importing from a file, .e.g a CSV or JSON file?
  2. How many people potentially in the datasheet?
  3. Will this be done once or will the people be regularly updated?
  4. Can the people be saved as pages (hidden in admin) or you'd rather have them in a table external to ProcessWire?

Manage People Datasheet

You might need to create a simple Process Module, maybe even a one pager that lists the 'people'. You can include some simple actions like delete or edit people. To add people, a click on some button could open a modal window for you to add a person (depends on whether you are importing a file of people or typing manually).

There's also the module RockGrid that you can use for listing the 'people'. I don't know if it can do data imports though. I think it works with ProcessWire pages only, but am not sure.

User registration

Since creating users is a manual process, you have a lot of control here. How you check if a user is on the allowed people list depends on the approach you take above, i.e. whether people are pages or are in a custom database. If they are pages, you can use $pages API, e.g. $newUser = $pages->get("template=people, first_name=$firstName,last_name=$lastName"); Then check if that returned something. If yes, register this user. If you are using a custom table, you'd need to use SQL to fetch, insert, update, etc, people. ProcessWire has a $database API that you can use

Your other option is a custom Fieldtype but that is a bit more technical, going by how you've described your current skill set. 

Depending on your timescales, you might be able to get some help in the forums. If this is needed fairly soon, you might want to consider hiring an experienced ProcessWire developer to carry out the work for you.

1- the idea was that the client update this list. The option that imports from a csv is an option but can be very handy. What I know is that the interest is to export in a csv registered user and other lists. So I a do people as pages, I can export an hidden category with lots of pages in a csv? 

2- The people's list are very very large. Actually there's a database in the old website that I need to import in the first place. 

3- will be regularly updated once or twice a year, maybe more. 

4- No the people can be pages. The peoples are gonna store in the same database, so the important thing is to have a tab in the admin, so can be easy to the client to see only the people, and not all the pages etc.. I want to create a tab because I think that the page tree, with all the names, are gonna be very large, and not very easy to read.

Edited by LukeCage
  • Like 1
Link to comment
Share on other sites

I would go with a custom module to give ability to your administrators to insert/remove/update the potentials users which ares stored in the pages tree.  If the people pages list is very large, it is not a problem, you will end up with a paginated pages tree, and you will have the ability to find easily those users (pages) from the search case or even the Pages  > Find menu. You can also write a small Process module to manage those pages with a datatable, rockgrid or whatever you would like to use.

-

Reading @kongondo's answer after writing I see that he already explained the idea.

 

4 hours ago, LukeCage said:

I can export an hidden category with lots of pages in a csv?

Check this thread.

4 hours ago, LukeCage said:

The people's list are very very large. Actually there's a database in the old website that I need to import in the first place. 

Simply build a template for "people" and import them as a pages. 

4 hours ago, LukeCage said:

No the people can be pages.

This make things a lot easier. Just build your Process module to manage those pages. You can have a working prototype at the end of the day with all the information found on this forum.

  • Like 3
Link to comment
Share on other sites

Yeah, what @flydev said. Pages is the easier route in your case. We are not saying it cannot be done by using your custom database and querying it directly. That's possible, but in your case, a lot more technical work.

Your client does not have to see the tree of people pages. You can have those hidden under a single parent whose parent is /admin/ rather than home (/). This way, only superusers can see the people tree. With a Process Module, you don't have to be visiting the page tree even as a superuser. You only need to know that they are there and the evidence is that you can see them in your Process Module :-).

The 'each person is a page' approach means that ProcessWire does all the heavy lifting, dealing with databases operations. Heck, your Process Module will allow you to filter users or sort them according to some column. Your database columns, depending on the data, can either be stored as single ProcessWire fields - name=text;surname=text,other_data=integer, etc OR as one blob of JSON text in a single text field, which can be retrieved and turned into an array. We need to see the column names and how many you got, to give a definite answer.

How has your client been updating the database in the old website? 

You still haven't told us how soon you need this ?

 

  • Like 1
Link to comment
Share on other sites

1 hour ago, kongondo said:

Yeah, what @flydev said. Pages is the easier route in your case. We are not saying it cannot be done by using your custom database and querying it directly. That's possible, but in your case, a lot more technical work.

Your client does not have to see the tree of people pages. You can have those hidden under a single parent whose parent is /admin/ rather than home (/). This way, only superusers can see the people tree. With a Process Module, you don't have to be visiting the page tree even as a superuser. You only need to know that they are there and the evidence is that you can see them in your Process Module :-).

The 'each person is a page' approach means that ProcessWire does all the heavy lifting, dealing with databases operations. Heck, your Process Module will allow you to filter users or sort them according to some column. Your database columns, depending on the data, can either be stored as single ProcessWire fields - name=text;surname=text,other_data=integer, etc OR as one blob of JSON text in a single text field, which can be retrieved and turned into an array. We need to see the column names and how many you got, to give a definite answer.

How has your client been updating the database in the old website?

You still haven't told us how soon you need this ?

 

They write to csv, then they send this to the developer. But after i said them they were absolutely doing this directly from the website, they were absolutely enthusiastic.

My question is: I have read how to do a module in the Admin (it is very easy to create it), but how i can display the pages only in that new tab? Like an html table or something similar? And maybe in all of those, insert the modify button (that redirect to the normal page edit). Technically i never do this, and i don't know where to start.

Link to comment
Share on other sites

1 hour ago, LukeCage said:

My question is: I have read how to do a module in the Admin (it is very easy to create it), but how i can display the pages only in that new tab? Like an html table or something similar? And maybe in all of those, insert the modify button (that redirect to the normal page edit). Technically i never do this, and i don't know where to start.

Luke, the reason am asking particular questions is so that we can offer a tailored response. Without more information, it is difficult to offer a specific answer. For instance, I asked, how many columns in the database? But it seems to me you now want to go with pages, as per our suggestion, right?

Assuming you are going with pages. 

Display

Your process module, in its execute function (I am assuming you've read about this?) will render your HTML table. You can either render a ProcessWire table, or your own custom HTML table, or use Process Lister or RockGrid. All of this can be paginated so that only a limited number of people are loaded at a time. See Process Blog module for displaying pages in a HTML table.

In the HTML table, do you want to display all data columns (e.g. name, surname, fiscal thingy, etc) OR do you want to display only full name (i.e. Steve Job?)

Modal

  • Then when client clicks on Steve Job, it opens a modal to the Steve Job page.
  • The Steve Job page has several fields for name, surname, fiscal thing, etc.
  • The client edits the fields he wants and closes the modal
  • The page reloads (or if using ajax, only the data reloads)
  • See Blog module (Process blog for opening pages in modal for editing)

Note: Since the pages are in admin, we will have to by-pass user access check in order for client to edit the page

Uploading new 'people'

  • We have a button or file field for uploading new people data as CSV (see my FieldtypeMatrix module for example)
  • When the csv file is uploaded, a script loops through it and creates people pages on the fly, mapping csv columns data to the ProcessWire page's fields. Before creating a page we check if there is already a people page with similar data {same email, same name, same surname, etc}
  • You then decide what you need to do; update if duplicate found or skip creation of that people page?
  • People page reloads (or ajax refresh)

These are ideas, but very doable. But we need specific answers to our questions. You never know; someone might just create a draft module for you ?

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

31 minutes ago, kongondo said:

Luke, the reason am asking particular questions is so that we can offer a tailored response. Without more information, it is difficult to offer a specific answer. For instance, I asked, how many columns in the database? But it seems to me you now want to go with pages, as per our suggestion, right?

Assuming you are going with pages.

Display

Your process module, in its execute function (I am assuming you've read about this?) will render your HTML table. You can either render a ProcessWire table, or your own custom HTML table, or use Process Lister or RockGrid. All of this can be paginated so that only a limited number of people are loaded at a time. See Process Blog module for displaying pages in a HTML table.

In the HTML table, do you want to display all data columns (e.g. name, surname, fiscal thingy, etc) OR do you want to display only full name (i.e. Steve Job?)

Modal

  • Then when client clicks on Steve Job, it opens a modal to the Steve Job page.
  • The Steve Job page has several fields for name, surname, fiscal thing, etc.
  • The client edits the fields he wants and closes the modal
  • The page reloads (or if using ajax, only the data reloads)
  • See Blog module (Process blog for opening pages in modal for editing)

Note: Since the pages are in admin, we will have to by-pass user access check in order for client to edit the page

Uploading new 'people'

  • We have a button or file field for uploading new people data as CSV (see my FieldtypeMatrix module for example)
  • When the csv file is uploaded, a script loops through it and creates people pages on the fly, mapping csv columns data to the ProcessWire page's fields. Before creating a page we check if there is already a people page with similar data {same email, same name, same surname, etc}
  • You then decide what you need to do; update if duplicate found or skip creation of that people page?
  • People page reloads (or ajax refresh)

These are ideas, but very doable. But we need specific answers to our questions. You never know; someone might just create a draft module for you ?

That's exactly what i want to do. The info are gonna be more than six or seven "fields" per person.

What i haven't done before is importing with csv and transform to pages, i have to dig more into this.

How can i display a ProcessWire table in excecute() ? I can not understand how to do that...

Link to comment
Share on other sites

Here's something to chew on.

Start with this tutorial: https://processwire.com/blog/posts/building-custom-admin-pages-with-process-modules/

Some code to play with. This creates a paginated ProcessWire-rendered HTML table.

  • Create a module as per above tutorial.
  • Use the following code in your Process module's execute() method.
  • You need to create some people pages. In this example, they use the template 'people'.
  • Edit functionality not included. Have a look at Blog module for that, here.
  • For CSV upload (not included), have a look at Matrix module here for uploading CSV file and here for reading CSV file.

 

/**
 *	Display, Add and Edit People.
 *
 *	Called when the URL is peoples's page URL + "/people/" i.e. URL Segment.
 *	Renders a table with People information. People can be edited via modal.
 *
 *	@access protected
 *	@return mixed $form rendered form
 *
 */
public function ___execute() {

    $modules = $this->wire('modules');
    $input = $this->wire('input')->post;
    $pages = $this->wire('pages');

    // CREATE A NEW FORM
    $form = $modules->get('InputfieldForm');
    $form->attr('id', 'people');
    $form->action = './';
    $form->method = 'post';

    // CREATE AN INPUTFIELD MARKUP: Will hold list of people table
    $m = $modules->get('InputfieldMarkup');
    $m->textFormat = Inputfield::textFormatNone;// make sure ProcessWire renders custom HTML
    // $m->label = $this->_('Edit');
    // $m->description = $this->_('Click on a title to edit the item.');

    // CREATE A NEW TABLE: for people
    $t = $modules->get('MarkupAdminDataTable');
    $t->setEncodeEntities(false);
    $t->setClass('peopleTable');

    // set header rows
    $peopleTableHeaders = array(
        '<input type="checkbox" class="toggle_all">',
        $this->_('Title'),
        $this->_('Name'),
        $this->_('Surname'),
        $this->_('Another Column'),
        $this->_('One More Column'),
        $this->_('Published'),
        #$this->_('Date'),
    );


    $t->headerRow($peopleTableHeaders);

    // grab a limited number of people to show in people dashboard. Limit is hardcoded in this example
    $people = $pages->find("template=people, include=all, sort=-created, parent!=7, limit=10");

    foreach ($people as $p) {
        if (!count($people)) break;// if no people found, break early
        // check if person page  is published or not
        $p->is(Page::statusUnpublished) ? $status = '<span class="unpublished">' . $this->_('No') . '</span>' : $status = $this->_('Yes');
        // set table rows
        $peopleTable = array(
            "<input type='checkbox' name='posts_action[]' value='{$p->id}' class='toggle'>",// disabled sorting on this in .js file
            "<a href='{$this->wire('config')->urls->admin}page/edit/?id={$p->id}&modal=1' class='editPeople pw-modal pw-modal-medium'>$p->title</a>",
            $p->title,
            $p->person_name,
            $p->person_surname,
            $p->another_column,
            $p->one_more_column,
            $status
        );

        // render the table rows with variables set above
        $t->row($peopleTable);

    }// end foreach $people as $p

    // display a headline indicating quantities. We'll add this to people dashboard
    $start = $people->getStart()+1;
    $end = $start + count($people)-1;
    $total = $people->getTotal();

    if($total) $peopleCount = "<h4>" . sprintf(__('People %1$d to %2$d of %3$d'), $start, $end, $total) . "</h4>";

    // add a description to people dashboard {postsCount, limitSelect and instruction OR no people found status}
    $m->description = $total == 0 ? $this->_('No items found.') : $peopleCount . $this->_('Click on a title to edit the item.');
    $m->notes = "People table notes";

    $currentUrl = $this->wire('page')->url . $this->wire('input')->urlSegmentsStr."/";// get the url segment string. In this case it is "people"
    $pagination = $people->renderPager(array('baseUrl' => $currentUrl));

    $m->attr('value', $pagination . $t->render() . $pagination);// wrap our table with pagination

    $form->add($m);

    $post = $this->wire('input')->post;

    // render the final form
    return $form->render();

}

 

Edited by kongondo
  • Like 7
Link to comment
Share on other sites

8 hours ago, LukeCage said:

The people's list are very very large

What is "very very large" ?

 

4 hours ago, flydev said:

You can also write a small Process module to manage those pages with a datatable, rockgrid or whatever you would like to use.

3 hours ago, LukeCage said:

My question is: I have read how to do a module in the Admin (it is very easy to create it), but how i can display the pages only in that new tab? Like an html table or something similar? And maybe in all of those, insert the modify button (that redirect to the normal page edit). Technically i never do this, and i don't know where to start.

1 hour ago, LukeCage said:

How can i display a ProcessWire table in excecute() ? I can not understand how to do that...

RockGrid, RockGrid, RockGrid! It's a perfect szenario for it and it was mentioned several times already by @kongondo and @flydev - it seems you didn't have a look yet?

 

8 hours ago, LukeCage said:

The option that imports from a csv is an option but can be very handy. What I know is that the interest is to export in a csv registered user and other lists. So I a do people as pages, I can export an hidden category with lots of pages in a csv? 

There are several modules to help you with CSV import: https://www.google.com/search?q=site:processwire.com+import+csv

 

  • Like 2
Link to comment
Share on other sites

Forgot one:

8 hours ago, LukeCage said:

What I know is that the interest is to export in a csv registered user and other lists. So I a do people as pages, I can export an hidden category with lots of pages in a csv?

One click with RockGrid, already built in - and they can even filter the grid before exporting ?

  • Like 1
Link to comment
Share on other sites

6 minutes ago, bernhard said:

One click with RockGrid, already built in - and they can even filter the grid before exporting 

Awesome! I really need to get some time to test it!

This topic should be marked as [almost solved], eh? ;-). Read @bernhard tutorial on Process Modules and use his RockGrid module ?

  • Like 3
Link to comment
Share on other sites

7 minutes ago, bernhard said:

Forgot one:

One click with RockGrid, already built in - and they can even filter the grid before exporting ?

Just now, kongondo said:

Awesome! I really need to get some time to test it!

This topic should be marked as [almost solved], eh? ;-). Read @bernhard tutorial on Process Modules and use his RockGrid module ?

I will try this first. If is not gonna work form i will go for @kongondo solution.

Next few days i will start programming, and I will let you know how it went!

Link to comment
Share on other sites

2 minutes ago, kongondo said:

Awesome! I really need to get some time to test it!

You should really do that as soon as possible ? I'm using it on all my projects and it's an absolutely awesome listing tool. Much better than the core listing in most of the cases IMHO (not praising my own work here, most of the awesomeness comes from agGrid).

I decided to make it free (MIT) so that others can use it in their modules (batch child editor, the new padloper, etc. - really a lot of possibilities here). I really think that it opens up a new world for processwire regarding how users can manage their content (GUI). 

4 minutes ago, LukeCage said:

Next few days i will start programming, and I will let you know how it went!

Great, good luck and have fun ?

  • Like 1
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

×
×
  • Create New...