Anyone know how to get a campaign to send to a segment? This code isn't working. It will send an email to all people in the campaign. It will not use the segment. (This is some more text so I can get it to pass the validation of SO.)
My code:
//get member list
$memberArray = $api->listMembers($inStockListId);
foreach ($memberArray['data'] as $member) {
$memberInfo = $api->listMemberInfo($inStockListId, $member['email']);
$_productId = $memberInfo['data'][0]['merges']['PRODUCTID'];
$productId='34';
if ($productId == $_productId) {
array_push($emailArray, $member['email']);
}
}
//create new segment for campaign
$listStaticSegmentId = $api->listStaticSegmentAdd($inStockListId, 'inStockStaticSegment');
//add members to segment
$val = $api->listStaticSegmentMembersAdd($inStockListId, $listStaticSegmentId, $emailArray);
$conditions = array();
$conditions[] = array(
'field' => 'email',
'op' => 'like',
'value' => '%'
);
$segment_options = array(
'match' => 'all',
'conditions' => $conditions
);
$type = 'regular';
$options = array(
'template_id' => $campaignTemplateId,
'list_id' => $inStockListId,
'subject' => 'In-Stock Notification',
'from_email' => 'from#email.com',
'from_name' => 'My From Name'
);
$content = array(
'html_main' => 'some pretty html content',
'html_sidecolumn' => 'this goes in a side column',
'html_header' => 'this gets placed in the header',
'html_footer' => 'the footer with an *|UNSUB|* message',
'text' => 'text content text content *|UNSUB|*'
);
$newCampaignId = $api->campaignCreate($type, $options, $content, $segment_options);
I figured it out. Essentially, here is the flow. If you want detailed code, send me a message and I'll be glad to help.
$api = new MCAPI($this->_apiKey);
$api->listMemberInfo($this->_listId, $member['email']);
$api->listUpdateMember($this->_listId, $member['email'], $mergeVars);
$api->listStaticSegmentDel($this->_listId, $segment['id']);
$api->listStaticSegmentAdd($this->_listId, $segmentName);
$api->listStaticSegmentMembersAdd($this->_listId, $segmentId, $emailArray);
$api->campaignCreate($type, $options, $content, $segment_options);
//$api->campaignSendTest($newCampaignId, array($member['email']));
$api->campaignSendNow($newCampaignId);
Note, this is done via the MailChimp PHP API.
Related
Is it possible to add an image to the gutenber block preview when using ACF to register the block ?
Here's the code to register the block:
acf_register_block(array(
'name' => 'bk-raisons',
'title' => __('Les raisons', 'diezel'),
'description' => __('Les raisons', 'diezel'),
'render_callback' => 'my_acf_block_render_callback',
'category' => 'spira-custom',
'icon' => 'align-wide',
'keywords' => array('bk-raisons'),
));
The preview appears when hovering the block.
Thank you !
I finally found a solution.
I don't know if you use Twig (Timber) or not.
If not check this : https://stackoverflow.com/a/67846162/6696150
For my part with Timber
When you declared your block add example attributes :
$img_quadruple = array(
'name' => 'img-quadruple',
'title' => __('Quatre images'),
'title_for_render' => 'img-quadruple',
'description' => __(''),
'render_callback' => 'ccn_acf_block_render_callback',
'category' => 'imgs',
'icon' => '',
'mode' => 'edit',
'keywords' => array( 'quatre images' ),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'preview_image_help' => get_template_directory_uri().'/assets/img/preview/preview_img_quadruple.jpg',
),
)
)
);
And when your declared your callback :
function ccn_acf_block_render_callback( $block, $content = '', $is_preview = false ) {
$context = Timber::context();
// Store block values.
$context['block'] = $block;
// Store field values.
$context['fields'] = get_fields();
// back-end previews
if ( $is_preview && ! empty( $block['data'] ) ) {
echo '<img src="'. $block['data']['preview_image_help'] .'" style="width:100%; height:auto;">';
return;
} elseif ( $is_preview ) {
echo 'Other condition';
return;
}
// Store $is_preview value.
$context['is_preview'] = $is_preview;
// Render the block.
Timber::render('gutenberg/gut_' . strtolower($block['title_for_render']) . '.twig', $context );
}
I am using Codeigniter 3.x and want to see an update_batch query, but not run it, while I am debugging the code.
This works for an update_batch:
$this->db->update_batch("`" . $this->fullGamesTable . "`", $fullGames, 'gameid');
and updates the database, but I want to view the update and not actually do the update.
Thanks.
Can you do like this
$data = array(
array(
'opt_id' => $hoptid1,
'q_id' => $hid,
'opt_val' => $sin_yes,
'opt_crct' => $sin_yescrt,
'opt_mark' => '1'
),
array(
'opt_id' => $hoptid2,
'q_id' => $hid,
'opt_val' => $sin_no,
'opt_crct' => $sin_nocrt,
'opt_mark' => '1'
)
);
$this->db->update_batch('option', $data, 'opt_id');
Try this
public function update_batch()
{
$data = $this->db->select('id,description')->from('insert_batch')->group_by('url')->get()->result_array();
$batch_update = [];
foreach ($data as $key => $value) {
$value['description'] = 'description';
$batch_update[] = [
'id' =>$value['id'],
'description' => $value['description']
];
}
echo "<pre>"; print_r($batch_update);
$this->db->update_batch('insert_batch',$batch_update,'id');
}
i am using drupal_validate_form on a node listing page .
it is validating it correctly only for 1st item after that it is not checking validation.
here is my code
foreach($result as $r){
$node_form = (object) array(
'uid' => $user->uid,
'type' => 'MY_CONTENT_TYPE',
'language' => LANGUAGE_NONE,
);
$form = drupal_get_form('MY_CONTENT_TYPE_node_form',$node_form);
$form['#submit'] = array('#type' => 'submit', '#value' => t('Next'));
$old_fs = #unserialize($r->form_state);
$old_fs['values']['uid'] = $user->uid;
$node = (object) array(
'uid' => $user->uid,
'type' => 'MY_CONTENT_TYPE',
'language' => LANGUAGE_NONE,
);
node_object_prepare($node);
$form_state = array();
$form_state['build_info']['args'] = array($node);
$form_state['values'] = $old_fs['values'];
$form_state['values']['op'] = t('Save');
$form_state['submitted'] = 1;
$form_state['complete form'] = array();
$form_state['triggering_element'] = array('#parents'=>array('next'),'#button_type'=>'submit');
unset($form['#token']);
drupal_validate_form('MY_CONTENT_TYPE_node_form', $form, $form_state);
$errors = form_get_errors();
$noOfError = 'empty';
if (!empty($errors)) {
$noOfError = count($errors);
}
form_clear_error();
}
thank You in advance
Finally i have to reset need_validation in $form .
Because every time form get for validation it will chack $form['#needs_validation'] in _form_validate();
so i added another line after
$form = drupal_get_form('MY_CONTENT_TYPE_node_form',$node_form);
$form['#needs_validation'] = TRUE;
and it will validate every form in that loop
I have made a drupal 7 site.
I'm looking for a solution for measuring the authors (blog writers, article writers) efficiensy.
I would like to see someweher, how many nodes are created by a user (author) per month and how many letters do these nodes contain.
Can you suggest me a modul or something else?
Thanks,
Tamás
Here is my solution:
<?php
/**
* Implements hook_menu().
*/
function authors_efficiency_menu() {
$items = array();
$items['admin/config/authors_efficiency'] = array(
'title' => 'Own Settings',
'description' => 'Parent item',
'position' => 'left',
'weight' => -100,
'page callback' => 'system_admin_menu_block_page',
'page arguments' => array(),
'access arguments' => array('access administration pages'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
// Need at least one child item before your section will appear.
$items['admin/config/authors_efficiency/efficiency'] = array(
'title' => 'Authors efficiency',
'description' => 'Authors efficiency',
'page callback' => 'authors_efficiency_page_callback',
'page arguments' => array(),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function authors_efficiency_page_callback($para=array()){
$output= '';
// define number of results per page
$num_per_page = 50;
$header = array('User','Month','Count','Length sum','Avarage length');
// define sql to fetch results
$query= db_select('node','n');
$query->condition('n.status', '1');
$query->condition('n.created', (time()-(120*24*60*60)), '>');
$query->join('field_data_body', 'b', 'n.nid = b.entity_id');
$query->join('users', 'u', 'n.uid = u.uid');
$query->condition('b.entity_type', 'node');
$query->addExpression('CONCAT(YEAR(FROM_UNIXTIME(n.created)),\'-\',LPAD(MONTH(FROM_UNIXTIME(n.created)), 2, \'0\'))', 'node_month');
$query->addExpression('SUM(CHAR_LENGTH(b.body_value))', 'node_char_length');
$query->addExpression('COUNT(*)', 'node_count');
$query->fields('n', array('uid'));
$query->fields('u', array('name'));
$query->groupBy('CONCAT(n.uid, \'#\', node_month)');
$query->orderBy('node_month', 'DESC');
$query->orderBy('u.name', 'ASC');
$count_query= db_select('node','n');
$count_query->condition('n.status', '1');
$count_query->condition('n.created', (time()-(120*24*60*60)), '>');
$count_query->addExpression('COUNT(*)', 'node_count');
$count_query->fields('n', array('uid'));
$count_query->groupBy('CONCAT(n.uid, \'#\', CONCAT(YEAR(FROM_UNIXTIME(n.created)),\'-\',LPAD(MONTH(FROM_UNIXTIME(n.created)), 2, \'0\')))');
$count_query = $count_query->countQuery();
$maxCount = $count_query->execute()->fetchField();;
$page = pager_default_initialize($maxCount, $num_per_page);
$offset = $num_per_page * $page;
$query->range($offset, $num_per_page);
$result= $query->execute()->fetchAll();
$rows = array();
foreach($result as $record){
$row = array(
$record->name,
$record->node_month,
$record->node_count,
$record->node_char_length,
round($record->node_char_length/$record->node_count),
);
$rows[] = $row;
}
// Depending on the context there may be a better choice than this
$output.= theme('table', array('header' => $header, 'rows' => $rows));
$output.= theme('pager');
return($output);
}
?>
I am creating a module in which there is a dependency between combo boxes. There are three combo boxes: country, state, and district. If I select India in the country combo box, then the state combo box will contain all states of India, and the same in the case of district.
I have done this by using AJAX. It works properly in add form, but when I am going to update any one, the following error occurs:
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /drupal/?q=system/ajax
StatusText: Service unavailable (with message)
ResponseText: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ajax' in 'where clause': SELECT district_name, country_id,state_id FROM {ajax_district} where id = ajax; Array
(
)
in edit_district_form() (line 291 of /home/mansmu/www/drupal/sites/default/modules/ajaxtest/ajaxtest.district.inc).
My code is:
////////////////////////////////////////////////////////
///////// FUNCTION FOR EDIT
////////////////////////////////////////////////////////
function edit_district_form($form, &$form_state) {
$request_url = request_uri();
// $request_id to get id of edit district.
$request_id = drupal_substr(strrchr($request_url, '/'), 1);
//// FOR country
$rows = array();
$result = db_query("SELECT id,country_name from {ajax_country} order by country_name");
while ($data = $result->fetchObject()) {
$id = $data->id;
$rows[$id] = $data->country_name;
}
//// FOR state
$state = array();
$result = db_query("SELECT id,state_name from {ajax_state} order by state_name");
while ($data = $result->fetchObject()) {
$id = $data->id;
$state[$id] = $data->state_name;
}
// $district_name varible to get name from database for a requested id.
$district_name = db_query("SELECT district_name, country_id,state_id FROM {ajax_district} where id = ".$request_id);
// Loop For show vehicle district name in text field to be update.
foreach ($district_name as $district) {*/
$form['values']['edit_country_name'] = array(
'#type' => 'select',
// '#default_value' => "{$district->country_id}",
'#required' => TRUE,
'#options' => $rows,
'#ajax' => array(
'effect' => 'fade',
'progress' => array('type' => 'none'),
'callback' => 'state_callback_edit',
'wrapper' => 'replace_edit_state',
),
);
$form['values']['edit_state_name'] = array(
'#type' => 'select',
// '#default_value' => "{$district->state_id}",
'#required' => TRUE,
'#options' => array(),
// The prefix/suffix provide the div that we're replacing, named by #ajax['wrapper'] above.
'#prefix' => '',
'#suffix' => '',
);
$form['values']['edit_district_name'] = array(
'#type' => 'textfield',
'#size' => 30,
//'#default_value' => "{$district->district_name}",
'#maxlength' => 80,
'#required' => TRUE,
);
}
$form['edit_district_submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
);
$form['actions']['cancel'] = array(
'#markup' => l(t('Cancel'), 'district'),
);
return $form;
}
////////////////////////////////////////////////////////
///////// FUNCTION FOR AJAX CALL BACK
////////////////////////////////////////////////////////
function state_callback_edit($form, &$form_state) {
// An AJAX request calls the form builder function for every change.
// We can change how we build the form based on $form_state.
if (!empty($form_state['values']['edit_country_name'])) {
$country_id = $form_state['values']['edit_country_name'];
$rows1 = array();
$result = db_query("SELECT id, state_name from {ajax_state} where country_id = $country_id order by state_name");
while ($data = $result->fetchObject()) {
$id = $data->id;
$rows1[$id] = $data->state_name;
}
$form['edit_state_name']['#options'] = $rows1;
}
return $form['values']['edit_state_name'];
}
Your line of code here:
$request_id = drupal_substr(strrchr($request_url, '/'), 1);
is returning the string 'ajax', making your third SQL statement look like this:
SELECT district_name, country_id,state_id FROM {ajax_district} where id = ajax;
Obviously 'ajax' is wrong there, I guess you want a value from the URL? You could use the arg() function to extract this so you don't need to run drupal_substr etc.
If your path is ajax/12 then arg(0) will return 'ajax', arg(1) will return 12 and so on.
Hope that helps
UPDATE
If you need to save the request ID in the form do something like this in your form function:
$form['request_id'] = array('#type' => 'value', '#value' => $request_id);
Then when you get into your ajax callback you can either get it from $form_state['values']['request_id'] or $form['request_id']['#value']