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

Describe the issue or problem
How to create a new Entity? (with DataObject, schema, DAO, Repository…)

I need to create an Entity through a plugin, but don’t know exactly how to do it.
It would be great to have a tutorial or template adding a new Entity and all the stuff.

The unique similar plugin I found is staticPages. However, it does not follow the new patterns from OJS 3.4 nor use the JSON Schema.

Suppose I want to create an Entity called Square with id, name, color and size. I guess the plugin files would be like (I omit the locale and settings files):


Am I correct? If so, I may fill my JSON Schema file properly, the Square.php would be almost an empty class inheriting DataObject.

And then, what?

  • What do I must implement in DAO.php to have at least CRUD operations?
  • How to load/link the JSON Schema?
  • What would be in Repository and how would it be to perform the simple CRUD? (maybe get many)

I read the docs about it, but seems more like using/extending existing ones. Also, the Doxygen for 3.4 would help.

What application are you using?
OJS 3.4

Hi @henriquejsfj,

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

  • Old patterns extending lib/pkp/classes/db/ 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.

Alec Smecher
Public Knowledge Project Team

1 Like