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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Can I call a search task from code? (VBO actions -> civicrm search task)
Pages: [1]

Author Topic: Can I call a search task from code? (VBO actions -> civicrm search task)  (Read 710 times)

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Can I call a search task from code? (VBO actions -> civicrm search task)
June 11, 2014, 07:22:18 am
Hi

I have set up a view displaying civicrm-contacts. Utilising the drupal modules "civicrm entity" and "views bulk operations" I'm able to make some custom actions using the civicrm api. As an example the current logged in user can select some contacts in the view, and make them "their" contacts - the action makes a call to civicrm_api("relationship", "create", ...), and the view has an exposed filter, where the user can choose to see only their own contacts or all the contacts. That this is possible is awesome!

Now I would like to make an action doing what the civicrm search task "Mailing Labels" does. Basically I would like to let the user select some contacts in the view, and select a VBO-action "Print Mailing Labels", which sends the user to the same form in civicrm as if you had done a search in civicrm and chosen that task. In the custom action being called by VBO, I have an array with all the chosen contact_id's, and I imagine all the action have to do is give this array to the Label function in civicrm, and voilá ... :) I have looked at the CRM/Contact/Form/Task/Label.php, but I'm a bit lost at how this works, or rather how I would call it with all the right arguments. It could also just skip the civicrm-form all together and just make the labels, as we always use the same settings for printing labels.

Has someone done something like this before?

Cheers and thanks in advance for any help and pointers.
/Anders:)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Can I call a search task from code? (VBO actions -> civicrm search task)
June 11, 2014, 02:53:44 pm
I don't think there's a super easy way to do this with CiviCRM - certainly in the past Pete has simply built the views so that they displayed the result in a label-appropriate way & used a drupal module to print the view into a pdf
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

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Can I call a search task from code? (VBO actions -> civicrm search task)
June 11, 2014, 03:25:35 pm
yep i would still go the way eileen describes - use views to find 'your' contacts, then provide them a PDF option that will print out that list of names but formatted for labels (that will use a different Views display)
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Can I call a search task from code? (VBO actions -> civicrm search task)
June 25, 2014, 04:59:16 am
Thanks as always for your amazingly quick responses.

After seeing CiviCRM's interface for making new address labels for postings, we quite liked it, and decided it would be nice to be able to change labels. We have actually used different and custom designed labels before, but stopped doing it some years back because we had to change a php script and experiment with it, to get it to work on the new labels, every time we changed. With CiviCRM's interface that is a lot more easy. So I did a bit of "hacking" to get it to work:

  • I made a custom action for my view, using aggregation, just to get all the id's of the chosen contacts in the view.
  • I made a custom search in civicrm, taking contact ID's as input, using the SQL clause contact_id IN (contact_id's...).
  • The custom action saves the chosen ID's in session. The view is in a block being build and displayed by a custom module. The module checks for new values from the action saved in session. If it finds a new set of ID's, it loads a colorbox with the custom search page in it, and it sets the deafult search value via php GET. Some javascript in the template for the custom search hides everything, and does the search for you and chooses the search task "print labels" for you. Meanwhile I just display a "please wait" mesage with a throbber.
  • In the end the Print label form is displayed in the colorbox, and the user can choose which label format they want to use, and print the labels.

Not the best solution, but it works, and we can use the print label search task from civicrm together with the view :)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Can I call a search task from code? (VBO actions -> civicrm search task)

This forum was archived on 2017-11-26.