MongoDB - Search by insertion order (date) sub-value - sql

Think you can give me your help on MongoDB .
My scheme is for example :
Array
(
[_id] => MongoId Object
(
[$id] => 538339ef5b17848a488b7e35
)
[group_name] => 'group 1'
[activity] => Array
(
[open] => Array
(
[company] => Array
(
[0] => Array
(
[name] => company 1
[date] => MongoDate Object
(
[sec] => 1400081160
[usec] => 0
)
),
[0] => Array
(
[name] => company 2
[date] => MongoDate Object
(
[sec] => 1500081160
[usec] => 0
)
),
[0] => Array
(
[name] => company 3
[date] => MongoDate Object
(
[sec] => 1600081160
[usec] => 0
)
),
[0] => Array
(
[name] => company 4
[date] => MongoDate Object
(
[sec] => 1700081160
[usec] => 0
)
)
)
)
)
)
Array
(
[_id] => MongoId Object
(
[$id] => 538339ef5b178424498b7e34
)
[group_name] => 'group 2'
[activity] => Array
(
[open] => Array
(
[company] => Array
(
[0] => Array
(
[name] => company 3
[date] => MongoDate Object
(
[sec] => 1300081160
[usec] => 0
)
),
[0] => Array
(
[name] => company 1
[date] => MongoDate Object
(
[sec] => 1600081160
[usec] => 0
)
),
[0] => Array
(
[name] => company 2
[date] => MongoDate Object
(
[sec] => 1800081160
[usec] => 0
)
),
[0] => Array
(
[name] => company 4
[date] => MongoDate Object
(
[sec] => 1900081160
[usec] => 0
)
)
)
)
)
)
And infact I would fill display the "groupname" only if such insertion order by DATE is "Company 1, Company 2, Company 3".
So normally it should show me in the example above only "Group 1", because the order is as required, while in the "Group 2" order starts with "Business 3, followed by Company 1. ... ".
--
For example if I'm looking like this:
[activity.open.company] => Array
(
[$in] => Array
(
[0] => company 1
[1] => company 2
[2] => company 3
)
)
This will highlight my whole world and not just the "Group 1"
--
Thank you sincerely for your help!
PS : Sorry for my english, I'm french.

When you query with an $in clause it basically becomes and $or on the items of the given array. The query you have written would match the two documents listed because they both have at least company 2 in them.

Related

How to interpret vin/vout on a Bitcoin transaction?

I used nownodes api to get this response on a transaction:
(
[txid] => 38ac1348219f8aa9349f497bfa6f8d05f775cafbbd26354867d22ca84f15e1e1
[version] => 2
[vin] => Array
(
[0] => stdClass Object
(
[txid] => 38cff250be850140644a1abf022b22f3e59cab15c6091706c3f73218a4d72050
[vout] => 1
[sequence] => 4294967295
[n] => 0
[addresses] => Array
(
[0] => 1EJtMFThodiQ1j26xy1kugFck9325C38CQ
)
[isAddress] => 1
[value] => 158316
[hex] => 4830450221009548f997389fd9881dfed78fe25fcce77f5b96d1545da91dfa13f56db3c02f6e02207fe239ac7916681edc36afd6a9a569981cd12c2c6801616bc15794be5c024431012102afe2e887e3ff56edcebe6b1aa6bf48f4a5a7f02cfc8d743e778896df2054adee
)
)
[vout] => Array
(
[0] => stdClass Object
(
[value] => 7000
[n] => 0
[hex] => a9144a09be6e2917ef00e5d72bc38035db5c5a5ed8ec87
[addresses] => Array
(
[0] => 38SVbkkFE8qcJuGyTJ9fY2cbGS3xknEfYr
)
[isAddress] => 1
)
[1] => stdClass Object
(
[value] => 146856
[n] => 1
[hex] => 76a91491fb9214e6ad9b3ea19c1fd7d3a646e12f804d2688ac
[addresses] => Array
(
[0] => 1EJtMFThodiQ1j26xy1kugFck9325C38CQ
)
[isAddress] => 1
)
)
[blockHash] => 000000000000000000050bfb2a645a5eb7ac882aeb1782bce37ef6a2652c383b
[blockHeight] => 743696
[confirmations] => 8
[blockTime] => 1657005608
[value] => 153856
[valueIn] => 158316
[fees] => 4460
[hex] => 02000000015020d7a41832f7c3061709c615ab9ce5f3222b02bf1a4a64400185be50f2cf38010000006b4830450221009548f997389fd9881dfed78fe25fcce77f5b96d1545da91dfa13f56db3c02f6e02207fe239ac7916681edc36afd6a9a569981cd12c2c6801616bc15794be5c024431012102afe2e887e3ff56edcebe6b1aa6bf48f4a5a7f02cfc8d743e778896df2054adeeffffffff02581b00000000000017a9144a09be6e2917ef00e5d72bc38035db5c5a5ed8ec87a83d0200000000001976a91491fb9214e6ad9b3ea19c1fd7d3a646e12f804d2688ac00000000
)
The transaction was for: 0.0001146 BTC
And the fee was: 0.0000446
Totalling: 0.0001592
However, based on teh result from Nownodes, how can I see what the transaction total was? I can easily see the fee under "Fees". But how do I calculate the actually amount that came in or went out for this transaction?
Thanks!
valueIn = vout[0][value] + vout[1][value] + [fees]
valueIn = 158316
Is that what you have been looking for?

PayPal Orders API payment to a third party payee

I want to facilitate sending money to a merchant's PayPal account. I've made an additional Business Account in the PayPal Sandbox. I've made an order call with this account as a payee. But when I get the order (after approval from the payer) then the payee is still my actor account. Do I need some special configuration in the sandbox? And in production does the intended payee need to give me special permissions?
Array
(
[intent] => AUTHORIZE
[application_context] => Array
(
[return_url] => http://example.com/cart/PP_Payment.php?success=true
[cancel_url] => http://example.com/cart/PP_Payment.php?success=false
[brand_name] => Company X
)
[payee] => Array
(
[email_address] => sb-u4hosest4#business.example.com
)
[inovoice_id] => 1-GD2U-70E7-4Y
[items] => Array
(
[0] => Array
(
[quantity] => 1
[name] => Rabenhorst Klostergarten BIO Mini
[unit_amount] => Array
(
[currency_code] => EUR
[value] => 1.04
)
[sku] => 97899
)
[1] => Array
(
[quantity] => 1
[name] => Lupinen Filet
[unit_amount] => Array
(
[currency_code] => EUR
[value] => 3.87
)
[sku] => 66911
)
[2] => Array
(
[quantity] => 1
[name] => Kühltasche/-akku
[unit_amount] => Array
(
[currency_code] => EUR
[value] => 6
)
[sku] => P002
)
)
[purchase_units] => Array
(
[0] => Array
(
[amount] => Array
(
[currency_code] => EUR
[value] => 15.86
[breakdown] => Array
(
[item_total] => Array
(
[currency_code] => EUR
[value] => 10.91
)
[shipping] => Array
(
[currency_code] => EUR
[value] => 4.95
)
)
)
)
)
)
Result: ##########
Array
(
[id] => 5KPxxxx
[links] => Array
(
[0] => Array
(
[href] => https://api.sandbox.paypal.com/v2/checkout/orders/5KPxxxx
[rel] => self
[method] => GET
)
[1] => Array
(
[href] => https://www.sandbox.paypal.com/checkoutnow?token=5KPxxxx
[rel] => approve
[method] => GET
)
[2] => Array
(
[href] => https://api.sandbox.paypal.com/v2/checkout/orders/5KPxxxx
[rel] => update
[method] => PATCH
)
[3] => Array
(
[href] => https://api.sandbox.paypal.com/v2/checkout/orders/5KPxxxx/authorize
[rel] => authorize
[method] => POST
)
)
[status] => CREATED
)
but when I get the order then the payee is me and not the selected third party
Array
(
[id] => 5KPxxxx
[intent] => AUTHORIZE
[purchase_units] => Array
(
[0] => Array
(
[reference_id] => default
[amount] => Array
(
[currency_code] => EUR
[value] => 15.86
[breakdown] => Array
(
[item_total] => Array
(
[currency_code] => EUR
[value] => 10.91
)
[shipping] => Array
(
[currency_code] => EUR
[value] => 4.95
)
)
)
[payee] => Array
(
[email_address] => mike#www.org
[merchant_id] => FXXX
[display_data] => Array
(
[brand_name] => Company X
)
)
[shipping] => Array
(
[name] => Array
(
[full_name] => test buyer
)
[address] => Array
(
[address_line_1] => ESpachstr. 1
[admin_area_2] => Freiburg
[admin_area_1] => Empty
[postal_code] => 79111
[country_code] => DE
)
)
)
)
[payer] => Array
(
[name] => Array
(
[given_name] => test
[surname] => buyer
)
[email_address] => mt-buyer#w3xxx.org
[payer_id] => 4xxx
[address] => Array
(
[country_code] => DE
)
)
[create_time] => 2020-03-22T09:32:48Z
[links] => Array
(
[0] => Array
(
[href] => https://api.sandbox.paypal.com/v2/checkout/orders/5KPxxxx
[rel] => self
[method] => GET
)
[1] => Array
(
[href] => https://api.sandbox.paypal.com/v2/checkout/orders/5KPxxxx/authorize
[rel] => authorize
[method] => POST
)
)
[status] => APPROVED
)
[payee] => Array
(
[email_address] => sb-u4hosest4#business.example.com
)
This payee is being ignored because it is not in the purchase_units object.
See the example in the documentation.
While you can for sure do intent:CAPTURE, another consideration is that intent:AUTHORIZE (and later capture) might not be supported without permissions.

How to simplify my result in Cakephp 3

My code is:
$costSheetQuery = $this->CostSheets->find('all')->where(['id IN' => $criteria]);;
$costSheetData = $costSheetQuery->all();
I print the array $costSheetData and it gives me the following relust:
Cake\ORM\ResultSet Object
(
[items] => Array
(
[0] => App\Model\Entity\CostSheet Object
(
[id] => 5
[key_value] => {"sample_date":"10-03-2018","mh_sc":"mh-sc","buyer":"buyer","season":"season","style":"styel","style_detail":"Style Details","sample_img":[[""]],"fab_category":[["FABRIC CATEGORY","FABRIC CATEGORY","FABRIC CATEGORY","FABRIC CATEGORY","FABRIC CATEGORY","FABRIC CATEGORY"]],"patt":[["PATT","PATT","PATT","PATT","PATT","PATT"]],"size":[["SIZE","SIZE","SIZE","SIZE","SIZE","SIZE"]],"ship_date":[[{"year":"2018"},{"month":"01"},{"day":"01"}]],"piece":[["10","20","30","40","50","60"]],"fabric_usage":[["USAGE"]],"fabric_yds":[["yds"]],"fabric_body":[["Body","Body","Body","Body","Body","Body"]],"cm":[["embrotery"]],"cm_value":[[" 10 ","12.00","","15","",""]],"trims":[["thread"]],"trims_value":[["10","","10","20","",""]]}
[created] => Cake\I18n\FrozenTime Object
(
[time] => 2018-03-10T16:47:52+00:00
[timezone] => UTC
[fixedNowTime] =>
)
[modified] => Cake\I18n\FrozenTime Object
(
[time] => 2018-03-10T16:47:52+00:00
[timezone] => UTC
[fixedNowTime] =>
)
[[new]] =>
[[accessible]] => Array
(
[key_value] => 1
[created] => 1
[modified] => 1
)
[[dirty]] => Array
(
)
[[original]] => Array
(
)
[[virtual]] => Array
(
)
[[errors]] => Array
(
)
[[invalid]] => Array
(
)
[[repository]] => CostSheets
)
)
)
Whats hell is going on. I just start hating cakephp. My additional bullshit in my array? I also try to separate as : $items->costSheetData as item is an object of $costSheetData. But it gives me an arrow. Any idea?

how to execute stored procedure in cakephp 3?

This is my function for login i call a stored procedure login for match user name and password, but it doesn't work for me it give me all the rows:
public function login($email,$password)
{
$consumers = TableRegistry::get('Consumers');
$result=$consumers->query("Call login('".$email."','".$password."')");
pr($result->toArray());die;
}
My stored procedure in phpmyadmin is below:
BEGIN
SELECT * FROM consumers WHERE email = email_id AND password = md_password;
END
When i am executing query it give me object but after converting this object into array it give me all the row of table.output is:
<pre class="pr">Array
(
[0] => Cake\ORM\Entity Object
(
[_properties:protected] => Array
(
[id] => 1
[name] => jeevan
[email] => j#gmail.com
[password] => asdf
[phone_no] => 8447726137
[ota] => cde
[status] => 0
[created_on] => Cake\I18n\FrozenTime Object
(
[date] => 2016-07-08 17:28:52
[timezone_type] => 3
[timezone] => UTC
)
[token_access] =>
[device_type] => 1
[push_id] => abc
[want_news] => 1
[postal_code] => 263136
[registration_type] => 1
)
[_original:protected] => Array
(
)
[_hidden:protected] => Array
(
)
[_virtual:protected] => Array
(
)
[_className:protected] =>
[_dirty:protected] => Array
(
)
[_new:protected] =>
[_errors:protected] => Array
(
)
[_invalid:protected] => Array
(
)
[_accessible:protected] => Array
(
[*] => 1
)
[_registryAlias:protected] => Consumers
)
[1] => Cake\ORM\Entity Object
(
[_properties:protected] => Array
(
[id] => 2
[name] => jack
[email] => jack#gmail.com
[password] => 123
[phone_no] => 7409757656
[ota] => chb
[status] => 1
[created_on] => Cake\I18n\FrozenTime Object
(
[date] => 2016-07-20 06:10:14
[timezone_type] => 3
[timezone] => UTC
)
[token_access] => ghcvhgv
[device_type] => 0
[push_id] => hgnjh
[want_news] => 1
[postal_code] => 263136
[registration_type] => 1
)
[_original:protected] => Array
(
)
[_hidden:protected] => Array
(
)
[_virtual:protected] => Array
(
)
[_className:protected] =>
[_dirty:protected] => Array
(
)
[_new:protected] =>
[_errors:protected] => Array
(
)
[_invalid:protected] => Array
(
)
[_accessible:protected] => Array
(
[*] => 1
)
[_registryAlias:protected] => Consumers
)
)</pre>
that mean the stored procedure not working, any idea really help me, thanks in advance!
You can call a stored procedure using the ConnectionManager's execute() method. It's important to remember to prepare the query so that you remove the risk of SQL injection:-
$this->connection = ConnectionManager::get('default');
$results = $this->connection->execute(
'CALL login(?, ?)',
[$email, md5($password)]
)->fetchAll('assoc');
When CakePHP runs execute() it will substitute the ? with the escaped and quoted values of $email and md5($password). For further details check out the official docs on Preparing a statement.
step 1:use the class as use Cake\Datasource\ConnectionManager;
step 2: then execute the procedure-
$this->connection = ConnectionManager::get('default');
$consumer = $this->connection->execute("CALL login('".$email."','".md5($password)."')")->fetchAll('assoc');
now it will give an array.
finally i got this answer in cakephp cookbook.

ActiveRecord result return by findAll method needs in different format

I executed following statement
$posts = Post::model()->with(array( 'category', 'member', 'profile' ))->findAll();
I printed $posts in log file. I got following result.
Array
(
[0] => Post Object
(
[_new:CActiveRecord:private] =>
[_attributes:CActiveRecord:private] => Array
(
[id] => 1
[post_text] => Sales needs to be increase by the end of this month. I don't wnat any reason behind this.
[member_id] => 2
[category_id] => 3
[published] => 0
[draft] => 1
[date_added] => 2014-04-06
)
[_related:CActiveRecord:private] => Array
(
[category] => Category Object
(
[_new:CActiveRecord:private] =>
[_attributes:CActiveRecord:private] => Array
(
[id] => 1
[category_name] => Anything
[type] => General
[date_added] => 2014-04-05
)
[_related:CActiveRecord:private] => Array
(
)
[_c:CActiveRecord:private] =>
[_pk:CActiveRecord:private] => 1
[_alias:CActiveRecord:private] => t
[_errors:CModel:private] => Array
(
)
[_validators:CModel:private] =>
[_scenario:CModel:private] => update
[_e:CComponent:private] =>
[_m:CComponent:private] =>
)
[member] => Member Object
(
[_new:CActiveRecord:private] =>
[_attributes:CActiveRecord:private] => Array
(
[id] => 1
[screen_name] => prashantb
[email] => prashantbharambe22#gmail.com
[date_added] => 2014-04-05
[first_name] => prashant
[last_name] => bharambe
)
[_related:CActiveRecord:private] => Array
(
[profile] => MemberProfile Object
(
[_new:CActiveRecord:private] =>
[_attributes:CActiveRecord:private] => Array
(
[id] => 1
[member_id] => 1
[city] => kalyan
[state] => maharashtra
[country] => india
[designation] => php developer
[date_added] => 2014-04-05
)
[_related:CActiveRecord:private] => Array
(
)
[_c:CActiveRecord:private] =>
[_pk:CActiveRecord:private] => 1
[_alias:CActiveRecord:private] => t
[_errors:CModel:private] => Array
(
)
[_validators:CModel:private] =>
[_scenario:CModel:private] => update
[_e:CComponent:private] =>
[_m:CComponent:private] =>
)
)
[_c:CActiveRecord:private] =>
[_pk:CActiveRecord:private] => 1
[_alias:CActiveRecord:private] => t
[_errors:CModel:private] => Array
(
)
[_validators:CModel:private] =>
[_scenario:CModel:private] => update
[_e:CComponent:private] =>
[_m:CComponent:private] =>
)
)
[_c:CActiveRecord:private] =>
[_pk:CActiveRecord:private] => 1
[_alias:CActiveRecord:private] => t
[_errors:CModel:private] => Array
(
)
[_validators:CModel:private] =>
[_scenario:CModel:private] => update
[_e:CComponent:private] =>
[_m:CComponent:private] =>
)
)
But I need a result in following format.
Array
(
[0] => Array
(
[id] => 1,
[post_text] => Sales needs to be increase by the end of this month. I don't wnat any reason behind this,
[member_id] => 2,
[category_id] => 3,
[published] => 0,
[draft] => 1,
[date_added] => 2014-04-06,
[category] => Array (
[id] => 1,
[category_name] => Anything,
[type] => General,
[date_added] => 2014-04-05,
),
[member] => Array (
[id] => 1,
[screen_name] => prashantb,
[email] => prashantbharambe94#gmail.com,
[date_added] => 2014-04-05,
[first_name] => prashant,
[last_name] => bharambe,
[profile] => Array(
[id] => 1
[member_id] => 1
[city] => kalyan
[state] => maharashtra
[country] => india
[designation] => php developer
[date_added] => 2014-04-05
)
)
)
)
In short I need all attributes values in one array. ( Model Attributes and its related model attributes )
I am new to yii. Please help me on this.
Yii doesn't work with arrays. Each DB record is represented by an ActiveRecord object. This way you can access your column values like this:
echo $model->post_text; // Sales needs to be increase...
echo $model->date_added; // 2014-04-06
echo $model->etc...
If you did set up relations right, you can access that data like this:
echo $model->category->category_name; // Anything
echo $model->member->screen_name; // prashantb
You have to create the array you showed manually. If you still need the data in an array, you can also access the attributes value:
print_r($model->attributes); // array( [id] => 1, [post_text] => 'Sales needs to be increase', ...)