[companydir module] how to simply create a FEU CRUD

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
MoltenCore
New Member
New Member
Posts: 3
Joined: Wed Apr 04, 2012 4:14 pm

[companydir module] how to simply create a FEU CRUD

Post by MoltenCore »

Hi folks,

I was looking in the forum how to allow FEU user to have a simple CRUD for their own data. All the post I read was looking a little bit complicated. I just found a simple way to do this. No need to modify any .php file. Just some template management. That's all !
(maybe this solution was already posted by someone. So sorry for that and delete my post)

we just need 2 modules installed:
- FrontEndUsers
- CompanyDirectory

1/ create 2 new pages
We need 2 pages:
- One to list only the company created by the user (he can edit). Create the page and give it the alias "feu-company-list".
- One to display the edit and new form. Create the page and give it the alias "feu-company-edit".
Thats all for the moment. We will go back to the content later.

2/ create a new template for the feu-company-list page
We just need a new template to list only the company that the user created. Go to the companydir template option, and create a new "summary template". Name it "feu_editing_list". Just copy and paste the default (sample) template and add some new code.

- at the top put the code:

Code: Select all

{cms_selflink page="feu-company-edit" text="ADD NEW COMPANY"}
this is to display the button to create a new record. We link the first page we just created. There is no company id in the tag so it will display a blank edit form to add a new record. Dont forget to allow feu user to add record in the companydir module preferences. U need to put the status "publish" by default for the new record otherwise the user will not be able to see the new record.

- Now find the first "foreach" loop: find the {foreach from=$items item=entry} and just after creat a new {if} condition to list only the records that match with the FEuser ID actualy logged. So put this:

Code: Select all

{if isset($userid) && $userid == $entry->owner_id}
U see that the FEuser id is store in the owner_id colomn in the companydir DB table.

- Add the edit button for each record to allow user to edit. Just before the first {/foreach} put the code

Code: Select all

{assign var="compid" value=$entry->id}   
{cms_selflink page="feu-company-edit" text="Edit" urlparam="&compid=$compid"}
Here we catch the current "company id" in the loop and we pass it through the "urlparam" option in the cms_selflink. This is important because we will be able to catch the id in the destination page (here the 2nd page we created "feu-company-edit", in the 1/) with the smarty code $smarty.get.compid.

- Dont forget to close the {/if} condition just before the first {/foreach}.

3/ add tag on the 2 new pages we created
Now we have to put some tags in the destination page to work with our new companydir template.

- So open the first page "feu-company-list" (see 1/) and put the tag in the content:

Code: Select all

{CompanyDirectory summarytemplate="feu_editing_list"}
we just add the tag to list the company but with the template we created in 2/ to list only the company of the current user logged.

- Open the 2nd page "feu-company-edit" (see 1/) and put the tag in the content:

Code: Select all

{CompanyDirectory action="fe_edit" companyid=$smarty.get.compid}
here we display the feu edit form (action="fe_edit") and the good company id to edit the good record. Remenber in the 2/ we put the (urlparam="&compid=$compid") in the cms_selflink. So here we can catch the id with $smarty.get.compid.

4/ Almost done !
Ok now we just need to put somewhere the link to the "feu-company-list" so that the user logged can access his personnal company list. I decide to put it just below the FEU message saying you are loggedin.
So go to the FEU module administration. Select the "logout form template" and put at the bottom:

Code: Select all

<p>{cms_selflink page="feu-company-list" text="admin your company"}</p>
FINISH !

Ok thanks to read my post. I will be glad if u can test this and go back to me if u have some questions or if i did wrong thing.
This method work with the CompanyDirectory module but it can work with all other module that allow FEU to modify data.

Hope this will help you.

See ya !
Post Reply

Return to “Tips and Tricks”