How to read function php and create a file xml [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
I need to read this function and create an xml with the title, description and etc fields.
then the table.
public function defineCustomTemplate()
{
$this->setNmfile(302444);
$this->setNmoperation("CPTEVALITHAB");
$this->setNmimport(302433);
$customTemplate = array();
$customTemplate[] = array('column' => 'nmfield01', 'term' => 103571, 'dataType' => 2, 'precision' => 50, 'description' => 213795, 'required' => 1);
$customTemplate[] = array('column' => 'nmfield02', 'term' => 102213, 'dataType' => 2, 'precision' => 50, 'description' => 302440, 'required' => 1);
$customTemplate[] = array('column' => 'nmfield03', 'term' => 302442, 'dataType' => 2, 'precision' => 50, 'description' => 302442, 'required' => 1);
$customTemplate[] = array('column' => 'nmfield04', 'term' => 302443, 'dataType' => 2, 'precision' => 50, 'description' => 302443, 'required' => 1);
return $customTemplate;
}
this function appears in several classes of the project and I would like to capture everywhere it is displayed and create the xml.
can someone help me?

You can use the SimpleXMLElement class in PHP to create an XML document with the data from the defineCustomTemplate() function.

approximate solution without fields hardcoding
$sxml = new \SimpleXMLElement(('<?xml version="1.0" encoding="utf-8"?><file></file>'));
$sxml->addAttribute('filename', $Nmfile);
$operation = $sxml->addChild('operations');
$operation->addAttribute('opname', $Nmoperation);
foreach ($customTemplate as $key => $item) {
$serverKeys = array_keys($item);
$import = $operation->addChild('import');
$import->addAttribute('import_id', $Nmimport);
foreach ($serverKeys as $i => $name) {
$ops = $import->addChild($name);
$ops->addAttribute($name,$item[$name]);
}
}
var_dump($sxml->asXML());
output template:
<?xml version="1.0" encoding="utf-8"?>
<file filename="302444">
<operations opname="CPTEVALITHAB">
<import import_id="0">
<column column="nmfield02"/>
...
</import>
</operations>
</file>

Related

Yii2: googleChart Widget extension in Carousel

I want show graphs in Carousel, the first graph is shown as well as expected see bellow,
But other slinding graphs are different as seen bellow
Note: All graphs are generated from the same databses tables, bellow is the code from my index.php in frontend/view directory
<?php
use backend\models\WaterLevel;
use backend\models\GaugeSite;
use scotthuangzl\googlechart\GoogleChart;
use kv4nt\owlcarousel\OwlCarouselWidget;
$this->title = 'Water Level';
$model = new WaterLevel();
$siteModel = new GaugeSite();
$siteId = $siteModel->getSiteIds();
$counter = count($siteId);
OwlCarouselWidget::begin([
'container' => 'div',
'containerOptions' => [
'id' => 'container-id',
'class' => 'container-class'
],
'pluginOptions' => [
'autoplay' => true,
'autoplayTimeout' => 3000,
'items' => 1,
'loop' => true,
'itemsDesktop' => [1199, 3],
'itemsDesktopSmall' => [979, 3]
]
]);
/**Loop to generate items */
for($i = 0;$i<$counter;$i++){
$id = $siteId[$i];
$data = $model->getLevels($id);
$readings = [['Hour', 'Water Level']];
foreach($data as $value){
array_push($readings,[$value['submition_time'],(int)$value['reading_level']]);
}
echo GoogleChart::widget(
array('visualization' => 'LineChart',
'data' => $readings,
'options' => array('title' => 'Water Level Reading')));
}
OwlCarouselWidget::end();?>
I also have tried to use the GoogleChart::widget in normal bootstrap4 Carousel, but it behaves the same. I appriciate of your idea to take me out from here.

How To Use External Class In YII2 Step By Step [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Improve this question
So i have a class i have used couple of times for other non YII projects but now i want to use the same class in a YII2 project. I have done some searches but i kind of got stuck along the way. Below is what i have done so far:
I created a folder called "utility" in the vendor directory, the utility folder contains my class named "AT_Response.class.php". So my question is how do i include or call and use this class in my model or controller.
I have checked some links like :
https://www.yiiframework.com/doc/guide/2.0/en/tutorial-yii-integration
https://forum.yiiframework.com/t/not-understanding-how-to-use-external-php-library/79679
Class Code:
<?php
class AT_Response {
static private $response = array
(
'9999' => array('description' => "Unexpected Response", 'definite' => true, 'status' => "Indeterminate"),
'00' => array('description' => "Success", 'definite' => true, 'status' => "Success"),
'NNC_AUTH_01' => array('description' => /*"Status unknown, please wait for settlement report"*/"System Error", 'definite' => true, 'status' => "Failure"),
'NNC_VTU_01' => array('description' => "Ttimed out", 'definite' => false, 'status' => "Indeterminate"),
'NNC_VTU_02' => array('description' => "Exceeded max number of requests for Phone number per time period", 'definite' => true, 'status' => "Failure"),
'NNC_VTU_03' => array('description' => "Invalid target MSISDN supplied", 'definite' => true, 'status' => "Failure"),
'-1' => array('description' => "Not successful", 'definite' => false, 'status' => "Failure"),
);
static function getResponseByCode($respCode) {
if (isset(self::$response[$respCode]))
return self::$response[$respCode];
//else
return self::$response['9999'];
}
}
Thanks
With a few changes you can use any custom class as a helper component. You need to use namespace and use statement for the existing class you have, see the below
<?php
namespace app\components;
class Response
{
/**
* #var array
*/
private static $response = array
(
'9999' => array('description' => "Unexpected Response", 'definite' => true, 'status' => "Indeterminate"),
'00' => array('description' => "Success", 'definite' => true, 'status' => "Success"),
'NNC_AUTH_01' => array('description' => /*"Status unknown, please wait for settlement report"*/"System Error", 'definite' => true, 'status' => "Failure"),
'NNC_VTU_01' => array('description' => "Ttimed out", 'definite' => false, 'status' => "Indeterminate"),
'NNC_VTU_02' => array('description' => "Exceeded max number of requests for Phone number per time period", 'definite' => true, 'status' => "Failure"),
'NNC_VTU_03' => array('description' => "Invalid target MSISDN supplied", 'definite' => true, 'status' => "Failure"),
'-1' => array('description' => "Not successful", 'definite' => false, 'status' => "Failure")
);
/**
* #param $respCode
*/
public static function getResponseByCode($respCode)
{
if (isset(self::$response[$respCode])) {
return self::$response[$respCode];
}
return self::$response['9999'];
}
}
Save the Above class in a file called Response.php in app\components folder if using basic-app or common\components if you are using advanced-app but dont forget to change the namespace in the code.
You can then call the function getResponseByCode() like app\components\Response::getResponseByCode($responseCode) or common\components\Response::getResponseByCode($responseCode)

php fedex set signature Label ADULT

I am working on wordpress site and using woocommerce extension http://www.woothemes.com/products/fedex-shipping-module/
I am Passing the values Signature value to adults. But it is not working
Please correct me where i am wrong
$request['RequestedShipment']['RateRequestTypes'] = $this->request_type;
$request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';
$request['RequestedShipment']['SpecialServicesRequested'][] = array(
'SpecialServiceTypes' => 'SIGNATURE_OPTION',
'SignatureOptionDetail' => array(
'OptionType' => 'ADULT'
)
);
`
Do i need to change something from the from the RateService_v13.wsdl file
Please suggest
Thanks
I resolved this issue
For further user having the same issue can resolve this by below code
$item['SpecialServicesRequested'] = array(
'SpecialServiceTypes' => 'SIGNATURE_OPTION',
'SignatureOptionDetail' => array(
'OptionType' => 'ADULT'
)
);
$request['RequestedShipment']['RequestedPackageLineItems'][] = $item;
If Suppose anyone is using Fedex Integration with Laravel you may use below code.
In place of _DIRECT you may use _ADULT or any other option.
$packageLineItem1 = new FedexShipServiceCT\RequestedPackageLineItem();
$packageLineItem1
->setSequenceNumber(1)
->setItemDescription('Product')
->setSpecialServicesRequested(new FedexShipServiceCT\PackageSpecialServicesRequested(array(
'SignatureOptionDetail' => new FedexShipServiceCT\SignatureOptionDetail(array(
'OptionType' => FedexShipServiceST\SignatureOptionType::_DIRECT
))
)))
->setDimensions(new FedexShipServiceCT\Dimensions(array(
'Width' => 1,
'Height' => 1,
'Length' => 1,
'Units' => FedexShipServiceST\LinearUnits::_IN
)))
->setWeight(new FedexShipServiceCT\Weight(array(
'Value' => 1,
'Units' => FedexShipServiceST\WeightUnits::_LB
)));
Thanks

Getting values depend on url [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have this array again:
$predmeti = [
'slo' => [
'ime' => 'Slovenščina',
'ucitelj' => 'Ana Berčon',
'nadimek' => '',
'ucilnica' => '11'
],
'mat' => [
'ime' => 'Matematika',
'ucitelj' => 'Nevenka Kunšič',
'nadimek' => '',
'ucilnica' => '12'
],
'ang' => [
'ime' => 'Angleščina',
'ucitelj' => 'Alenka Rozman',
'nadimek' => 'Rozi',
'ucilnica' => '3'
],
'mob' => [
'ime' => 'Medijsko oblikovanje',
'ucitelj' => 'Iztok Mulej',
'nadimek' => 'HTML ninja',
'ucilnica' => 'MM2'
]
];
I want to get values of every key depend on url I am accesing. For example I have url /predmet?ime=slo, then I want to get data only for key 'slo'.
How do I achieve that?
if(isset($_GET['ime']) && isset($predmeti[$_GET['ime']])){
$data = $predmeti[$_GET['ime']];
}
Use the parameter in the URL
<?php
$param = $_GET['ime'];
print_r($predmeti[$param]);
?>

How to log dimension like AWS CloudWatch bundled metric

Can anyone explain how to use the AWS PHP SDK to log the metric in the style like the above screen.
I use the following PHP code but the select menu is showing "ELB: AvaliabiltyZone", how to make it show "Aggregated by AvaliabiltyZone"? What is the logic used here?
$response = $cw->put_metric_data("ELB", array(
array(
"MetricName" => "Latency",
"Dimensions" => array(
array("Name" => "AvaliabiltyZone" , "Value" => "us-east-1c")
),
"Timestamp" => "now",
"Value" => 1,
"Unit" => "None"
),
));
AvaliabiltyZone
You misspelled "AvailabilityZone"
This maybe won't answer the question, but it might fix some things...
$cw = new AmazonCloudWatch();
$cw->set_region('monitoring.'.$region.'amazonaws.com');
$res1 = $CW->put_metric_data('Sys/RDS' ,
array(array('MetricName' => 'Uptime' ,
'Dimensions' => array(array('Name' => 'AvaliabiltyZone',
'Value' => 'us-east-1c')),
'Value' => $Uptime,
'Unit' => 'Seconds')));
Click Here

Categories