This topic is locked
[SOLVED]

Forum template

10/19/2022 2:40:19 PM
PHPRunner General questions
H
hudster author

Hi

Just asking for some advice on which might be the best way to do this.

In my site I am creating forums for different professional communities. To avoid them getting muddled, I'm wondering whether it is best to have the forum template running in several different instances with logins eg:
mydomain.com/community1
mydomain.com/community2

Or whether it is better to create permissions at a user level to only be able to view forum categories (ie: community 1 can only see community 1 posts). I have looked at some of the tutorials from Fernando Humanes on this and the hierachy of users and wonder if that might be a good solution. The question for me is how to restrict this on a user/group level.

Thoughts appreciated.

Terry

admin 10/19/2022

If these are two different communities than having two separate projects, two URLs and two different databases is a natural choice.

While it is possible to handle this in a single project and assign access to certain categories to different users, it will just increase the complexity of the project.

Another approach, the same project, two different databases. I recommend checking SaaS application design article.

H
hudster author 10/19/2022

Thanks, Sergey.

This is what I thought. I wondered about the SaaS idea. I looked at the article. Would it need me to publish a new project each time through phpr and upload it to the server, or does defining each community in the user database work (and say publishing 10 community databases in advance)?

Thanks
Terry

fhumanes 10/20/2022

Hello,

If in your case, a user only and exclusively belongs to a community, Sergey's solution is very possible that it is the best.

If a user can belong to several communities (which is normal), then the solution of different databases, it is very possible that they do not work for you.

In my Forum example, https://fhumanes.com/blog/gestor-de-proyectos/gestion-de-un-foro/

It is quite simple to add the access control of the "categories" depending on the user and the communities that belong.

On the "XLINESOFT template" I can't tell you anything, because I do not know what is developed.

Cheers,
fernando

admin 10/20/2022

If you decide to proceed the way that is described in SaaS article, there will be a single project and multiple databases. All communites can share the same URL though it would be easier to dedicate subdomains like community1.website.com. In either case, adding a new community would be a matter of adding a new database.

H
hudster author 10/26/2022

Thank you both for the replies. Really helpful!
I will probably go down the SaaS route. Is there a way to enable people to be a member of multiple projects through this? ie: rather than just accessing one database, they can access database 1 and 3?

I think there will be a limited number of forums, so would it be better to do this via dynamic permissions in the security section?

Thanks in advance
Terry

admin 10/26/2022

I'm not sure it will be easy to make it work with two projects, permissions are project specific. It is like using the same login to post on both Twitter and Reddit.

I think you can try session keys/JWT approach if you need to let certain users access multiple communities. Still going to be complicated.

H
hudster author 10/26/2022

Thanks again.

I think I have a potential work around using the categories, which is working well! I thought I would share my method in case it is helpful for other people. I took a simplier approach in the end - simple is underrated :)

Each "community" will be a category. In this case, the community doesn't need to create multiple categories to post in, so the category = "community" name. This way I can subscribe users to a category (or more than one category). I have created a master_details link between forumusers_admin and forumcategorysubscribers table - so when adding a new user, the category can be added. It also means if new communities form, then a new category can be added.

For example: the categories are now "Community X", "Community Y" etc

To achieve this, I added an additional bit to the MySQL query for the forumtopics table (highlighted bold below). This links each forum post to the userid through the forumcategorysubscribers table.

SELECT
forumtopics.topic,
forumtopics.topic AS topic2,
forumtopics.startedby,
forumtopics.startedby AS startedby2,
forumtopics.id,
forumtopics.categoryid,
forumtopics.views,
forumtopics.activity,
forumtopics.pinned,
c.color,
forumtopics.question,
forumtopics.created,
forumtopics.solved,
u.image,
forumcategorysubscribers.userid,
(select
COUNT(*)
FROM forumreplies AS r
WHERE r.topicid = forumtopics.id
) AS forumreplies
FROM forumtopics
INNER JOIN forumcategories AS c ON c.id = forumtopics.categoryid
INNER JOIN forumcategorysubscribers ON forumtopics.categoryid = forumcategorysubscribers.categoryid
LEFT OUTER JOIN forumusers AS u ON u.id = forumtopics.startedby
ORDER BY forumtopics.pinned DESC, forumtopics.activity DESC

The next thing I did was to add the following to the "List page:before SQL query" in the editor screen
if($_SESSION["user_id"]) $strWhereClause = "userid=".$_SESSION["user_id"];

Now when a user logs in, they can only see the topics to which they have been subscribed. To ensure users only add to their subscribed categories when adding or editing new topics, I created a query for the look up wizard as follows.
SELECT forumcategories.id, forumcategories.name, forumcategories.color, forumcategorysubscribers.userid FROM forumcategories INNER JOIN forumcategorysubscribers ON forumcategories.id = forumcategorysubscribers.categoryid

and added a where clause of
"userid=".$_SESSION["user_id"];

My final challenge, which I am still working on is editing the code snippet at the top of the forum topics page - at the moment the filter shows all forum categories even if a user is not subscribed. If I cannot work it out, I may just delete the snippet as it is not required for my forum purposes. Still, it would be good to know how if anyone has any advice!