I'm having some trouble here V_shop_menu $order_uuid is not populating. Now I'm guessing this is because its yet to be created this is done further below. The problem I have is there are 2 statements here doing inserts to tables but they both rely on each other.
I have a bit of chicken and egg situation as I need $shop_menu_uuid from the top area to complete the bottom insert. I was led to believe that as they are in the same public function it would just work but this is not the case.
What do I need to do to make this happen?
Thanks!
public function add_shopmenu(){
$postData = $this->input->post();
$condition['conditions'][] = "site_name ='".$this->sessionInfo['site']."'";
$site = $this->frontguide_Model->selectSingleRow("t_place",$condition);
$site_uuid = $site['site_uuid'];
unset($condition);
$condition['conditions'][] = "site_uuid ='".$site['site_uuid']."'";
$condition['conditions'][] = "shop_menu_name ='".$postData['shop_menu_name']."'";
$shopmenu_name = $this->frontguide_Model->selectData("v_shop_menus",$condition);
unset($condition);
$condition['conditions'][] = "site_uuid ='".$site['site_uuid']."'";
$shopmenus = $this->frontguide_Model->selectData("v_shop_menus",$condition);
$shop_menu_enabled = (isset($postData['shop_menu_enabled']))?$postData['shop_menu_enabled']:"false";
$shop_menu_uuid = $this->frontguide_functions->uuid();
$v_shop_menu= array(
"shop_menu_uuid" =>$shop_menu_uuid,
"site_uuid" =>$site_uuid,
"order_uuid" =>$order_uuid,
"shop_menu_extension" =>$shop_menu_extension,
"shop_menu_name" =>$postData['shop_menu_name'],
"shop_menu_greet_long" =>$postData['shop_menu_greet_long'],
"shop_menu_greet_short" =>$postData['shop_menu_greet_short'],
"shop_menu_timeout" =>$postData['shop_menu_timeout'],
"shop_menu_enabled" => $shop_menu_enabled,
"shop_menu_cid_prefix"=>$postData['shop_menu_cid_prefix']
);
log_message('debug',print_r($v_shop_menu,TRUE));
$vgu_response = $this->frontguide_Model->insert("v_shop_menus",$v_shop_menu);
$shop_menu_option_digits = $postData['shop_menu_option_digits'];
$shop_menu_option_order = $postData['shop_menu_option_order'];
$shop_menu_option_description = $postData['shop_menu_option_description'];
$shop_menu_option_param = $postData['shop_menu_option_param'];
for($i=0;$i<count($shop_menu_option_digits);$i++){
$option = array();
$option['shop_menu_option_digits'] = $shop_menu_option_digits[$i];
$option['shop_menu_option_order'] = $shop_menu_option_order[$i];
$option['shop_menu_option_description'] = $shop_menu_option_description[$i];
$option['shop_menu_option_param'] = $shop_menu_option_param[$i];
$shop_menu_option_uuid= $this->frontguide_functions->uuid();
$option['shop_menu_option_uuid'] = $shop_menu_option_uuid;
$option['shop_menu_uuid'] = $shop_menu_uuid;
$option['site_uuid'] = $site_uuid;
$vgu_response = $this->frontguide_Model->insert("v_shop_menu_options",$option);
}
$order_uuid = $this->frontguide_functions->uuid();
$order_data = array(
"site_uuid"=>$site_uuid,
"order_uuid"=>$order_uuid,
“offer_uuid" => "a6788e9b-67bc-bd1b-df59-ggg5d51289ab",
"order_context"=>$site['site_name'],
"order_name" =>$postData['shop_menu_name'],
"order_number" =>$shop_menu_extension,
"order_continue" =>'true',
"order_order" =>'333',
"order_enabled" =>"true",
);
$v_orders = $this->frontguide_Model->insert("v_orders",$order_data);
Now I'm guessing this is because its yet to be created this is done
further below.
Yes you are right.
It is quite simple.
Insert v_shop_menus data without $order_uuid .
after inserting in v_orders, get the $order_uuid and update the v_shop_menus using $shop_menu_uuid.
Related
I'm trying to get the total times two authors have edited or coauthored books. (They are selected by a user using checkboxes, so I've used GET to see if the checkbox is selected).
I am cross referencing the authors 'a' (mj) and 'b' (ms) from 'a's' (mj) xml doc that features all their publishing information.
Currently I have this:
if ($_GET['author'] == 'mj55'){
$getMj = new DOMDocument();
$getMj->load("Margret-Jane.xml");
$mjxpath = new DOMXpath($getMj);
$mjAuth = $mjxpath->query("////author[#id = 'mj55']")->length;
$mjEdit = $mjxpath->query("////editor[#id = 'mj55']")->length;
$mjResult = ($mjAuth + $mjEdit);
if ($_GET['author'] == 'ms10' ) {
$mjmsA = $mjxpath->query("////author[#id = 'ms10']")->length;
$mjmsE = $mjxpath->query("////editor[#id = 'ms10']")->length;
$mjmsTotal = ($mjmsA + $mjmsE);
echo $mjmsTotal;
}
}
if I put an echo $mjResult at the end of the first if statement, I get the correct output. But I don't get any output at all from the echo $mjmsTotal
you used a nested if and that's why you are getting a result of only first if.. try to use both the if statement totally independent with each other. Here is an example-
$getMj = new DOMDocument();
$getMj->load("Margret-Jane.xml");
$mjxpath = new DOMXpath($getMj);
if ($_GET['author'] == 'mj55'){
$mjAuth = $mjxpath->query("////author[#id = 'mj55']")->length;
$mjEdit = $mjxpath->query("////editor[#id = 'mj55']")->length;
$mjResult = ($mjAuth + $mjEdit);
}
if ($_GET['author'] == 'ms10' ) {
$mjmsA = $mjxpath->query("////author[#id = 'ms10']")->length;
$mjmsE = $mjxpath->query("////editor[#id = 'ms10']")->length;
$mjmsTotal = ($mjmsA + $mjmsE);
echo $mjmsTotal;
}
You can reduce this to one condition, this saves having to hard code all of the different authors/editors.
First check if the author is set, then include this value in the XPath expressions...
if ( !empty($_GET['author'])) {
$getMj = new DOMDocument();
$getMj->load("Margret-Jane.xml");
$mjxpath = new DOMXpath($getMj);
$mjAuth = $mjxpath->query("//author[#id = '{$_GET['author']}']")->length;
$mjEdit = $mjxpath->query("//editor[#id = '{$_GET['author']}']")->length;
$mjResult = ($mjAuth + $mjEdit);
echo $mjResult;
}
I use the default codeiginter pagination library. I tried implementing this in a previously created page which shows all vacancies, but since we are getting TOO many on the site, the performance is terrible. This is why I need pagination on this page. Note that this is not the cleanest solution, there is a new track going on which overhauls the entire page and starts from scratch. This is a quick & dirty solution because we need to keep it working on our live environment until the rework is done.
This is the controller code I have:
public function overviewVacancies($city = null)
{
$this->is_logged_in();
// Load Models
$this->load->model('vacancy/vacancies_model');
$this->load->model('perk/interests_model');
$this->load->model('perk/engagement_model');
$this->load->model('user/userSavedVacancies_model');
// Passing Variables
$data['title'] = lang("page_title_activities_overview");
$data['description'] = lang('meta_desc_activities');
$data['class'] = 'vacancy';
$data['engagements'] = $this->engagement_model->getAll();
$data['interests'] = $this->interests_model->getAllInterests();
$data['bread'] = $this->breadcrumbmanager->getDashboardBreadcrumb($this->namemanager->getDashboardBreadName("0"), $this->namemanager->getDashboardBreadName("1"));
$data['tasks'] = $this->interests_model->getAllTasks();
// Set session data
$this->session->set_userdata('previous',"http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
$this->session->set_userdata('previous-title', "1");
$filterdata = array(
'interests' => $this->input->post('interests'),
'skills' => $this->input->post('skills'),
'fulldate' => $this->input->post('daterange'),
'location' => $this->input->post('location'),
'city' => $this->input->post('sublocality_level_1'),
'capital' => $this->input->post('locality')
);
if (!empty($filterdata['interests'])) {
$filterdata['interests'] = rtrim($filterdata['interests'], ";");
$filterdata['interests'] = str_replace(' ', '', $filterdata['interests']);
$filterdata['interests'] = str_replace(';', ',', $filterdata['interests']);
}
if (!empty($filterdata['skills'])) {
$filterdata['skills'] = str_replace(' ', '', $filterdata['skills']);
$filterdata['skills'] = explode(",", $filterdata['skills']);
}
//Manually clear the commune and city variables if the location was empty
if (empty($filterdata['location'])) {
$filterdata['city'] = '';
$filterdata['capital'] = '';
}
if($city == null){
$orgId = $this->organization_model->getOrgIdByName(LOCATION);
}
else{
$orgId = $this->organization_model->getOrgIdByName($city);
$data['bread'] = $this->breadcrumbmanager->getLocalBreadcrumb($this->namemanager->getDashboardBreadName("0"), $city, $data['title'], $data['vacancydetails']);
}
//Set the location to the subdomain automatically (e.g. when the link is clicked) so the activities of that subdomain only show up
if (!empty(LOCATION)) {
$data['title'] = sprintf(lang('page_title_local_activities'), ucwords(LOCATION));
$data['description'] = sprintf(lang('meta_desc_local_activities'), ucwords(LOCATION));
$filterdata['location'] = LOCATION;
$data['bgcolor'] = $this->localSettings_model->getBgColorHexValueForOrgId($orgId->org_id);
}
if (!empty($filterdata['fulldate'])) {
$splitfromandto = explode(" - ", $filterdata['fulldate']);
$filterdata['datefrom'] = $splitfromandto[0];
$filterdata['dateto'] = $splitfromandto[1];
} else {
$filterdata['datefrom'] = null;
$filterdata['dateto'] = null;
}
//Put these variables in the data variable so we can prefill our filters again with the previous values
//This is necessary because we don't use AJAX yet
$data['filterdata'] = $filterdata;
//Pagination : We do it here so we can re-use the filter query to count all our results
$this->load->library('pagination');
$data['all_vacancies'] = $this->vacancies_model->getFilteredVacancies($filterdata);
$pagconfig['base_url'] = base_url().VACANCY_OVERVIEW;
$pagconfig['total_rows'] = count($data['all_vacancies']);
$pagconfig['per_page'] = 1;
$pagconfig['uri_segment'] = 2;
$pagconfig['use_page_numbers'] = TRUE;
$this->pagination->initialize($pagconfig);
$data['links'] = $this->pagination->create_links();
$start = max(0, ( $this->uri->segment(2) -1 ) * $pagconfig['per_page']);
//This variable contains all the data necessary for a vacancy to be displayed on the vacancy overview page
$data['vacancies'] = $this->vacancies_model->getFilteredVacancies($filterdata, false, null, false, null, false, false, $pagconfig['per_page'], $start);
// Template declaration
$partials = array('head' => '_master/header/head', 'navigation' => '_master/header/navigation_dashboard', 'content' => 'dashboard/vacancy/overview', 'footer' => '_master/footer/footer');
$data['vacancygrid'] = $this->load->view('dashboard/vacancy/vacancygrid', $data, TRUE);
$this->template->load('_master/master', $partials, $data);
}
As you can see in the code i keep a variable called $filterdata, this contains all data which is used in our filters, since we don't use AJAX in this version, we need to pass it to the view every time to fill it up again and present it to the visitor.
However, using pagination this breaks because it just reloads my controller method and thus the values in $filterdata are lost.
How do I go about this?
Note: it does not have to be a clean solution, it just needs to work since this page is going offline in a couple of weeks anyway.
Thanks a lot in advance!
I'm currently looking at a script that a previous developer made that is meant to look a table, if the id does not exist then create the new code, if it does exist, overwrite the existing one.
Sounds fairly simple, but I can't get my head around how Yii manages the overwrite and new verification code. It is only adding new records, not over writing.
$invitingUser = User::model()->findByPk(Yii::app()->user->id);
if ($invitingUser->isAttending($eventId)) {
// Event attending
$event = Event::model()->findByPk($eventId);
//
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation(array($guestInviteForm));
if (isset($_POST['GuestInviteForm'])) {
$guestInviteForm->attributes = $_POST['GuestInviteForm'];
// Perform Validation
$valid = $guestInviteForm->validate();
if ($valid) {
// Check if a Verification Code entry for this user already exists
$existingVerificationCode = VerificationCode::model()->findByAttributes(array('user_id' => $user->user_id, 'type' => VerificationCode::TYPE_GUEST_INVITE));
//THE CODE ONLY SEEMS TO RUN THIS.
if (is_null($existingVerificationCode)) {
// Create Verification Code instance
$verificationCode = new VerificationCode();
$verificationCode->type = VerificationCode::TYPE_GUEST_INVITE;
$verificationCode->user_id = $invitingUser->id;
$verificationCode->verification_code = VerificationCode::generateVerificationCode();
$verificationCode->forename = $guestInviteForm->forename;
$verificationCode->surname = $guestInviteForm->surname;
$verificationCode->event_id = $eventId;
$verificationCode->save(false);
} else {
// Update existing Verification Code enty
$existingVerificationCode->type = VerificationCode::TYPE_GUEST_INVITE;
$existingVerificationCode->user_id = $invitingUser->id;
$existingVerificationCode->forename = $guestInviteForm->forename;
$existingVerificationCode->surname = $guestInviteForm->surname;
$code = $existingVerificationCode->verification_code = VerificationCode::generateVerificationCode();
$existingVerificationCode->save(false);
}
The code never seems to enter the else here
//THE CODE ONLY SEEMS TO RUN THIS.
if (is_null($existingVerificationCode)) {
// Create Verification Code instance
$verificationCode = new VerificationCode();
$verificationCode->type = VerificationCode::TYPE_GUEST_INVITE;
$verificationCode->user_id = $invitingUser->id;
$verificationCode->verification_code = VerificationCode::generateVerificationCode();
$verificationCode->forename = $guestInviteForm->forename;
$verificationCode->surname = $guestInviteForm->surname;
$verificationCode->event_id = $eventId;
$verificationCode->save(false);
} else {
// Update existing Verification Code enty
$existingVerificationCode->type = VerificationCode::TYPE_GUEST_INVITE;
$existingVerificationCode->user_id = $invitingUser->id;
$existingVerificationCode->forename = $guestInviteForm->forename;
$existingVerificationCode->surname = $guestInviteForm->surname;
$code = $existingVerificationCode->verification_code = VerificationCode::generateVerificationCode();
$existingVerificationCode->save(false);
}
1st. After form validation:
if ($valid) {
Verification code select done:
$existingVerificationCode = VerificationCode::model()->findByAttributes(array('user_id' => $user->user_id, 'type' => VerificationCode::TYPE_GUEST_INVITE));
If you translate it to SQL it will be something like this:
SELECT * FROM verification_code WHERE user_id=x AND type=x
2nd. Check if record exists
if (is_null($existingVerificationCode)) {
If its not - creating new, populating, saving.
Else updating:
$existingVerificationCode->type = VerificationCode::TYPE_GUEST_INVITE;
$existingVerificationCode->user_id = $invitingUser->id;
$existingVerificationCode->forename = $guestInviteForm->forename;
$existingVerificationCode->surname = $guestInviteForm->surname;
$code = $existingVerificationCode->verification_code = VerificationCode::generateVerificationCode();
$existingVerificationCode->save(false);
save(false) means save without validation. Consider model attributes - fields in your database table.
Seems like it ever goes in the ELSE because it never finds $existingVerificationCode.
We don't have the whole code, but from what I see, I suspect you're checking the wrong user, because it's weird to search for an event for $user, and if that doesn't exist, to create one related to $invitingUser.
$existingVerificationCode = VerificationCode::model()->findByAttributes(array('user_id' => $user->user_id, 'type' => VerificationCode::TYPE_GUEST_INVITE));
// ...
$verificationCode->user_id = $invitingUser->id;
My Code:
$RuleNameArray = array();
$dbgetreportsrulename = new DB_MSSQL;
$dbgetreportsrulename->query("Select RulesID,RulesName_Lang_$languageid as RuleName from Main_Rules");
for ($igrn=0;$igrn < $dbgetreportsrulename->num_rows();$igrn++) {
if ($dbgetreportsrulename->next_record()){
$dbgetreportsrulename_RuleID = $dbgetreportsrulename->f('RulesID');
$dbgetreportsrulename_RuleName = $dbgetreportsrulename->f('RuleName');
}
$RuleNameArray = array($dbgetreportsrulename_RuleID => $dbgetreportsrulename_RuleName);
}
How i can keep all entry in $RuleNameArray, because now he keep only last entry.
If you want to keep your all entry then your $RuleNameArray should be :
$RuleNameArray[$dbgetreportsrulename_RuleID] = $dbgetreportsrulename_RuleName;
You can try like this also,
$RuleNameArray[] = array($dbgetreportsrulename_RuleID => $dbgetreportsrulename_RuleName);
^
I have to assign a long array to a codeigniter session but its not working. If I am using an array with three four element then this work. My array is given below.
$value['id'] = $checkout_product['checkout']['id'];
$value['user_id'] = $checkout_product['checkout']['user_id'];
$value['name'] = $checkout_product['checkout']['name'];
$value['maker'] = $checkout_product['checkout']['maker'];
$value['model'] = $checkout_product['checkout']['model'];
$value['color'] = $checkout_product['checkout']['color'];
$value['size'] = $checkout_product['checkout']['size'];
$value['slug'] = $checkout_product['checkout']['slug'];
$value['route_id'] = $checkout_product['checkout']['route_id'];
$value['description'] = $checkout_product['checkout']['description'];
$value['quantity'] = $checkout_product['checkout']['quantity'];
$value['p_units'] = $checkout_product['checkout']['p_units'];
$value['images'] = $checkout_product['checkout']['images'];
$value['label_type'] = $checkout_product['checkout']['label_type'];
$value['product_type'] = $checkout_product['checkout']['product_type'];
$value['auction_id'] = $checkout_product['checkout']['auction_id'];
$value['product_id'] = $checkout_product['checkout']['product_id'];
$value['budget_min'] = $checkout_product['checkout']['budget_min'];
$value['budget_max'] = $checkout_product['checkout']['budget_max'];
$value['bid_start_date'] = $checkout_product['checkout']['bid_start_date'];
$value['bid_end_date'] = $checkout_product['checkout']['bid_end_date'];
$value['status'] = $checkout_product['checkout']['status'];
$value['bid_id'] = $checkout_product['checkout']['bid_id'];
$value['bidder_id'] = $checkout_product['checkout']['bidder_id'];
$value['bid_product_id'] = $checkout_product['checkout']['bid_product_id'];
$value['bid_date'] = $checkout_product['checkout']['bid_date'];
$value['bid_qty'] = $checkout_product['checkout']['bid_qty'];
$value['bid_amount'] = $checkout_product['checkout']['bid_amount'];
$value['total_amount'] = $checkout_product['checkout']['total_amount'];
$value['payable_amount'] = $checkout_product['checkout']['payable_amount'];
$value['shipping_in'] = $checkout_product['checkout']['shipping_in'];
$value['shipping_method'] = $checkout_product['checkout']['shipping_method'];
$value['shipping_amount'] = $checkout_product['checkout']['shipping_amount'];
$value['pro_type'] = $checkout_product['checkout']['pro_type'];
$value['warranty_month'] = $checkout_product['checkout']['warranty_month'];
$value['warranty_type'] = $checkout_product['checkout']['warranty_type'];
$value['bid_note'] = $checkout_product['checkout']['bid_note'];
$value['bid_status'] = $checkout_product['checkout']['bid_status'];
$value['customer_id'] = $checkout_product['checkout']['customer_id'];
$value['customer_username'] = $checkout_product['checkout']['customer_username'];
$value['customer_firstname'] = $checkout_product['checkout']['customer_firstname'];
$value['customer_lastname'] = $checkout_product['checkout']['customer_lastname'];
$value['customer_email'] = $checkout_product['checkout']['customer_email'];
$value['customer_image'] = $checkout_product['checkout']['customer_image'];
$this->session->set_userdata('checkout', $value);
This code is not working for me. Please help me how I can post big array in session in codeigniter.
By default CodeIgniter stores the session data in a cookie, which has an upper limit of 2KB-4KB in size depending on browser.
If you are trying to store more than 4KB of data in the session you will start running into issues.
The easiest solution is to store the session details in the DB. The Codeigniter session documentation details the process for storing the session in the DB.