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 (Moderator: Donald Lobo) »
  • RFC: Cheatsheet for application developers
Pages: [1] 2

Author Topic: RFC: Cheatsheet for application developers  (Read 3161 times)

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
RFC: Cheatsheet for application developers
March 17, 2011, 09:07:31 pm
At tonight's meetup in Washington, DC, one topic that came up is that some third-party developers implement PHP customizations using the Drupal API's (e.g. db_query) instead of Civi API's (e.g. CRM_Core_DAO). In my own experience, the reason I do this is because Drupal's community provides more robust developer documentation. Unfortunately, this has a few negative side-effects:

 * Code contains a mix of naming and formatting conventions (e.g. Drupal-style and Civi-style), making it harder to read and write.
 * Code is unnecessarily CMS-dependent. It works on Drupal -- but not Joomla (or standalone or Word Press, when/if that's implemented).
 * Code is not very suitable for sharing across organizational lines.

There has obviously been some good work going into improving the developer documentation -- with particular improvements for key use-cases (e.g. creating a custom CiviReport). But I haven't found a resource documenting the meat-and-potatoes of web application development -- e.g. defining new web controllers or executing SQL queries. The best option I've found is reading/grep'ing the current codebase for examples.

Based on that experience, I've written a first draft of a cheatsheet for PHP developers working with CiviCRM and/or Drupal -- a collection of small code snippets and hyperlinks organized around topics that any PHP application developer should recognize (e.g. "Logging", "SQL Query", "Web Forms"). It's pretty rough and very terse, but it might be useful for other devs:

h t t p : / / arms.dl.locker10.com/devel-doc/cheatsheet.html

Anyway, I'd appreciate any reactions/feedback/contributions.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: RFC: Cheatsheet for application developers
March 18, 2011, 12:48:43 am
Hi,

CRM_Core_DAO is not meant as an API (as in "to be used by external code") but more an internal tool (that's "just" a wrapper around the DB).

We recommend avoiding accessing directly the DB (as the schema might change between versions, that you might miss a hidden relation and forget to update related tables...).

We have a "real" API, that exposes higher level entities, and provide get, create and delete methods. (if you pass the id as param to the create, it's an update)

That is described in our book http://en.flossmanuals.net/civicrm/ch066_api and in the wiki http://wiki.civicrm.org/confluence/display/CRMDOC33/CiviCRM+Public+APIs

And  we have massively improved it for the forthcoming 3.4

http://civicrm.org/API_version_3

Let us know if something is missing and better still join us in our work of updating the wiki, so you can shape it the way you think is the most efficient!

Backporting the api 3 to an existing install is trivial (a few files to copy), and I would suggest you to do it if you start a new project.

X+

P.S. If you want more information about the architecture (that is quite a different logic than drupal), read the older blog posts on the architecture serie, it was very helpful for me
http://civicrm.org/category/civicrm-blog-categories/civicrm-architecture-series
« Last Edit: March 18, 2011, 11:32:39 am by xavier »
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: RFC: Cheatsheet for application developers
March 19, 2011, 01:15:16 am
Please don't read too much into the fact that I used "db_query/CRM_Core_DAO" as examples. Yes, api/v2 and api/v3 provide a safer way to CRUD current entities. Yes, api/v3 looks like a big improvement. And I hope to find an opportunity to try it out.             

Also, there is some good material/insights spread out among the flossmanual, the wiki, and the blog.  And where those fall short, one can often figure something out by critically reading Civi's code for 20 minutes.  I've been through that process.  Several times.

My feeling was that Civi's developer documentation is somewhat narrow -- it's decent-to-strong on some important points (e.g.  entity CRUD) and weak-to-non-existent on others (e.g.  pageflow mechanics).  Properly filling those gaps obviously requires a good chunk of work -- work whose value is debtable on a micro level ("Why should someone spend several hours writing about pageflow mechanisms?"). Anyway, the point of the draft cheatsheet was to try to cover broader ground in a concise and low-effort way.

The idea of joining in a wiki update project sounds nice in principle, but I'm not sure what it means in reality.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: RFC: Cheatsheet for application developers
March 19, 2011, 03:22:19 am
Quote from: totten on March 19, 2011, 01:15:16 am

My feeling was that Civi's developer documentation is somewhat narrow -- it's decent-to-strong on some important points (e.g.  entity CRUD) and weak-to-non-existent on others (e.g.  pageflow mechanics).  Properly filling those gaps obviously requires a good chunk of work -- work whose value is debtable on a micro level ("Why should someone spend several hours writing about pageflow mechanisms?"). Anyway, the point of the draft cheatsheet was to try to cover broader ground in a concise and low-effort way.

Agree. I think that template, hook, api is well covered.

I'm not sure trying to document more the internals (DB_Object, quick form...) is really worthwhile the effort, as it will be replaced sooner? than later by more modern components. Mixed feelings on that one.

Quote from: totten on March 19, 2011, 01:15:16 am
The idea of joining in a wiki update project sounds nice in principle, but I'm not sure what it means in reality.

Could you join the Api list ? We are going to discuss specifically the api part, and where it fits with the other civicrm/ajax/doc, autogenerated examples and the book.

http://lists.civicrm.org/lists/subscribe/civicrm-api
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: RFC: Cheatsheet for application developers
March 19, 2011, 03:24:02 am
Quote from: totten on March 19, 2011, 01:15:16 am

My feeling was that Civi's developer documentation is somewhat narrow -- it's decent-to-strong on some important points (e.g.  entity CRUD) and weak-to-non-existent on others (e.g.  pageflow mechanics).  Properly filling those gaps obviously requires a good chunk of work -- work whose value is debtable on a micro level ("Why should someone spend several hours writing about pageflow mechanisms?"). Anyway, the point of the draft cheatsheet was to try to cover broader ground in a concise and low-effort way.

Agree. I think that template, hook, api is well covered.

I'm not sure trying to document more the internals (DB_Object, quick form...) is really worthwhile the effort, as it will be replaced sooner? than later by more modern components. Mixed feelings on that one and I'm not quite sure how it vould boiled down to fit on a cheatsheet?

Quote from: totten on March 19, 2011, 01:15:16 am
The idea of joining in a wiki update project sounds nice in principle, but I'm not sure what it means in reality.

Could you join the Api list ? We are going to discuss specifically the api part, and where it fits with the other civicrm/ajax/doc, autogenerated examples and the book.

http://lists.civicrm.org/lists/subscribe/civicrm-api
« Last Edit: March 19, 2011, 05:34:04 am by xavier »
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: RFC: Cheatsheet for application developers
March 19, 2011, 04:45:04 am
Hi,

I took a look at your cheatsheet & I think there is some good stuff in there.

At the moment the wiki structure is a problem as I see it. I rarely browse successfully to what I am looking for & search it using google. (civisearch is good but I can never remember how to get to it)

It would be great to get some momentum on improving developer documentation & working your stuff into the wiki. Obviously anyone can edit the wiki but ideally we would have a few people bouncing ideas off each other on it.

We would love you to contribute to the api documentation we need to work on - at least there is some momentum around that - which makes it a bit easier. Alternatively you might put some thought / time into making the other dev stuff on the wiki more logical.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: RFC: Cheatsheet for application developers
March 19, 2011, 06:01:39 am
Hi,

Sorry, didn't "click" on the link (for those as blind as I am ;):
http://arms.dl.locker10.com/devel-doc/cheatsheet.html

In understand much better what you want to do/have done. I also think that's very helpful for the drupalers to translate between their framework and civi. Would be great to have someone from joomla adding their part. Some comments (I'm sure you have most of them already)

Usability suggestion: instead of radio buttons for the topics, simply put a link on their name

Design suggestion: would be nice to apply a nice theme (eg one from jquery-ui ?), http://visualjquery.com/ was always opened on a tab when I started jquery, in no small part because it was looking pretty

Content suggestion: the api is documenting the v2, would be great to put the v3 syntax first and add an "obsoleted" warning on the v2

API : I think http://sandbox.civicrm.org/civicrm/ajax/doc (and that's on every civi install as of 3.4) is cheating enough to be mentioned ;)

About: CiviCRM: Extras: Data Access
* CiviCRM lacks an API for searching activities. arms_util_activity_search($params) fills this gap.

In theory, get actions have searching/filtering/paging features.
So far, contact is more advanced than the other entities, but I think lobo & Eileen are working on Activity.get soon (this week-end ?).

Anyway, whomever needs search options that aren't there are more than welcome to step in and add them to the get action (and so beside the api, that's also available on smarty and as web service).

X+

P.S. What is arms?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: RFC: Cheatsheet for application developers
March 19, 2011, 01:09:43 pm
but I think lobo & Eileen are working on Activity.get soon (this week-end ?).


I think Lobo agreed to do it for 4.1 so .... no
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xcf33

  • I post frequently
  • ***
  • Posts: 181
  • Karma: 7
  • CiviCRM version: 3.3.2
  • CMS version: Drupal 6.19/6.20
  • MySQL version: 5.x
  • PHP version: 5.2.6
Re: RFC: Cheatsheet for application developers
March 19, 2011, 02:26:55 pm
Tim, I think a cheat sheet or more robust Documentation for developers would be welcomed.

I love the way Drupal's API website is structured, I hope that's something that Civi can copy.

Some of the sentiment is echoed again with regarding to a lot of useful functions that CiviCRM provides.

i.e. PseudoConstant, Utils, etc etc.

Just a map of all the (static) methods, even if they are generated from reflection documentation in PHP would be helpful to developers beyond using the hooks and APIs.



Cheers!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: RFC: Cheatsheet for application developers
March 19, 2011, 02:29:10 pm
You get a free T-shirt if you want to form a documentation team & work on it!
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: RFC: Cheatsheet for application developers
March 19, 2011, 03:28:30 pm

Seems like the the clouds are lining up, the moon and sun are in alignment and the atmosphere has the right atomic mix for the formation of a documentation team :)

Lets get it started. As with everything else, lets start it small and focussed. get the doc site running, commit to writing good phpdoc stuff for the important core files and them figure out other things from there

glad to hear eileen promising t-shirts. I'll take a large please :P

lobo

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: RFC: Cheatsheet for application developers
March 22, 2011, 06:06:21 pm
I concur with @changx and would take it a step further that it would be useful to go ahead and document some of the form/page workflow (ie preprocess->build->defaults->rules-> postprocess).  Regardless of whether or not we plan on replacing it.  for two simple reasons we may not replace it for a year or more and two the need is huge. 

I'm perfectly capable of reading the code, and frequently do, but having a basic primer would have saved my 100's or hours over the last couple of years.
http://www.rootyhollow.com

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: RFC: Cheatsheet for application developers
March 23, 2011, 01:40:14 am
1. I've made a few updates to the cheatsheet based on xavier's comments (e.g. change radio buttons to hyperlinks, reference API v3).

2. On the topic of documentation vs. major refactoring... I tend to agree with jalama. Unless there are concrete plans to overhaul several layers in the next 3 months, documentation about the status quo will still be valuable -- esp.  considering how much infrastructure has remained the same between CiviCRM 2.x - 4.x.

3. On the topic of phpdoc... I hadn't run phpdoc on the CiviCRM codebase before, but I did tonight.  It seems to be pre-configured to focus on the api v3 functions -- which I guess is used to build http://api.civicrm.org/v3/.  How is that site published now? I wouldn't mind throwing together some scripts to auto-publish nightly documentation sets for APIs+core on each branch.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: RFC: Cheatsheet for application developers
March 23, 2011, 01:47:06 am
Re phpdoc - Michau Mach set that up - if you can catch him on IRC he'd be the person to talk to.

In general, have you looked through the wiki / had any thoughts about how that might be better structured/ whether it's possible to incorporate some of your work / ideas into it?

I really like what you are doing but if you host it yourself you'll also have to maintain it yourself
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: RFC: Cheatsheet for application developers
March 23, 2011, 02:41:30 am
Quote from: Eileen on March 23, 2011, 01:47:06 am
Re phpdoc - Michau Mach set that up - if you can catch him on IRC he'd be the person to talk to.

OK, thanks.

Quote from: Eileen on March 23, 2011, 01:47:06 am
In general, have you looked through the wiki / had any thoughts about how that might be better structured/ whether it's possible to incorporate some of your work / ideas into it?

I really like what you are doing but if you host it yourself you'll also have to maintain it yourself

I'll try to look at that in the next 24-48 hours. I do really like the idea of putting the content in a wiki so that others can edit it, but I need to play around with Confluence a bit. I feel that the little things (e.g. hyperlinks within code snippets, syntax highlighting, navbars) have a big cumulative affect on the way we read and write, and I need to understand Confluence's presentation options better.

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • RFC: Cheatsheet for application developers

This forum was archived on 2017-11-26.