I'm working in a project and I need to consult the attendees response. I want to create a script that every hours check if some attendee change your response status, but I can't find any documentation how this works, an example of my code when I insert the event:
if (isset($_SESSION['access_token'])) {
$client->setAccessToken($_SESSION['access_token']);
$service = new Google_Service_Calendar($client);
$event = new Google_Service_Calendar_Event(array(
'summary' => $summary,
'location' => $location,
'description' => $descripcion,
'colorId'=> "5",
'start' => array(
'dateTime' => $datetimeini,
'timeZone' => 'America/Caracas'
),
'end' => array(
'dateTime' => $datetimeini,
'timeZone' => 'America/Caracas'
),
'recurrence' => array(
'RRULE:FREQ=DAILY;COUNT=1'
),
'attendees' => array(
array('email' => $paciente,'responseStatus'=> 'needsAction'),
array('email' => $doctor)
),
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 12 * 60),
array('method' => 'popup', 'minutes' => 60)
),
),
));
$new_event = null;
$new_event_id = "";
$new_event = $service->events->insert($idcalendar, $event);
if($new_event!=null){
$new_event_id= $new_event->getid();
$event = $service->events->get($idcalendar,$new_event_id);
$response = new Google_Service_Calendar_EventAttendee($client);
if($event != null){
$resultado=array(
"respuesta"=>"exitoso",
"id evento"=>$event->getid(),
"sumario"=>$event->getSummary(),
"estado"=>$event->getstatus(),
"response"=>$event->getresponseStatus()
);
}else{
echo 'hay problemas.';
}
If I try this code on response I just get null. I want to get the real response.
You may use the Events: watch method which watches for changes to Events resources.
HTTP request
POST https://www.googleapis.com/calendar/v3/calendars/calendarId/events/watch
In the request body, supply data with the following structure:
{
"id": string,
"token": string,
"type": string,
"address": string,
"params": {
"ttl": string
}
}
Related
I use this library:
https://github.com/php-curl-class/php-curl-class
Base on documentation I write function for post order:
public function create_order()
{
$curl = new Curl();
$curl->setHeader('CustomerId', 'xxxxxxx');
$curl->setHeader('UserName', 'xxxxxxxxxx');
$curl->setHeader('ActionApiKey', 'xxxxxxxxxxxxxxx');
$order = array(
"createEmpty" => false,
"header" => array(
"comment" => "string",
"country" => "Polska",
"currency" => "PLN",
"isFileRequired" => true,
"actionCustomerId" => "81790",
"payer" => "EndCustomer",
"paymentType" => "CashOnDelivery",
"partnerOrderId" => "81790",
"deliveryAddresType" => "EndCustomer",
"cashOnDeliveryType" => "FullRate",
"cashOnDelivery" => 155,
"deliveryCompanyName" => "TEST API ORDER DO NOT SHIP",
"deliveryCity" => "Poznań",
"deliveryPhone" => "xxxxxxx",
"deliveryStreet" => "xxxxxxxxxx",
"deliveryZipCode" => "xxxxxxx"
),
"items" => array(
array(
"actionProductId" => "MULLOGKAM0087",
"quantity" => 1,
"price" => 122,
"backOrderType" => "BackOrder"
)
)
);
$curl->setHeader('Content-Type', 'application/json');
$curl->post('xxxxxxxxxxxxxxxxxxxxx/v2/Order', json_encode($order));
if ($curl->error) {
echo 'Error: ' . $curl->error_code . ': ' . $curl->error_message;
} else {
echo 'Respone: ' . $curl->response;
}
}
After run controller, I get white page (I not get any error) but order not created. I test in Insomia API client and with this headers and data order created sucess.
Im not sure I correct post headers also with order data ?
i'm new, and i've a problem with webservice.
when i try to retrieve customers filtering by date_add i get this error:
<message><![CDATA[This filter does not exist. Did you mean: "deleted"? The full list is: "id", "id_default_group", "id_lang", "newsletter_date_add", "ip_registration_newsletter", "last_passwd_gen", "secure_key", "deleted", "passwd", "lastname", "firstname", "email", "id_gender", "birthday", "newsletter", "optin", "website", "company", "siret", "ape", "outstanding_allow_amount", "show_public_prices", "id_risk", "max_payment_days", "active", "note", "is_guest", "id_shop", "id_shop_group"]]></message>
this is my code:
$yesterday = date("Y-m-d H:i:s", time() - 60 * 60 * 24);
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
// Qui imposto le opzion dell'array per il Webservice: in questo caso i clienti e setto che il formato è json
$opt = array( 'resource' => 'customers',
'filter[date_add]' => '['.$yesterday.']&date=1',
'display' => 'full',
'output_format' => 'JSON'
);
// faccio la chiamata
$xml = $webService->get($opt);
I'm stuck, I do not know what to do !!! any help is appreciated
Looking at the Customer class webservice parameters, there is no date_add:
protected $webserviceParameters = array(
'fields' => array(
'id_default_group' => array('xlink_resource' => 'groups'),
'id_lang' => array('xlink_resource' => 'languages'),
'newsletter_date_add' => array(),
'ip_registration_newsletter' => array(),
'last_passwd_gen' => array('setter' => null),
'secure_key' => array('setter' => null),
'deleted' => array(),
'passwd' => array('setter' => 'setWsPasswd'),
),
'associations' => array(
'groups' => array('resource' => 'group'),
)
);
If you have access to the server installation, you could add the date_add field to the webserviceParameters.
Or the function getWebserviceObjectList to change the behavour.
If you don't have access to the server installation, you can use the sort to get the latest customers until you reach the one you already have. You can use with limit to use in a foreach or while loop.
EDIT After some testing and inspecting what was going on:
First, it's we don't need to add the field date_add to the $webserviceParameters.
The request should be:
$opt = array( 'resource' => 'customers',
'filter[date_add]' => '['.$begin.','.$finish.']',
'date' => 1,
'display' => 'full',
'output_format' => 'JSON'
);
If you only add one date to the filter it will try to match only that date.
Then you need to change the PSWebServiceLibrary.php in line 284 and add the field 'date':
$params = array('filter', 'display', 'sort', 'limit', 'id_shop', 'id_group_shop', 'date');
Now it should work. I tested myself.
EDIT 2:
This is my full test, after changing the the line i mentioned in PSWebserviceLibrary.php, this retrieves my customers with date_add in the interval date.
<?php
require_once( 'PSWebServiceLibrary.php' );
echo 'starting<br />'.PHP_EOL;
try {
// creating web service access
$webService = new PrestaShopWebservice(MY_BASE_URL, WS_KEY, true);
$yesterday = date("Y-m-d", time() - 60 * 60 * 24);
$begin = date("Y-m-d", time() - 60 * 60 * 24 * 30);
$opt = array( 'resource' => 'customers',
'filter[date_add]' => '['.$begin.','.$yesterday.']',
'date' => 1,
'display' => 'full',
'output_format' => 'JSON'
);
//Retrieving the XML data
$xml = $webService->get($opt);
}
catch (PrestaShopWebserviceException $ex) {
// Shows a message related to the error
echo 'Other error: <br />' . $ex->getMessage();
}
?>
first of all: thanks
I modified as your indication, but the result does not change, still gives me the same error.
protected $webserviceParameters = array(
'fields' => array(
'id_default_group' => array('xlink_resource' => 'groups'),
'id_lang' => array('xlink_resource' => 'languages'),
'newsletter_date_add' => array(),
'ip_registration_newsletter' => array(),
'last_passwd_gen' => array('setter' => null),
'secure_key' => array('setter' => null),
'deleted' => array(),
'passwd' => array('setter' => 'setWsPasswd'),
/** inizio modifica aggiunta per il webservice */
'date_add' => array(),
/** fine della modifica */
),
'associations' => array(
'groups' => array('resource' => 'group'),
)
);
I can not understand
I have been looking into select2 and yii and have managed to load data via json request/response.
The issue I'm faced with is when I try to select an entry of the returned data, I can not.
Where am I going wrong ? The data returnd by the action is json formatted as CustomerCode and Name
Widget code in form
$this->widget('bootstrap.widgets.TbSelect2', array(
'asDropDownList' => false,
'name' => 'CustomerCode',
'options' => array(
'placeholder' => 'Type a Customer Code',
'minimumInputLength' => '2',
'width' => '40%',
'ajax' => array(
//'url'=> 'http://api.rottentomatoes.com/api/public/v1.0/movies.json',
'url'=> Yii::app()->getBaseUrl(true).'/customer/SearchCustomer',
'dataType' => 'jsonp',
'data' => 'js: function (term,page) {
return {
term: term, // Add all the query string elements here seperated by ,
page_limit: 10,
};
}',
'results' => 'js: function (data,page) {return {results: data};}',
),
'formatResult' => 'js:function(data){
var markup = data.CustomerCode + " - ";
markup += data.Name;
return markup;
}',
'formatSelection' => 'js: function(data) {
return data.CustomerCode;
}',
)));
code snipped from controller action SearchCustomer
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
$this->renderJSON(Customer::model()->searchByCustomer($term));
renderJSON function from base controller class
protected function renderJSON($data)
{
header('Content-type: application/json');
echo $_GET['callback'] . "(";
echo CJSON::encode($data);
echo ")";
foreach (Yii::app()->log->routes as $route) {
if($route instanceof CWebLogRoute) {
$route->enabled = false; // disable any weblogroutes
}
}
Yii::app()->end();
}
Appreciate any help on this
i try.
change
'dataType' => 'jsonp' to 'dataType' => 'json'
and check json format
https://github.com/ivaynberg/select2/issues/920
Im working on Zend Framework 2 especially with Zend Forms. I have declared a Select dropdown box in
Form:
$selectElement = new Element\Select('selectElement');
$selectElement->setAttribute('title', 'Select a Value')
->setAttribute('id', 'id');
$data = array(
array(
//Fetching the values from database
),
);
$selectElement->setAttribute('multiple', 'multiple')
->setValueOptions($data);
$this->add($selectElement);
InputFilter:
$inputFilter->add($factory->createInput(array(
'name' => 'selectElement',
'required' => false,
'filters' => array(
array(
'name' => 'Int'
),
),
)));
I have used Zend Debug to get the values which are in the selectElement dropbox in this fashion:
$dataSelectElements = $this->getRequest()->getPost('selectElement');
\Zend\Debug\Debug::dump($dataSelectElements);
Debug Result:
array(4) {
[0] => string(2) "20"
[1] => string(2) "22"
[2] => string(2) "23"
[3] => string(2) "75"
}
Basically Im getting the id's from the selectElement form to store it in the database. Right now Im getting a notice and zend form error:
Notice Error:
Notice: Array to string conversion in ..\zendframework\zendframework\library\Zend\Filter\Int.php on line 29
And a form invalid error:
array(1) {
[0] => array(1) {
["selectElement "] => array(1) {
["explodeInvalid"] => string(35) "Invalid type given. String expected"
}
}
}
Is there a solution to over come this problem. Any help would be appreciated.
The Int filter will attempt to make an Integer out of your array of data, which is not going to work.
Previously I've used the Callback filter, which can be used to loop through the data and check if each value is an Int.
For example:
'filters' => array(
array(
'name' => 'Callback',
'options' => array(
'callback' => function($values) {
return array_filter($values, function($value) {
return ((int)$value == $value);
});
}
)
),
),
I did bit differently, something like this
form
class Companyform extends Form
{
public function __construct()
{
// we want to ignore the name passed
parent::__construct('company');
$this->setAttribute ('method', 'post');
$this->setAttribute ('class', 'form-horizontal');
$this->add ( array (
'name' => 'parentID',
'type' => 'Zend\Form\Element\Select',
'attributes' => array(
'id' => 'parentID',
'type' => 'select',
'placeholder' => "Parent Company",
),
'options' => array(
'label' => 'Parent Company'
)
));
$this->add(array(
'name' => 'btnsubmit',
'attributes' => array(
'id' => 'btnsubmit',
'type' => 'submit',
'value' => 'Add',
'class' => 'btn btn-primary'
),
));
}
}
controller
public function addAction()
{
$request = $this->getRequest();
$companyList = $this->_getCompanyList();
$form = new Companyform();
$form->get('parentID')->setAttribute('options',$companyList);
if ($request->isPost())
{
$company = new Company();
$form->setInputFilter($company->getInputFilter());
$form->setData($request->getPost());
if ($form->isvalid())
{
}
}
}
public function _getCompanyList()
{
$companies = $this->Em()->getEntityManager()->getRepository('XXXX\Entity\Company')->findBy(array('isDeleted'=>'0'));
$companyIDList = array();
$companyIDList[0] = "No Parent";
foreach ($companies as $company)
{
$companyIDList[$company->id] = $company->companyName;
}
return $companyIDList;
}
Entity class
protected $inputFilter;
public function setInputFilter(InputFilterInterface $inputFilter)
{
throw new \Exception("Not used");
}
public function getInputFilter()
{
if (!$this->inputFilter) {
$inputFilter = new InputFilter();
$factory = new InputFactory();
$inputFilter->add($factory->createInput(array(
'name' => 'companyName',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 2,
'max' => 255,
),
),
),
)));
$this->inputFilter = $inputFilter;
}
return $this->inputFilter;
}
You may need to add following library in entity
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;
In ZendFramework 2, when you creating a (add) element from your Form file, Check the attribute: inarrayvalidator is true.
$this->add(array(
'name' => 'select_name',
'type' => 'select',
'id' => 'select_name',
'options' => array(
'label' => 'Select Name',
),
'attributes' => array(
'id' => 'select_id',
'inarrayvalidator' => true,
),
));
I hope, this works...
What I am trying to do is create a selectlist using the form API, where a user can select rows and press a delete button that deletes the selected rows from the database and reloads the table with a conformation that those selected had been deleted. With my current code, when I hit the delete button I get this error:
Warning: Invalid argument supplied for foreach() in form_execute_handlers() (line 1431 of C:\xampp\htdocs\amaware\includes\form.inc).
Here is the code:
/**
* Implements hook_menu().
*/
function smsfeed_menu() {
$items = array();
$items['admin/config/content/smsfeed'] = array(
'title' => 'SMS Messages and Newsletters',
'description' => 'Edit the Setting for the SMS Feed and Newsletter',
'page callback' => 'drupal_get_form',
'page arguments' => array('smsfeed_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/config/content/smsfeed/settings'] = array(
'title' => 'Settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 1,
);
$items['admin/config/content/smsfeed/newsletter'] = array(
'title' => 'Newsletter',
'page callback' => 'drupal_get_form',
'page arguments' => array('newsletter_table_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_LOCAL_TASK,
'weigth' => 2,
);
$items['admin/config/content/smsfeed/feed'] = array(
'title' => 'SMS Feed',
'page callback' => 'drupal_get_form',
'page arguments' => array('feed_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
$items['admin/config/content/smsfeed/questions'] = array(
'title' => 'Questions',
'page callback' => 'drupal_get_form',
'page arguments' => array('questions_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_LOCAL_TASK,
'weigth' => 4,
);
return $items;
}
/**
* Page callback: SMS Settings
*
* #see smsfeed_menu()
*/
function smsfeed_form($form, &$form_state) {
$form['response_time'] = array(
'#type' => 'textfield',
'#title' => t('Response Time (In Days)'),
'#default_value' => variable_get('response_time', 3),
'#size' => 2,
'#maxlength' => 2,
'#description' => t('The response time, in days, that users should expect.'),
);
$form['feed_keyword'] = array(
'#type' => 'textfield',
'#title' => t('Feed Keyword'),
'#default_value' => variable_get('feed_keyword', 'FEED'),
'#size' => 10,
'#maxlength' => 10,
'#description' => t('The keyword users should text to have their message moderated and added to the website feed.'),
);
$form['join_keyword'] = array(
'#type' => 'textfield',
'#title' => t('Join Keyword'),
'#default_value' => variable_get('join_keyword', 'JOIN'),
'#size' => 10,
'#maxlength' => 10,
'#description' => t('The keyword users should text to be added to the newsletter list.'),
);
$form['quit_keyword'] = array(
'#type' => 'textfield',
'#title' => t('Quite Keyword'),
'#default_value' => variable_get('quit_keyword', 'QUIT'),
'#size' => 10,
'#maxlength' => 10,
'#description' => t('The keyword users should text to be removed from the newsletter list.'),
);
return system_settings_form($form);
}
/**
* Page Callback Newsletter
*/
function newsletter_table_form($form, $form_state) {
$rows = array();
$header = array(t('User Name'), t('User Number'), t('User E-mail'),);
$query = db_select('sms_newsletter');
$query->fields('sms_newsletter', array('name', 'number', 'email',))
->orderBy('name', 'ASC');
$results = $query->execute();
foreach ($results as $line) {
$rows[] = array(
$line->name,
$line->number,
$line->email,
);
}
$form['table'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $rows,
'#empty' => t('No users found'),
);
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delect Selected'),
'#submit' => 'newsletter_table_form_delete'
);
return $form;
}
function newsletter_table_form_delete ($form, &$form_state) {
foreach ($form_state['values']['collections'] as $key => $value) {
if ($value) {
$delete = db_delete('sms_newsletter')
-> execute();
}
}
}
Any help is deeply appreciated.
EDIT:
I've edited my news_letter_table_form to read:
function newsletter_table_form_delete ($form, $form_state) {
foreach (($form_state['values']['table']) as $rows) {
//$delete = db_delete('sms_newsletter')
//-> execute();
drupal_set_message ('' . $rows . '');
//drupal_set_message ('' . $form_state['values']['table'] . '');
}
}
And the new output leaves me puzzled as to how I'd identify selected rows, and delete them from the database. Using the above newsletter_table_form_delete I get the following output:
If I select the top row nothing happens
If I select the second row the output is 1
If I select the third row the output is 2 and so on
If I select multiple rows the output is an unordered html list of the selected rows.
I'm curious now how I could take what I have now and change it so I can delete selected rows from the database.
Thanks again!
Try changing
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delect Selected'),
'#submit' => 'newsletter_table_form_delete'
);
to
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delect Selected'),
'#submit' => array('newsletter_table_form_delete') // <-- make this an array
);
Based on the additional info added in your question edit, I noticed that your tableselect is built without specifying array keys like:
foreach ($results as $line) {
$rows[] = array( // <-- No array keys specified here
$line->name,
$line->number,
$line->email,
);
}
Since there were no keys specified, the default by PHP is a 0-based index. That is why you are getting no results for the top row, 1 for the second row, and so on.
See the documentation for the tableselect element for an example.
I don't know what your database table structure looks like but you will probably need to query the Primary Key for the table and include it as array keys to your $rows array. That way, when you process the data in your delete function, you have the Primary Key of the row you want to delete and delete it.
For me this wasn't clear straight away so.
I would just like to add that in the end what nmc was saying is you should construct your rows like this, where you add a key to row.
foreach ($results as $line) {
$rows[$line->name] = array(
$line->name,
$line->number,
$line->email,
);