Example #1
0
 /**
  * Processa parâmetros da coleta de software
  *
  * @param $strNewClassValues
  * @param $arrCollectsDefClasses
  * @param $strCollectType
  * @param $strClassName
  */
 public function coletaSoftware($strNewClassValues, $arrCollectsDefClasses, $strCollectType, $strClassName, $computador)
 {
     $logger = $this->get('logger');
     // Primeiro preciso pegar todas as tags que forem software
     $arrSoftware = TagValueHelper::getSoftwareTags($strNewClassValues);
     // Agora insere cada registro de software individualmente
     foreach ($arrSoftware as $software) {
         // Armazeno todas as propriedades dessa classe enviadas pela requisição
         $arrTags = TagValueHelper::getTagsFromValues($software);
         // Crio um array multidimensional com as tags e os valores
         foreach ($arrTags as $tagNames) {
             // Essa função garante que só serão retornados caracteres com UTF8 Válido
             $texto = TagValueHelper::UTF8Sanitize(TagValueHelper::getValueFromTags($tagNames, $software));
             $arrTagsNames[$tagNames] = $texto;
         }
         // Para software, cada identificador será uma propriedade
         $softwareName = $arrTagsNames['IDSoftware'];
         // Remove o IDSoftware do array
         unset($arrTagsNames['IDSoftware']);
         // Armazeno o IDSoftware como Propriedade
         $idClassProperty = $arrCollectsDefClasses[$strCollectType][$strClassName][$softwareName]['idClassProperty'];
         // Se o IDSoftware não existir, cria
         if (empty($idClassProperty)) {
             $logger->debug("Software {$softwareName} não encontrado. Adicionando um novo software");
             // Pega o Id da classe
             $idClass = $this->getDoctrine()->getRepository('CacicCommonBundle:Classe')->findOneBy(array('nmClassName' => $strClassName));
             $property = new ClassProperty();
             $property->setNmPropertyName($softwareName);
             $property->setTePropertyDescription($arrTagsNames['DisplayName']);
             // Referência à classe
             $property->setIdClass($idClass);
             // Grava a propriedade nova
             $this->getDoctrine()->getManager()->persist($property);
             $this->getDoctrine()->getManager()->flush();
             // Retorna o novo ID
             $idClassProperty = $property->getIdClassProperty();
         }
         // Chama função que grava a propriedade
         $this->gerColsSetProperty('IDSoftware', $software, $idClassProperty, $computador);
         // Agora gravo todas as propriedades para o software na tabela propriedade_software
         $propriedadeSoftware = $this->getDoctrine()->getRepository('CacicCommonBundle:PropriedadeSoftware')->findOneBy(array('classProperty' => $idClassProperty, 'computador' => $computador));
         $classPropertyObject = $this->getDoctrine()->getRepository('CacicCommonBundle:ClassProperty')->findOneBy(array('idClassProperty' => $idClassProperty));
         if (empty($propriedadeSoftware)) {
             // Se não tiver nome coloco o ID Software no nome
             if (empty($arrTagsNames['DisplayName'])) {
                 $nmSoftware = $softwareName;
             } else {
                 $nmSoftware = $arrTagsNames['DisplayName'];
             }
             $softwareObject = $this->getDoctrine()->getRepository('CacicCommonBundle:Software')->findOneBy(array('nmSoftware' => $nmSoftware));
             if (empty($softwareObject)) {
                 $softwareObject = new Software();
                 // Se não tiver nome coloco o ID Software no nome
                 if (empty($arrTagsNames['DisplayName'])) {
                     $softwareObject->setNmSoftware($softwareName);
                 } else {
                     $softwareObject->setNmSoftware($arrTagsNames['DisplayName']);
                 }
                 // Grava software recém inserido
                 $this->getDoctrine()->getManager()->persist($softwareObject);
                 $this->getDoctrine()->getManager()->flush();
             }
             // Depois adiciono as propriedades
             $propriedadeSoftware = new PropriedadeSoftware();
             $propriedadeSoftware->setClassProperty($classPropertyObject);
             $propriedadeSoftware->setComputador($computador);
             // Ajusta valores coletados
             $propriedadeSoftware->setDisplayName($arrTagsNames['DisplayName']);
             $propriedadeSoftware->setDisplayVersion($arrTagsNames['DisplayVersion']);
             $propriedadeSoftware->setURLInfoAbout($arrTagsNames['URLInfoAbout']);
             $propriedadeSoftware->setSoftware($softwareObject);
             // Grava no banco de dados
             $this->getDoctrine()->getManager()->persist($propriedadeSoftware);
             $this->getDoctrine()->getManager()->flush();
         } else {
             // Se não tiver nome coloco o ID Software no nome
             if (empty($arrTagsNames['DisplayName'])) {
                 $nmSoftware = $softwareName;
             } else {
                 $nmSoftware = $arrTagsNames['DisplayName'];
             }
             // Adiciona referência à tabela de softwares
             $softwareObject = $this->getDoctrine()->getRepository('CacicCommonBundle:Software')->findOneBy(array('nmSoftware' => $nmSoftware));
             if (empty($softwareObject)) {
                 $softwareObject = new Software();
                 // Se não tiver nome coloco o ID Software no nome
                 if (empty($arrTagsNames['DisplayName'])) {
                     $softwareObject->setNmSoftware($softwareName);
                 } else {
                     $softwareObject->setNmSoftware($arrTagsNames['DisplayName']);
                 }
                 // Grava software recém inserido
                 $this->getDoctrine()->getManager()->persist($softwareObject);
                 $this->getDoctrine()->getManager()->flush();
             }
             // Ajusta valores coletados
             $propriedadeSoftware->setDisplayName($arrTagsNames['DisplayName']);
             $propriedadeSoftware->setDisplayVersion($arrTagsNames['DisplayVersion']);
             $propriedadeSoftware->setURLInfoAbout($arrTagsNames['URLInfoAbout']);
             $propriedadeSoftware->setSoftware($softwareObject);
             // Salva valor da coleta
             $this->getDoctrine()->getManager()->persist($propriedadeSoftware);
             $this->getDoctrine()->getManager()->flush();
         }
     }
 }