TinyButStrong Error When Merging Block with Dynamic Queries - tinybutstrong

I am attempting to merge an array based on a value from another array, but I get this kind of error: "TinyButStrong Error when merging block [docList]: invalid query '2022_0817_wes' because VarRef item '2022_0817_wes' is not found."
The following is how I constructed the HTML Template:
<div class="fileList">
<p class="text"><span class="fileNumber">[urlList2.#; block=div; noerr].</span> <span class="fileTitle">[urlList2.title; magnet=span; noerr]<br></span>
<span class="indent fileInfo"><span>[urlList2.event; magnet=((span)); noerr]</span><span> • [urlList2.eventdate; magnet=span; noerr]</span><br></span>
<a id="[onshow.intranet; if [val]=1; then [urlList2.intraneturl; noerr]; else [urlList2.url; strconv=no; noerr]; noerr]" class="indent watch" href="Watch"><span class="fa fa-video-camera"></span> Watch Now</a><br>
<a class="indent download" href="[onshow.intranet; if [val]=1; then [urlList2.intraneturl; noerr]; else [urlList2.url; strconv=no; noerr]; noerr]"><span class="fa fa-download"></span> Download Video</a> <span class="fileSize">([urlList2.filesize; noerr])</span> - Right-click and choose “Save Link As” or “Save Target As”
<span class="">[docList.filename; noerr] <span class="fileSize">([docList.filesize; noerr])</span></span></p>
</div>
And then PHP code, I am trying to pass the parameter to the array I want to use for the sub-block:
$TBS->MergeBlock('urlList2', 'array', $urlList);
$TBS->MergeBlock('docList', 'array', '%p1%');
The following snippet is an example from the array for sub-block:
Array
(
[2022_0814_tes_various] => Array
(
[0] => Array
(
[bucket] => fb
[key] => Bulletin.pdf
[filename] => Bulletin
[filesize] => 639.5KB
[url] => https://s3....
)
[1] => Array
(
[bucket] => fb
[key] => 2022/2022-08-14_00-00-00_SBP-S22-Lesson-25.pdf
[filename] => 2022-08-14_00-00-00_SBP-S22-Lesson-25
[filesize] => 76.7KB
[url] => https://s3....
)
)
[2022_0814_sms] => Array
(
[0] => Array
(
[bucket] => fb
[key] => Bulletin.pdf
[filename] => Bulletin
[filesize] => 639.5KB
[url] => https://s3....
)
[1] => Array
(
[bucket] => fb
[key] => 2022/2022-08-14_00-00-00_SBP-S22-Lesson-25.pdf
[filename] => 2022-08-14_00-00-00_SBP-S22-Lesson-25
[filesize] => 76.7KB
[url] => https://s3....
)
)
)

Related

displaying particular data from entire json using laravel

I have an issue in printing the data from the below json in laravel. Find below the json data and help me with this.
DarthSoup\Cart\Item Object ( [rowId] => 76cc22e6f533b8ef3d08e6eca0f110b4 [id] => 61XJrpB7CgiYSRCX6hR78wCEABhjLI7jNLzPyDrkYA3LyIVisz [name] => linux [quantity] => 1 [price] => 109 [options] => DarthSoup\Cart\CartItemOptions Object ( [items:protected] => Array ( [package] => Super Lite ) ) [subItems] => DarthSoup\Cart\SubItemCollection Object ( [items:protected] => Array ( ) ) [created_at:protected] => Carbon\Carbon Object ( [date] => 2018-06-22 05:41:18.674548 [timezone_type] => 3 [timezone] => UTC ) [updated_at:protected] => Carbon\Carbon Object ( [date] => 2018-06-22 05:41:18.674574 [timezone_type] => 3 [timezone] => UTC ) [associatedModel:protected] => [taxRate:protected] => 19 ) 1
From the above json how to display the "price=>109" and "package=>super Lite"...
I'm getting an error as "Cannot use object of type DarthSoup\Cart\Item as array"
Find below the controller Code:
public function addCart(Request $request)
{
$name = $request->input();
$hosting=$name['hosting'];
$package=$name['package'];
$price=$name['price'];
$response=Cart::add(['id'=>str_random(50) ,'name' => $hosting, 'quantity' => 1, 'price' => $price, 'options' => ['package' => $package]]);
//dd($response);
return Cart::content();
return view('main.cart',Cart::content());
}
Blade file is given below:
#foreach($response->options as $option){
{{$option['name']}}
}
#endforeach
In my output I need to display the value of price,name and package...please help me to solve this error...
First this is not json, it is php object
if your variable name is $item then you can try this
$item->rowId;
$item->id;
$item->name;
$item->price;
foreach($item->options as $option){
echo $option->package;
}

Put/Get UploadField submitted image from custom Form -> Silverstripe 3.1

I have a small problem programming with the use of UploadField . I have created pages to make a light CMS on the FrontEnd. But I don't know how retrieve this image to the page «Update».
There is the code from the page «Create» :
$uploadField = new UploadField( 'ImageEvenement', 'Image' );
There is the code I tried to get working for the page «Update»
$evenID = Session::get('evenementID');
$evenement = Versioned::get_by_stage('PageCalendrierEvenement', 'Stage')->byID($evenID);
..
$SavedImage = File::get()->byID($evenement->ImageEvenementID)
$uploadField = new UploadField( 'ImageEvenement', 'Image', $SavedImage );
How can I retrieve the submitted image to $SavedImage ? My idea to get the ID from File don't work.
Another method :
$SavedImage = $evenement->ImageEvenement();
If I dump data from $SavedImage I'm viewing :
Image Object
(
[destroyed] =>
[model:protected] => DataModel Object
(
[customDataLists:protected] => Array
(
)
)
[record:protected] => Array
(
[ClassName] => Image
[Created] => 2015-07-15 14:41:24
[LastEdited] => 2015-07-16 15:03:25
[Name] => images.jpg
[Title] => images
[Filename] => assets/Membres/9/calendrier/images.jpg
[ShowInSearch] => 1
[ParentID] => 15
[OwnerID] => 9
[ID] => 22
[RecordClassName] => Image
)
[changed:DataObject:private] => Array
(
)
[original:protected] => Array
(
[ClassName] => Image
[Created] => 2015-07-15 14:41:24
[LastEdited] => 2015-07-16 15:03:25
[Name] => images.jpg
[Title] => images
[Filename] => assets/Membres/9/calendrier/images.jpg
[ShowInSearch] => 1
[ParentID] => 15
[OwnerID] => 9
[ID] => 22
[RecordClassName] => Image
)
[brokenOnDelete:protected] =>
[brokenOnWrite:protected] =>
[components:protected] =>
[unsavedRelations:protected] =>
[sourceQueryParams:protected] =>
[failover:protected] =>
[customisedObject:protected] =>
[objCache:ViewableData:private] => Array
(
)
[class] => Image
[extension_instances:protected] => Array
(
[BetterButtonDataObject] => BetterButtonDataObject Object
(
[owner:protected] =>
[ownerBaseClass:protected] => DataObject
[ownerRefs:Extension:private] => 0
[class] => BetterButtonDataObject
)
[SiteTreeFileExtension] => SiteTreeFileExtension Object
(
[owner:protected] =>
[ownerBaseClass:protected] => File
[ownerRefs:Extension:private] => 0
[class] => SiteTreeFileExtension
)
[Hierarchy] => Hierarchy Object
(
[markedNodes:protected] =>
[markingFilter:protected] =>
[_cache_numChildren:protected] =>
[owner:protected] =>
[ownerBaseClass:protected] => File
[ownerRefs:Extension:private] => 0
[class] => Hierarchy
)
)
[beforeExtendCallbacks:protected] => Array
(
)
[afterExtendCallbacks:protected] => Array
(
)
)
Any idea?
class PageCalendrierEvenement extends Page {
private static $db = array(
"Titre" => "Varchar(50)",
"DateDepart" => "Date",
"DateFin" => "Date",
);
private static $has_one = array(
'Creator' => 'Member',
'ImageEvenement' => 'Image',
);
..
}
Thank you!
has one relations need the "ID" suffix in the name of the relation (as it's saved to db...), e.g.
$uploadField = new UploadField( 'ImageEvenementID', 'Image', $SavedImage );
then it should save automatically.
OR, what i do for a single relation:
$imageField = UploadField::create('ImageEvenement', 'Image');
$imageField->setAllowedFileCategories('image');
$imageField->setAllowedMaxFileNumber(1);
hope that helps.
My code works fine but are not clean and not using SilverStripe function classes. The reason for non working saving images to dataobject, is because that I have not use :
$form->saveInto($evenement)
I would like to thank you Wmk for give me the get method to fill form with values on another post :
$form->loadDataForm($evenement)
Finaly, all works fine now!
Finaly after long time brain searching, I have found the trick! The command to use with UploadField is setValue($value) with fileIDs include with it. My final code is :
$evenement = Versioned::get_by_stage('PageCalendrierEvenement', 'Stage')->byID($evenID);
...
$uploadField = new UploadField( 'ImageEvenement', 'Image' );
$data['ImageID'] = $evenement->ImageEvenement()->ID;
$fileIDs[]=$data['ImageID'];
$uploadField->setValue(array('Files' => $fileIDs));
Thats it!

Reverse output from simplexml

Cannot reverse output, tried with array_reverse and usort.
I'm trying to import products from an XML to Magento with magmi datapump, works fine but I need the output in reverse order for Magento to link simple products with configurable products,
Any ideas?
$xml = simplexml_load_file("23.xml") or die("Error: Cannot create object");
foreach($xml->wapiitems->record as $book) {
$item = $book->fields->itemno;
if (strlen($item) <= 6) {
$type = "configurable";
$ca = "color,size";}
else {
$type = "simple";
$ca = "";}
$newProductData = array(
'sku' => (string)$book->fields->itemno, // name
'type' => (string)$type, // sku
'color' => (string)$book->subtables->descriptions->record->fields->variant1name, // special price
'size' => (string)$book->subtables->descriptions->record->fields->variant3name, // price
'attribute_set' => 'Default', // attribute_set
'store' => 'admin',
'name' => (string)$book->subtables->descriptions->record->fields->description, // full description
'configurable_attributes' => (string)$ca // short description
);
//$dp->ingest($newProductData);
echo "</br>";
print_r ($newProductData);
$newProductData=null; //clear memory
unset($newProductData); //clear memory
}
unset($xml);
$dp->endImportSession(); // end import
My output is:
Array ( [sku] => 90349 [type] => configurable [color] => [size] => [attribute_set] => Default [store] => admin [name] => [configurable_attributes] => color,size )
Array ( [sku] => 903490101004 [type] => simple [color] => Red [size] => 4 [attribute_set] => Default [store] => admin [name] => Q-Irine Cover [configurable_attributes] => )
Array ( [sku] => 903490101005 [type] => simple [color] => Black [size] => 5 [attribute_set] => Default [store] => admin [name] => Q-Irine Cover [configurable_attributes] => )
Array ( [sku] => 903490101006 [type] => simple [color] => Black [size] => 6 [attribute_set] => Default [store] => admin [name] => Q-Irine Cover [configurable_attributes] => )
But I need this:
Array ( [sku] => 903490101006 [type] => simple [color] => Black [size] => 6 [attribute_set] => Default [store] => admin [name] => Q-Irine Cover [configurable_attributes] => )
Array ( [sku] => 903490101005 [type] => simple [color] => Black [size] => 5 [attribute_set] => Default [store] => admin [name] => Q-Irine Cover [configurable_attributes] => )
Array ( [sku] => 903490101004 [type] => simple [color] => Red [size] => 4 [attribute_set] => Default [store] => admin [name] => Q-Irine Cover [configurable_attributes] => )
Array ( [sku] => 90349 [type] => configurable [color] => [size] => [attribute_set] => Default [store] => admin [name] => [configurable_attributes] => color,size )
Not sure how Magmi Datapump is linking the simple and configurable products based on your example, but assuming that all that is required for your problem is that configurable products get imported after the simple products, you could do something like this:
Create an intermediate array of product records after pulling them out of XML by changing $newProductData = array(...) to $newProductData[] = array(...)
Now use something like this to sort your intermediate array by product type:
usort($newProductData, function($a, $b)
{
if ($a['type'] == 'configurable' && $b['type'] == 'simple') {
return 1;
} else if ($a['type'] == 'simple' && $b['type'] == 'configurable') {
return -1;
} else {
return strnatcmp($a['sku'], $b['sku']);
}
});
Finally, iterate over the sorted array and complete the import:
foreach ($newProductData as $data) {
$dp->ingest($data);
}

CodeIgniter, variable declaration

I have a problem with undefined variable. In view/somefolder/somefile.php they echo some variabla (<?php echo $news;?> ) . I tried everything to find where this variable is defined (Find in Path at PHPStorm), but without result. When I put print_r($GLOBALS) to test, I got
[_ci_cached_vars:protected] => Array
(
[unread] => 0
[unans] => 0
[ques_unread] => 0
[is_loged] =>
[level] =>
[avatar] => media/img/avatar.png
[username] =>
[root_cat] => 0
[logErr] =>
[radio_list] => Array
(
)
[entitet] => 1
[current_modul] => infograda
[tree] => <ul></ul>
[category] => stdClass Object
(
[id] => 153
[title] => HRONIKA
[description] =>
[parent_id] => 0
[order] => 52
[module] => infograda
[expanded] => 0
[content_type_id] => 1
)
[module] => infograda
[active] =>
[additionHtml] =>
[news] => Array
(
[0] => stdClass Object
(
[id] => 1574
[content_id] => 1574
[module] => infograda
[order] =>
[title] => Title
[text] => <div class="uvod_holder">
in Codeigniter, a view is loaded from a controller. For example:
Controller:
// this file resides in application\controllers\mycontroller.php
class Mycontroller extends CI_Controller{
function mypage() {
$data = array('news' => 'some news');
$this->load->view('page', $data);// will load views\page.php and pass the $data array
}
}
View
<!--this file resides in application\views\page.php -->
<html>
<head></head>
<body><?= $news; ?></body>
</html>
To make this work, your URL will say http://localhost/index.php/mycontroller/mypage (if you're working locally)
Your variable is being set in the controller that loads that view.

pass multi-dimensional array from controller to view codeignighter

how do i pass a multi diminutional array to a view?
controller code
public function index(){
data['navs'] = array(
'name' => array('one', 'two', 'three'),
'link' => array('one', 'two', 'three'));
$this->load->view('adminView', $data);}
view code
<?php if ($navs) {
foreach ($navs as $nav) {
echo('<li>' . $nav->name . '</li>');
}
}?>
First of all you need to build the array, the right way. It should be something like:
$data['navs'] = array( array( 'name' => 'one',
'link' => 'linkone'),
array( 'name' => 'two',
'link' => 'linktwo')
);
$this->load->view('adminView', $data);
Then in your view:
foreach($navs as $n){
echo "<li><a href='{$n['link']}'>{$n['name']}</a></li>";
}
Once in the view, refer to your data as array elelements, not object properties (you are passing the array of arrays, not array of objects). Based on your controller, your view code should look like that:
foreach ($navs as $nav) {
echo('<li>' . $nav['name'] . '</li>');
}
However, that won't output the right result because your $nav['link'] and $nav['name'] are two arrays. You'd need to call any of their elements or change controller accordingly.
how to fetch dynamic array value by using controller of codeigniter in php
Array
(
[id] => 2
[name] => Wellness & Spa
[isSelected] => true
[subModules] => Array
(
[0] => Array
(
[id] => 1
[name] => Spa1
[isSelected] => true
[0] => object:81
)
[1] => Array
(
[id] => 2
[name] => Spa2
[isSelected] => true
[0] => object:82
)
[2] => Array
(
[id] => 3
[name] => Wellness
[isSelected] => true
[0] => object:83
)
)
)

Resources