Mongodb-PHP: What is the query for retriving record of messages with status unread - mongodb

I am using neatbeans & using mongodb with php for a webapp. I am retriving messages with following command through php.
include_once '../lib/mongodb/MongoDbConnector.php';
$mongoDb = new MongoDbConnector();
$mongoDb = $mongoDb->getConnection();
$mongoDb = $mongoDb->selectCollection("message");
$countM = $mongoDb->find(array('client_id' => new MongoId($valueU['_id'])), array('status' => 'unread'));
$unreadM = $countM->count();
The query doesnot work. showing me the data & count of messages who have client_id in it.
What to do???

The query is not well formated, it should be like this:
$countM = $mongoDb->find(array('client_id' => new MongoId($valueU['_id']), 'status' => 'unread'));
Also check if $valueU['_id'] is a string or a mongoID object.

Related

Yii2 MongoDB delete single row from document

I try this two way to delete but unable to do so:--
Try one:-
$query = new Query();
$query->delete()->from('table_name')->where(['disease_id' => 'A0PO919Q-12', 'status' => 1]);
Try Two:-
$collection = Yii::$app->mongodb->getCollection('table_name');
$collection->delete(['disease_id' => 'A0PO919Q-12']);
Can anyone try to delete data from mongo DB in Yii2 Framewrok
I find the solution
$collection = Yii::$app->mongodb->getCollection('table_name');
$collection->remove(['disease_id' => 'A0PO919Q-12']);

Can't Relate Contact and Opportunity in SuiteCRM / SugarCRM CE

I'm working on a script to import data into SuiteCRM / SugarCRM CE. I need to create a Contact and an Opportunity. I then need to relate the two.
I have a many to many relationship between Contacts and Opportunities. Each contact should be able to create multiple opportunities. Each opportunity should be able to be assigned to multiple contacts.
When I run the code it says "1 Relationship(s) created", but when I check Suite there's nothing listed under the contact or opportunity subpanels.
FYI, I renamed the Opportunities module "Gigs" and am using this API Wrapper: github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class
Here's the code:
<?php
// Load Composer Dependencies for Sugar API Wrapper
require_once('vendor/autoload.php');
// Create Sugar Object
$sugar = new \Asakusuma\SugarWrapper\Rest;
// Set Sugar Connection Items
$sugar->setUrl('https://example.com/suitecrm/service/v2/rest.php');
$sugar->setUsername('User');
$sugar->setPassword('Pass');
// Connect to Sugar
$sugar->connect();
// Did something go wrong with the connection? Report it.
$error = $sugar->get_error();
if($error !== FALSE) {
return $error['name'];
}
// Ok... We're going to try and create a test entry in Sugar/Suite
// Create a Contact
$modules = 'Contacts';
// Set Values
$values = array(
'contact_type_c' => 'Prospect',
'lead_source' => 'Website',
'first_name' => 'Test',
'last_name' => 'Contact',
'phone_mobile' => '(123) 456-7890',
'email1' => 'test#test.com'
);
// Put it in Suite
$result = $sugar->set($modules, $values);
$contactID = $result['id'];
// Ok, now let's create a Opportunity
$modules = "Opportunities";
$values = array(
'name' => 'My Test Gig',
'sales_stage' => 'New Inquiry',
'amount' => '400'
);
$result = $sugar->set($modules, $values);
$gigID = $result['id'];
// Lastly, let's relate the two - HERE'S WHERE I HAVE PROBLEMS!
// Set Relationship
$moduleName = 'Contacts';
$moduleID = $contactID;
$linkFieldName = 'opportunities';
$relatedIDs = array($gigID);
$nameValueList = array(); // Passing empty array because we don't have any fields that need it
$delete = 0;
$result = $sugar->set_relationship($moduleName, $moduleID, $linkFieldName, $relatedIDs, $nameValueList, $delete);
echo $result['created'] . " relationship(s) made";
?>
The Contact and Opportunity are created just fine. It's the relationship that's not happening.
Ugh... Ok, I get it.
I looked at the API documentation and was passing $relatedIDs back as an array. What I didn't realize is that the API was doing this as well. So what got passed into Suite was a multidimensional array instead of a single array.

get_entry_list() method with query parameter on sugar crm 7 does not work

My code is as below..
Please note that I am trying to retrive all the accounts whose where the Accounts.name='bhagya'.
The same query workes for me in SugarCRM Version 6.5 (Community edition) but in case of SugarCRM 7 it is not working when I mention query parameter. If I mention 'query'=>'' then I get all the records from the sugarcrm 7 server. It fails when I specify any filter for query parameter. I am using RestAPI - 4.1
$get_entry_list_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => 'Accounts',
//The SQL WHERE clause without the word "where".
//'query' => "Accounts.billing_address_postalcode='60329'",
// 'query' => "Accounts.name='Ingrid Rofalsky'",
'query'=>'',
//The SQL ORDER BY clause without the phrase "order by".
'order_by' => "",
//The record offset from which to start.
'offset' => 0,
//A list of fields to include in the results.
'select_fields' => array(
'id',
'name',
),
//A list of link names and the fields to be returned for each link name.
'link_name_to_fields_array' => array(),
//The maximum number of results to return.
'max_results' => 10,
//If deleted records should be included in results.
'deleted' => 0,
//If only records marked as favorites should be returned.
'favorites' => false,
);
print_r($get_entry_list_parameters);
$get_entry_list_result = call('get_entry_list', $get_entry_list_parameters, $url);
echo '<pre>';
print_r($get_entry_list_result);
echo '</pre>';
Can some one help me on this..
Thank you.
Regards
- Bhagya
The Rest API has changed a lot in Sugar7.
The URL for the invokation should look like
http://servname.com/pro720/rest/v10/Accounts?filter[0][name][$starts]=B&filter[0][email_addresses.email_address]=burgers#example.com&fields=name,account_type,description,email
Where you are filtering the accounts with a name that starts with B, the mail address is burgers#example.com and where you retrieve only the fields name,account_type,description and email
Changing the module name to lowercase in query option solved this problem.
I got the answer for my query from below link.
https://community.sugarcrm.com/sugarcrm/topics/get_entry_list_method_with_query_parameter_on_sugar_crm_7_does_not_work?topic-reply-list%5Bsettings%5D%5Bfilter_by%5D=all&topic-reply-list%5Bsettings%5D%5Bpage%5D=1#reply_14588280
Thanks again
Regards
- Bhagya

Using the new 'data' option for CakeEmail attachments with CakePHP 2.4.x

The CakeEmail help page states that the data option has been added as of 2.4, so you no long have to have a physical file to add an attachment to an email.
I've got the following code:
$Email->from(array($this->Session->read('Auth.User.email') => $this->Session->read('Auth.User.name')))
->to($this->request->data['email-to'])
->subject($this->request->data['email-subject'])
->attachments(array('attachement1.pdf', array('data' => $pdf)))
->send($this->request->data['email-message']);
But whenever I run that I get an Internal Error saying File Not Found: "".
I had a look at the source code (which I'm beginning to learn is often more useful than reading the documentation!): https://github.com/cakephp/cakephp/blob/master/lib/Cake/Network/Email/CakeEmail.php
Changing my code to:
$Email = new CakeEmail('default');
$Email->from(array($this->Session->read('Auth.User.email') => $this->Session->read('Auth.User.name')))
->to($this->request->data['email-to'])
->subject($this->request->data['email-subject'])
->attachments(array('attachement1.pdf' => array('data' => $pdf, 'mimetype' => 'application/pdf')))
->send($this->request->data['email-message']);
Notice on the attachments line, the array is assigned to the filename variable, rather than passed in as a parameter!
For completeness, if anyone else is reading this and is wondering how I am generating my PDF with CakePDF:
// Create PDF for attachment
$CakePdf = new CakePdf();
$CakePdf->template('claim', 'default');
//get the pdf string returned
$pdf = $CakePdf->output();

Fetch the Account ID based on Primary Emailaddress in Sugar CRM

We have a website and when a record is inserted / updated we runs a script to update the sugar CRM Accounts module.
The Accounts module have a field website_id_c . When an insert occurs to DB we set the last insert ID to website_id_c of Sugar CRM and the remaining values to get inserted.
Insert script is something like below .
$name_value_field=array(
array('name' => 'name','value' => $name),
array('name' => 'primary_contactperson_c','value' => $ownername),
array('name' => 'billing_address_street','value' => $address),
array('name' => 'billing_address_postalcode','value' => $postalcode),
array('name' => 'email1','value' => $email),
array('name' => 'website_id_c','value' => $id_retrieved),
);
if(!empty($sessn_id))
{
$result=$soap->set_entry("Accounts",$name_value_field);
}
This uses the SOAP nusoap client to communicate with Sugar CRM cloud. Insertion works fine and update also.
$response = $soap->get_entry_list('Accounts',
array('id'),
"website_id_c='$websiteID'");
$account_id = $response['entry_list'][0]['id'];
But currently I want to retrieve the account_id to update the record on the basis on Email. I changed the fields with email . But I feel its stored in some other place and the primary address key is stored in the Accounts module. So first we want to fetch that id from the Email module, and then query the Accounts module on the basis of this Email address id to get the Account Values.
$response = $soap->get_entry_list('Accounts',
array('id'),
"email1='email#example.com'");
Which is the module that stores the Email address ? I have not worked on Sugar before. So feel free to ask me if you didn't get me exactly.
Thanks
The email field and its relation to accounts is stored in two other tables, so you need to retrieve the accounts with a sub select.
$response = $soap->get_entry_list(
$module = 'Accounts',
$fields = array('id'),
$query = "accounts.id IN (
SELECT eabr.bean_id
FROM email_addr_bean_rel eabr
JOIN email_addresses ea ON (ea.id = eabr.email_address_id)
WHERE
eabr.bean_module = 'Accounts'
AND eabr.deleted = 0
AND ea.email_address = 'email#example.com'
)",
$orderBy = "accounts.name",
$offset = 0,
$max = 10
);
My soap clients get_entry_list method is as
get_entry_list($module,
$fields = array(),
$query='',
$order_by='',
$offset=0,
$limit = 1000)
Make the necessary changes accordingly .