Thanks in advance!
I am new to CakePHP, and I am trying to get just count of lessons of course. I am using CakePHP with friendsofcake's crud.
$this->Crud->on('beforePaginate', function(\Cake\Event\Event $event) {
$query = $event->getSubject()->query;
$query->contain(['Lessons']);
});
with this code, I am getting all the lessons of the course, but I need only counts, because if a course having 50 lessons, why I should get all the lessons?
Output:-
App\Model\Entity\Course Object
(
[id] => 7
[language_id] => 2
[course_title] => test
[course_desc] =>
[audio_path] =>
[img_path] =>
[inappiosid] =>
[inappandroidid] =>
[sOrder] => 1
[lessons] => Array
(
[0] => App\Model\Entity\Lesson Object
(
[id] => 4
[course_id] => 7
[lesson_title] => test
[lesson_description] => test
[file_path] => test
[sOrder] => 1
[[new]] =>
[[accessible]] => Array
(
[course_id] => 1
[lesson_title] => 1
[lesson_description] => 1
[file_path] => 1
[sOrder] => 1
[course] => 1
)
)
)
[[new]] =>
[[accessible]] => Array
(
[language_id] => 1
[course_title] => 1
[course_desc] => 1
[audio_path] => 1
[img_path] => 1
[inappiosid] => 1
[inappandroidid] => 1
[sOrder] => 1
[language] => 1
[customer_orders] => 1
[lessons] => 1
)
)
Related
Have look Please i have 2 arrays array1 and array2 i want to compare these arrays and need the array back which is not exist in array2.
I really to resolve this issue i am working on app.
So kindly help me to resolve this issue
Thanks in Advance.
Here is array 1
Array
(
[0] => Array
(
[image_id] => 4
[user_id] => 2
[user_type] => user
[canvas_id] => 1
[canvas_mac] => 123.234.232.121
)
[1] => Array
(
[image_id] => 3
[user_id] => 2
[user_type] => user
[canvas_id] => 1
[canvas_mac] => 123.234.232.121
)
[2] => Array
(
[image_id] => 2
[user_id] => 2
[user_type] => user
[canvas_id] => 1
[canvas_mac] => 123.234.232.121
)
[3] => Array
(
[image_id] => 1
[user_id] => 2
[user_type] => user
[canvas_id] => 1
[canvas_mac] => 123.234.232.121
)
)
Here is array2
Array
(
[0] => Array
(
[image_id] => 1
[user_id] => 2
[user_type] => user
[canvas_id] => 1
[canvas_mac] => 123.234.232.121
)
[1] => Array
(
[image_id] => 4
[user_id] => 2
[user_type] => user
[canvas_id] => 1
[canvas_mac] => 123.234.232.121
)
)
I need result like this
Result Array
Array(
[0] => Array
(
[image_id] => 3
[user_id] => 2
[user_type] => user
[canvas_id] => 1
[canvas_mac] => 123.234.232.121
)
[1] => Array
(
[image_id] => 2
[user_id] => 2
[user_type] => user
[canvas_id] => 1
[canvas_mac] => 123.234.232.121
)
)
Please try array_udiff (http://php.net/array_udiff). Does it meet your requirements?
I am trying to output a username and user email outside of a foreach loop. I am trying to send an email to all WordPress users that are within a certain User Role.
Here is my code:
// Get users and their roles
$user_args = array(
'role__in' => 'new_role',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$users = get_users($user_args);
foreach ( $users as $user ) :
$user_name = $user->user_email;
$user_email = $user->display_name;
endforeach;
So I can then use them in other areas of the page, ie:.
echo 'Hello, ' . $user_name;
echo 'Send to: ' .$user_email;
I've printed out the $users array which contains the following:
Array
(
[0] => WP_User Object
(
[data] => stdClass Object
(
[ID] => 46
[user_login] => huw
[user_pass] => u7CqxbuQDvApUAF6tT.
[user_nicename] => huw
[user_email] => huw#xxxx.co.uk
[user_url] =>
[user_registered] => 2017-02-06 11:13:09
[user_activation_key] => 1486379590:$P$BkisA4T5j1S/ZjRageafNYHfsdin1S0
[user_status] => 0
[display_name] => Huw Daniel Rowlands
)
[ID] => 46
[caps] => Array
(
[sssg] => 1
[new_role] => 1
[site_member] => 1
[test_role] => 1
)
[cap_key] => jciw_capabilities
[roles] => Array
(
[0] => sssg
[1] => new_role
[2] => site_member
[3] => test_role
)
[allcaps] => Array
(
[read] => 1
[sssg] => 1
[new_role] => 1
[site_member] => 1
[test_role] => 1
)
[filter] =>
)
[1] => WP_User Object
(
[data] => stdClass Object
(
[ID] => 308
[user_login] => jeremy
[user_pass] => LLOKbkPOWQsBKUIk2qL1
[user_nicename] => magnus
[user_email] => jeremy#gmail.com
[user_url] =>
[user_registered] => 2017-05-03 19:24:42
[user_activation_key] => 1493839482:$P$BI/IYldCzsXZowLEiNfxiUkIwVdDKV0
[user_status] => 0
[display_name] => Jeremy
)
[ID] => 308
[caps] => Array
(
[new_role] => 1
[sssg] => 1
[site_member] => 1
)
[cap_key] => jciw_capabilities
[roles] => Array
(
[0] => new_role
[1] => sssg
[2] => site_member
)
[allcaps] => Array
(
[read] => 1
[new_role] => 1
[sssg] => 1
[site_member] => 1
)
[filter] =>
)
)
If you want to send an email to all users with a certain role, try something like this:
// Get users and their roles
$user_args = array(
'role__in' => 'new_role',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$users = get_users($user_args);
foreach ( $users as $user ) :
$user_email = $user->user_email;
$user_name = $user->display_name;
send_email($user_name, $user_email);
endforeach;
And then write your email function:
function send_email($name, $email) {
// Do email sending stuff here with $name & $email
}
i have two arrays and i want two merge using the same value within each array..
the first array is :
[0] => Array
(
[id] => 1
[uid] => 0090000157
[cid] => 0090000007
[extension] => 202
[secret] => Myojyo42f!
[leader] => 1
[simultaneous] =>
[confbridge_id] => 2
[created_at] => 2015-07-26 12:20:20
[updated_at] => 2015-07-26 12:20:20
)
[1] => Array
(
[id] => 2
[uid] => 0090000159
[cid] => 0090000007
[extension] =>
[secret] => Myojyo42f!
[leader] =>
[simultaneous] =>
[confbridge_id] => 2
[created_at] => 2015-07-26 14:23:41
[updated_at] => 2015-07-26 14:23:41
)
)
and the second array is:
Array
(
[0] => Array
(
[_id] => 55b52f4c2bab38fc63b6272a
[event] => ConfbridgeJoin
[channel] => SIP/peer_voip301confbridge-0000001b
[uniqueid] => 1437937478.63
[conference] => 0090000156
[calleridnum] => 0090000157
[calleridname] => 0090000157
[__v] => 0
[sipSetting] => Array
(
[accountcode] =>
[accountcode_naisen] => 202
[extentype] => 0
[extenrealname] =>
[name] => 0090000157
[secret] => Myojyo42f!
[username] => 0090000157
[context] => innercall_xdigit
[gid] => 101
[cid] => 0090000007
)
)
[1] => Array
(
[_id] => 55b53a2e2bab38fc63b6272b
[event] => ConfbridgeJoin
[channel] => SIP/peer_voip301confbridge-0000001c
[uniqueid] => 1437940260.66
[conference] => 0090000156
[calleridnum] => 0090000158
[calleridname] => UID2
[__v] => 0
[sipSetting] => Array
(
[accountcode] =>
[accountcode_naisen] => 203
[extentype] => 0
[extenrealname] =>
[name] => 0090000158
[secret] => Myojyo42f!
[username] => 0090000158
[context] => innercall_xdigit
[gid] => 101
[cid] => 0090000007
)
)
)
i want to merge array with the same value for example :
first array has = [uid] => 0090000157
second array has = [calleridnum] => 0090000157
is it possible to merge them?
this is my code
{foreach from=$participants item=participant key=p }
{foreach from=$conference_participants item=conference_participant key=c}
{if$participants.calleridnum == $conference_participants.uid}
//how to get data here ?
{/if}
{/foreach}
{/foreach}
Could this be what you're looking for?
Sorry for all the changes, I should have tested it... grr
(I've put this in PHPFiddle:
<pre>
<?php
$participants = [
[ 'calleridnum' => 1,
'test' => 'yay'
]
];
$conferance_participants = [
[ 'uid' => 1,
'test' => 'yay2',
'dit' => 'deze'
]
];
foreach ($participants as $participant=>$p) {
foreach ($conferance_participants as $conferance_participant=>$c) {
if ($p['calleridnum'] == $c['uid']) {
// ID's match do the magic here
foreach ( $c as $key=>$val ) {
if (!isset($p[$key])) {
// Value is new, copy the conferance_participant to the participant
$participants[$participant][$key] = $val;
}
} // Merging data
} // If: Match
}
}
print_r( $participants );
?>
)
Presently m working with CakePhp..i got some problem with combining two array and prepare for a json encoded array.. i used array_merge() property but its not working.. how can i encoded both of these two array..
M doing like this :
return json_encode(array_merge ($product_list,$price_list));
i have two php array as follows :
array 1:
Array
(
[0] => Array
(
[PriceList] => Array
(
[price_id] => 2
[price_name] => abc
[date_time] => 2015-07-06 16:22:56
[dealer_type] => Dealer
[purpose] => dealer
[status] => ACTIVE
)
)
[1] => Array
(
[PriceList] => Array
(
[price_id] => 3
[price_name] => xyz
[date_time] => 2015-07-06 16:22:56
[dealer_type] => Dealer
[purpose] => dealer
[status] => ACTIVE
)
)
)
array 2:
Array
(
[0] => Array
(
[Product] => Array
(
[cat_id] => 1
[subcat_id] => 3
[brand_id] => 1
[p_code] => PP12567
[name] => akai
[model_no] =>
[specification] => color tv
[color] =>
[quality] =>
[size] =>
[p_unavail] => 1
[demo_avail] => 0
[brochure] =>
[status] => active
)
[ProductPrice] => Array
(
[id] => 154
[p_code] => PP12567
[price_id] => 1
[quantity] => 233
[purchase_price] => 344.00
[selling_price] => 44.00
[discount_price] => 33.00
[tax] => 5.00
[datetime] => 2015-07-23 15:47:11
)
[ProductSubCategory] => Array
(
[subcat_id] => 3
[cat_id] => 1
[subcat_name] => samsung
[status] => active
)
[ProductCategory] => Array
(
[cat_id] => 1
[cat_name] => Electronics
[cat_type] => Product
[status] => active
)
)
[1] => Array
(
[Product] => Array
(
[cat_id] => 1
[subcat_id] => 4
[brand_id] => 1
[p_code] => PBC-676767
[name] => music
[model_no] => 33
[specification] =>
[color] =>
[quality] =>
[size] =>
[p_unavail] => 0
[demo_avail] => 0
[brochure] =>
[status] => active
)
[ProductPrice] => Array
(
[id] => 156
[p_code] => PBC-676767
[price_id] => 1
[quantity] => 767
[purchase_price] => 54.00
[selling_price] => 55.00
[discount_price] => 22.00
[tax] => 3.00
[datetime] => 2015-07-23 15:47:11
)
[ProductSubCategory] => Array
(
[subcat_id] => 4
[cat_id] => 1
[subcat_name] => sony
[status] => active
)
[ProductCategory] => Array
(
[cat_id] => 1
[cat_name] => Electronics
[cat_type] => Product
[status] => active
)
)
)
how to combine these two array into one and encoded into a json array..
You have to use array_merge but not directly on array1 and array2:
$toEncodeArray = [array_merge ($array1[0], $array2[0])] ;
If you only want the associative array (without the wrapping array), simply do:
$toEncodeArray = array_merge ($array1[0], $array2[0]) ;
In my "CouponsController.php", I have the following 2 functions:
public function index() {
$this->set('coupons', $this->Coupon->find('all'));
}
public function restaurants() {
$this->set('coupons', $this->Coupon->findBycategory_id('1'));
$this->render("index");
}
Basically, I want index function to return all coupons, and restaurants to return just category 1 (but I want to use the same view file).
I end up getting this errror:
Notice (8): Undefined index: Coupon [APP/View/Coupons/index.ctp, line 16]
It's because of how the array is returned for each of them. Here is my VIEW file and the results for each page:
Coupons/index.ctp:
foreach ($coupons as $c) {
print_r($c);
}
INDEX function:
Array ( [Coupon] => Array ( [id] => 1 [vendor_id] => 1 [category_id] => 1 [title] => $10 For Whatever [price] => 10.00 [value] => 20.00 [start_at] => 2012-02-07 12:03:00 [end_at] => 2012-02-29 12:03:05 [details] => Test [terms] => Test [mini_views] => 0 [large_views] => 0 [created] => 2012-02-08 12:03:12 ) ) Array ( [Coupon] => Array ( [id] => 2 [vendor_id] => 2 [category_id] => 2 [title] => Test [price] => 100.00 [value] => 200.00 [start_at] => 0000-00-00 00:00:00 [end_at] => 0000-00-00 00:00:00 [details] => [terms] => [mini_views] => 0 [large_views] => 0 [created] => 2012-02-08 12:14:03 ) )
RESTAURANTS function:
Array ( [id] => 1 [vendor_id] => 1 [category_id] => 1 [title] => $10 For Whatever [price] => 10.00 [value] => 20.00 [start_at] => 2012-02-07 12:03:00 [end_at] => 2012-02-29 12:03:05 [details] => Test [terms] => Test [mini_views] => 0 [large_views] => 0 [created] => 2012-02-08 12:03:12 )
Well it's just how cakephp returns it, a turnaround would be
foreach ($coupons as $coupon) {
$c = $coupon;
if (isset($coupon["Coupon"])) { // if is set index in array ["Coupon"] {
$c = $coupon["Coupon"];
}
print_r($c);
}
or
public function restaurants() {
$params = array('conditions' => array('Coupon.category_id' => 1));
$this->set('coupons', $this->Coupon->find('all', $params));
$this->render("index");
}