What is wrong with this association ? Related data are not being fetched - cakephp

function export(){
ini_set('memory_limit', '256M');
$this->loadModel('Profile');
$this->loadModel('ExamPayment');
//$this->loadModel('ExamApplication');
//$clemrep = $this->ExamApplication->find('all');
$ufacid = Authcomponent::user('faculty_id');
$options = array( 'conditions' => array('ExamPayment.status' => "Successful",'ExamPayment.faculty_id'=> $ufacid) );
$this->ExamPayment->Behaviors->load('Containable');
$this->ExamPayment->contain(
array('User'=>array('Profile'),'Exam','Faculty','ExamApplication')
);
$examApps = $this->ExamPayment->find('all', $options, array('contain'=>
'ExamApplication'
));
$examApplications = array();
foreach ($examApps as $key => $examApplication) {
$fname = isset($examApplication['User']['Profile']['fname'])? trim($examApplication['User']['Profile']['fname'] ):null;
$lname = isset($examApplication['User']['Profile']['lname'])? trim($examApplication['User']['Profile']['lname'] ):null;
$phone = isset($examApplication['User']['Profile']['phone'])? trim($examApplication['User']['Profile']['phone'] ):null;
$gender = isset($examApplication['User']['Profile']['gender'])? trim($examApplication['User']['Profile']['gender'] ):null;
$nationality = isset($examApplication['User']['Profile']['nationality'])? trim($examApplication['User']['Profile']['nationality'] ):null;
//$adddress = isset($examApplication['User']['Profile']['adddress'])? trim($examApplication['User']['Profile']['adddress'] ):null;
//$dob = isset($examApplication['User']['Profile']['dob'])? trim($examApplication['User']['Profile']['dob'] ):null;
$examApplications[] = array(
'ExamApplication' => array(
'full_name' => $fname . ' ' . $lname,
'email' => $examApplication['User']['email'],
'phone' => $phone,
//'adddress' => $adddress,
//'date_of_birth' => $dob,
'gender' => $examApplication['User']['Profile']['gender'],
'nationality' => $examApplication['User']['Profile']['nationality'],
// 'state' => $examApplication['User']['Profile']['state'],
//'ref_number' => $examApplication['ExamApplication']['ref_number'],
//'role' => $examApplication['User']['role'],
'exam' => $examApplication['Exam']['exam'],
//'init' => $examApplication['Exam']['init'],
'code' => $examApplication['Faculty']['code'],
'med_school' => $examApplication['ExamApplication']['med_school'],
'med_school_address' => $examApplication['ExamApplication']['med_school_address'],
'med_school_year' => $examApplication['ExamApplication']['med_school_year'],
'med_board_year' => $examApplication['ExamApplication']['med_board_year'],
'discharge_year' => $examApplication['ExamApplication']['discharge_year'],
'discharge_type' => $examApplication['ExamApplication']['discharge_type'],
'exam_date' => $examApplication['ExamApplication']['exam_date'],
'exam_center' => $examApplication['ExamApplication']['exam_center'],
//'exam_fee' => $examApplication['ExamPayment']['exam_fee'],
'status' => $examApplication['ExamPayment']['status'],
)
);
}
//pr($clemrep);
pr($examApplications);
exit();
$this->set(compact('examApplications'));
$this->layout = null;
$this->autoLayout = false;
Configure::write('debug','0');
}[attached is the output i get][1]
Below is the ouput of the array, my question is, why are some value blank?
Array
(
[0] => Array
(
[ExamApplication] => Array
(
[full_name] => FRANK CHIDI NWANKPA
[email] => franknwankpa#gmail.com
[phone] => 07030940000
[gender] => Male
[nationality] => NG
[exam] => Primary
[code] => 205
[med_school] =>
[med_school_address] =>
[med_school_year] =>
[med_board_year] =>
[discharge_year] =>
[discharge_type] =>
[exam_date] =>
[exam_center] =>
[status] => Successful
)
)
[1] => Array
(
[ExamApplication] => Array
(
[full_name] => BANKOLE ARAFAT ABOSEDE
[email] => bankolearafat#gmail.com
[phone] => 08062683798
[gender] => Female
[nationality] => NG
[exam] => Primary
[code] => 205
[med_school] =>
[med_school_address] =>
[med_school_year] =>
[med_board_year] =>
[discharge_year] =>
[discharge_type] =>
[exam_date] =>
[exam_center] =>
[status] => Successful
)
)
[2] => Array
(
[ExamApplication] => Array
(
[full_name] => Uvieroghene Ogbebor
[email] => uvieo#yahoo.com
[phone] => 08038975401
[gender] => Male
[nationality] => NG
[exam] => Primary
[code] => 205
[med_school] =>
[med_school_address] =>
[med_school_year] =>
[med_board_year] =>
[discharge_year] =>
[discharge_type] =>
[exam_date] =>
[exam_center] =>
[status] => Successful
)
)
why are some values blank, i found out that the content of the "ExamApplication" model is not being displayed , however, the model has already been loaded.
What could be happening?
Please help me

Related

How to show dynamic output in the wp_bakery vc_map dropdown?

I am using the wp_bakery page builder plugin. What I am doing is, I have to display the custom output in the dropdown
Expected output
Current Output
if I use the below code then I am getting the correct output.
$params=array(
'name' => __('Speaker'),
'base' => 'speaker',
'category' => __(My shortcodes'),
'class' => 'js-example-basic-single',
"icon" => get_template_directory_uri() . "/images/shortcode_slider.png",
'params' => array(
array(
'type' => 'dropdown',
'heading' => __('Speakers'),
'param_name' => 'speakersname',
'class' => 'js-example-basic-single',
'admin_label' => true,
//'value' => array($selectSpeaker),
'value' => array(__( 'Item One', 'textdomain' ) => '1'), //static added
'description' => __('Select speakers')
))
);
echo"<pre />";
print_r($params);
vc_map( $params );
array output
Array
(
[name] => Speaker
[base] => speaker
[category] => My shortcodes
[class] => js-example-basic-single
[icon] => https://example.com/wordpress/wp-content/themes/testing/images/shortcode_slider.png
[params] => Array
(
[0] => Array
(
[type] => dropdown
[heading] => Speakers
[param_name] => speakersname
[class] => js-example-basic-single
[admin_label] => 1
[value] => Array
(
[Item One] => 1
)
[description] => Select speakers
)
)
)
But If I use the below code then I am getting the current output(Screenshot shared above)
$speakerpost_args = array( 'post_type'=>'speaker','post_status' => 'publish', 'posts_per_page' => 80);
$speaker_posts = wp_get_recent_posts($speakerpost_args);
$selectSpeaker="";
foreach ($speaker_posts as $key => $value) {
$selectSpeaker.="__( 'Item One', 'textdomain' ) => '1',";
}
$params=array(
'name' => __('Webinar Speaker'),
'base' => 'speaker',
'category' => __('Hybreed shortcodes'),
'class' => 'js-example-basic-single',
"icon" => get_template_directory_uri() . "/images/shortcode_slider.png",
'params' => array(
array(
'type' => 'dropdown',
'heading' => __('Speakers'),
'param_name' => 'speakersname',
'class' => 'js-example-basic-single',
'admin_label' => true,
'value' => array($selectSpeaker), //dynamic value
//'value' => array(__( 'Item One', 'textdomain' ) => '1'),
'description' => __('Select speakers')
))
);
echo"<pre />";
print_r($params);
vc_map( $params );
Array output
Array
(
[name] => Speaker
[base] => speaker
[category] =>My shortcodes
[class] => js-example-basic-single
[icon] => https://exmple.com/wordpress/wp-content/themes/testing/images/shortcode_slider.png
[params] => Array
(
[0] => Array
(
[type] => dropdown
[heading] => Speakers
[param_name] => speakersname
[class] => js-example-basic-single
[admin_label] => 1
[value] => Array
(
[0] => __( 'Item One', 'textdomain' ) => '1' // here is the issue
)
[description] => Select speakers
)
)
)
Need to append values as array items not as string concatenation.
Change
$selectSpeaker="";
foreach ($speaker_posts as $key => $value) {
$selectSpeaker.="__( 'Item One', 'textdomain' ) => '1',";
}
To:
$selectSpeaker=[];
foreach ($speaker_posts as $key => $value) {
$selectSpeaker[__( 'Item One', 'textdomain' )] = '1';
}

Using a variable outside PHP Foreach Loop

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
}

how to merge array with the same value in smarty?

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 );
?>
)

Cakephp: Contain Behavior, conditions on array of array

I have a problem with contain behavior conditions and empty array.
There is part of code:
$menusTopUser = $this->Menu->find('all', array(
'contain' => array('TemplateRegion', 'Language', 'Item', 'MenusUserGroup' => array('conditions' => array('MenusUserGroup.user_group_id ' => $this->Auth->user('UserGroup.id')))
),
'conditions' => array(
'TemplateRegion.alias' => 'menu_top_user',
'Menu.active' => 1,
'Language.ISO-639-2' => $this->Session->read('Config.frontendLanguage'),
),
'fields' => array('Menu.title', 'Item.slug', 'Menu.url', 'Menu.target', 'Language.ISO-639-2'),
'order' => array('Menu.lft'),
'recursive' => 0));
$this->set(compact('menusTopUser'));
My associations look like:
Menu
hasMany: MenusUserGroup
MenusUserGroup
belongsTo: Menu, UserGroup
After executing the find, I have the next array where there are many MenusUserGroup empty. How make to filter only the record with 'MenusUserGroup.user_group_id ' => $this->Auth->user('UserGroup.id')?
Array(
[0] => Array
(
[Menu] => Array
(
[title] => Offerte e modulistica promoter
[url] =>
[target] => _self
[id] => 11
)
[Item] => Array
(
[slug] => offerte-e-modulistica-promoter
[id] => 36
)
[Language] => Array
(
[ISO-639-2] => ita
[id] => 1
)
[TemplateRegion] => Array
(
[id] => 10
)
[MenusUserGroup] => Array
(
)
)
[1] => Array
(
[Menu] => Array
(
[title] => Offerte e modulistica agenti
[url] =>
[target] => _self
[id] => 10
)
[Item] => Array
(
[slug] => offerte-modulistica
[id] => 29
)
[Language] => Array
(
[ISO-639-2] => ita
[id] => 1
)
[TemplateRegion] => Array
(
[id] => 10
)
[MenusUserGroup] => Array
(
[0] => Array
(
[id] => 7
[menu_id] => 10
[user_group_id] => 5
)
)
)
[2] => Array
(
[Menu] => Array
(
[title] => Gestione contratti
[url] =>
[target] => _self
[id] => 13
)
[Item] => Array
(
[slug] =>
[id] =>
)
[Language] => Array
(
[ISO-639-2] => ita
[id] => 1
)
[TemplateRegion] => Array
(
[id] => 10
)
[MenusUserGroup] => Array
(
[0] => Array
(
[id] => 10
[menu_id] => 13
[user_group_id] => 5
)
)
)
Use a join.
$menusTopUser = $this->Menu->find('all', array(
// join statement
'joins' => array(
array(
'table' => 'menus_user_groups',
'alias' => 'MenuUserGroupJoin',
'type' => 'INNER',
'conditions' => array(
'MenuUserGroupJoin.menu_id = Menu.id',
// condition
'MenuUserGroupJoin.user_group_id = ' . $this->Auth->user('UserGroup.id'),
),
),
),
'contain' => array('TemplateRegion', 'Language', 'Item', 'MenusUserGroup'),
'conditions' => array(
'TemplateRegion.alias' => 'menu_top_user',
'Menu.active' => 1,
'Language.ISO-639-2' => $this->Session->read('Config.frontendLanguage'),
),
'fields' => array('Menu.title', 'Item.slug', 'Menu.url', 'Menu.target', 'Language.ISO-639-2'),
'order' => array('Menu.lft'),
'recursive' => 0));

Cakephp : Two arrays in foreach loop?

I have 2 arrays. 1 fetching from database and other one is from view page. I am developing a online test exam website so i have to check if the answer entered by user is correct or not.Here is the 1st one.
Array
(
[0] => Array
(
[Question] => Array
(
[id] => 51f92e34-c5a8-4de3-b264-0ff0d0483c4c
[aptitude_id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[paper_id] => 51f924cc-a158-441e-9119-0ff0d0483c4c
[qus] => What is ur name?
[slug] => name-find
[image] =>
[opt1] => x
[opt2] => y
[opt3] => a
[opt4] => b
[opt5] => c
[answer_id] => 4
[description] =>
[ansimage] =>
)
[Aptitude] => Array
(
[id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[name] => php
[slug] => php
)
[Paper] => Array
(
[id] => 51f924cc-a158-441e-9119-0ff0d0483c4c
[aptitude_id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[name] => aptitude1
[slug] => aptitude1
)
[Answer] => Array
(
[id] => 4
[name] => D
)
)
[1] => Array
(
[Question] => Array
(
[id] => 51fe4098-c344-4790-9e46-0fb4d0483c4c
[aptitude_id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[paper_id] => 51f924cc-a158-441e-9119-0ff0d0483c4c
[qus] => Place?
[slug] => place
[image] =>
[opt1] => ss
[opt2] => sss
[opt3] => ss
[opt4] => ss
[opt5] => ss
[answer_id] => 3
[description] =>
[ansimage] =>
)
[Aptitude] => Array
(
[id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[name] => php
[slug] => php
)
[Paper] => Array
(
[id] => 51f924cc-a158-441e-9119-0ff0d0483c4c
[aptitude_id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[name] => aptitude1
[slug] => aptitude1
)
[Answer] => Array
(
[id] => 3
[name] => C
)
)
[2] => Array
(
[Question] => Array
(
[id] => 51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c
[aptitude_id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[paper_id] => 51f924cc-a158-441e-9119-0ff0d0483c4c
[qus] => hayywep?
[slug] => dada
[image] =>
[opt1] => a
[opt2] => a
[opt3] => a
[opt4] => a
[opt5] => a
[answer_id] => 3
[description] =>
[ansimage] =>
)
[Aptitude] => Array
(
[id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[name] => php
[slug] => php
)
[Paper] => Array
(
[id] => 51f924cc-a158-441e-9119-0ff0d0483c4c
[aptitude_id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[name] => aptitude1
[slug] => aptitude1
)
[Answer] => Array
(
[id] => 3
[name] => C
)
)
)
and
Array
(
[51f92e34-c5a8-4de3-b264-0ff0d0483c4c] => 3
[51fe4098-c344-4790-9e46-0fb4d0483c4c] => 3
[51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c] => 3
)
i wrote this code
foreach($res as $res1):
foreach($ans as $ans1):
if($res1['Question']['answer_id']==$ans1)
{
print_r($res1['Question']['id']);
}
endforeach;
endforeach;
Output:
51f92e34-c5a8-4de3-b264-0ff0d0483c4c
51f92e34-c5a8-4de3-b264-0ff0d0483c4c
51f92e34-c5a8-4de3-b264-0ff0d0483c4c
51fe4098-c344-4790-9e46-0fb4d0483c4c
51fe4098-c344-4790-9e46-0fb4d0483c4c
51fe4098-c344-4790-9e46-0fb4d0483c4c
51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c
51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c
51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c
how to remove the duplication?
Try array_unique
$_results = array();
foreach($res as $res1):
foreach($ans as $ans1):
if($res1['Question']['answer_id']==$ans1)
{
$_results[] = $res1['Question']['id'];
}
endforeach;
endforeach;
$results = array_unique($_results);
pr($results);

Resources