Updated 026 How to setup a store message method along side the email helper class (markdown)

Amigo 2019-07-16 15:37:33 +02:00
parent eff6df286b
commit 1c577a9cce

@ -1,16 +1,22 @@
# HOW TO SETUP A STORE MESSAGE METHOD ALONG SIDE THE EMAIL HELPER CLASS
[00:00:00](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m00s)
* ### Example In Code
In a previous tutorial on the Email Helper, mention had been made of storing messages or emails once it has been send. [00:00:24](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m24s) At this stage it is important to know that the Email Helper Class is added to the Helper folder of the components back end. It's usually called the component's name, 'Jobtracking' and 'Email', that's the Email Helper class. To use it in the Custom Script three brackets may be used, '[[[component]]]email' and send. [00:00:59](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m59s) That is how to construct script.
### Code Snippet In Method
At the bottom of this class in the 'Send' method, [00:01:21](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m21s) there is a snippet, thought insignificant as it may seem, it is very beneficial, as may be seen, the result of the email that was sent is placed in 'sendEmail' and this result is transferred to the method as well. [00:01:47](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m47s) First it does a search in the Helper class (which is usually a component name, 'Helper', which is the Helper Class) whether this method exists in that class.
[00:01:17](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m17s)
This method will not exist unless it is manually written in the component area. The area where this method should be written , is in the component(In the Component Builder Dashboard) in an area called Admin Helper.[00:02:13](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m13s)
At the bottom of this class in the 'Send' method, there is a snippet, thought insignificant as it may seem, it is very beneficial, as may be seen, the result of the email that was sent is placed in 'sendEmail' and this result is transferred to the method as well. [00:01:47](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m47s) First it does a search in the Helper class (which is usually a component name, 'Helper', which is the Helper Class) whether this method exists in that class.
This method will not exist unless it is manually written in the component area. The area where this method should be written , is in the component(In the Component Builder Dashboard) in an area called Admin Helper.
### Adding Code To Admin Helper Area
[00:02:19](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m19s)
Open a component(Learning manager) and go to Libs & Helpers. Scroll down and 'Add PHP(admin_helper)' may be seen and in there is a function called 'storemessage', where the component may be editted. [00:02:47](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m47s) This 'Storemessage' has a signature that exists of values that is transferred to the method.
In the Email Helper Class it also has a signature. [00:03:19](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m19s) Wherever it gives this '=null' with a value, that is the default value. If a value is not added to this position, there is one, two, three, four, five, positions, then it will default it to '=null'. [00:03:51](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m51s) From there all the values receives the value '=null' . It is only nessesary to add the first four values. Those values are all used in this method(see video). [00:04:17](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m17s) This script "if(method_exists('Jobtracking Helper','storeMessage'))" asks whether the method has been created. If not, it simply skips it and returns the value of '$sendmail'. [00:04:52](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m52s) If it have been created, it will pass these variables that correspond to the signature. In that method that is in the Helper Class (PHP), the necessary checks and balances must be done. Since the email address is known, a search may be done with the 'getVar' in the User Class. The recipient must equal 'email', and returns the 'id'. [00:05:09](https://www.youtube.com/watch?v=peVNLsAncGY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m09s) That is how the 'getVar' operates. Then having the user ID, the number can be verified and be set to the message as 'User'. That is then set as the Email.