The function below is from the SmartJobBoard script and its main job is to send an email notification whenever a job seeker applies to a job.
What I want is to put a condition that will make it run depending on whether an $application_email is present. If no $application_email is present, then the function should not run.
public static function sendApplyNow($info, $file = '', $data_resume = array(), $current_user_sid = false, $notRegisterUserData = false, $score = false)
{
if ($current_user_sid) {
$user_info = SJB_UserManager::getUserInfoBySID($current_user_sid);
$sender_email_address = $user_info['email'];
} else {
$sender_email_address = $notRegisterUserData['email'];
}
$application_email = SJB_Applications::getApplicationEmailbyListingId($info['listing']['id']);
$email_address = !empty($application_email) ? $application_email : $info['listing']['user']['email'];
$questionnaire = !empty($info['submitted_data']['questionnaire'])?unserialize($info['submitted_data']['questionnaire']):'';
$questionnaireInfo = array();
if ($questionnaire) {
$listingInfo = SJB_ListingManager::getListingInfoBySID($info['listing']['id']);
$questSID = isset($listingInfo['screening_questionnaire'])?$listingInfo['screening_questionnaire']:0;
$questionnaireInfo = SJB_ScreeningQuestionnaires::getInfoBySID($questSID);
$passing_score = 0;
switch ($questionnaireInfo['passing_score']) {
case 'acceptable':
$passing_score = 1;
break;
case 'good':
$passing_score = 2;
break;
case 'very_good':
$passing_score = 3;
break;
case 'excellent':
$passing_score = 4;
break;
}
if ($score >= $passing_score) {
$questionnaireInfo['passing_score'] = 'Passed';
}
else {
$questionnaireInfo['passing_score'] = 'Not passed';
}
}
if (!empty($info['listing']['subuser']['sid'])) {
$subUserInfo = SJB_UserManager::getUserInfoBySID($info['listing']['subuser']['sid']);
if (!empty($subUserInfo)) {
$email_address = $subUserInfo['email'];
}
}
$data = array(
'user' => SJB_Array::getPath($info, 'listing/user'),
'listing' => $info['listing'],
'applicant_request' => $info['submitted_data'],
'data_resume' => $data_resume,
'questionnaire' => $questionnaire,
'score' => $score,
'questionnaire_info' => $questionnaireInfo);
$email = SJB_EmailTemplateEditor::getEmail($email_address, self::SEND_APPLY_NOW_SID, $data);
$email->setReplyTo($sender_email_address);
if ($file != '') {
$email->setFile($file);
}
return $email->send('Apply Now');
}
Appreciate your help.
Thanks.
<?php
$application_email = SJB_Applications::getApplicationEmailbyListingId($info['listing']['id']);
if(empty($application_email)) return; # New line
$email_address = !empty($application_email) ? $application_email : $info['listing']['user']['email'];
Related
I have an e-commerce site in opencart and I have a problem in the RG field which is as follows, when the user registers it fills all the fields normally but in the RG field there are those users that have one digit less in the RG that they are usually 9 more digits have users with 8 and they usually register on the site more when they are going to make a purchase they can not conclude it because the RG is with a number less would like to know if it is possible to put a code that does the following when the User to enter a RG with one digit less or less than 9 add a 0 at the end of the field so that it is complete.
This is uexatamente the input that I need to change so that when the user clicks on register it will be saved with the longest digit
<Input type = "text" name = "custom_field [account] [2]" value = "" placeholder = "RG" id = "input-custom-field2" class = "form-control">
I do not know if this is where I am going to implement my code but this is one of the controllers responsible for the registration of the form
<?php
class ControllerAccountRegister extends Controller {
private $error = array();
public function index() {
if ($this->customer->isLogged()) {
$this->response->redirect($this->url->link('account/account', '', 'SSL'));
}
$this->load->language('account/register');
$this->document->setTitle($this->language->get('heading_title'));
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment.js');
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js');
$this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');
$this->load->model('account/customer');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$customer_id = $this->model_account_customer->addCustomer($this->request->post);
// Clear any previous login attempts for unregistered accounts.
$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
$this->customer->login($this->request->post['email'], $this->request->post['password']);
unset($this->session->data['guest']);
// Add to activity log
$this->load->model('account/activity');
$activity_data = array(
'customer_id' => $customer_id,
'name' => $this->request->post['firstname']
//'name' => $this->request->post['firstname'] . ' ' . $this->request->post['lastname']
);
$this->model_account_activity->addActivity('register', $activity_data);
$this->response->redirect($this->url->link('account/success'));
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_register'),
'href' => $this->url->link('account/register', '', 'SSL')
);
$data['heading_title'] = $this->language->get('heading_title');
$data['text_account_already'] = sprintf($this->language->get('text_account_already'), $this->url->link('account/login', '', 'SSL'));
$data['text_your_details'] = $this->language->get('text_your_details');
$data['text_your_address'] = $this->language->get('text_your_address');
$data['text_your_password'] = $this->language->get('text_your_password');
$data['text_newsletter'] = $this->language->get('text_newsletter');
$data['text_yes'] = $this->language->get('text_yes');
$data['text_no'] = $this->language->get('text_no');
$data['text_select'] = $this->language->get('text_select');
$data['text_none'] = $this->language->get('text_none');
$data['text_loading'] = $this->language->get('text_loading');
$data['entry_customer_group'] = $this->language->get('entry_customer_group');
$data['entry_firstname'] = $this->language->get('entry_firstname');
// $data['entry_lastname'] = $this->language->get('entry_lastname');
$data['entry_email'] = $this->language->get('entry_email');
$data['entry_telephone'] = $this->language->get('entry_telephone');
$data['entry_fax'] = $this->language->get('entry_fax');
$data['entry_company'] = $this->language->get('entry_company');
$data['entry_address_1'] = $this->language->get('entry_address_1');
$data['entry_address_2'] = $this->language->get('entry_address_2');
$data['entry_postcode'] = $this->language->get('entry_postcode');
$data['entry_city'] = $this->language->get('entry_city');
$data['entry_country'] = $this->language->get('entry_country');
$data['entry_zone'] = $this->language->get('entry_zone');
$data['entry_newsletter'] = $this->language->get('entry_newsletter');
$data['entry_password'] = $this->language->get('entry_password');
$data['entry_confirm'] = $this->language->get('entry_confirm');
$data['button_continue'] = $this->language->get('button_continue');
$data['button_upload'] = $this->language->get('button_upload');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['firstname'])) {
$data['error_firstname'] = $this->error['firstname'];
} else {
$data['error_firstname'] = '';
}
// if (isset($this->error['lastname'])) {
// $data['error_lastname'] = $this->error['lastname'];
// } else {
// $data['error_lastname'] = '';
// }
if (isset($this->error['email'])) {
$data['error_email'] = $this->error['email'];
} else {
$data['error_email'] = '';
}
if (isset($this->error['telephone'])) {
$data['error_telephone'] = $this->error['telephone'];
} else {
$data['error_telephone'] = '';
}
if (isset($this->error['address_1'])) {
$data['error_address_1'] = $this->error['address_1'];
} else {
$data['error_address_1'] = '';
}
if (isset($this->error['city'])) {
$data['error_city'] = $this->error['city'];
} else {
$data['error_city'] = '';
}
if (isset($this->error['postcode'])) {
$data['error_postcode'] = $this->error['postcode'];
} else {
$data['error_postcode'] = '';
}
if (isset($this->error['country'])) {
$data['error_country'] = $this->error['country'];
} else {
$data['error_country'] = '';
}
if (isset($this->error['zone'])) {
$data['error_zone'] = $this->error['zone'];
} else {
$data['error_zone'] = '';
}
if (isset($this->error['custom_field'])) {
$data['error_custom_field'] = $this->error['custom_field'];
} else {
$data['error_custom_field'] = array();
}
if (isset($this->error['password'])) {
$data['error_password'] = $this->error['password'];
} else {
$data['error_password'] = '';
}
if (isset($this->error['confirm'])) {
$data['error_confirm'] = $this->error['confirm'];
} else {
$data['error_confirm'] = '';
}
$data['action'] = $this->url->link('account/register', '', 'SSL');
$data['customer_groups'] = array();
if (is_array($this->config->get('config_customer_group_display'))) {
$this->load->model('account/customer_group');
$customer_groups = $this->model_account_customer_group->getCustomerGroups();
foreach ($customer_groups as $customer_group) {
if (in_array($customer_group['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$data['customer_groups'][] = $customer_group;
}
}
}
if (isset($this->request->post['customer_group_id'])) {
$data['customer_group_id'] = $this->request->post['customer_group_id'];
} else {
$data['customer_group_id'] = $this->config->get('config_customer_group_id');
}
if (isset($this->request->post['firstname'])) {
$data['firstname'] = $this->request->post['firstname'];
} else {
$data['firstname'] = '';
}
// if (isset($this->request->post['lastname'])) {
// $data['lastname'] = $this->request->post['lastname'];
// } else {
// $data['lastname'] = '';
// }
if (isset($this->request->post['email'])) {
$data['email'] = $this->request->post['email'];
} else {
$data['email'] = '';
}
if (isset($this->request->post['telephone'])) {
$data['telephone'] = $this->request->post['telephone'];
} else {
$data['telephone'] = '';
}
if (isset($this->request->post['fax'])) {
$data['fax'] = $this->request->post['fax'];
} else {
$data['fax'] = '';
}
if (isset($this->request->post['company'])) {
$data['company'] = $this->request->post['company'];
} else {
$data['company'] = '';
}
if (isset($this->request->post['address_1'])) {
$data['address_1'] = $this->request->post['address_1'];
} else {
$data['address_1'] = '';
}
if (isset($this->request->post['address_2'])) {
$data['address_2'] = $this->request->post['address_2'];
} else {
$data['address_2'] = '';
}
if (isset($this->request->post['postcode'])) {
$data['postcode'] = $this->request->post['postcode'];
} elseif (isset($this->session->data['shipping_address']['postcode'])) {
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
} else {
$data['postcode'] = '';
}
if (isset($this->request->post['city'])) {
$data['city'] = $this->request->post['city'];
} else {
$data['city'] = '';
}
if (isset($this->request->post['country_id'])) {
$data['country_id'] = $this->request->post['country_id'];
} elseif (isset($this->session->data['shipping_address']['country_id'])) {
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
} else {
$data['country_id'] = $this->config->get('config_country_id');
}
if (isset($this->request->post['zone_id'])) {
$data['zone_id'] = $this->request->post['zone_id'];
} elseif (isset($this->session->data['shipping_address']['zone_id'])) {
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
} else {
$data['zone_id'] = '';
}
$this->load->model('localisation/country');
$data['countries'] = $this->model_localisation_country->getCountries();
// Custom Fields
$this->load->model('account/custom_field');
$data['custom_fields'] = $this->model_account_custom_field->getCustomFields();
if (isset($this->request->post['custom_field'])) {
if (isset($this->request->post['custom_field']['account'])) {
$account_custom_field = $this->request->post['custom_field']['account'];
} else {
$account_custom_field = array();
}
if (isset($this->request->post['custom_field']['address'])) {
$address_custom_field = $this->request->post['custom_field']['address'];
} else {
$address_custom_field = array();
}
$data['register_custom_field'] = $account_custom_field + $address_custom_field;
} else {
$data['register_custom_field'] = array();
}
if (isset($this->request->post['password'])) {
$data['password'] = $this->request->post['password'];
} else {
$data['password'] = '';
}
if (isset($this->request->post['confirm'])) {
$data['confirm'] = $this->request->post['confirm'];
} else {
$data['confirm'] = '';
}
if (isset($this->request->post['newsletter'])) {
$data['newsletter'] = $this->request->post['newsletter'];
} else {
$data['newsletter'] = '';
}
if ($this->config->get('config_account_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
if ($information_info) {
$data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/agree', 'information_id=' . $this->config->get('config_account_id'), 'SSL'), $information_info['title'], $information_info['title']);
} else {
$data['text_agree'] = '';
}
} else {
$data['text_agree'] = '';
}
if (isset($this->request->post['agree'])) {
$data['agree'] = $this->request->post['agree'];
} else {
$data['agree'] = false;
}
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/register.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/account/register.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/account/register.tpl', $data));
}
}
public function validate() {
if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$this->error['firstname'] = $this->language->get('error_firstname');
}
// if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
// $this->error['lastname'] = $this->language->get('error_lastname');
// }
if ((utf8_strlen($this->request->post['email']) > 96) || !preg_match('/^[^\#]+#.*.[a-z]{2,15}$/i', $this->request->post['email'])) {
$this->error['email'] = $this->language->get('error_email');
}
if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
$this->error['warning'] = $this->language->get('error_exists');
}
if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
$this->error['telephone'] = $this->language->get('error_telephone');
}
if ((utf8_strlen(trim($this->request->post['address_1'])) < 3) || (utf8_strlen(trim($this->request->post['address_1'])) > 128)) {
$this->error['address_1'] = $this->language->get('error_address_1');
}
if ((utf8_strlen(trim($this->request->post['city'])) < 2) || (utf8_strlen(trim($this->request->post['city'])) > 128)) {
$this->error['city'] = $this->language->get('error_city');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) {
$this->error['postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['country_id'] == '') {
$this->error['country'] = $this->language->get('error_country');
}
if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') {
$this->error['zone'] = $this->language->get('error_zone');
}
// Customer Group
if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->post['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
// Custom field validation
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
$this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
if ((utf8_strlen($this->request->post['password']) < 4) || (utf8_strlen($this->request->post['password']) > 20)) {
$this->error['password'] = $this->language->get('error_password');
}
if ($this->request->post['confirm'] != $this->request->post['password']) {
$this->error['confirm'] = $this->language->get('error_confirm');
}
// Agree to terms
if ($this->config->get('config_account_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
if ($information_info && !isset($this->request->post['agree'])) {
$this->error['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
}
}
return !$this->error;
}
public function customfield() {
$json = array();
$this->load->model('account/custom_field');
// Customer Group
if (isset($this->request->get['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->get['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->get['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
$json[] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'required' => $custom_field['required']
);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
may be you can use this script.
function putZeroToLastItem($text) {
$length = strlen($text);
if( $length < 9 ) {
$text .= '0'
}
return $text
}
I hope , this script will solve your porblem.
<?php
$num = 3;
$num_padded = sprintf("%02d", $num);
echo $num_padded; // returns 03
?>
Try this simple snippet
You want to add 0 after the number (9 digit)? Use jquery if you want it in client side.
function addZero (data){
return data+(data <10 ? '0':'');
}
var num =$('#number').val();
var nNum = addZero(num);
Hope it helps.
A reduced way of #mehfatitem:
function putZeroToLastItem($text) {
return (strlen($text) < 9) ? $text . '0' : $text;
}
Below is the function for saving some reservation details to the database. get_hall() query returns 2 halls(haal1 and hall2). bus when going to the database only hall1 is inserting. I want to insert hall1 next reservation hall2. How to improve below code.
function save_reserve_detail($date,$time,$flag){
$halls = $this->halls_model->get_hall();
foreach ($halls AS $each) {
$hall = $each['hall_id'];
break;
}
$reference_no = date("YmdHis");
if ($flag == 1) {
$hall_id = $hall;
$type = 1;
$date = $date;
} else if ($flag == 2) {
$hall_id = $hall;
$type = 0;
$date = $date;
}
$data = array(
'reference_no' => $reference_no,
'date' => $date,
'type' => $type,
'hall' => $hall
);
$result = $this->db->insert('reserving_details', $data);
if ($result) {
return $reference_no;
} else {
return 0;
}
}
Remove the break from foreach . now the $hall contains an array of 2 values. now use a for loop to insert the value into the table.
<?php
function save_reserve_detail($date,$time,$flag){
$halls = $this->halls_model->get_hall();
foreach ($halls AS $each) {
$hall = $each['hall_id'];
// break;
}
$reference_no = date("YmdHis");
if ($flag == 1) {
$hall_id = $hall;
$type = 1;
$date = $date;
} else if ($flag == 2) {
$hall_id = $hall;
$type = 0;
$date = $date;
}
for($i=0;$i<sizeof($hall);$i++){
$data = array(
'reference_no' => $reference_no,
'date' => $date,
'type' => $type,
'hall' => $hall[$i]
);
$result = $this->db->insert('reserving_details', $data);
if ($result) {
return $reference_no;
} else {
return 0;
}
}
}
?>
Even you can alter your insert('reserving_details', $data); code which can handle array insertion.
Is there any maximal length of controller class in codeigniter?
for me one controller wasn't working but when i deleted some lines the same code started working . anyone know whats going on ?
working code :
<?php
if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class C_Object_details extends CI_Controller {
function __construct() {
parent::__construct();
respoti_profiler();
$this->load->library('session');
$this->load->model('m_object_details');
$this->params['set_tag'] = array();
$this->params['title_auto'] = true;
}
protected function convert_meta_results($result_meta) {
$meta_list = array();
foreach ($result_meta as $value) {
$meta_list[$value['meta_key']] = $value['meta_value'];
}
return $meta_list;
}
public function index() {
$id = (int) $this->uri->segment(2);
$object = $this->m_object_details->get_object($id);
if (empty($object)) {
show_404(sprintf('Brak obiektu o id: %s', $id));
}
$result_meta = $this->m_object_details->get_object_meta($id);
$meta_list = $this->convert_meta_results($result_meta);
unset($result_meta);
$rooms = array();
if ($object['post_url'] === 'hotel') {
$room_list = $this->m_object_details->get_room_list($object['post_code']);
foreach ($room_list as $key => $val) {
$where_in[] = $val['room_id'];
}
/* pobranie danych meta pokoi */
$room_meta_list = $this->m_object_details->get_room_meta($where_in);
foreach ($room_meta_list as $key => $value) {
$rooms[$value['metaroom_room_id']]['meta'][$value['metaroom_key']] = $value['metaroom_value'];
}
foreach ($room_list as $key => $val) {
$rooms[$val['room_id']]['room'] = $val;
}
unset($room_list, $room_meta_list);
}
//wygenerowanie listy atrybutow pokoi
$rooms_pref = array();
foreach ($rooms as $value) {
if (isset($value['meta'])) {
foreach ($value['meta'] as $key1 => $value) {
if (strpos($key, 'pref-') === false) {
continue;
}
$rooms_pref[$key1] = $value;
}
}
}
## OPINIE ##
$count = 0;
$opinia = 0;
$arr_opinion = array();
if (isset($meta_list['obj_booking_opinion'])) {
$arr_opinion[] = $meta_list['obj_booking_opinion'];
}
if (isset($meta_list['obj_google_opinion'])) {
$arr_opinion[] = $meta_list['obj_google_opinion'];
}
if (isset($meta_list['obj_hrs_opinion'])) {
$arr_opinion[] = $meta_list['obj_hrs_opinion'];
}
if (isset($meta_list['obj_ta_opinion'])) {
$arr_opinion[] = $meta_list['obj_ta_opinion'];
}
foreach ($arr_opinion as $value) {
$tmp_value = 0 + ( str_replace(',', '.', $value) );
if ($tmp_value > 0) {
$count++;
$opinia += $tmp_value;
}
}
if ($count === 0) {
$opinia = 0;
} else {
$opinia = round($opinia / $count, 1);
}
if ($opinia < 10) {
$opinia = number_format($opinia, 1, '.', '');
}
$arr_opinioncount = array();
if (isset($meta_list['obj_booking_opinioncount'])) {
$arr_opinioncount[] = $meta_list['obj_booking_opinioncount'];
}
if (isset($meta_list['obj_hrs_opinioncount'])) {
$arr_opinioncount[] = $meta_list['obj_hrs_opinioncount'];
}
if (isset($meta_list['obj_google_opinioncount'])) {
$arr_opinioncount[] = $meta_list['obj_google_opinioncount'];
}
if (isset($meta_list['obj_ta_opinioncount'])) {
$arr_opinioncount[] = $meta_list['obj_ta_opinioncount'];
}
$ilosc_opini = 0;
foreach ($arr_opinioncount as $value) {
$ilosc_opini += $value;
}
## KONIEC OPINI ##
## LINKI DO GALERI ##
$link_thumb = 'http://exifex.pl/system/uploads/300/';
$link_full = 'http://exifex.pl/system/uploads/';
$gallery_thumb = glob(sprintf("/home/respoti/domains/exifex.pl/public_html/system/uploads/300/%s*", $object['post_code']));
$gallery_full = glob(sprintf("/home/respoti/domains/exifex.pl/public_html/system/uploads/%s*", $object['post_code']));
## KONIEC LINKI DO GALERII ##
## hotele wyciag
if (isset($meta_list['attraction_price'])) {
$atr_price = $meta_list['attraction_price'];
} else
$atr_price = null;
if (isset($meta_list['rest_pricerange'])) {
$rest_price_range = $meta_list['rest_pricerange'];
} else {
$rest_price_range = null;
}
//dodane dzis
if (isset($meta_list['attraction_eventsorganized'])) {
$attr_type = $meta_list['attraction_eventsorganized'];
} else {
$attr_type = null;
}
if (isset($meta_list['rest_openhoursrange_start'])) {
$pn_pt = $meta_list['rest_openhoursrange_start'];
} else {
$pn_pt = null;
}
if (isset($meta_list['rest_openhoursrange_end'])) {
$pn_pt_e = $meta_list['rest_openhoursrange_end'];
} else {
$pn_pt_e = null;
}
if (isset($meta_list['rest_openhoursweekend_start'])) {
$pt = $meta_list['rest_openhoursweekend_start'];
} else {
$pt = null;
}
if (isset($meta_list['rest_openhoursweekend_end'])) {
$pt_e = $meta_list['rest_openhoursweekend_end'];
} else {
$pt_e = null;
}
if (isset($meta_list['rest_openhourssunday_start'])) {
$sun = $meta_list['rest_openhourssunday_start'];
} else {
$sun = null;
}
if (isset($meta_list['rest_openhourssunday_end'])) {
$sun_e = $meta_list['rest_openhourssunday_end'];
} else {
$sun_e = null;
}
if (isset($meta_list['nightlife_openhourssunday_start'])) {
$n_sun = $meta_list['nightlife_openhourssunday_start'];
} else {
$n_sun = null;
}
if (isset($meta_list['nightlife_openhourssunday_end'])) {
$n_sun_e = $meta_list['nightlife_openhourssunday_end'];
} else {
$n_sun_e = null;
}
if (isset($meta_list['nightlife_openhoursweekend_start'])) {
$n_pt = $meta_list['nightlife_openhoursweekend_start'];
} else {
$n_pt = null;
}
if (isset($meta_list['nightlife_openhoursweekend_end'])) {
$n_pt_e = $meta_list['nightlife_openhoursweekend_end'];
} else {
$n_pt_e = null;
}
if (isset($meta_list['nightlife_openhoursrange_start'])) {
$n_pn_pt = $meta_list['nightlife_openhoursrange_start'];
} else {
$n_pn_pt = null;
}
if (isset($meta_list['nightlife_openhoursrange_end'])) {
$n_pn_pt_e = $meta_list['nightlife_openhoursrange_end'];
} else {
$n_pn_pt_e = null;
}
if (isset($meta_list['nightlife_open_1_start'])) {
$pn_1 = $meta_list['nightlife_open_1_start'];
} else
$pn_1 = null;
if (isset($meta_list['nightlife_open_1_end'])) {
$pn_2 = $meta_list['nightlife_open_1_end'];
} else
$pn_2 = null;
if (isset($meta_list['nightlife_open_2_start'])) {
$wt_1 = $meta_list['nightlife_open_2_start'];
} else
$wt_1 = null;
if (isset($meta_list['nightlife_open_2_end'])) {
$wt_2 = $meta_list['nightlife_open_2_end'];
} else
$wt_2 = null;
if (isset($meta_list['nightlife_open_3_start'])) {
$sr_1 = $meta_list['nightlife_open_3_start'];
} else
$sr_1 = null;
if (isset($meta_list['nightlife_open_3_end'])) {
$sr_2 = $meta_list['nightlife_open_3_end'];
} else
$sr_2 = null;
if (isset($meta_list['nightlife_open_4_start'])) {
$czw_1 = $meta_list['nightlife_open_4_start'];
} else
$czw_1 = null;
if (isset($meta_list['nightlife_open_4_end'])) {
$czw_2 = $meta_list['nightlife_open_4_end'];
} else
$czw_2 = null;
if (isset($meta_list['nightlife_open_5_start'])) {
$pt_1 = $meta_list['nightlife_open_5_start'];
} else
$pt_1 = null;
if (isset($meta_list['nightlife_open_5_end'])) {
$pt_2 = $meta_list['nightlife_open_5_end'];
} else
$pt_2 = null;
if (isset($meta_list['nightlife_open_6_start'])) {
$sob_1 = $meta_list['nightlife_open_6_start'];
} else
$sob_1 = null;
if (isset($meta_list['nightlife_open_6_end'])) {
$sob_2 = $meta_list['nightlife_open_6_end'];
} else
$sob_2 = null;
if (isset($meta_list['nightlife_open_7_start'])) {
$nd_1 = $meta_list['nightlife_open_7_start'];
} else
$nd_1 = null;
if (isset($meta_list['nightlife_open_7_end'])) {
$nd_2 = $meta_list['nightlife_open_7_end'];
} else
$nd_2 = null;
//rest
if (isset($meta_list['rest_open_1_start'])) {
$r_pn_1 = $meta_list['rest_open_1_start'];
} else
$r_pn_1 = null;
if (isset($meta_list['rest_open_1_end'])) {
$r_pn_2 = $meta_list['rest_open_1_end'];
} else
$r_pn_2 = null;
if (isset($meta_list['rest_open_2_start'])) {
$r_wt_1 = $meta_list['rest_open_2_start'];
} else
$r_wt_1 = null;
if (isset($meta_list['rest_open_2_end'])) {
$r_wt_2 = $meta_list['rest_open_2_end'];
} else
$r_wt_2 = null;
if (isset($meta_list['rest_open_3_start'])) {
$r_sr_1 = $meta_list['rest_open_3_start'];
} else
$r_sr_1 = null;
if (isset($meta_list['rest_open_3_end'])) {
$r_sr_2 = $meta_list['rest_open_3_end'];
} else
$r_sr_2 = null;
if (isset($meta_list['rest_open_4_start'])) {
$r_czw_1 = $meta_list['rest_open_4_start'];
} else
$r_czw_1 = null;
if (isset($meta_list['rest_open_4_end'])) {
$r_czw_2 = $meta_list['rest_open_4_end'];
} else $r_czw_2 = null;
if (isset($meta_list['rest_open_5_start'])) {
$r_pt_1 = $meta_list['rest_open_5_start'];
} else $r_pt_1 = null;
if (isset($meta_list['rest_open_5_end'])) {
$r_pt_2 = $meta_list['rest_open_5_end'];
} else
$r_pt_2 = null;
if (isset($meta_list['rest_open_6_start'])) {
$r_sob_1 = $meta_list['rest_open_6_start'];
} else
$r_sob_1 = null;
if (isset($meta_list['rest_open_6_end'])) {
$r_sob_2 = $meta_list['rest_open_6_end'];
} else
$r_sob_2 = null;
if (isset($meta_list['rest_open_7_start'])) {
$r_nd_1 = $meta_list['rest_open_7_start'];
} else
$r_nd_1 = null;
if (isset($meta_list['rest_open_7_end'])) {
$r_nd_2 = $meta_list['rest_open_7_end'];
} else
$r_nd_2 = null;
$params = array(
'object' => $object,'meta' => $meta_list,'rooms' => $rooms,
'rooms_pref' => $rooms_pref,'opinia' => $opinia,'opinia_opisowa' => config('opinia_opisowa'),
'ilosc_opini' => $ilosc_opini,
'link_thumb' => $link_thumb,
'link_full' => $link_full,
'gallery_thumb' => $gallery_thumb,
'gallery_full' => $gallery_full,
'title' => $object['post_title'],
'email' => $meta_list['email_object'],
'web' => $meta_list['obj_site'],
'phone' => $meta_list['obj_phone'],
'typ' => $object['post_url'],
'adres' => $object['post_address'],
'post_code' => $object['post_post'],
'fb' => $meta_list['obj_fb'],
'pref' => $this->m_object_details->get_pref($id),
'typ_hot' => $object['post_object_type'],
'kuchnia' => $this->m_object_details->get_kitchen($id),
'rcena' => $rest_price_range,
'acena' => $atr_price,
'typ_obj' => $this->m_object_details->get_smth($id, 'attraction_eventsorganized'),
'pn_pt' => $pn_pt,'pn_pt_e' => $pn_pt_e,'pt' => $pt,'pt_e' => $pt_e,'sun' => $sun,
'sun_e' => $sun_e,'n_pn_pt' => $n_pn_pt,
'n_pn_pt_e' => $n_pn_pt_e,'n_pt' => $n_pt,
'n_pt_e' => $n_pt_e,'n_sun' => $n_sun,'n_sun_e' => $n_sun_e,
'attr_type' => $attr_type,'pn_1' => $pn_1,'pn_2' => $pn_2,
'wt_1' => $wt_1,'wt_2' => $wt_2,'sr_1' => $sr_1,'sr_2' => $sr_2,
'czw_1' => $czw_1,'czw_2' => $czw_2,'pt_1' => $pt_1, 'pt_2' => $pt_2,
'sob_1' => $sob_1,'sob_2' => $sob_2,
'nd_1' => $nd_1,'nd_2' => $nd_2,'r_pn_1' => $r_pn_1,'r_pn_2' => $r_pn_2,'r_wt_1' => $r_wt_1,
'r_wt_2' => $r_wt_2,'r_sr_1' => $r_sr_1,'r_sr_2' => $r_sr_2,
'r_czw_1' => $r_czw_1,'r_czw_2' => $r_czw_2,
'r_pt_1' => $r_pt_1,'r_pt_2' => $r_pt_2,'r_sob_1' => $r_sob_1,
'r_sob_2' => $r_sob_2,'r_nd_1' => $r_nd_1,'r_nd_2' => $r_nd_2
);
$hotel_data = array(
'hotel_adres' => $object['post_address'],
'hotel_email' => $meta_list['email_object'],
'hotel_telefon' => $meta_list['obj_phone'],
'hotel_post_code' => $object['post_post'],
'hotel_gps_lat' => $meta_list['lat'],
'hotel_gps_lng' => $meta_list['lng'],
'hotel_name' => $object['post_title'],
);
//$this->session->set_userdata('hotel_adres',$adres);
$this->session->set_userdata($hotel_data);
$this->params = array_merge($this->params, $params);
$this->load->view('object_details/index', $this->params);
}
}
not working was added this :
$email = $meta_list['email_object'];
$web = $meta_list['obj_site'];
$telefon = $meta_list['obj_phone'];
$adres = $object['post_address'];
$post_code = $object['post_post'];
$typ = $object['post_url'];
$typ_hot = $object['post_object_type'];
$fb = $meta_list['obj_fb'];
$moc = $this->m_object_details->get_all_meta_key();
$kuchnia = $this->m_object_details->get_kitchen($id);
body is limited to 30 k chars ::<
Codeigntier does not have any rule for class/function code length.Its same as PHP.
As I know PHP does not have any limitation for clasname or function length.So CI does not have any limitation.
But Its hard to debug your such long code where you made mistake.
I am using the following code to enter submitted names into the database. The code, when working correctly, should capture the names and other information submitted in the form and create three unique entries in the database. This is not happening. Instead the code is capturing the last name in the three pack and entering its information into the database. You can view the form here beta website. The payment processing script is disabled on the form. What do I need to change in the for loop code to fix this issue? Any assistance is greatly appreciated. Thank you. I have added all of the code that is used in the script below. Hopefully this will give you a better understanding of what is going on in the script.
class DreamModelDream extends JModel {
function getDetails()
{
$session = JFactory::getSession();
if($session->get('dreamticket'))
{
return $session->get('dreamticket');
}
$data = new stdClass();
$data->tickets = -1;
$data->fiftytickets = '';
$data->qty = 0;
$data->fiftyqty = 0;
$data->firstname = '';
$data->firstname2 = '';
$data->firstname3 = '';
$data->lastname = '';
$data->lastname2 = '';
$data->lastname3 = '';
$data->address = '';
$data->address2 = '';
$data->address3 = '';
$data->city = '';
$data->city2 = '';
$data->city3 = '';
$data->postal = '';
$data->postal2 = '';
$data->postal3 = '';
$data->phone = '';
$data->phone2 = '';
$data->phone3 = '';
$data->altphone = '';
$data->altphone2 = '';
$data->altphone3 = '';
$data->email = '';
$data->email2 = '';
$data->email3 = '';
$data->giftname = '';
$data->giftaddress = '';
$data->giftcity = '';
$data->giftpostal = '';
$data->sec_firstname = '';
$data->sec_firstname2 = '';
$data->sec_firstname3 = '';
$data->sec_lastname = '';
$data->sec_lastname2 = '';
$data->sec_lastname3 = '';
$data->agegroup = 0;
$data->expm = 0;
$data->expy = 0;
$data->nameoncard = '';
$data->cctype = '';
$data->ccnum = '';
$data->Media_Radio = false;
$data->Media_TV = false;
$data->Media_Newspaper = false;
$data->Media_Mail = false;
$data->Media_Web = false;
$data->Media_Kinsmen_Member = false;
$data->Media_Other = false;
$data->Radio_CJCY = false;
$data->Radio_MY96 = false;
$data->Radio_ROCK = false;
$data->Radio_CHAT = false;
$data->Radio_POWER = false;
$data->Radio_Other = false;
$data->total = false;
$data->billingphone = '';
$data->agree = 0;
$data->ord_type = 0;
$data->creditcard = '';
$data->user_ip = $_SERVER['REMOTE_ADDR'];
return $data;
}
function getConfirmDetails()
{
$post = JRequest::get('post');
$ticket = new stdClass();
foreach($post as $key => $value)
{
$ticket->$key = $value;
}
$session = JFactory::getSession();
$session->set('dreamticket', $ticket);
if(!strlen($post['firstname'])){
return "Your first name is missing<br>";
}
if(!strlen($post['lastname'])){
return "Your last name is missing<br>";
}
if(!strlen($post['address'])){
return "Your address is missing<br>";
}
if(!strlen($post['city'])){
return "Your city is missing<br>";
}
if(!strlen($post['postal'])){
return "Your postal code is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal'])) {
//return "Your postal code is invalid for this province<br>";
}
if(!strlen($post['phone'])){
return "Your phone number is missing<br>";
}
if(!strlen($post['email'])){
return "Your email is missing<br>";
}
if($post['tickets'] == '-1'){
////////// TICKET 2
if(!strlen($post['firstname2'])){
return "Your first2 name is missing<br>";
}
if(!strlen($post['lastname2'])){
return "Your last2 name is missing<br>";
}
if(!strlen($post['address2'])){
return "Your address2 is missing<br>";
}
if(!strlen($post['city2'])){
return "Your city2 is missing<br>";
}
if(!strlen($post['postal2'])){
return "Your postal2 code is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal2'])) {
//return "Your postal2 code is invalid for this province<br>";
}
if(!strlen($post['phone2'])){
return "Your phone number2 is missing<br>";
}
/////////////Ticket 3
if(!strlen($post['firstname3'])){
return "Your first name3 is missing<br>";
}
if(!strlen($post['lastname3'])){
return "Your last name3 is missing<br>";
}
if(!strlen($post['address3'])){
return "Your address3 is missing<br>";
}
if(!strlen($post['city3'])){
return "Your city3 is missing<br>";
}
if(!strlen($post['postal3'])){
return "Your postal code3 is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal3'])) {
//return "Your postal code3 is invalid for this province<br>";
}
if(!strlen($post['phone3'])){
return "Your phone number3 is missing<br>";
}
}
//////// END TICKET CHECK
if(!strlen($post['nameoncard'])){
return "Your Name on Credit Card is missing<br>";
}
if($post['cctype'] == "Please select one"){
return "Your Credit Card Type is missing<br>";
}
if(!strlen($post['ccnum'])){
return "Your Credit Card Number is missing<br>";
}
if(!strlen($post['billingphone'])){
return "Your billing phone number is missing<br>";
}
if(!strlen($post['agree'])){
return "Your must agree to the Lottery rules in order to proceed<br>";
}
return $ticket;
}
function process()
{
$user = JFactory::getUser();
jimport('joomla.database.table');
$params = JComponentHelper::getParams('com_dream');
$session = JFactory::getSession();
$data = $session->get('dreamticket');
if(!is_object($data))
{
return false;
}
$dif = strtotime("-1 hour");
$timestamp = date("F j, Y, g:i a",$dif);
$ord_id = date('ymdHis') . rand(1000,9999);
$ticket_total = (int) (($data->tickets == '-1') ? '250' : (int) $data->tickets * 100);
$fiftyticket_total = (int) (($data->fiftytickets == '0') ? '' : (int) $data->fiftytickets * 10);
$ordertotal = $ticket_total + $fiftyticket_total;
if(strlen($data->expm) == 1)
{
$data->expm = '0'.$data->expm;
}
if(strlen($data->expy) != 2)
{
$data->expy = substr($data->expy, 2, 2);
}
$data->total = $ordertotal;
JTable::addIncludePath(JPATH_BASE.DS.'administrator'.DS.'components'.DS.'com_dream'.DS.'tables');
$table = JTable::getInstance('Tickets', 'Table');
$table->auth = $auth;
$table->billingphone = $data->billingphone;
$table->Media_Radio = isset($data->Media_Radio) ? 1 : 0;
$table->Media_TV = isset($data->Media_TV) ? 1 : 0;
$table->Media_Newspaper = isset($data->Media_Newspaper) ? 1 : 0;
$table->Media_Mail = isset($data->Media_Mail) ? 1 : 0;
$table->Media_Web = isset($data->Media_Web) ? 1 : 0;
$table->Media_Kinsmen_Member = isset($data->Media_Kinsmen_Member) ? 1 : 0;
$table->Media_Other = isset($data->Media_Other) ? 1 : 0;
$table->Radio_CJCY = isset($data->Radio_CJCY) ? 1 : 0;
$table->Radio_MY96 = isset($data->Radio_MY96) ? 1 : 0;
$table->Radio_ROCK = isset($data->Radio_ROCK) ? 1 : 0;
$table->Radio_CHAT = isset($data->Radio_CHAT) ? 1 : 0;
$table->Radio_POWER = isset($data->Radio_POWER) ? 1 : 0;
$table->Radio_Other = isset($data->Radio_Other) ? 1 : 0;
$table->agegroup = $data->agegroup;
$table->orderdate = date('Y-m-d H:i:s');
$table->ip = $_SERVER['REMOTE_ADDR'];
$table->ord_type = ($user->get('id') > 0) ? 'CallCentre' : 'online';
$table->ord_id = $ord_id;
if($data->tickets == '0') {
$table->ticket_type = 'None';
} elseif($data->tickets == '-1') {
$table->ticket_type = '3Pack';
} elseif($data->tickets == '1') {
$table->ticket_type = '1ticket';
} elseif($data->tickets == '5') {
$table->ticket_type = '8tickets';
}
if($data->fiftytickets == '0') {
$table->fiftyticket_type = 'None';
} elseif($data->fiftytickets == '1') {
$table->fiftyticket_type = '1ticket';
} elseif($data->fiftytickets == '2') {
$table->fiftyticket_type = '3tickets';
}
$table->province = 'AB';
$table->creditcard = $data->cctype;
if(isset($data->giftpurchase)) {
$table->giftname = $data->giftname;
$table->giftadress = $data->giftadress;
$table->giftcity = $data->giftcity;
$table->giftpostal = $data->giftpostal;
}
$data->ord_id = $ord_id;
$tickets = 1;
$table->qty = $data->tickets;
if($data->tickets === '-1')
{
$tickets = 3;
$table->qty = 3;
} elseif($data->tickets === '1')
{
$tickets = 1;
$table->qty = 1;
} elseif($data->tickets === '5')
{
$tickets = 8;
$table->qty = 8;
}
$threepack = '';
$i = '';
for($i = 0; $i < $tickets; $i++)
{
$firstname = 'firstname'.$threepack;
$lastname = 'lastname'.$threepack;
$address = 'address'.$threepack;
$city = 'city'.$threepack;
$postal = 'postal'.$threepack;
$phone = 'phone'.$threepack;
$altphone = 'altphone'.$threepack;
$sec_firstname = 'sec_firstname'.$threepack;
$sec_lastname = 'sec_lastname'.$threepack;
$email = 'email'.$threepack;
$table->firstname = $data->$firstname;
$table->lastname = $data->$lastname;
$table->address = $data->$address;
$table->city = $data->$city;
$table->postal = $data->$postal;
$table->phone = $data->$phone;
$table->altphone = $data->$altphone;
$table->sec_firstname = $data->$sec_firstname;
$table->sec_lastname = $data->$sec_lastname;
$table->email = $data->$email;
$table->id = 0;
if($data->tickets === '-1' || $data->tickets === '5')
{
if($threepack == 2)
{
$threepack = 3;
} else {
$threepack = 2;
}
}
}
$fiftytickets = 1;
$table->fiftyqty = $data->fiftytickets;
if($data->fiftytickets === '1')
{
$fiftytickets = 1;
$table->fiftyqty = 1;
} elseif($data->fiftytickets === '2')
{
$fiftytickets = 3;
$table->fiftyqty = 3;
}
$table->order_total = $data->total;
$table->store();
//sending confirmation mail
$mailcontent = '';
for($i = 0; $i < $data->tickets; $i++)
I have figured out the issues with the for loop. The fiftytickets code needed to be moved above the for loop and the $table->store() function needed to be moved into the for loop and placed after the $table->id line. Now when a ticket or tickets are purchased, three entries with the same name or unique names are inserted into the database.
I'm developing a system for a client that creates a csv of packing labels which is sent to a printer. The client has six different items. Customers order products in bulk from my client. Two items (product A and product B) share the same packing line. In order to make packing more efficient my client wants to alternate between packing product A and packing product B first.
For example, if John, Sally, and James all ordered both products, the system needs to write John's orders to the csv starting with product A, Sally's orders starting with product B, and James' orders starting with product A again.
I've pasted my non-working code below, but this is really screwing with my head and I'm having a really tough time with it.
foreach($orders as $order) {
$name = null;
$phone = null;
$account = DAO_ContactPerson::get($order->account_id);
$delivery = false;
if($account->is_agency) {
$name = $order->getAttribute('name');
$phone = $order->getAttribute('phone');
} else {
$name = sprintf("%s %s",
$account->getPrimaryAddress()->first_name,
$account->getPrimaryAddress()->last_name
);
$phone = $account->phone;
}
$name = trim($name);
$phone = trim($phone);
$items = $order->getItems();
if($order->getAttribute('delivery')) {
$type = 'deliveries';
$destination = 'Delivery';
$address = sprintf("%s %s %s",
$order->getAttribute('delivery_address.line1'),
$order->getAttribute('delivery_address.line2'),
$order->getAttribute('delivery_address.postal')
);
} else {
$type = 'pickups';
$agency = DAO_ContactPerson::getAgency($order->getAttribute('pickup'));
$destination = $agency->name;
// Override account id so orders are grouped by agency
$order->account_id = $agency->id;
$address = null;
}
// var_dump($order->id);
// Init account array
if(!isset($rows[$type][$order->account_id]))
$rows[$type][$order->account_id] = array('combined' => array(), 'separate' => array());
foreach($items as $item) {
$packing = 'separated';
if($item->product_id == 3 || $item->product_id == 4)
$packing = 'combined';
if(!isset($rows[$type][$order->account_id][$packing][$item->product_id]))
$rows[$type][$order->account_id][$packing][$item->product_id] = array();
$i = 0;
while($i < $item->quantity) {
$rows[$type][$order->account_id][$packing][$item->product_id][] = array(
'number' => $order->id,
'destination' => $destination,
'size' => $item->product_id,
'name' => $name,
'address' => $address,
'phone' => $phone
);
$i++;
}
}
// if($order->id == 176) {
// var_dump($rows[$type][$order->account_id][$packing]);
// }
}
$this->weight = 1;
$pickups = count($rows['pickups']);
for($i = 0; $i < $pickups; $i++) {
$account =& $rows['pickups'][$i];
$account['output'] = array();
if(isset($account['combined'])) {
$combined_products =& $account['combined'];
if(!empty($combined_products)) {
foreach($combined_products as $prod_id => $combined) {
usort($combined_products[$prod_id], array($this, "_compareBoxes"));
}
// Flip weights once we finish with this account
$last_box = end($combined_products);
$last_box = array_pop($last_box);
reset($combined_products);
if($this->weight == 1) {
$this->weight = -1;
if($last_box['size'] == 3) {
asort($combined_products);
}
} else {
if($last_box['size'] == 4) {
arsort($combined_products);
}
$this->weight = 1;
}
foreach($combined_products as $combined) {
$account['output'][] = $combined;
}
foreach($account['separated'] as $separate) {
$account['output'][] = $separate;
}
}
} else {
if(isset($account['separated']))
$account['output'] = $account['separated'];
}
}
$deliveries = count($rows['deliveries']);
for($i = 0; $i < $deliveries; $i++) {
$account =& $rows['deliveries'][$i];
$account['output'] = array();
if(isset($account['combined'])) {
$combined_products =& $account['combined'];
if(!empty($combined_products)) {
foreach($combined_products as $prod_id => $combined) {
usort($combined_products[$prod_id], array($this, "_compareBoxes"));
}
// Flip weights once we finish with this account
$last_box = end($combined_products);
$last_box = array_pop($last_box);
reset($combined_products);
if($this->weight == 1) {
$this->weight = -1;
if($last_box['size'] == 3) {
asort($combined_products);
}
} else {
if($last_box['size'] == 4) {
arsort($combined_products);
}
$this->weight = 1;
}
foreach($combined_products as $combined) {
$account['output'][] = $combined;
}
foreach($account['separated'] as $separate) {
$account['output'][] = $separate;
}
}
} else {
if(isset($account['separated']))
$account['output'] = $account['separated'];
}
}
$rows['output'] = $rows['pickups'];
array_push($rows['output'], $rows['deliveries']);
$output = '';
foreach($rows['output'] as $account_id => $boxes) {
if(!empty($boxes['output'])) {
foreach($boxes['output'] as $labels) {
if(!empty($labels)) {
foreach($labels as $label) {
$output .= implode(',', $label) . "<br>";
}
}
}
}
}
The _compareBoxes method looks like this:
private function _compareBoxes($a, $b) {
if($a['size'] == $b['size']) {
return 0;
}
if($this->weight == 1) {
// Medium first, then Large
return ($a['size'] < $b['size']) ? -1 : 1;
}
if($this->weight == -1) {
// Large first, then Medium
return ($a['size'] > $b['size']) ? -1 : 1;
}
}