简体   繁体   English

批准编辑

[英]Approval of edits

I want to know the best solution for reviewing edits of a user that needs to be approved by a admin. 我想知道最好的解决方案,用于审查需要管理员批准的用户编辑。

At the moment i have a Users table with the following fields. 目前,我有一个带有以下字段的Users表。

  • Username 用户名
  • Password 密码
  • Created_at Created_at
  • Updated_at 的updated_at

I have a relation table user_profile with the following fields 我有一个具有以下字段的关系表user_profile

  • User_id 用户身份
  • Firstname 名字
  • Lastname
  • Street
  • Zip 压缩
  • State
  • About_me 关于我

I also have a table pending_user_profile for the approvals 我也有一个表pending_user_profile用于批准

  • User_id 用户身份
  • Firstname 名字
  • Lastname
  • Street
  • Zip 压缩
  • State
  • About_me 关于我

At the moment i am checking if there is a user_id in the pending_user_profile table to show the pending data inside the edit screen on the application. 目前,我正在检查pending_user_profile表中是否存在user_id,以在应用程序的编辑屏幕中显示未决数据。

Im checking it like this: PendingUser::where('user_id', $this->id)->exists(); 我像这样检查它: PendingUser::where('user_id', $this->id)->exists();

The pending data is also shown for the admin. 还显示管理员的待处理数据。 (basically im just getting everything inside the pending_user_profile. So the admin knows what users have edited there information. (基本上,我只是将所有内容都保存在“ pending_user_profile”中。因此,管理员知道哪些用户在此处编辑了信息。

Im getting the data like this: PendingUser::all(); 我正在获取这样的数据: PendingUser::all();

First question: I'm not sure how this will hold up when i have loads of users. 第一个问题:我不确定在有大量用户时这将如何保持下去。 So im trying to find a better solution for this, or want to know that the solution im using now is maybe totally fine and i should not be worried about it at all. 因此,即时通讯试图为此找到更好的解决方案,或者想知道即时通讯使用的解决方案可能完全正常,我完全不必担心。 Is my approach for checking for pending fields a good approach? 我检查未决字段的方法是否是好方法?

Second question: When storing the pending fields im not sure how to deal with it. 第二个问题:在存储待处理字段时,我不确定如何处理。 Should i compare all fields before submitting them to the pending fields? 在提交给未决字段之前,我应该比较所有字段吗? this way im just storing the fields that are changed. 这样,我只是存储更改的字段。 The downside for this option is that i have to get data from 2 separate tables. 此选项的缺点是我必须从2个单独的表中获取数据。

Any help will be appreciated. 任何帮助将不胜感激。

Thanks in advance! 提前致谢!

I wouldn't create another table for this. 我不会为此创建另一个表。 Just add a version and a status to your user_profile table. 只需在您的user_profile表中添加versionstatus即可。 If the user edit it, create a new record, with a higher version, with a status pending . 如果用户对其进行编辑,请创建一个新记录,该记录具有较高的版本,并且状态为pending You can compare then. 您可以进行比较。 If the admin accepts it, set the status to active and delete or keep the previous one. 如果管理员接受,请将状态设置为active然后删除或保留前一个状态。

Then you can set relationships for both for the User: 然后,您可以为用户设置两者的关系:

public function pendingProfile() {
    return $this->hasOne('UserProfile')
        ->where('status', 'pending')
        ->orderBy('version', 'desc');
}

public function currentProfile() {
    return $this->hasOne('UserProfile')->where('status', 'active');

    // Here you can also take the latest version if you delete any other active, 
    // or add the where and order as above to get the latest
}

If you don't mind adding a new table: 如果您不介意添加新表:

  1. you could store the new values to the extra table and in the main table you could add a column which specifies whether the row has a pending edit. 您可以将新值存储到额外的表中,并且可以在主表中添加一列,以指定该行是否具有待处理的编辑。 When admin approves the changes, the new values are fetched from the extra table and updated into the main table. 管理员批准更改后,将从附加表中获取新值,并将其更新到主表中。
  2. You can immediately update the main table but keep old data in the extra table. 您可以立即更新主表,但将旧数据保留在附加表中。 This way if the admin approves, you simply delete old data and if rejected, the old data is returned. 这样,如果管理员批准,您只需删除旧数据,如果被拒绝,则返回旧数据。 Remember to update the status column 记住要更新状态栏

i suggest the DB structure i have found and asked a question about in this link : in this link 我建议我在此链接中找到并询问有关的数据库结构: 在此链接中

i get a pretty good feed back on this system with saving multiple table changes which every table have their on diffrent structure. 通过保存多个表更改,每个表都有其不同的结构,我在此系统上得到了很好的反馈。 and also i should tell that i am using Zend Frameword.so for users that their changes need admin approval i do not use for example Product model .i uses another mother named ChangeApprovalNeededProduct model that extends Product Model but when calling save method on them i prevent system from saving changes to Product table instead i gather changed data in an key value table and save them somewhere else named Changes table. 而且我还应该告诉我,我正在使用Zend Frameword.so为用户,他们的更改需要管理员批准,我不使用例如产品模型。我使用了另一个名为ChangeApprovalNeededProduct模型的母亲来扩展产品模型,但是当对他们调用保存方法时,我会阻止从保存更改到产品表的系统,而不是我将更改的数据收集在键值表中,并将它们保存在其他名为更改表的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM