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) »
  • Custom script to create a mailing
Pages: [1]

Author Topic: Custom script to create a mailing  (Read 1092 times)

dragontree

  • Guest
Custom script to create a mailing
December 17, 2009, 02:41:54 am
I want to use the Joomla send article link function to also be able to create a mailing in civimail.
I added a checkbox for that. So if the user checks it, then he/she will be redirected to the first step of the new mailing.
The trick is that when the user gets to the mailing wizard, the mailing should already have been created and the Joomla article content added as html_body for the mailing.

This doesn't sound that hard to do, right?
I created ArticleToMailing.php to the civi bin directory. In that file i have the following code:
Code: [Select]
<?php
session_start
();
require_once 
'../civicrm.config.php';
require_once 
'CRM/Mailing/BAO/Mailing.php';

$articleId=CRM_Utils_Array::value( 'article_id', $_REQUEST);
$query = "SELECT introtext FROM jos_content WHERE id = $articleId";
$dao =& CRM_Core_DAO::executeQuery( $query, CRM_Core_DAO::$_nullArray );
$dao->fetch( );

$params['body_html'] = $dao->introtext;;
$params['created_date'] = date('YmdHis');
$params['name']=CRM_Utils_Array::value( 'subject', $_REQUEST);
$params['created_id']=CRM_Utils_Array::value( 'user_id', $_REQUEST);

$mailing = CRM_Mailing_BAO_Mailing::create($params, $ids);
?>

Nothing complex really.
I don't get any error messages and the mailing is added to the database.
BUT the mailing doesn't show up in the drafts so I cannot edit it.
What am I missing?

dragontree

  • Guest
Re: Custom script to create a mailing
December 17, 2009, 03:25:31 am
Thanks to kurund, I got it working.

The problem was that $params['groups'] is also a required parameter.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Custom script to create a mailing
December 17, 2009, 05:12:34 am
I've asked this before - but how are you supposed to know what the required parameters are for any given function? It doesn't seem right that you should have to unpick the code to figure it out but the standard for documentation appears to be just to give the name of the array.

How do the wise ones of the core team know - what's the secret because I'm sure it's not reverse engineering the code to figure out what must be passed in.
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: Custom script to create a mailing
December 17, 2009, 06:49:25 am

we need to do a better job writing code documentation for various functions and classes. We basically do a lot of code and function checking and its gets easier once u know the code base

wanna help lead the code documentation project?

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Custom script to create a mailing

This forum was archived on 2017-11-26.