PHP form plugin

Status
Not open for further replies.

atamashi

New Member
Hi, Mustafa_s, help me please.
I collected survey data received radio buttons.en a form.
The data is in a table and in each column can evaluate a value that is 1, 2, 3, 4 or 5. To graph for each column need to count how many times each value appears. Counts they write in another table whose columns are excellent, very good, good, fair and poor. In the survey form in your PHP form Plugin I have written this script (I have corrected the code) but does not work yet and do not understand what is wrong or that I lack. Thanks for your help

// Cheque para asegurar que este archivo se incluye en Joomla!
defined('_JEXEC') or die();

$callcenters = (array) $formModel->formData['calif_canos_por_favor___su_servicio_recibido_del_call_center_ha_sido'];
$callcenters = is_array($callcenters) ? $callcenters[0] : $callcenters;
if (is_array($callcenters)){
foreach ($callcenters as $call){
if ($call == 5) {
$callexc = $callexc + 1;
} elseif ($call == 4) {
$callmuyb = $callmuyb + 1;
} elseif ($call == 3) {
$callbue = $callbue + 1;
} elseif ($call == 2) {
$callreg = $callreg + 1;
} elseif ($call == 1) {
$callmalo = $callmalo + 1;
}
}
}

// Get the db and the query
$db = JFactory::getDbo();
$query = $db->getQuery(true);

// Clear down any previous query
$query->clear();

// Update the query to decrease the value contained
// in the field "spaces" by 1 for the current course id.
$query->update('carta_calidad')->set('excelente = $callexc','muy_bueno = $callmuyb','bueno = $callbue','regular = $callreg','malo = $callmalo')->where('nombre = Call-Center');
$db->setQuery($query);
$db->execute();
 
Where did you put this code, in a file or directly into the "PHP code" box?
When is it run ("Process script")?
Did you set Joomla's error reporting to max?
You can debug by inserting var_dump($some-variable);exit; to see what you get (or if it's running at all).
$query->update('carta_calidad')->set('excelente = $callexc','muy_bueno = $callmuyb','bueno = $callbue','regular = $callreg','malo = $callmalo')->where('nombre = Call-Center');
This won't do, see http://fabrikar.com/forums/index.php?wiki/common-php-tasks/ for how to build correct query params
Code:
$callcenters = (array) $formModel->formData['calif_canos_por_favor___su_servicio_recibido_del_call_center_ha_sido'];
$callcenters = is_array($callcenters) ? $callcenters[0] : $callcenters;
if (is_array($callcenters)){
What should this do?
 
Thank you, I am very happy with your answer. I'm in the third world and I am completing a web application for a company with the goal of helping my familia.Gracias again.
this code is directly into the "PHP code" box
this code run onAfterProcess
No, i dont set Joomla's error reporting to max. Thanks for your guide to using var_dump, looking something like.
About:
$query->update('carta_calidad')->set('excelente = $callexc','muy_bueno = $callmuyb','bueno = $callbue','regular = $callreg','malo = $callmalo')->where('nombre = Call-Center');

ok, thanks for your feedback, I will rectify my query

About:
$callcenters = (array) $formModel->formData['calif_canos_por_favor___su_servicio_recibido_del_call_center_ha_sido'];
$callcenters = is_array($callcenters) ? $callcenters[0] : $callcenters;
if (is_array($callcenters)){

Here I need to keep an array of the "su_servicio_recibido_del_call_center_ha_sido" column of the table
"Calif_canos_por_favor". This column will only exist integers from 1 to 5. I need to know
few as 5 contains the column, few as 4 and so on ... To update with those amounts
another table for a graphics card. This is what I need to do with php form plugin.
 
Rather than dive straight in with code, it would healp if you could describe your table setup and the process.

From what I can understand, you are trying to build a survey summary for products. I'll call your tables 'survey' and 'summary' for the purposes of explanation.

So you have a 'survey' table, which consists of a product ID and a number of question. Each question is a 1 to 5 rating.

And you have a 'summary' table, which consists of a product ID, and a summary (count) of all of the combined ratings from the survey.

So, if you had results like this for your survey:

product_id, question1, question2, question3
1, 2, 3, 4
1, 5, 5, 5
2, 1, 5, 4
2, 1, 2, 3

Your summary tables would look like this:

product_id, total1, total2, total3, total4, total5
1, 0, 1, 2, 1, 3
2, 2, 3, 1, 1, 1

... indicating that (say) product 2 had 2 "one" ratings, 3 "two", ratings, etc.

Is this correct?

-- hugh
 
thank you for your explanation.

No, It's similar:

answer service1 service2 service3
1 2 3 4
2 5 5 5
3 1 5 4
4 1 2 3

and my summary tables would look like this:

service_name Excellent(5) Very good(4) Good(3) Regular(2) bad(1)
service1 1 0 0 1 2
service2 2 0 1 1 0
service3 1 2 1 0 0

service_name would tags for chart plotted on the x axis..
 
Excuse Me, for clarity, you have understood me in general:
"Each question is a 1 to 5 rating" is ok
"summary (count) of all of the combined ratings" is ok
Thanks for the guidance you can give me
 
Hi, Cheesegrits and troester!

In Php form plugin (box) I'm dealing with this code and using var_dump for debugging, but it does not work. that I'm not
doing wrong or I'm missing. Help me please.
Code is:

defined('_JEXEC') or die();

// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query
->select(array('su_servicio_recibido_del_call_center_ha_sido',
'la_facilidad_de_acceso_al_lugar_de_atenci_n_ha_sido',
'el_tiempo_de_espera_en_sala_ha_sido',
'el_tiempo_de_espera_de_asignaci_n_de_cita_ha_sido',
'su_servicio_recibido_del_personal_de_atenci_n_al_usuario_ha_sido',
'su_servicio_recibido_del_personal_asistencial_ha_sido',
'su_servicio_recibido_del_personal_m_dico_ha_sido'))
->from('calif_canos_por_favor')
->where('el_tiempo_de_espera_en_sala_ha_sido' IS NOT NULL);
// Assign the query to the db
$db->setQuery($query);
// Load the results as an array of objects.
$rows = $db->loadObjectList();

$i = 0;
$calls = array();
foreach ($rows as $row)
{
$calls[$i] = $row->su_servicio_recibido_del_call_center_ha_sido;
$i++;
}

foreach ($calls as $call){
if ($call == 5) {
$callexc = $callexc + 1;
var_dump($callexc);exit;
} elseif ($call == 4) {
$callmuyb = $callmuyb + 1;
} elseif ($call == 3) {
$callbue = $callbue + 1;
} elseif ($call == 2) {
$callreg = $callreg + 1;
} elseif ($call == 1) {
$callmalo = $callmalo + 1;
}
}
 
Hi,
Although I can not even make the code work me,
I am considering to improve the code rather than using array_column

$i = 0;
$calls = array();
foreach ($rows as $row)
{
$calls[$i] = $row->su_servicio_recibido_del_call_center_ha_sido;
$i++;
}

The code would look like:

defined('_JEXEC') or die();

// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query
->select(array('su_servicio_recibido_del_call_center_ha_sido',
'la_facilidad_de_acceso_al_lugar_de_atenci_n_ha_sido',
'el_tiempo_de_espera_en_sala_ha_sido',
'el_tiempo_de_espera_de_asignaci_n_de_cita_ha_sido',
'su_servicio_recibido_del_personal_de_atenci_n_al_usuario_ha_sido',
'su_servicio_recibido_del_personal_asistencial_ha_sido',
'su_servicio_recibido_del_personal_m_dico_ha_sido'))
->from('calif_canos_por_favor')
->where('el_tiempo_de_espera_en_sala_ha_sido' IS NOT NULL);
// Assign the query to the db
$db->setQuery($query);
// Load the results as an array of objects.
$rows = $db->loadObjectList();

$calls = array_column($rows, 'su_servicio_recibido_del_call_center_ha_sido');

foreach ($calls as $call){
if ($call == 5) {
$callexc = $callexc + 1;
var_dump($callexc);exit;
} elseif ($call == 4) {
$callmuyb = $callmuyb + 1;
} elseif ($call == 3) {
$callbue = $callbue + 1;
} elseif ($call == 2) {
$callreg = $callreg + 1;
} elseif ($call == 1) {
$callmalo = $callmalo + 1;
}
}

it is possible to use Fabrik array_column?
 
How much data are you expecting to have in the survey table? Thousands of rows? Millions of rows?

It makes a difference as to the best approach.

-- hugh
 
Hi, cheesegrits and troester!

to complete the idea of my code,
to upload my results summary table I addiciono this code:


// Clear down any previous query
$query->clear();
// Update the query to my summary table 'carta_calidad'
// in the fields excelente, muy_bueno, bueno, regular, malo.
$query->update('carta_calidad')->set('excelente = $callexc','muy_bueno = $callmuyb','bueno = $callbue','regular = $callreg','malo = $callmalo')->where('nombre = Call-Center');
$db->setQuery($query);
$db->execute();



My full code is:

// Cheque para asegurar que este archivo se incluye en Joomla!
defined('_JEXEC') or die();

// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);

// Clear down any previous query
$query->clear();
$query
->select(array('su_servicio_recibido_del_call_center_ha_sido',
'la_facilidad_de_acceso_al_lugar_de_atenci_n_ha_sido',
'el_tiempo_de_espera_en_sala_ha_sido',
'el_tiempo_de_espera_de_asignaci_n_de_cita_ha_sido',
'su_servicio_recibido_del_personal_de_atenci_n_al_usuario_ha_sido',
'su_servicio_recibido_del_personal_asistencial_ha_sido',
'su_servicio_recibido_del_personal_m_dico_ha_sido'))
->from('calif_canos_por_favor')
->where('el_tiempo_de_espera_en_sala_ha_sido' IS NOT NULL);
// Assign the query to the db
$db->setQuery($query);
$db->execute();

// Load the results as an array of objects.
$rows = $db->loadObjectList();
dump($rows, 'Califica-Call');

$i = 0;
$calls = array();
foreach ($rows as $row)
{
$calls[$i] = $row->su_servicio_recibido_del_call_center_ha_sido;
$i++;
}

foreach ($calls as $call){
if ($call == 5) {
$callexc = $callexc + 1;
var_dump($callexc);exit;
} elseif ($call == 4) {
$callmuyb = $callmuyb + 1;
} elseif ($call == 3) {
$callbue = $callbue + 1;
} elseif ($call == 2) {
$callreg = $callreg + 1;
} elseif ($call == 1) {
$callmalo = $callmalo + 1;
}
}

// Clear down any previous query
$query->clear();
// Update the query to my summary table 'carta_calidad'
// in the fields excelente, muy_bueno, bueno, regular, malo.
$query->update('carta_calidad')->set('excelente = $callexc','muy_bueno = $callmuyb','bueno = $callbue','regular = $callreg','malo = $callmalo')->where('nombre = Call-Center');
$db->setQuery($query);
$db->execute();


but as I said before, it does not work and does not work I dump ().
Why is it?
 
There's a button to insert code in your postings...
If you don't get any dump output it's not run because of incorrect settings or syntax errors.
Start line by line
First try
Code:
echo 'Hallo'; exit;
If you don't get a blank page with only "Hello" on it your plugin isn't run at all.
If you get it add line after line
 
Hi, troester!

I have added echo 'Hello'; exit; in the first line of the script and it does not run at all. That some of the settings can cause this?
Published in is selected Yes
do php
Both in
on Both
and
In Process script is selected end of form submission (onAfterProcess)
 
Enable Joomla error reporting (set to max)
Delete all your code (copy/paste to somewhere)
test with only
Code:
echo 'Hello';exit;
Then add line by line
 
Hi, troaster!

I have placed this

Code:
defined ( '_ jexec') or die ();

$ Db = JFactory :: getDbo ();

echo 'Hello'; exit;


and the result is that sends me to login, but does not disconnect the user.
 
Hola amigos del staff, troester, cheesegrit, hugh, rob...

Para facilitar su ayuda, y porque soy consciente que el registro de mi consulta en el futuro
puede ayudar a otros que quieran usar con ?xito a fabrik, estoy volviendo a formular de manera
m?s completa mi consulta. Siguiendo su sugerencia de mejores pr?cticas, y porque el ingl?s
no es mi idioma nativo, lo har? en espa?ol:

En nuestra empresa queremos evaluar la calidad de nuestro servicio consultando a los
usuarios registrados en nuestro sitio.
Para ello hemos elaborado un formulario cuyo resumen de resultados pasaremos a otra tabla
mediante programaci?n a fin de graficarlos para que los pueda usar la gerencia
en la toma de decisiones.
La introducci?n del formulario se presenta as? a los usuarios registrados:

PRESENTACION%20DEL%20FORMULARIO%20CALIFICANOS%20POR%20FAVOR.png

El cuestionario de preguntas se ve as? en el formulario:
ENCUESTA%20CONSULTA%201.png

ENCUESTA%20CONSULTA%202.png


En fabrik, en listas, la correspondiente al cuestionario tiene los elementos as?:

ELEMENTOS%20LISTA%20CALIFICANOS.png

Cada elemento ha sido creado usando el complemento radio-button, veamos uno:
ELEMENTO%20RADIO.png

y los elementos de la tabla resumen de resultados, carta_calidad se ve as?:

ELEMENTOS%20DE%20LISTA%20SUMARIO.png

El acceso configurado para ambas tablas y para todos sus elementos es para usuarios registrados.

El formulario con el cuestionario se llama "Calif?canos por favor" o sea "calif_canos_por_favor".
En el formulario "calif_canos_por_favor" he creado un PHP plugin:

PLUGIN1.png

La configuraci?n del plugin se ve as?:
DETALLES%20PLUGIN1.png

Su codigo se ve as?:

CODIGO1%20PLUGIN1.png

CODIGO2%20PLUGIN1.png

Este es el c?digo completo del plugin:

Code:
// Cheque para asegurar que este archivo se incluye en Joomla!
defined('_JEXEC') or die();

// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);

// Clear down any previous query
$query->clear();
$query
->select(array('su_servicio_recibido_del_call_center_ha_sido',
'la_facilidad_de_acceso_al_lugar_de_atenci_n_ha_sido',
'el_tiempo_de_espera_en_sala_ha_sido',
'el_tiempo_de_espera_de_asignaci_n_de_cita_ha_sido',
'su_servicio_recibido_del_personal_de_atenci_n_al_usuario_ha_sido',
'su_servicio_recibido_del_personal_asistencial_ha_sido',
'su_servicio_recibido_del_personal_m_dico_ha_sido'))
->from('calif_canos_por_favor')
->where('el_tiempo_de_espera_en_sala_ha_sido' IS NOT NULL);
// Assign the query to the db
$db->setQuery($query);
$db->execute();

// Load the results as an array of objects.
$rows = $db->loadObjectList();
//dump($rows, 'Califica-Call');

$i = 0;
$calls = array();
foreach ($rows as $row)
{
$calls[$i] = $row->su_servicio_recibido_del_call_center_ha_sido;
$i++;
}

foreach ($calls as $call){
if ($call == 5) {
$callexc = $callexc + 1;
var_dump($callexc);exit;
} elseif ($call == 4) {
$callmuyb = $callmuyb + 1;
} elseif ($call == 3) {
$callbue = $callbue + 1;
} elseif ($call == 2) {
$callreg = $callreg + 1;
} elseif ($call == 1) {
$callmalo = $callmalo + 1;
}
}

// Clear down any previous query
$query->clear();
// Update the query to my summary table 'carta_calidad'
// in the fields excelente, muy_bueno, bueno, regular, malo.
$query->update('carta_calidad')->set('excelente = $callexc','muy_bueno = $callmuyb','bueno = $callbue','regular = $callreg','malo = $callmalo')->where('nombre = Call-Center');
$db->setQuery($query);
$db->execute();

La l?gica del c?digo se resume as?:
Necesito guardar en un array la columna
"su_servicio_recibido_del_call_center_ha_sido" de la tabla
"calif_canos_por_favor".
En esta columna solo existiran valores enteros de 1 a 5.
Necesito saber cu?ntos como 5 contiene la columna, cu?ntos como 4 y as? sucesivamente
Para actualizar con esas cantidades los elementos excelente, muy_bueno, bueno, regular y malo
de la tabla carta_calidad.
Necesito as? la tabla carta_calidad para poder
elaborar un gr?fico cuyas etiquetas en el eje x
correspondan a la primera columna llamada nombres.
En la columna nombres menciono los servicios evaluados.
Por ejemplo, "su_servicio_recibido_del_call_center_ha_sido", pasa ser "Call-Center"
en el primer registro.
An?logamente, en los siguientes registros estar?n resumidos los resultados de la encuesta
correspondientes a cada pregunta.

Aqui estan las tablas calif?canos por favor y carta calidad en mi phpMyAdmin:
tablas%20en%20MYSQL.png

Cuando el usuario graba su votaci?n en la encuesta, el resultado que aparece en
la tabla carta_calidad se ve as?:
RESULTADO%20CARTACALIDAD%20EN%20PHPMYADMIN.png

Por tanto, el plugin no ha funcionado. No hay resultados, siguen los ceros.

Tengo resuelto el modo de elaborar el gr?fico. Requiero vuestro apoyo solo
para obtener la tabla carta_calidad con los datos resumen.
Estoy muy agradecido por su apoyo y est?n recibiendo mi mejor calificaci?n.
Con su ayuda espero poder terminar ?sta ?ltima parte de la aplicaci?n.
 
ok, not problem...

Hello friends of the staff, Troester, cheese greet, hugh, rob ...

I had written:

"To facilitate your help, and because I am aware that the registration of my practice in the future
You can help others who want to use successfully fabrik, I'm going to make so
fuller my office. Following the suggestion of best practices, and because English
it's not my native language, I will in Spanish:"
But I can also use google to translate for and here is my version in English:

In our company we want to assess the quality of our service in consultation with the
Registered users on our site.
So we've developed a form of which a summary of results pass to another table
programmatically to plot them so that management can use
in the decision-making.
The introduction of the form is thus presented to registered users:
PRESENTACION%20DEL%20FORMULARIO%20CALIFICANOS%20POR%20FAVOR.png

The list of questions is well seen in the form:
ENCUESTA%20CONSULTA%201.png

ENCUESTA%20CONSULTA%202.png


In fabrik, lists, corresponding to the questionnaire has the elements as follows:
ELEMENTOS%20LISTA%20CALIFICANOS.png

Each element has been created using the radio-button snap, see one:
ELEMENTO%20RADIO.png

and the elements of the summary table of results, carta_calidad looks like this:
ELEMENTOS%20DE%20LISTA%20SUMARIO.png

Access configured for both tables and all its elements is for registered users.
The form of the questionnaire is called "Review us please" or is "calif_canos_por_favor".
In the form "calif_canos_por_favor" I created a PHP plugin:
PLUGIN1.png

Plugin configuration looks like this:
DETALLES%20PLUGIN1.png

The code looks like this:

CODIGO1%20PLUGIN1.png

CODIGO2%20PLUGIN1.png

This is the complete code of plugin:
Code:
// Cheque para asegurar que este archivo se incluye en Joomla!
defined('_JEXEC') or die();

// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);

// Clear down any previous query
$query->clear();
$query
->select(array('su_servicio_recibido_del_call_center_ha_sido',
'la_facilidad_de_acceso_al_lugar_de_atenci_n_ha_sido',
'el_tiempo_de_espera_en_sala_ha_sido',
'el_tiempo_de_espera_de_asignaci_n_de_cita_ha_sido',
'su_servicio_recibido_del_personal_de_atenci_n_al_usuario_ha_sido',
'su_servicio_recibido_del_personal_asistencial_ha_sido',
'su_servicio_recibido_del_personal_m_dico_ha_sido'))
->from('calif_canos_por_favor')
->where('el_tiempo_de_espera_en_sala_ha_sido' IS NOT NULL);
// Assign the query to the db
$db->setQuery($query);
$db->execute();

// Load the results as an array of objects.
$rows = $db->loadObjectList();
//dump($rows, 'Califica-Call');

$i = 0;
$calls = array();
foreach ($rows as $row)
{
$calls[$i] = $row->su_servicio_recibido_del_call_center_ha_sido;
$i++;
}

foreach ($calls as $call){
if ($call == 5) {
$callexc = $callexc + 1;
var_dump($callexc);exit;
} elseif ($call == 4) {
$callmuyb = $callmuyb + 1;
} elseif ($call == 3) {
$callbue = $callbue + 1;
} elseif ($call == 2) {
$callreg = $callreg + 1;
} elseif ($call == 1) {
$callmalo = $callmalo + 1;
}
}

// Clear down any previous query
$query->clear();
// Update the query to my summary table 'carta_calidad'
// in the fields excelente, muy_bueno, bueno, regular, malo.
$query->update('carta_calidad')->set('excelente = $callexc','muy_bueno = $callmuyb','bueno = $callbue','regular = $callreg','malo = $callmalo')->where('nombre = Call-Center');
$db->setQuery($query);
$db->execute();

Code logic is summarized as follows:

I need to store in a column array
"Su_servicio_recibido_del_call_center_ha_sido" table
"Calif_canos_por_favor".
This column will only exist integer values of 1-5.
I need to know how many as 5 contains the column, many as 4 and so on
To upgrade to these amounts the excellent and elements muy_bueno, good, fair, bad
carta_calidad of the table.
so I need the table to carta_calidad
draw a graph with labels on the x axis
correspond to the first column called names.
In the column names I mention the services tested.
For example, "I su_servicio_recibido_del_call_center_ha_sido" happens to be "Call-Center"
in the first record.
Similarly, the following records will be summarized the results of the survey
for each question.
Here are the tables Review us please and wine quality in my phpMyAdmin:
tablas%20en%20MYSQL.png

When a user records a vote in the poll, the result showing on
the carta_calidad table looks like this:
RESULTADO%20CARTACALIDAD%20EN%20PHPMYADMIN.png

Therefore, the plug has failed. No results are zeros.
I have resolved how to develop the chart. I require only your support
carta_calidad for the summary table data.
I am very grateful for their support and are receiving my best rating.
With your help I hope to finish this last part of the application.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top