Plugin: How to create a new Entity? (with DataObject, schema, DAO, Repository...)

Hi @henriquejsfj,

We have a few database persistence models fighting for supremacy at the moment…

  • Old patterns extending lib/pkp/classes/db/DAO.inc.php: These are not recommended for new code, but will be available for a long time. As you’ve noted, the static pages plugin uses this pattern.
  • Eloquent models, e.g.:
    • lib/pkp/classes/userGroup/relationships/UserGroupStage.php
    • lib/pkp/classes/userGroup/relationships/UserUserGroup.php
  • EntityDAO models (extending lib/pkp/classes/core/EntityDAO), e.g.:
    • lib/pkp/classes/announcement/DAO.php
    • lib/pkp/classes/author/DAO.php
    • lib/pkp/classes/category/DAO.php
    • lib/pkp/classes/decision/DAO.php
    • lib/pkp/classes/doi/DAO.php
    • lib/pkp/classes/emailTemplate/DAO.php
    • lib/pkp/classes/galley/DAO.php
    • lib/pkp/classes/institution/DAO.php
    • lib/pkp/classes/log/event/DAO.php
    • lib/pkp/classes/publication/DAO.php
    • lib/pkp/classes/section/DAO.php
    • lib/pkp/classes/submission/DAO.php
    • lib/pkp/classes/submissionFile/DAO.php
    • lib/pkp/classes/user/DAO.php
    • lib/pkp/classes/userGroup/DAO.php

I don’t yet know of any plugins implementing the EntityDAO toolset or using Eloquent models, but depending on your needs you can follow either of those models. If you need to expose your entity through the API, I would recommend using EntityDAO.

You’ll be pioneering the use of these in plugins, so you might start by coding it as new classes parallel to an existing example, then moving it into a plugin when you’ve got the basics figured out. I’d be happy to comment on the code if you try that.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like