php sprintf not working as expected - php

$actions = array(
'EDIT' => sprintf('Edit',
'abf_cm',
'edit_course',
$item['course_id'],
'thickbox edit-box',
'edit_'.$item['course_id']
),
'DELETE' => sprintf('Delete','course_management','do_process','delete',$item['course_id']),
);
In doing so, the edit part is not being displayed.Am i doing anything wrong.
I also tried using the placeholders
'EDIT' => sprintf('Edit',
'abf_cm',
'edit_course',
$item['course_id'],
'thickbox edit-box',
'edit_'.$item['course_id']
),
but still no results. I also noticed that when i remove the class and id attributes in the earlier version, then it works fine.
Can you please give me a satisfactory explanation of this and tell me where am i doing wrong.
EDIT:
Im using this inside Wordpress for creating custom table using WP_List_Table class
function column_course_name($item ) {
//Build row actions
$actions = array(
'EDIT' => sprintf('Edit',
'abf_cm',
'edit_course',
$item['course_id'],
'thickbox edit-box',
'edit_'.$item['course_id']
),
'DELETE' => sprintf('Delete','book_management','do_process','delete',$item['course_id']),
);
//Return the title contents
return sprintf('%1$s%3$s',
/*$1%s*/ strlen($item['course_name'])>0?$item['course_name']:'<span style="color:silver">(No Name)</span>',
/*$2%s*/ $item['course_id'],
/*$3%s*/ $this->row_actions($actions) //row_actions is a method in this class
);
}
update:
Well, its strange to mention but the code works when i use a single class( ie when i delete the space between the two classes for the tag) .
Any thoughts?

Dipesh, maybe you have errors in the code around this snippet.
Try to check your code in isolation. I copied your code to the separate .php script with little set-up and checked $actions array with print_r, like this:
edit_array.php
<?php
$item = array();
$item['course_id'] = 1;
$actions = array(
'EDIT' => sprintf('Edit',
'abf_cm',
'edit_course',
$item['course_id'],
'thickbox edit-box',
'edit_'.$item['course_id']
),
'DELETE' => sprintf('Delete','course_management','do_process','delete',$item['course_id']),
);
print_r($actions);
I ran this script from console and got the following results:
$ php edit_array.php
Array
(
[EDIT] => Edit
[DELETE] => Delete
)
Generated link for $actions['EDIT'] is HTML valid, so one can safely conclude that your code itself is working fine, and error lies somewhere else.

Related

php function gives a loop - hostfact API

I'm using hostfact https://www.hostfact.nl for our billing. Now I want to extend the code and get a loop on executing the internalAPI in hooks.php. I tried to find an answer in the documentation https://www.hostfact.nl/developer/api/ but without success.
// When a client is edited, the bankParameters are checked and validated.
// That is only an example
function action_debtor_is_edited($parameters){
$params = array(
'DebtorCode' => $parameters['DebtorCode']
);
$hostfactResult = internalAPI('debtor', 'show', $params);
$bankParams = array(
'Identifier' => '2',
'AccountNumber' => 'AT6734080000000000',
'AccountBank' => 'test bank',
'AccountCity' => 'city',
'AccountBIC' => 'RLNODASD'
);
$bankResult = internalAPI('debtor', 'edit', $bankParams);
}
I've already asked the support and got follwoing answer:
One of the option is keeping track of the situation. For example, use
a static or global variable. When you call an (internal)API call from
a webhook, first flag that variable, so in the newly called webhook
you know that is not needed to execute the webhook again (at least not
the part which causes the loop). In the original call, after receiving
the result, the flag can be unset again.
My Problem is, I'm new to PHP and don't understand what I should do to avoid the loop. The $bankParams variable is intentionally hardcoded.
Can you help?

Drupal 7 collapsible fieldset issues with ajax

I am sending data via ajax to my PHP callback function inside my custom module... Everything is working great. The problem I am having is: the html i am returning and rendering in the ajax complete funciton is composed of fieldsets which wont expand/collapse. Things i have tested :
1). If I render the same html ( fieldsets ) into one of the custom blocks in that same module, they work great, the collapse and expand.
2). I have tried including this inside the callback function,
drupal_add_js('misc/form.js');
drupal_add_js('misc/collapse.js');
inside the fieldset render array,
return array(
'#type' => 'fieldset',
'#title' => t($title),
'#attributes' => array(
'class' => $class,
),
'#attached' => array(
'js' => array(
'misc/form.js',
'misc/collapse.js',
),
),
);
The
$class
variable contains collapsed and collapsible. I have also tried using
#theme => 'fieldset'
Instead of #type => 'fieldset'
the javascript files
misc/collapse.js
misc/form.js
are already being included from a different function inside my module. And looking at the source of the page, are indeed being included to the head of the page.
This has to be related to bringing them in via ajax, I know when you bring elements into the document via ajax, in-order to set events for those new elements you have to use
$(document).on('event', 'class', function(){
//code here
});
and I am wondering if this could be the reason that the fieldsets wont collapse/expand.
If you get data with AJAX with jQuery once you have to use Drupal.behaviors like this:
Drupal.behaviors.MYBEHAVIOR = {
attach: function (context, settings) {
$('MYELEMENT.MYBEHAVIOR', context).once('MYBEHAVIOR', function () {
// Apply the MYBEHAVIOR effect to the elements only once.
});
}
};
See more at the js documentation https://drupal.org/node/756722

Yii php: Displaying a widget in a Tab

i've been using Yii framework for some time now, and i've been really having a good time especially with these widgets that makes the development easier. I'm using Yii bootsrap for my extensions..but i'm having a little trouble understanding how each widget works.
My question is how do i display the widget say a TbDetailView inside a tab?
i basically want to display contents in tab forms..however some of them are in table forms...some are in lists, detailviews etc.
I have this widget :
$this->widget('bootstrap.widgets.TbDetailView',array(
'data'=>$model,
'attributes'=>$attributes1,
));
that i want to put inside a tab
$this->widget('bootstrap.widgets.TbWizard', array(
'tabs' => $tabs,
'type' => 'tabs', // 'tabs' or 'pills'
'options' => array(
'onTabShow' => 'js:function(tab, navigation, index) {
var $total = navigation.find("li").length;
var $current = index+1;
var $percent = ($current/$total) * 100;
$("#wizard-bar > .bar").css({width:$percent+"%"});
}',
),
and my $tabs array is declared like this :
$tabs = array('studydetails' =>
array(
'id'=>'f1study-create-studydetails',
'label' => 'Study Details',
'content' =>//what do i put here?),
...
...);
when i store the widget inside a variable like a $table = $this->widget('boots....);
and use the $table variable for the 'content' parameter i get an error message like:
Object of class TbDetailView could not be converted to string
I don't quite seem to understand how this works...i need help..Thanks :)
You can use a renderPartial() directly in your content, like this:
'content'=>$this->renderPartial('_tabpage1', [] ,true),
Now yii will try to render a file called '_tabpage1.php' which should be in the same folder as the view rendering the wizard. You must return what renderPartial generates instead of rendering it directly, thus set the 3rd parameter to true.
The third parameter that the widget() function takes is used to capture output into a variable like you are trying to do.
from the docs:
public mixed widget(string $className, array $properties=array ( ), boolean $captureOutput=false)
$this->widget('class', array(options), true)
Right now you are capturing the object itself in the variable trying to echo out an object. Echo only works for things that can be cast to a string.

SugarCRM REST API set_relationship between Quote and ProductBundles

I am using SugarCRM Pro 6.5.5
I need to create a Quote and add Products to it with the REST API. All bundles > Prof the set_entry's work, and the set_relationship for ProductBoducts works fine. But, set_relationship for Quotes > ProductBundles does not work.
Here is my input for ProductBundles > Products: this works fine
{
"session":"5qklti658f0ooou135vt8fkbi4",
"module":"ProductBundles",
"module_id":"50b71673-b555-9d68-04c9-508ef9582f47",
"link_field_name":"products",
"related_ids":[
"a9615ab1-cd89-1549-f9b8-508f00c6fa84"
]
}
Here is my input for Quotes > ProductBundles: this does not work
{
"session":"jqodi1pu8u2l8basca1hhcbt27",
"module":"Quotes",
"module_id":"bc01a88a-35c9-25ed-dfac-508ef206a264",
"link_field_name":"product_bundles",
"related_ids":[
"50b71673-b555-9d68-04c9-508ef9582f47"
]
}
BUT it still returns:
{
"created":1,
"failed":0,
"deleted":0
}
But, no record is created in the product_bundle_quote table.
I have dug into the Sugar code a little, and found something interesting.
In service/core/SoapHelperWebService.php on line 735, is this:
$mod->$link_field_name->add($related_ids, $name_value_pair);
Which calls the add method in file data/Relationships/M2MRelationship.php on line 118. Interestingly, $lhsLinkName is NULL, which causes the method to return false. Here is a snippet:
public function add($lhs, $rhs, $additionalFields = array())
{
$lhsLinkName = $this->lhsLink;
$rhsLinkName = $this->rhsLink;
if (empty($lhs->$lhsLinkName) && !$lhs->load_relationship($lhsLinkName))
{
$lhsClass = get_class($lhs);
$GLOBALS['log']->fatal("could not load LHS $lhsLinkName in $lhsClass");
return false;
}
if (empty($rhs->$rhsLinkName) && !$rhs->load_relationship($rhsLinkName))
{
$rhsClass = get_class($rhs);
$GLOBALS['log']->fatal("could not load RHS $rhsLinkName in $rhsClass");
return false;
}
It returns FALSE in the first if() block, which means the record is never created.
Also, this shows up in my log:
[2139][1][FATAL] could not load LHS in ProductBundle
So yeah, I'm stuck here. I tried searching for everything I could, including the error, but I haven't found anything helpful.
This is a Sugar bug, which will be fixed in the 6.7 release. In the meantime, check out this forums post for the code fix.
http://forums.sugarcrm.com/f6/create-quote-line-items-web-service-api-83183/
This does turn out to be a Sugar Bug, but not the one in the other answer. It's actually related to this bug: Bug 32064. They were able to provide me with a custom module that I could upload and activate to address the issue before release 6.7 when this is slated to be addressed officially. You'll probably want to contact SugarCRM directly for this workaround, depending on your time frame.
I was having the same issue and in order to resolve that i added the below mentioned code in product bundles vardef and it's start working fine.
'quotes' =>
array (
'name' => 'quotes',
'type' => 'link',
'vname'=>'LBL_PRODUCT_BUNDLES',
'relationship' => 'product_bundle_quote',
'source'=>'non-db',
),
Thanks!
You have to link the quote to products too.
make sure in your quote vardef there's the following:
'products' =>
array (
'name' => 'products',
'type' => 'link',
'relationship' => 'quote_products',
'vname' => 'LBL_PRODUCTS',
'source'=>'non-db',
),
and in your webservice, set the relationship between quote and products
{
"session":$session_id,
"module":"Quotes",
"module_id":$quote_id,
"link_field_name":"products",
"related_ids":[
$product_id
]
}
It works for me.

How do I set the 'value' in my Zend form checkbox?

The Zend Form is proving to be a bit tricky for me, even as much as I am working with it lately...
I have this form and I am attempting to dynamically create the several checkboxes for it. It is working out alright, except I cannot seem to get the 'value' attribute to change.
In my Zend form class I have this snippet...
// psychotic symptoms
$this->addElement('checkbox', 'psychoticsymptom', array(
'label' => 'psychoticsymptom',
'name' => 'psychoticsymptom',
));
In my view (phtml) I am calling it like this...
<div class="element">
<?php // Psychotic Symptoms
$Criteria = new Criteria();
$Criteria->add( DictionaryPeer::CATEGORY, 'MAR: Psychotic Symptoms' );
$Criteria->addAscendingOrderByColumn( 'Ordinal' );
$this->PsychoticSymptomsList = DictionaryPeer::doSelect( $Criteria );
foreach( $this->PsychoticSymptomsList as $Symptom ) {
$form->psychoticsymptom->setValue($Symptom->getDictionaryId());
$form->psychoticsymptom->setAttrib('name', $Symptom->getWord());
echo $Symptom->getDictionaryId(); // prove my id is coming through... (it is)
$form->psychoticsymptom->getDecorator('label')->setTag(null);
echo $form->psychoticsymptom->renderViewHelper();
$form->psychoticsymptom->setLabel($Symptom->getWord());
echo $form->psychoticsymptom->renderLabel();
echo '<br />';
}
?>
</div>
Everything seems to be working fine, except the value attribute on each checkbox is rendering a value of '1'. I have tried moving the 'setValue' line to several different positions, as to set the value before the form element renders but I am having no luck getting this to work. It's worth any effort to me because I need to do the same type of operation in many areas of my application. I would have done this a bit different too, but I am re-factoring another application and am trying to keep some things unchanged (like the database for instance).
Any help is much appriciated
Thanks
you can try to overwrite the "checkedValue" and "uncheckedValue". check this reference
$this->addElement('checkbox', 'psychoticsymptom', array(
'label' => 'psychoticsymptom',
'name' => 'psychoticsymptom',
'checkedValue' => 'checked Value',
'uncheckedValue' => 'unchecked Value'
));
You seem to only have one psychoticsymptom element "checkbox" which your adding (changing) the value too for each $this->PsychoticSymptomsList.
Maybe you would be better off using a multicheckbox element instead.

Categories