コード例 #1
0
ファイル: SMW_DV_Quantity.php プロジェクト: seedbank/old-repo
 protected function makeUserValue()
 {
     $printunit = false;
     // the normalised string of a known unit to use for printouts
     // Check if a known unit is given as outputformat:
     if ($this->m_outformat && $this->m_outformat != '-' && $this->m_outformat != '-n' && $this->m_outformat != '-u') {
         // first try given output unit
         $wantedunit = SMWNumberValue::normalizeUnit($this->m_outformat);
         if (array_key_exists($wantedunit, $this->m_unitids)) {
             $printunit = $wantedunit;
         }
     }
     // Alternatively, try to use the main display unit as a default:
     if ($printunit === false) {
         $this->initDisplayData();
         if (count($this->m_displayunits) > 0) {
             $printunit = reset($this->m_displayunits);
         }
     }
     // Finally, fall back to main unit:
     if ($printunit === false) {
         $printunit = $this->getUnit();
     }
     $this->m_unitin = $this->m_unitids[$printunit];
     $this->m_unitvalues = false;
     // this array depends on m_unitin if displayunits were used, better invalidate it here
     $value = $this->m_dataitem->getNumber() * $this->m_unitfactors[$this->m_unitin];
     $this->m_caption = '';
     if ($this->m_outformat != '-u') {
         // -u is the format for displaying the unit only
         $this->m_caption .= $this->m_outformat != '-' && $this->m_outformat != '-n' ? smwfNumberFormat($value) : $value;
     }
     if ($printunit !== '' && $this->m_outformat != '-n') {
         // -n is the format for displaying the number only
         if ($this->m_outformat != '-u') {
             $this->m_caption .= $this->m_outformat != '-' ? ' ' : ' ';
         }
         $this->m_caption .= $printunit;
     }
 }
コード例 #2
0
 protected function makeUserValue()
 {
     $value = false;
     if ($this->m_outformat && $this->m_outformat != '-' && $this->m_outformat != '-n' && $this->m_outformat != '-u') {
         // first try given output unit
         $printunit = SMWNumberValue::normalizeUnit($this->m_outformat);
         $this->m_unitin = $this->getUnitID($printunit);
         switch ($this->m_unitin) {
             case 'K':
                 $value = $this->m_dataitem->getNumber();
                 break;
             case '°C':
                 $value = $this->m_dataitem->getNumber() - 273.15;
                 break;
             case '°F':
                 $value = ($this->m_dataitem->getNumber() - 273.15) * 1.8 + 32;
                 break;
             case '°R':
                 $value = $this->m_dataitem->getNumber() * 1.8;
                 break;
                 // default: unit not supported
         }
     }
     if ($value === false) {
         // no valid output unit requested
         $value = $this->m_dataitem->getNumber();
         $this->m_unitin = 'K';
         $printunit = 'K';
     }
     $this->m_caption = '';
     if ($this->m_outformat != '-u') {
         // -u is the format for displaying the unit only
         $this->m_caption .= $this->m_outformat != '-' && $this->m_outformat != '-n' ? smwfNumberFormat($value) : $value;
     }
     if ($printunit !== '' && $this->m_outformat != '-n') {
         // -n is the format for displaying the number only
         if ($this->m_outformat != '-u') {
             $this->m_caption .= $this->m_outformat != '-' ? ' ' : ' ';
         }
         $this->m_caption .= $printunit;
     }
 }
コード例 #3
0
ファイル: SMW_DV_Number.php プロジェクト: Tjorriemorrie/app
 /**
  * This method is used when no user input was given to find the best
  * values for m_unitin and m_caption. After conversion,
  * these fields will look as if they were generated from user input,
  * and convertToMainUnit() will have been called (if not, it would be
  * blocked by the presence of m_unitin).
  *
  * Overwritten by subclasses that support units.
  */
 protected function makeUserValue()
 {
     $this->m_caption = '';
     if ($this->m_outformat != '-u') {
         // -u is the format for displaying the unit only
         $this->m_caption .= $this->m_outformat != '-' && $this->m_outformat != '-n' ? smwfNumberFormat($this->m_dataitem->getNumber()) : $this->m_dataitem->getNumber();
     }
     // no unit ever, so nothing to do about this
     $this->m_unitin = '';
 }