Welcome
2 1 9
Welcome 9 2 0 1 Hello Agenda 19/06/2019 Registration & - - PowerPoint PPT Presentation
Welcome 9 2 0 1 Hello Agenda 19/06/2019 Registration & Welcome Practical presentations Part 1 Lunch time Abdelhafid El Hour Practical presentations Part 2 Development engineer Q&A with your 4D team 2 9 0 1
2 1 9
2 1 9
Abdelhafid El Hour
Development engineer
19/06/2019
2 1 9
Managing municipal library
2 1 9
Shared objects / collections
$sharedObject:=New shared object $sharedCollection:=New shared collection $sharedCollection.push($sharedObject)
Locking identifier negative
$sharedObject and $sharedCollection make a shared group. They share the same locking identifier
2 1 9
Nesting shared object
Shared Object / Collection
Shared group
28
Shared group
28
Shared group
28
Shared group
29
Shared group
28
2 1 9
Create table
Use (Storage) Storage.tables:=New shared collection $tables:=Storage.tables End use Use ($tables) //----------------- BOOK -------------- $table:=New shared object Use ($table) $table.dataclass:="Book" $table.label:="Livre" $table.name:="title" $table.perspective:="Catalogue" $table.panel:="Book_panel" $table.countFormat:="### ### ##0 books;;" $callback:=New shared object $table.callback:=$callback $formula:=New formula(Author_load ) $table.callback.load:=$formula End use end use
Use is necessary
Storage
$tables.push($table)
$tables
$table
$callback
30 30
STOP
2 1 9
Create table
Use (Storage) Storage.tables:=New shared collection $tables:=Storage.tables End use Use ($tables) //----------------- BOOK -------------- $table:=New shared object Use ($table) $table.dataclass:="Book" $table.label:="Livre" $table.name:="title" $table.perspective:="Catalogue" $table.panel:="Book_panel" $table.countFormat:="### ### ##0 books;;" $callback:=New shared object $table.callback:=$callback $formula:=New formula(Author_load ) $table.callback.load:=$formula End use end use
Storage
$tables.push($table)
$tables
$table
$callback
29 29 29
2 1 9
Exception
Storage
Objet partagé
Collection partagée-29 Shared object Locking identifier negative Objet partagé
30
Objet partagé
30
Objet partagé
30
Storage don’t shard its locking with
2 1 9
My town library
lb_tables
initialization : sfw_fill_lb_tables
lb_items pup_perspective
clic : sfw_fill_lb_tables clic : sfw_display_item clic : sfw_fill_lb_items
initialization : sfw_fill_lb_items
clic : sfw_fill_lb_items
2 1 9
Form and subform
Widget in the form of object type ‘Subform container’ OBJECT SET SUBFORM(*;"sf_panel";"Author_panel")
2 1 9
Form
Form and subform
Subform instance Form Form
How we can access to the ‘Form’ of the subForm ?
C_POINTER($subForm) $subForm:=OBJECT Get pointer(Object named;"sf_panel") $subForm->entity:=Form.entity $subForm->UUID:=Form.UUID $subForm->currentTable:=Form.currentTable
$subForm is a pointer to an object Subform container
2 1 9
Form Subform instance
Form un subform
Form Form
$evt:=Form event Case of : ($evt=On Data Change) CALL SUBFORM CONTAINER(-1000) End case C_POINTER($subForm) $evt:=Form event Case of : ($evt=-1000) $subForm:=OBJECT Get pointer(Object current) Form.entity:=$subForm->entity Form.UUID:=$subForm->UUID Form.currentTable:=$subForm->currentTable End caseMethod object
Code executed in the parent form context Object method of the container
2 1 9
Reference your texts
Use bookmarks
$section:=WP Get section(Form.booksDoc;$i) $rangeSection:=WP Create range($section;wk start text;wk end text) WP CREATE BOOKMARK($rangeSection;$categoriesfromServer[$i-1].name) ………………………………. $_ptr_bookmarks:=OBJECT Get pointer(Object named;"bookmarks") ARRAY TEXT($_ptr_bookmarks->;0) WP GET BOOKMARKS(Form.booksDoc;$_ptr_bookmarks->)Form method
Associate a bookmark to a text2 1 9
Reference your texts
Use bookmarks
C_OBJECT($wpRange) Case of : (Form event=On Data Change) $_ptr_bookmarks:=OBJECT Get pointer(Object named;"bookmarks") $bookMark:=$_ptr_bookmarks->{$_ptr_bookmarks->} $wpRange:=WP Get bookmark range(Form.booksDoc;$bookMark) WP SELECT(Form.booksDoc;$wpRange) End caseObject method ‘bookmarks’ Range referenced by bookmark Select a range
2 1 9
Organize your pages with tables
$picture:=ds.Image.get($book.images.thumbnail.record).thumbnail` $WPTableDescription:=WP Insert table($WPRange;wk append) WP Table append row($WPTableDescription;$picture;$book.description) $cells:=WP Table get cells($WPTableDescription;1;1;MAXLONG;MAXLONG) WP SET ATTRIBUTES($cells;wk border color;"white") $fcolumn:=WP Table get columns($WPTableDescription;2;1) WP SET ATTRIBUTES($fcolumn;wk width;"380pt") $scolumn:=WP Table get columns($WPTableDescription;1;1) WP GET ATTRIBUTES($scolumn;wk width;$width) WP SET ATTRIBUTES($WPTableDescription;wk vertical align;wk top) $oPicts:=WP Create picture range($scolumn) WP SET ATTRIBUTES($oPicts;wk width;$width)Form method
Hide the borders Change the width
2 1 9
Customize the context menu
Uncheck the context menu
$contextualMenu:=Create menu APPEND MENU ITEM($contextualMenu;ak standard action title) SET MENU ITEM PROPERTY($contextualMenu;-1;Associated standard action;ak copy) APPEND MENU ITEM($contextualMenu;ak standard action title) SET MENU ITEM PROPERTY($contextualMenu;-1;Associated standard action;ak cut) APPEND MENU ITEM($contextualMenu;ak standard action title) SET MENU ITEM PROPERTY($contextualMenu;-1;Associated standard action;ak paste) APPEND MENU ITEM($contextualMenu;"-") APPEND MENU ITEM($contextualMenu;ak standard action title) SET MENU ITEM PROPERTY($contextualMenu;-1;Associated standard action;ak font style) $menuSubSize:=Create menu APPEND MENU ITEM($menuSubSize;ak standard action title) SET MENU ITEM PROPERTY($menuSubSize;-1;Associated standard action;"fontSize?value=10pt") APPEND MENU ITEM($menuSubSize;ak standard action title) SET MENU ITEM PROPERTY($menuSubSize;-1;Associated standard action;"fontSize?value=12pt") APPEND MENU ITEM($menuSubSize;ak standard action title) SET MENU ITEM PROPERTY($menuSubSize;-1;Associated standard action;"fontSize?value=14pt") APPEND MENU ITEM($menuSubSize;ak standard action title) SET MENU ITEM PROPERTY($menuSubSize;-1;Associated standard action;"fontSize?value=16pt") APPEND MENU ITEM($contextualMenu;"Size";$menuSubSize) APPEND MENU ITEM($contextualMenu;"-") APPEND MENU ITEM($contextualMenu;ak standard action title) SET MENU ITEM PROPERTY($contextualMenu;-1;Associated standard action;"visibleHiddenChars") Form.contextualMenu:=$contextualMenuUse actions
https://doc.4d.com/4Dv17/4D/17.1/Actions-standard.300-4201167.fr.html
Limit users action
Case of : (Form event=On Clicked) If (Contextual click) Dynamic pop up menu(Form.contextualMenu) End if End case2 1 9
http://monsite.com/books?page=3
Path / Query Parameters
Domain name
‘Path' Path to a resource
Query String
Empire of Magic Dimensions of Humor Linguistic Theories of Humor An Anatomy of Humor Text Types and Corpora License to Laugh The iPhone Pocket Guide Head First PHP MySQL Class Actions Action Theory The God of the Prophets The X-Discipline Essentials of Shinto Identity Poetics Translation Complex Inequality The Pervasive Image Horizons in Hermeneutics The Arts in Education Interacting with Video International Adventures Seven Types of Adventure Tale Frightening Fiction Beyond the Cyborg Emmanuel Levinas Empire of Magic Dimensions of Humor Linguistic Theories of Humor An Anatomy of Humor Text Types and Corpora License to Laugh The iPhone Pocket Dimensions of Humor Linguistic Theories of Humor An Anatomy of Humor Text Types and Corpora License to Laugh The iPhone Pocket Guide Head First PHP
2 1 9
http://localhost:8080/books/0ougn1
Path / Query Parameters
//4DRouting {"path" : "/books/:permalink", "restrict" : true}
$permalink:=routing_request.pathParams.permalink
Request object
Path parameter
2 1 9
Load router
//4DRouting {"path" : "/books/:permalink", "restrict" : true}
swfw_load_router
{"permalink" : 1}
2 1 9
Match urls
//4DRouting {"path" : "/books/:permalink", "restrict" : true}
swfw_findHandlerRequest
http://localhost:8080/books/0ougn1
["books", "0ougn1" ] ["books", ":permalink" ]
2 1 9
Get path parameters
swfw_dispatcher
http://localhost:8080/books/0ougn1
["books", "0ougn1" ] {"permalink" : "0ougn1"} {"permalink" : 1}
2 1 9
Path Parameters
C_OBJECT($book) $book:=ds.Book.query("permalink = :1";routing_request.pathParams.permalink).first() If ($book#Null) routing_request.book:=$book.toObject("*,publisher.name, owners.author.firstName, owners.author.lastName") end if <h2 ><!--#4DEVAL routing_request.book.title—-></h2> <p><!--#4DEVAL routing_request.book.description—-></p>
HTML
Get the path parameter Set ‘book’ attribute inside the request object The first entity Entity selection ‘books’
2 1 9
http://monsite.com/books/?search=balzac
Query Parameters
//4DRouting {"path" : "/books", "restrict" : true}
$motCle:=routing_request.queryParams.search
Query parameter Optional
C_OBJECT($booksEntitySelection) If (OB Is defined(routing_request.queryParams; "search")) $booksEntitySelection:=ds.Book.query("title = :1 or owners.author.firstName = :1 or owners.author.lastName = :1";"@"+routing_request.queryParams.search+"@") Else $booksEntitySelection:=ds.Book.all() End if routing_request._books:=$booksEntitySelection.toCollection("UUID, permalink, title, images, owners.author.firstName, owners.author.lastName")Check if the parameter exists
2 1 9
http://monsite.com/books?page=14
Don’t send all your data
swfw_pagination_build ($totalItem;$page)
$totalItem:=$1 // Nombre total d’élément $currentPage:=$2 // La page à affichée $pagination:=New object $pagination.visiblePages:=8 $pagination.itemOnPage:=18 $totalPages:=Int($totalItem/$pagination.itemOnPage) If (Mod($totalItem;$pagination.itemOnPage)#0) $totalPages:=$totalPages+1 End if $half:=Int($pagination.visiblePages/2) $start:=$pagination.currentPage-$half $end:=$start+$pagination.visiblePages-1 $pagination.startItem:=($currentPage-1)*$pagination.itemOnPage $pagination.endItem:=$currentPage*$pagination.itemOnPage routing_request.pagination:=$pagination swfw_load_section ("pages/pagination.shtml")1 2 3 4 5 6 7 8
Total pages
Le Petit Prince Le Petit Prince Le Rouge et le Noir Le Grand Meaulnes Les Misérables Le Petit Prince Le Rouge et le Noir Le Grand Meaulnes ……… Les Misérables Le Petit Prince Le Rouge et le Noir Le Grand Meaulnes Les Misérables Le Petit Prince Le Rouge et le Noir Le Grand Meaulnes
<ul> <!--#4DEVAL $i:=routing_request.pagination.start—> <!--#4DLOOP ($i<=routing_request.pagination.end))--> <li><a href="#"><!--#4DEVAL $i—></a></li> <!--#4DEVAL $i:=$i+1--> <!—#4DENDLOOP—> </ul>
Use pagination
total d’item Books or Albums
2 1 9
Verrouillage des enregistrements
Pessimiste Optimiste
C_OBJECT($info) C_BOOLEAN($done) $entity:=ds.Employee(5) Repeat $entity.salary:=100 $info:=$entity.save() $done:=$info.success If (Not($done)) $entity.reload() End if Until ($done) C_OBJECT($info) $entity:=ds.Employee(5) $info:=$entity.lock() If ($info.success) $entity.salary:=100 $entity.save() $entity.unlock() End if
Pose du verrou Sauvegarde Libération du verrou Modification sans verrou Tentative de sauvegarde Test de la réussite
Ce schéma est un des schémas possibles
2 1 9
Status object
$info.success $info.status
True False
dk status locked dk status stamp has changed dk status wrong permission dk status serious error dk status success
2 1 9
Verrouillage des enregistrements
dk status locked dk status stamp has changed dk status wrong permission dk status serious error … dk status locked Le verrou peut provenir de :
dk status stamp has changed Le changement de stamp peut provenir :
dk status wrong permission A venir … dk status serious error
2 1 9
Déverrouillage des enregistrements
Quand .unlock est appelé A la fin du process ayant posé le verrou Quand le ref comptage de l'entité passe à zéro
2 1 9
Attacher des pièces jointes
$entity:=ds.Borrowing_cart.query("current_state = :1";7).first() $file:=Get 4D folder(HTML Root folder)+"pages"+Folder separator+"emailTemplate.shtml" $templateHtml:=Document to text($file) PROCESS 4D TAGS($templateHtml;$emailBody;$entity;"cid:LivresRetard") $server:=New object $server.host:="smtp.gmail.com" $server.port:=465 $server.user:="woroldtour2019@gmail.com" $server.password:="20194Dworldtour" $transporter:=SMTP New transporter($server) $email:=New object $email.subject:="Panier en retard $email.from:="woroldtour2019@gmail.com" $email.to:="abdelhafid.elhour@4d.com" $logopth:=Get 4D folder(HTML Root folder)+"town2.jpg" $niceDay:=Get 4D folder(HTML Root folder)+"niceDay.jpg" $email.attachments:=New collection $email.attachments.push(MAIL New attachment($logopth;"Livre en retars";"LivresRetard";"image/jpeg";mail disposition inline)) $email.attachments.push(MAIL New attachment($niceDay;"Have a nice day.jpg")) $email.htmlBody:=$emailBody $status:=$transporter.send($email) If (Not($status.success)) ALERT("Une erreur est survenue pendant l'envoi de l'e-mail : "+$status.message) End if Personnaliser le corps de l’email avec une page HTML Ajouter une pièce jointe ‘inline’ PJ lien dans le message2 1 9
Avant de commencer …
De quoi avant nous besoin ? Faire un slide avec les différents ingrédients nécessaires