Code readed by Symfony differently in Controller and Command - php

I'm working on a Symfony2 project to put Google Analytics in a database. User will fills a form with the date and checks the datas he want to collect. When he clicks on "Submit", it call a gaController which call a command.
protected function configure()
{
$this->setName ( 'GA2' )
->addArgument ( 'startDate', InputArgument::REQUIRED, 'Start date (format: YYYY-MM-DD)' )
->addArgument ( 'endDate', InputArgument::REQUIRED, 'End date (format: YYYY-MM-DD)' )
->addArgument ( 'metrics', InputArgument::REQUIRED, 'Metrics (format: metric,metric2,...,metricN')
->addArgument ( 'dimensions', InputArgument::OPTIONAL, 'Dimensions (format: dimension1,dimension2,...,dimensionN');
}
The problem is, metrics and dimensions are read by my Controller as Array, and the Command-Line as String ! Exemple :
Controller read :
array (size=4)
0 => string 'ga:users' (length=8)
1 => string 'ga:newUsers' (length=11)
2 => string 'ga:sessionsPerUser' (length=18)
3 => string 'ga:percentNewVisits' (length=19)
array (size=3)
0 => string 'ga:sessionCount' (length=15)
1 => string 'ga:daysSinceLastSession' (length)
2 => string 'ga:userDefinedValue' (length=19)
Command-Line read :
String(59) "ga:users,ga:newUsers,ga:sessionsPerUser"
String(59) "ga:sessionCount,ga:daysSinceLastSession,ga:userDefinedValue"
But I'm using implode/explode to get an array/string. I need the Command-Line to put it in Windows Scheduler.
Thanks for your help.

Related

How to extends properly Cms Page and Block WebAPI

I would like to extends/override the APIs of CMS Pages and Blocks to add custom fields (for example, an array of store_ids to allow the creation of a CMS block on different stores with an webapi call, it's my main goal).
I tried many things, but this does not seem clean, standards-compliant. I have the impression of overloading the whole module CMS (data interface, repository interface, model, repository factory, etc..) just for adding new fields in webapi.
I will explain what I have done for now :
1/ I wrote an new data api \BlockInterface who extends the core interface to add my new field (store_id) and declare his getter and setter methods.
namespace Reflet\CmsExtension\Api\Data;
interface BlockInterface extends \Magento\Cms\Api\Data\BlockInterface
{
/**
* New fields
*/
const STORE_ID = 'store_id';
/**
* Get Store Ids
*
* #return array
*/
public function getStoreId();
/**
* Set Store Ids
*
* #param array $storeIds
* #return \Reflet\CmsExtension\Api\Data\BlockInterface
*/
public function setStoreId($storeIds);
}
2/ I implements the Data Interface in the new \Block model object.
3/ With many in the di.xml file, I override the block model type.
4/ I reimplement the api \BlockRepositoryInterface and the webapi.xml file to change the data type used in the repository.
5/ I testing the getById() and the save() methods for the block #1 with simple repository call and webapi.
Here, is my result :
1/ If, I get the block #1 with the repository, the store_id is load in the result object.
array (size=12)
'row_id' => string '1' (length=1)
'block_id' => string '1' (length=1)
'created_in' => string '1' (length=1)
'updated_in' => string '2147483647' (length=10)
'title' => string 'Catalog Events Lister' (length=21)
'identifier' => string 'catalog_events_lister' (length=21)
'content' => string '{{block class="Magento\\CatalogEvent\\Block\\Event\\Lister" name="catalog.event.lister" template="lister.phtml"}}' (length=113)
'creation_time' => string '2017-02-14 14:33:20' (length=19)
'update_time' => string '2017-02-14 14:33:20' (length=19)
'is_active' => string '1' (length=1)
'store_id' =>
array (size=1)
0 => string '0' (length=1)
'stores' =>
array (size=1)
0 => string '0' (length=1)
2/ If, I get the block #1 with the WebAPI, the store_id is also load in the result object.
public 'store_id' =>
array (size=1)
0 => string '0' (length=1)
public 'id' => int 1
public 'identifier' => string 'catalog_events_lister' (length=21)
public 'title' => string 'Catalog Events Lister' (length=21)
public 'content' => string '{{block class="Magento\\CatalogEvent\\Block\\Event\\Lister" name="catalog.event.lister" template="lister.phtml"}}' (length=113)
public 'creation_time' => string '2017-02-14 14:33:20' (length=19)
public 'update_time' => string '2017-02-14 14:33:20' (length=19)
public 'active' => boolean true
3/ If, I save the block #1 with the WebAPI, an error occurs, he load the wrong BlockInterface. I need to reimplement the BlockRepository ? I don't think it's the good and cleaner method (...) ?
public 'message' => string 'Property "StoreId" does not have corresponding setter in class "Magento\Cms\Api\Data\BlockInterface".' (length=101)
public 'trace' => string '#0 /var/www/vhosts/reflet.com/storemanager/vendor/magento/framework/Reflection/NameFinder.php(59): Magento\Framework\Reflection\NameFinder->findAccessorMethodName(Object(Zend\Code\Reflection\ClassReflection), 'StoreId', 'getStoreId', 'isStoreId')
#1 /var/www/vhosts/reflet.com/storemanager/vendor/magento/framework/Webapi/ServiceInputProcessor.php(158): Magento\Framework\Reflection\NameFinder->getGetterMethodName(Object(Zend\Code\Reflection\ClassReflection), 'StoreId')
#2 /var/www/vhosts/reflet.com/storemanag'... (length=2239)
For this example, I use the 'store_id' only, but in the future, it's must be works with all custom fields in Page or Block object.
How do you recommend this modification to be as clean as possible and limit conflicts in the future ? Do you have an example ?
If you want to test, you can find in this archive, my two current Magento modules (Reflet_Api an simple adapter to call REST WebApi and Reflet_CmsExtension to override CMS Blocks) : https://drive.google.com/file/d/0B12trf96j0ALSjhZdmJPTzBPT0U/view
Thank you for your answers.
Best regards.
Jonathan

laravel: Undefined property: stdClass::$game

i am trying to get some values out of an Std Object in Laravel.
I can get anything out, with no problem, but not the last one
my object looks like this (var_dump())
object(stdClass)[208]
public 'id' => int 2
public 'vorname' => string 'Thomas' (length=5)
public 'nachname' => string 'Kemmet' (length=5)
public 'geburtstag' => string '1988-05-05' (length=10)
public 'verein_id' => int 1
public 'verein_name' => string 'Kolandorf' (length=20)
public 'game' => string '2016-10-28' (length=10)
when i do
echo $spieler->id;
i get the id. But when i try
echo $spieler->game;
i get an error with Undefined property: stdClass::$game
why is it like this? and how to get the last value...
Make sure that the game field is a string in the database you retrieve it from.
Try changing the order of the fields in order to see if its always the last one which has the problem.

How to integrate square with Laravel

I have an app in Laravel and I am following this tutorial. I cloned a sample repo from here and When I try to make a pyament form this, it gives me the following response
Caught exception!
Response body:
object(stdClass)[6]
public 'errors' =>
array (size=1)
0 =>
object(stdClass)[7]
public 'category' => string 'INVALID_REQUEST_ERROR' (length=21)
public 'code' => string 'VALUE_TOO_LOW' (length=13)
public 'detail' => string '`amount_money.amount` must be greater than 100.' (length=47)
public 'field' => string 'amount_money.amount' (length=19)
Response headers:
array (size=12)
0 => string 'HTTP/1.1 400 Bad Request' (length=24)
'Content-Type' => string 'application/json' (length=16)
'Vary' => string 'Origin, Accept-Encoding' (length=23)
'X-Content-Type-Options' => string 'nosniff' (length=7)
'X-Download-Options' => string 'noopen' (length=6)
'X-Frame-Options' => string 'SAMEORIGIN' (length=10)
'X-Permitted-Cross-Domain-Policies' => string 'none' (length=4)
'X-Xss-Protection' => string '1; mode=block' (length=13)
'Date' => string 'Sat, 29 Oct 2016 08:23:51 GMT' (length=29)
'Keep-Alive' => string 'timeout=60' (length=10)
'Strict-Transport-Security' => string 'max-age=631152000' (length=17)
'content-length' => string '161' (length=3)
It worked when i tried the sandbox.
How can I make square to charge any amount that is less than USD 100?
How can I validate the card i.e. in the form given in the github repo, they don't ask for card holder name?
How can I integrate other payment methods with square like cash or cheque?
It sounds like you are trying to make a web based point of sale. To answer your questions:
The minimum charge for Credit Cards, both in the Square Register app and the API is $1.00 (the 100 amount includes cents)
The cards are primarily validated with CVV and postal code, which you should see as required fields in the form.
At this time you cannot create payments for other tender types like cash or check through the API. (This is primarily because our transaction APIs are used for e-commerce exclusively, while custom point of sales are usually created with our Register APIs)

CakePHP- saving associated model data

I have two models .. One is called Schedule and the other ScheduleContact.
Schedule belongsTo ScheduleContact
From an action belonging to scheduleController, I want to save values coming from a serialized form for the main model as well as the associated model.
In my view I have the following
<?php echo $this->Form->input('Schedule.start_at', array('id' => 'start_at', 'type' => 'hidden')); ?>
<?php echo $this->Form->input('Schedule.finish_at', array('id' => 'finish_at', 'type' => 'hidden')); ?>
<?php echo $this->Form->input('ScheduleContact.0.name', array('id' => 'name','div' => 'inline-input')); ?>
<?php echo $this->Form->input('ScheduleContact.0.surname', array('id' => 'surname','div' => 'inline-input compact')); ?>
etc..
The request data comes in this form (from var_dump($this->request->data)):
array (size=3)
'Schedule' =>
array (size=3)
'start_at' => string '2014-3-25 11:15' (length=15)
'finish_at' => string '2014-03-25 11:30:00' (length=19)
'donation_method_id' => string '1' (length=1)
'ScheduleContact' =>
array (size=1)
0 =>
array (size=6)
'name' => string 'Jane' (length=4)
'surname' => string 'Powell' (length=6)
'address' => string 'Hamilton Hodell, 5th Floor 66-68 Margaret Street' length=39)
'city' => string 'London' (length=6)
'tel_no' => string '+44(0)20-7636 1221' (length=18)
'email' => string 'powell_jane#gmail.com' (length=22)
'log' =>
array (size=3)
'ds' => string 'default' (length=7)
'sql' => string 'SELECT `Schedule`.`id`, `Schedule`.`donation_method_id`, `Schedule`.`schedule_contact_id`, `Schedule`.`start_at`, `Schedule`.`finish_at`, `DonationMethod`.`id`, `DonationMethod`.`donation_method`, `DonationMethod`.`recovery_time`, `DonationMethod`.`duration`, `ScheduleContact`.`id`, `ScheduleContact`.`name`, `ScheduleContact`.`surname`, `ScheduleContact`.`address`, `ScheduleContact`.`city`, `ScheduleContact`.`tel_no`, `ScheduleContact`.`email`, `ScheduleContact`.`donor_id` FROM `blood_services_db`.`schedule'... (length=852)
'hash' => string '5f2b2b3a462f6555cb5290fb49c42df04a7948e0' (length=40)
Finally I am trying to save the data like so :
if($this->Schedule->saveAssociated($this->request->data)){
which is not saving anything to the database, therefore the this if condition is never met.
What could be wrong ? Thanks
Basically the problem was that saveAssociated needs to be applied in the main model. With that in mind, as it was set up above, the main model had a bolongsTo relationship, which means that the current model contains the foreign key., which is also indeed correct. So where is the problem you might ask?
The problem is that saveAsocciated is equivalent to
$user = $this->User->save($this->request->data);
// If the user was saved, Now we add this information to the data
// and save the Profile.
if (!empty($user)) {
// The ID of the newly created user has been set
// as $this->User->id.
$this->request->data['Profile']['user_id'] = $this->User->id;
}
Which means that it attempts to save the main model first. Therefore my setup was incorrect since the main model needed to be ScheduleContact, since the foreign key will be saved inside the Schedule model after data in ScheduleContact id successfully inserted.
There you go... CakePHP is Great once you get past that learning curve.
Your Model-Name is breaking Cake's naming convention. It should be:
ScheduleContact
A few questions to give you a better answer:
Can you add the Model Association Variables ($belongsTo, etc)?
Do you use Containable behaviour?

accessing google calendar data

I'm trying to get some basic event info from a public google calendar. In PHP it looks like this:
$xml = simplexml_load_file('http://www.google.com/calendar/feeds/[username]/public/basic?start-min=2014-01-01T00:00:00&start-max=2016-03-24T23:59:59');
var_dump($xml);
This brings back the XML data as expected, with the event data.
public 'id' => string 'http://www.google.com/calendar/feeds/[username]/public/basic/k524jsujs242bag0fsqfveiij8' (length=98)
public 'published' => string '2014-01-29T21:04:51.000Z' (length=24)
public 'updated' => string '2014-01-29T22:12:20.000Z' (length=24)
public 'category' =>
object(SimpleXMLElement)[1996]
public '#attributes' =>
array (size=2)
'scheme' => string 'http://schemas.google.com/g/2005#kind' (length=37)
'term' => string 'http://schemas.google.com/g/2005#event' (length=38)
public 'title' => string 'busy' (length=4)
public 'summary' => string 'When: Thu Jan 30, 2014 11am to 12pm PST<br>' (length=49)
My problem is that in the events, none of the Titles are populated-- they all simply show "busy", even though there is a valid title saved in the actual calendar event.
Anyone know how to get the actual event title?
Problem was that the calendar, while public, wasn't set in the Google Apps admin to share ALL event data.
See here for more info: https://productforums.google.com/forum/#!topic/calendar/-YcGbl1uw5Y

Categories