|
@@ -0,0 +1,77 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace FTTHBundle\Service;
|
|
|
+
|
|
|
+use Exception;
|
|
|
+use FTTHBundle\Entity\ONU;
|
|
|
+use FTTHBundle\Factory\ExceptionFactory;
|
|
|
+use FTTHBundle\Utils\ClientStateEnum;
|
|
|
+use FTTHBundle\Utils\ONUStateEnum;
|
|
|
+use WebserviceBundle\Services\Webservice;
|
|
|
+use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
+
|
|
|
+class ClientService
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * @var Webservice
|
|
|
+ */
|
|
|
+ protected $webservice;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var ContainerInterface
|
|
|
+ */
|
|
|
+ protected $serviceContainer;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param Webservice $webservice
|
|
|
+ * @param ContainerInterface $serviceContainer
|
|
|
+ */
|
|
|
+ public function __construct(Webservice $webservice, ContainerInterface $serviceContainer)
|
|
|
+ {
|
|
|
+ $this->webservice = $webservice;
|
|
|
+ $this->serviceContainer = $serviceContainer;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $id int
|
|
|
+ * @return Client || Exception
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public function getById($id){
|
|
|
+ try{
|
|
|
+ $this->checkContainerParameter();
|
|
|
+ $filters = array("qb-ids" => $id, 'qb-criteria' => true);
|
|
|
+ return $this->webservice->getData($this->serviceContainer->getParameter('client'), $filters)[0];
|
|
|
+ }catch (Exception $ex){
|
|
|
+ ExceptionFactory::make($ex->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param ONU $onu
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public function setStateOnu(ONU $onu){
|
|
|
+ try{
|
|
|
+ $clientEnums = new ClientStateEnum();
|
|
|
+ $client = $this->getById($onu->getClientId());
|
|
|
+ if(!is_null($client) && $clientEnums->containsStatesDisabled($client['currentState'])){
|
|
|
+ ExceptionFactory::make("Not is possible use client with current state 'cancelled' or 'deleted'");
|
|
|
+ }
|
|
|
+ $onu->setCurrentState(ONUStateEnum::ACTIVE);
|
|
|
+ }catch (Exception $ex){
|
|
|
+ ExceptionFactory::make($ex->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private function checkContainerParameter(){
|
|
|
+ if(!$this->serviceContainer->hasParameter('client')){
|
|
|
+ ExceptionFactory::make("Don't exists parameters 'client' to search the webservice");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|