Created
July 29, 2016 21:35
-
-
Save tessguefen/f1831b6984533a9f29e2c409f95a0209 to your computer and use it in GitHub Desktop.
Randomize Array -- miva
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <mvt:comment>JSON Data</mvt:comment> | |
| <mvt:assign name="l.settings:rotating_img_data" value="'[ | |
| { | |
| \"name\": \"Ben1\", | |
| \"number\": \"(800) 520-2890\", | |
| \"src\": \"http://www.example.com/img/bio/ben.png\" | |
| }, | |
| { | |
| \"name\": \"James2\", | |
| \"number\": \"(951) 123-4567\", | |
| \"src\": \"http://www.example.com/images/products/affirm-icon-product-page_2x.png\" | |
| }, | |
| { | |
| \"name\": \"Jamie3\", | |
| \"number\": \"(909) 563-4768\", | |
| \"src\": \"http://www.example.com/images/products/affirm-icon-product-page_2x.png\" | |
| }, | |
| { | |
| \"name\": \"Ben4\", | |
| \"number\": \"(800) 520-2890\", | |
| \"src\": \"http://www.example.com/img/bio/ben.png\" | |
| }, | |
| { | |
| \"name\": \"James5\", | |
| \"number\": \"(951) 123-4567\", | |
| \"src\": \"http://www.example.com/images/products/affirm-icon-product-page_2x.png\" | |
| }, | |
| { | |
| \"name\": \"Jamie6\", | |
| \"number\": \"(909) 563-4768\", | |
| \"src\": \"http://www.example.com/images/products/affirm-icon-product-page_2x.png\" | |
| } | |
| ]'" /> | |
| <mvt:comment>Decode JSON Data</mvt:comment> | |
| <mvt:assign name="l.success" value="miva_json_decode(l.settings:rotating_img_data, l.settings:salespersons)" /> | |
| <mvt:comment>Assign array length</mvt:comment> | |
| <mvt:assign name="l.salespersons_count" value="miva_array_elements( l.settings:salespersons )" /> | |
| <mvt:comment>Shuffle array attempt</mvt:comment> | |
| Before:<br><mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:salespersons), ',', '<br>'))" /><br> | |
| <mvt:foreach iterator="salesperson" array="salespersons"> | |
| <mvt:assign name="g.tempRand" value="random(l.salespersons_count - 1) + 1" /> | |
| <mvt:if expr="('|' $ g.tempRand $ '|') CIN l.randomnums"> | |
| <mvt:while expr="('|' $ g.tempRand $ '|') CIN l.randomnums"> | |
| <mvt:assign name="g.tempRand" value="random(l.salespersons_count - 1) + 1" /> | |
| </mvt:while> | |
| <mvt:assign name="l.randomnums" value="l.randomnums $ '|' $ g.tempRand $ '|'" /> | |
| <mvt:else> | |
| <mvt:assign name="l.randomnums" value="l.randomnums $ '|' $ g.tempRand $ '|'" /> | |
| </mvt:if> | |
| <mvt:assign name="l.success" value="miva_array_insert(l.settings:salespersons_two, l.settings:salespersons[g.tempRand], -1)" /> | |
| </mvt:foreach> | |
| After:<br><mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:salespersons_two), ',', '<br>'))" /><br> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment