I have a table store the data of image in long blob type, how to retrieve image show in phpexcel? My sample of code:
$order = "SELECT * FROM tblorder";
$tblorder = $conn->query($order);
$row_order = $tblorder->fetch(PDO::FETCH_ASSOC);
$image =$row_order["image"];
$data = base64_encode($image);
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('image');
$objDrawing->setDescription('image');
$objDrawing->getIndexedFilename($data);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setCoordinates('A85');
$objDrawing->setWorksheet($sheet->getActiveSheet());
$pExcel = new PHPExcel();
$pExcel->setActiveSheetIndex(0);
$aSheet = $pExcel->getActiveSheet();
$aSheet->setTitle('Name');
$data ='data://image/jpg;base64,'.base64_encode($row['Picture']);
$gdImage = imagecreatefromjpeg($data);
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('Sample image');
$objDrawing->setDescription('Sample image');
$objDrawing->setImageResource($gdImage);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(150);
$objDrawing->setCoordinates('I1');
$objDrawing->setWorksheet($aSheet);
Related
Is there a way to obtain values from Serializer (CsvEncoder) by index instead of by name of field ?
By example :
$serializer = new Serializer([new ObjectNormalizer()], [new CsvEncoder($delimiter = "\t", $enclosure = '"')]);
$csvFile = __DIR__ . '/../../uploads/' . 'test.txt';
$csvContents=file_get_contents($csvFile);
$datas = $serializer->decode($csvContents, 'csv');
foreach($datas as $data) {
$idCli = $data['C1 Numéro/client'];
}
Is there a way to use $data[0] instead of $data['C1 Numéro/client'];
Simple database structure:
If I do:
SELECT info FROM `wp_participants_database` WHERE standard = '456' AND zertifikatsnummer = 'iso777' AND _firmennamen = 'Firma789';
I get: "d", which is fine.
But when im using $wpdb, like here:
$query = "SELECT info FROM wp_participants_database WHERE standard = %d AND zertifikatsnummer = %d AND _firmennamen = %d";
$firmennamenx = $wpdb->get_row($wpdb->prepare( $query, '456', 'iso777', 'Firma789' ));
echo $firmennamenx->info;
I get: "b", why?
Try with below code
$query = "SELECT info FROM wp_participants_database WHERE standard = %d AND zertifikatsnummer = %s AND _firmennamen = %s";
$firmennamenx = $wpdb->get_row($wpdb->prepare( $query, '456', 'iso777', 'Firma789' ));
echo $firmennamenx->info;
Here %d is for the decimal values and %s for the string value. Your other fields are having the string value so for that you need to set %s
Hope now you got my point why you need to set %s.
I'm using the woocommerce_checkout_create_order_line_item action to update/add some order item meta data.
At the same time, within the same function, I want to use wc_get_order_item_meta to get a different meta value from the same item but I can't get it to work within this action hook.
I think the issue is that I'm not managing to get the $item_id needed to use wc_get_order_item_meta.
Am I going about this in the wrong way?
I've tried the method here How to get order items ids to get some product meta data?
Below code will return all details of order with order item meta.just take those values in count which you want to use remove others.
function action_woocommerce_checkout_create_order_line_item( $item, $cart_item_key, $values, $order ) {
$order_id = $order->get_order_number();
$order = wc_get_order( $order_id );
$order_data = $order->get_data();
//Order Data and order item metas
$order_id = $order_data['id'];
$order_parent_id = $order_data['parent_id'];
$order_status = $order_data['status'];
$order_currency = $order_data['currency'];
$order_version = $order_data['version'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method_title = $order_data['payment_method_title'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method = $order_data['payment_method'];
## Creation and modified WC_DateTime Object date string ##
// Using a formated date ( with php date() function as method)
$order_date_created = $order_data['date_created']->date('Y-m-d H:i:s');
$order_date_modified = $order_data['date_modified']->date('Y-m-d H:i:s');
// Using a timestamp ( with php getTimestamp() function as method)
$order_timestamp_created = $order_data['date_created']->getTimestamp();
$order_timestamp_modified = $order_data['date_modified']->getTimestamp();
$order_discount_total = $order_data['discount_total'];
$order_discount_tax = $order_data['discount_tax'];
$order_shipping_total = $order_data['shipping_total'];
$order_shipping_tax = $order_data['shipping_tax'];
$order_total = $order_data['cart_tax'];
$order_total_tax = $order_data['total_tax'];
$order_customer_id = $order_data['customer_id']; // ... and so on
## BILLING INFORMATION:
$order_billing_first_name = $order_data['billing']['first_name'];
$order_billing_last_name = $order_data['billing']['last_name'];
$order_billing_company = $order_data['billing']['company'];
$order_billing_address_1 = $order_data['billing']['address_1'];
$order_billing_address_2 = $order_data['billing']['address_2'];
$order_billing_city = $order_data['billing']['city'];
$order_billing_state = $order_data['billing']['state'];
$order_billing_postcode = $order_data['billing']['postcode'];
$order_billing_country = $order_data['billing']['country'];
$order_billing_email = $order_data['billing']['email'];
$order_billing_phone = $order_data['billing']['phone'];
## SHIPPING INFORMATION:
$order_shipping_first_name = $order_data['shipping']['first_name'];
$order_shipping_last_name = $order_data['shipping']['last_name'];
$order_shipping_company = $order_data['shipping']['company'];
$order_shipping_address_1 = $order_data['shipping']['address_1'];
$order_shipping_address_2 = $order_data['shipping']['address_2'];
$order_shipping_city = $order_data['shipping']['city'];
$order_shipping_state = $order_data['shipping']['state'];
$order_shipping_postcode = $order_data['shipping']['postcode'];
$order_shipping_country = $order_data['shipping']['country'];
};
//To get Order item metas please use below code
foreach ($order->get_items() as $item_key => $item_values):
## Using WC_Order_Item methods ##
// Item ID is directly accessible from the $item_key in the foreach loop or
$item_id = $item_values->get_id();
## Using WC_Order_Item_Product methods ##
$item_name = $item_values->get_name(); // Name of the product
$item_type = $item_values->get_type(); // Type of the order item ("line_item")
$product_id = $item_values->get_product_id(); // the Product id
$wc_product = $item_values->get_product(); // the WC_Product object
## Access Order Items data properties (in an array of values) ##
$item_data = $item_values->get_data();
$product_name = $item_data['name'];
$product_id = $item_data['product_id'];
$variation_id = $item_data['variation_id'];
$quantity = $item_data['quantity'];
$tax_class = $item_data['tax_class'];
$line_subtotal = $item_data['subtotal'];
$line_subtotal_tax = $item_data['subtotal_tax'];
$line_total = $item_data['total'];
$line_total_tax = $item_data['total_tax'];
endforeach;
// add the action
add_action( 'woocommerce_checkout_create_order_line_item', 'action_woocommerce_checkout_create_order_line_item', 10, 4 );
I have a problem I'm generating an array with PHPExcel but to insert the date on the base gives an error because the date is in excel format and need mysql here is the code used
$objReader = new PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load( $targetFile );
$objPHPExcel->setActiveSheetIndex(0);
$lastRow = $objPHPExcel->getActiveSheet()->getHighestRow();
$dataExcel = array();
for ( $i = 2; $i <= $lastRow; $i++ ){
$dataExcel[$i]['usr_date_entry'] = $objPHPExcel->getActiveSheet()->getCell('K'.$i)->getCalculatedValue();
}
´echo $dataExcel[0]['usr_date_entry']; // return 21774´
if(count($priceRange)){
$facets = new \Elastica\Facet\Range('price');
$facets->setField('price');
foreach ($min as $key => $value) {
$facets->addRange(intval($min[$key])*100, intval($max[$key])*100);
}
$facets->setGlobal(false);
$query->addFacet($facets);
}
This doesn't work for me, I am trying to search on two ways.
Like this:
$client = $this->container->get('fos_elastica.client')
$searcher = new \Elastica\Search($client)
$esResultSet = $searcher->search($query , 500)
$arrayOfResults = $esResultSet->getResults()
$facets = $esResultSet->getFacets()
Or like this
$resultSet = $finder->find($query, 500)
Neither of this works. Why my facet range doesn't work?
Here is more code:
$boolQuery = new \Elastica\Query\Bool();
$fieldText = new \Elastica\Query\Text();
$fieldText->setFieldQuery('name', $keyword);
$fieldText->setFieldParam('name', 'analyzer', 'my_analyzer');
$boolQuery->addMust($fieldText);
$fieldText = new \Elastica\Query\Text();
$fieldText->setFieldQuery('description', $keyword);
$fieldText->setFieldParam('description', 'analyzer', 'my_analyzer');
$boolQuery->addShould($fieldText);
$fieldTerms = new \Elastica\Query\Terms();
$fieldTerms->setTerms('country_id', $countryArray);
$boolQuery->addMust($fieldTerms);
$fieldTerms = new \Elastica\Query\Terms();
$fieldTerms->setTerms('taxon_ids', $themeArray);
$boolQuery->addMust($fieldTerms);
$query->setSort(array("price" => array("order" => "asc")));