<?php
/**
 * This is the model class for table "vehiclecolor".
 *
 * The followings are the available columns in table 'vehiclecolor':
 * @property string $ID
 * @property string $epoch
 * @property integer $computed
 * @property string $c01
 * @property string $c02
 * @property string $c03
 * @property string $c04
 * @property string $c05
 * @property string $c06
 * @property string $c07
 * @property string $c08
 * @property string $c09
 * @property string $c10
 * @property string $c11
 * @property string $c12
 * @property string $c13
 * @property string $c14
 * @property string $c15
 * @property string $c16
 * @property string $c17
 * @property double $scw01
 * @property double $scw02
 * @property double $scw03
 * @property double $scw04
 * @property double $scw05
 * @property double $scw06
 * @property double $scw07
 * @property double $scw08
 */
class VehicleColor extends ActiveRecord
{

  public static function model($className=__CLASS__)
  {
    return parent::model($className);
  }

  public function getColorArray()
  {
    return $this->attributes;
  }

  public function tableName()
  {
    return 'vehiclecolor';
  }

  public function getColorsArray($limit = null)
  {
    if(!$this->computed)
      return null;

    //formato HHLLSS

    $color = ColorHelper::formatHTML($this->c01);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c02);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c03);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c04);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c05);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c06);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c07);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c08);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c09);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c10);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c11);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c12);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c13);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c14);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c15);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c16);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];

    $color = ColorHelper::formatHTML($this->c17);
    $colorArray[] = $color['code'];
    $colorW[] = $color['weight'];


    array_multisort($colorW, SORT_DESC, $colorArray);
    if (isset($limit) && $limit < count($colorArray))
      $colorArray = array_slice($colorArray, 0, $limit);

    return $colorArray;
  }

}
