Get instructions css from php

0

Look, it's that in a BD the classes that are used to style a nav a color are already set. Good but I'm going to show you everything for photos.

In that image you see the names of the classes depending on which navigation bar it is. and the following css apply:

.blue-seadog {
    background-color: #00AEEF;
}

.teal {
    background-color: #009688 !important;
}

.amber.darken-1 {
    background-color: #ffb300 !important;
}

.green {
    background-color: #4CAF50 !important;
}

.red {
    background-color: #F44336 !important;
}

And everything up there very well, what I need is the following: get those color codes from a cakephp driver, since I need them for the following:

$worksheet->getStyle('H'.$i)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('FFFF0000');

In that line I give a color to an excel cell, and depending on whether the data is of a certain state, it must have the same color as the navigation bar of that state.

For example when we are in the asset view then the navigation bar is green, and in the excel the active users should be green.

    
asked by Andrés Vélez 05.07.2018 в 21:23
source

1 answer

0
{
    "require": {
        "sabberworm/php-css-parser": "*"
    }
} 

That in the composer.json

Then you open the terminal and you give composer update and you're done, you go back to the project

in the controller you do this:

use Sabberworm\CSS\Parser;
use Sabberworm\CSS\OutputFormat;

create a function if you want

 public function crearClaveValor($arreglo)
        {
            $estilos[]="";
            foreach ($arreglo as $valor) {
                $pos = (strpos($valor, "{"));
                $clases = substr($valor, 0, $pos);
                $clases = trim($clases);
                $valor = str_replace("{", "", $valor);
                $estilos[$clases] = str_replace($clases, "", $valor);
            }
            return $estilos;
        }

You save the styles in an arrangement

 $oCssParser = new Parser(file_get_contents(WWW_ROOT . 'css' . DS . 'mdb.css'));
        $oCssDocument = $oCssParser->parse();
        $estilos = explode("}", $oCssDocument->render(OutputFormat::createPretty()));
        $estilos = $this->crearClaveValor($estilos);

If you print $estilos with pr($estilos); you would see it like this:

And now you just have to look for the colors like this:

$color = ".".$estado->color; //aquí obtienes la clase
                $matches = []; 
                preg_match ('/#[0-9|A|a|B|b|C|c|D|d|E|e|F|f]+/' , $estilos[$color], $matches); //buscar el color
                $color = ($matches[0]); //guardas el color
                $color = str_replace("#", "", $color);
                $worksheet->getStyle('H'.$i)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB($color);

and as proof here I show you what it would look like

with the help of @KacosPro

    
answered by 06.07.2018 в 01:07