Commit 5147deb3 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Corrections suite à màj du web service Leocarte.

parent 2e8453fb
Loading
Loading
Loading
Loading
+7 −35
Original line number Diff line number Diff line
@@ -2,10 +2,10 @@

namespace UnicaenLeocarte\Service\Photo;

use UnicaenApp\Util;
use UnicaenLeocarte\Exception\NotFoundException;
use UnicaenLeocarte\Service\Soap\SoapClientAwareInterface;
use UnicaenLeocarte\Service\Soap\SoapClientAwareTrait;
use Zend\Stdlib\Exception\ExtensionNotLoadedException;

/**
 * Guichet pour les opérations concernant les photos.
@@ -16,7 +16,7 @@ class PhotoService implements SoapClientAwareInterface
{
    use SoapClientAwareTrait;

    const UTILISATION_PHOTO_AUTORISEE = 'Utilisation autorisée';
    const UTILISATION_PHOTO_AUTORISEE = 3;

    /**
     * @var array
@@ -43,9 +43,9 @@ class PhotoService implements SoapClientAwareInterface
            throw new NotFoundException("Aucun droit photo trouvé");
        }

        $string = $resource->data->value->stringValue;
        $value = $resource->value->integerValue;

        return $string === self::UTILISATION_PHOTO_AUTORISEE;
        return $value === self::UTILISATION_PHOTO_AUTORISEE;
    }

    /**
@@ -81,9 +81,9 @@ class PhotoService implements SoapClientAwareInterface
        }

        // c'est le contenu "binaire" de la photo qui est retourné par le WS
        $imgData = $resource->data->value->imageValue;
        $value = $resource->value->imageValue;

        return $imgData;
        return $value;
    }

    /**
@@ -155,38 +155,10 @@ class PhotoService implements SoapClientAwareInterface
     */
    private function _createImage($texte)
    {
        if (! extension_loaded('gd')) {
            throw new ExtensionNotLoadedException("L'extension PHP 'gd' doit être activée pour fabriquer l'image");
        }

        $width  = $this->generationPhotoNonAutoriseeConfig['width'];
        $height = $this->generationPhotoNonAutoriseeConfig['height'];

        $tmpImageFilePath = sys_get_temp_dir() . '/' . uniqid('unicaen-leocarte-') . '.png';

        // Create the image
        $img = imagecreatetruecolor($width, $height);

        // Create some colors
        $white = imagecolorallocate($img, 255, 255, 255);
        $grey = imagecolorallocate($img, 245, 245, 245);
        $black = imagecolorallocate($img, 0, 0, 0);
        imagefilledrectangle($img, 0, 0, $width - 1, $height - 1, $grey);

        // Add the text
        $text = utf8_decode($texte);
        $x = 10;
        $y = 20;
        foreach (explode('|', $text) as $part) {
            imagestring($img, 2, $x, $y, $part, $black);
            $y += 15;
        }

        // Using imagepng() results in clearer text compared with imagejpeg()
        imagepng($img, $tmpImageFilePath);
        imagedestroy($img);

        return file_get_contents($tmpImageFilePath);
        return Util::createImageWithText($texte, $width, $height);
    }

    /**