How to pass two parameters to a select to a SELECT query in vtiger? - vtiger

I would like to pass two parameters to a SELECT query for one scenario in a vtiger custom function. Like below ..
function start_date($projectid, $stage){
$adb = PearDatabase::getInstance();
$stage = "Stage-0";
$data = $adb->pquery("SELECT startdate FROM vtiger_projecttask WHERE projectid = ?", array($projectid), array($stage);
$num_rows = $adb->num_rows($data);
for($i=0; $i<$num_rows; $i++) {
$col3[$i] = $adb->query_result($data, $i,'startdate');
}
}
But it is not allowing me to execute this type of query. How can i form a query with two parameters in vtiger?
Thanks and Regards.

Please try this code as below. This will work.
function start_date($projectid, $stage){
$adb = PearDatabase::getInstance();
$stage = "Stage-0";
$data = $adb->pquery("SELECT startdate FROM vtiger_projecttask WHERE projectid = ? and stage = ?", array($projectid,$stage));
$num_rows = $adb->num_rows($data);
for($i=0; $i<$num_rows; $i++) {
$col3[$i] = $adb->query_result($data, $i,'startdate');
}
}

Related

Assign database value to Django variable

Looking to do something like this is Django:
$price = mysql_query("SELECT price FROM products WHERE product = '$product'");
$result = mysql_fetch_array($price);
If $result['price'] == 1:
do something
My thought was something like below but seems to be way off:
item = Order.objects.get(quote_number = quotex)
price = item.quote_status
headers = {
# Already added when you pass json= but not when you pass data=
# 'Content-Type': 'application/json',
'X-API-KEY': '',
}
messages.success(request, price)
if price == 2:
Price == 2 does not see the number 2 where messages 2 on price var
please note this is not being used to output to a template, as I already know how to do that.

how to generate glossary ID through google cloud api

Share me the screenshot where and how to generate glossary id through google cloud and i have code in php
THIS IS MY CODE:-
$translationServiceClient = new TranslationServiceClient();
/** Uncomment and populate these variables in your code */
$text = 'Hello, world!';
$sourceLanguage = 'en';
$targetLanguage = 'fr';
$projectId = env('project_id');
$glossaryId = 'manual-translate-automl';
$glossaryPath = $translationServiceClient->glossaryName(
$projectId,
'us-central1',
$glossaryId
);
$contents = [$text];
$formattedParent = $translationServiceClient->locationName(
$projectId,
'us-central1'
);
$glossaryConfig = new TranslateTextGlossaryConfig();
$glossaryConfig->setGlossary($glossaryPath);
// Optional. Can be "text/plain" or "text/html".
$mimeType = 'text/plain';
try {
$response = $translationServiceClient->translateText(
$contents,
$targetLanguage,
$formattedParent,
[
'sourceLanguageCode' => $sourceLanguage,
'glossaryConfig' => $glossaryConfig,
'mimeType' => $mimeType
]
);
// Display the translation for each input text provided
foreach ($response->getGlossaryTranslations() as $translation) {
printf('Translated text: %s' . PHP_EOL, $translation->getTranslatedText());
}
} finally {
$translationServiceClient->close();
}

How to do a MaxBy in RavenDb MapReduce

Using the Northwind database from RavenDB tutorial I'm trying to group orders by employee and get the most resent order for every employee.
Map:
from order in docs.Orders
select new {
Employee = order.Employee,
Count = 1,
MostRecent = order.OrderedAt,
MostRecentOrderId = order.Id
}
Reduce with nonexisting MaxBy:
from result in results
group result by result.Employee into grp
select new {
Employee = grp.Key,
Count = grp.Sum(result => result.Count),
MostRecent = grp.Max(result => result.MostRecent),
MostRecentOrderId = grp.MaxBy(result => result.MostRecent).MostRecentOrderId,
}
Reduce attempt:
from result in results
group result by result.Employee into grp
let TempMostRecent = grp.Max(result => result.MostRecent)
select new {
Employee = grp.Key,
Count = grp.Sum(result => result.Count),
MostRecent = TempMostRecent,
MostRecentOrderId = grp.First(result => result.MostRecent == TempMostRecent).MostRecentOrderId
}
However my reduce attempt returns 0 results.
Also: will RavenDB treat the Order.OrderetAt as a proper DateTime value and order them correctly?
You need to do it like
from order in docs.Orders
select new {
Employee = order.Employee,
Count = 1,
MostRecent = order.OrderedAt,
MostRecentOrderId = order.Id
}
from result in results
group result by result.Employee into grp
let maxOrder = grp.OrderByDescending(x=>x.MostRecent).First()
select new {
Employee = grp.Key,
Count = grp.Sum(result => result.Count),
MostRecent = maxOrder.MostRecent,
MostRecentOrderId = maxOrder.MostRecentOrderId,
}

Get result from vTiger webservice

I am writing a wordpress-plugin which queries data from the vTiger Webservice-API. I read the tutorial (https://wiki.vtiger.com/index.php/Webservices_tutorials#QueryResult) and know the reference (https://wiki.vtiger.com/index.php/Webservice_reference_manual). In the tutorial the use Zend-JSON and HTTP_Client. I use cURL (because it was installed and I thought it was worth a try to use before I install other utilities). It works quite well and I am able to Login to vTiger with our API-User and send the queries. What I receive is something like this:
array(2) {
["success"]=>
bool(true)
["result"]=>
array(4) {
["sessionName"]=>
string(21) "4d103e2058f9d365c22ff"
["userId"]=>
string(4) "19x9"
["version"]=>
string(4) "0.22"
["vtigerVersion"]=>
string(5) "6.5.0"
}
}
Looks very good to me but the Thing I am missing is the actual data from my query.
This is my PHP-Code:
$vtiger->initCurl();
$challengeToken = $vtiger->getChallengeToken();
$sessionId = $vtiger->getSessionId($challengeToken);
$result = $vtiger->query($sessionId, "SELECT firstname FROM 'Contacts' WHERE lastname = 'XXX';");
$wpdb->replace( $wpdb->prefix.$_CONFIG['dbtable'], array( 'id' => 1, 'syncfields' => $result), array('%d', '%s') );
$vtiger->logout($sessionId);
$vtiger->closeCurl();
$result = json_decode($result, true);
return var_dump(($result['success']) ? $result : "Error");
What am I missing to get the firstname (or any other value from the vTiger-DB)?
In the Code I am just writing the Response to the wp-db (extra-Table).
Thanks,
Nico
Vtiger Result Return in array format. you should change your code
$vtiger->initCurl();
$challengeToken = $vtiger->getChallengeToken();
$sessionId = $vtiger->getSessionId($challengeToken);
$result = $vtiger->query($sessionId, "SELECT firstname FROM 'Contacts' WHERE lastname = 'XXX';");
$syncfield = result['0'];
$wpdb->replace( $wpdb->prefix.$_CONFIG['dbtable'], array( 'id' => 1, 'syncfields' => $syncfield), array('%d', '%s') );
$vtiger->logout($sessionId);
$vtiger->closeCurl();
$result = json_decode($result, true);
return var_dump(($result['success']) ? $result : "Error");
ŮŽAlso You Can Use vtiger CRM Webservice Client Library
http://forge.vtiger.com/projects/vtwsclib/

how can i fetch database records between two dates in drupal

I need to fetch the table records from start_date to end_date ,i tried some queries but its showing all records
class uniview8PastpaymentController extends ControllerBase {
public static function load($entry = array()) {
$maxDate = \Drupal::request()->query->get('set_start_date');
drupal_set_message(t("$maxDate"));
$minDate = \Drupal::request()->query->get('set_end_date');
drupal_set_message(t("$minDate"));
$select = db_select('pastpayments', 'example');
$select->fields('example');
// Add each field and value as a condition to this query.
foreach ($entry as $field => $value) {
$query->condition('paiddate', array($maxDate, $minDate), 'BETWEEN');
}
// Return the result in object format.
return $select->execute()->fetchAll();
}
Example
$start_time = '1493029282.696';
$end_time = '1493029283.304';
$query = \Drupal::database()->select('cache_data', 'nfd');
$query->fields('nfd', ['cid', 'data', 'expire']);
$query->condition('created', array($start_time, $end_time), 'BETWEEN');
$result = $query->execute();