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
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?
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.:
- EntityDAO models (extending
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.
Public Knowledge Project Team