CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • 5.0 Saloon »
  • Doctrine
Pages: [1]

Author Topic: Doctrine  (Read 623 times)

jaapjansma

  • I post frequently
  • ***
  • Posts: 247
  • Karma: 9
    • CiviCoop
  • CiviCRM version: 4.4.2
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.4
Doctrine
March 11, 2014, 02:18:58 am
Hey folks,

As this bit of the forum is where we might discuss a few things for the 5.0 branch. I would really love to see to use doctrine as a database layer. The DAO is then doctrine, the BAO is then entities and using (custom)repository classes to fetch, store and delete objects from the database.

But what should be clear is that we doctrine is not only a database layer, but it is storage engine for storing objects into a relational database. So in doctrine you have to think of classes and objects and the relations between classes, eg UML diagrams and design patterns.

Would love to hear comments on doctrine why we should use it, or why not.
Developer at Edeveloper / CiviCoop

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Doctrine
March 12, 2014, 12:22:59 am
1) Here's a benefit: Doctrine supports lazy-loading -- which I think can be handy in that it reduces the amount of work done in a PHP controller. For example, instead of:

Code: [Select]
// PHP Controller
$contribution = civicrm_api3('Contribution', 'getsingle', array('id' => $123));
$smarty->assign('contribution', $contribution['values']);
$contact = civicrm_api3('Contact', 'get', array('id' => $contribution['values']['contact_id'));
$smarty->assign('contact', $contact);
// Smarty Template
{$contact.display_name} donated {$contribution.total_amount} dollars.

One can say:

Code: [Select]
// PHP Controller
$smarty->assign('contribution', $entityManager->find('Civi\Contribution', 123));
// Smarty Template
{$contribution->getContact()->getDisplayName()} donated {$contribution->getTotalAmount()} dollars.

Thus, in several simple/boring use-cases, it's not necessary to write so many explicit loading calls (with civicrm_api3 or {crmAPI}) -- you can get related data by simply traversing the relationship.

2. There's been a chunk of progress at https://github.com/civicrm/civicrm-core/tree/doctrine/ . Specifically, we've been experimenting with (1) defining the full/correct data model with Doctrine annotations, (2) updating the event-registration form to use Doctrine instead of DAO, and (3) creating a basic REST API based on Doctrine entities (instead of BAO/APIv3).

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • 5.0 Saloon »
  • Doctrine

This forum was archived on 2017-11-26.