1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace WebserviceBundle\Services;
- class Webservice
- {
- protected $serviceContainer;
-
- public function __construct($serviceContainer)
- {
- $this->serviceContainer = $serviceContainer;
- }
- /**
- * @param string $webservice
- * @param array $params
- * @return array
- */
- public function getChoices($webservice, $params = array())
- {
- $choices = array();
- $objectsJson = $this->getArray($webservice, $params);
- foreach ($objectsJson as $object) {
- $choices[$object['name']] = $object['id'];
- }
- return $choices;
- }
-
- /**
- * @param string $webservice
- * @param array $params
- * @return array
- */
- public function getArray($webservice, $params = array())
- {
- $objectsJson = array();
- if ($this->serviceContainer->hasParameter($webservice)) {
- $url = $this->serviceContainer->getParameter($webservice);
- $url .= '?filters[qb-criteria]';
- foreach ($params as $param => $value) {
- $url .= "&filters[{$param}]=$value";
- }
- $objectsJson = json_decode(file_get_contents($url), true);
- }
-
- return $objectsJson;
- }
- /**
- * @param string $webservice
- * @param array $filters
- * @param array $order_by
- * @param integer $limit
- * @param integer $offset
- * @return array
- */
- public function getData($webservice, $filters = array(), $order_by = array(), $limit = null, $offset = null)
- {
- if ($this->serviceContainer->hasParameter($webservice)) {
- $url = $this->serviceContainer->getParameter($webservice) . "?";
-
- if($filters) {
- $url .= http_build_query(array('filters' => $filters));
- }
-
- if($order_by) {
- $url .= http_build_query(array('order_by' => $order_by));
- }
-
- if($limit) {
- $url .= "&limit={$limit}";
- }
-
- if($offset) {
- $url .= "&offset={$offset}";
- }
- $data = json_decode(file_get_contents($url), true);
- //$data['url'] = $url;
- return $data;
- }
- return array();
- }
- }
|