/**
 * Smarty modifier
 * -------------------------------------------------------------
 * Name:     smarty_modifier_oxformdate<br>
 * Purpose:  Conterts date/timestamp/datetime type value to user defined format
 * Example:  {$object|oxformdate:"foo"}
 * -------------------------------------------------------------
 *
 * @param object $oConvObject   oxField object
 * @param string $sFieldType    additional type if field (this may help to force formatting)
 * @param bool   $blPassedValue bool if true, will simulate object as sometimes we need to apply formatting to some regulat values
 *
 * @return string
 */
function smarty_modifier_oxformdate($oConvObject, $sFieldType = null, $blPassedValue = false)
{
    // creating fake bject
    if ($blPassedValue || is_string($oConvObject)) {
        $sValue = $oConvObject;
        $oConvObject = new oxField();
        $oConvObject->fldmax_length = "0";
        $oConvObject->fldtype = $sFieldType;
        $oConvObject->setValue($sValue);
    }
    $myConfig = oxConfig::getInstance();
    // if such format applies to this type of field - sets formatted value to passed object
    if (!$myConfig->getConfigParam('blSkipFormatConversion')) {
        if ($oConvObject->fldtype == "datetime" || $sFieldType == "datetime") {
            oxDb::getInstance()->convertDBDateTime($oConvObject);
        } elseif ($oConvObject->fldtype == "timestamp" || $sFieldType == "timestamp") {
            oxDb::getInstance()->convertDBTimestamp($oConvObject);
        } elseif ($oConvObject->fldtype == "date" || $sFieldType == "date") {
            oxDb::getInstance()->convertDBDate($oConvObject);
        }
    }
    return $oConvObject->value;
}
 /**
  * Converter for datetime field search. If not full time will be searched.
  *
  * @param string $sFullDate searched date
  *
  * @return string
  */
 protected function _convertTime($sFullDate)
 {
     $sDate = substr($sFullDate, 0, 10);
     $oConvObject = new oxField();
     $oConvObject->setValue($sDate);
     oxDb::getInstance()->convertDBDate($oConvObject, true);
     $oStr = getStr();
     // looking for time field
     $sTime = substr($sFullDate, 11);
     if ($oStr->preg_match("/([0-9]{2}):([0-9]{2}) ([AP]{1}[M]{1})\$/", $sTime, $aTimeMatches)) {
         if ($aTimeMatches[3] == "PM") {
             $iIntVal = (int) $aTimeMatches[1];
             if ($iIntVal < 13) {
                 $sTime = $iIntVal + 12 . ":" . $aTimeMatches[2];
             }
         } else {
             $sTime = $aTimeMatches[1] . ":" . $aTimeMatches[2];
         }
     } elseif ($oStr->preg_match("/([0-9]{2}) ([AP]{1}[M]{1})\$/", $sTime, $aTimeMatches)) {
         if ($aTimeMatches[2] == "PM") {
             $iIntVal = (int) $aTimeMatches[1];
             if ($iIntVal < 13) {
                 $sTime = $iIntVal + 12;
             }
         } else {
             $sTime = $aTimeMatches[1];
         }
     } else {
         $sTime = str_replace(".", ":", $sTime);
     }
     return $oConvObject->value . " " . $sTime;
 }
Beispiel #3
0
 /**
  * Get article long description
  *
  * @return object $oField field object
  */
 public function getLongDescription()
 {
     if ($this->_oLongDesc === null) {
         // initializing
         $this->_oLongDesc = new oxField();
         // choosing which to get..
         $sOxid = $this->getId();
         $sViewName = getViewName('oxartextends', $this->getLanguage());
         $oDb = oxDb::getDb();
         $sDbValue = $oDb->getOne("select oxlongdesc from {$sViewName} where oxid = " . $oDb->quote($sOxid));
         if ($sDbValue != false) {
             $this->_oLongDesc->setValue($sDbValue, oxField::T_RAW);
         } elseif ($this->oxarticles__oxparentid->value) {
             if (!$this->isAdmin() || $this->_blLoadParentData) {
                 $oParent = $this->getParentArticle();
                 if ($oParent) {
                     $this->_oLongDesc->setValue($oParent->getLongDescription()->getRawValue(), oxField::T_RAW);
                 }
             }
         }
     }
     return $this->_oLongDesc;
 }
Beispiel #4
0
 public function testOxFieldConvertToPseudoHtml()
 {
     $oField = new oxField("a&g<e>n\"t'ūrų Литовские für\r\n");
     $oField->convertToPseudoHtml();
     $this->assertEquals("a&amp;g&lt;e&gt;n&quot;t&#039;ūrų Литовские für<br />\n", $oField->getRawValue());
 }
 /**
  * returns quoted field value for using in update statement
  *
  * @param string  $sFieldName name of field
  * @param oxField $oField     field object
  *
  * @return string
  */
 protected function _getUpdateFieldValue($sFieldName, $oField)
 {
     $mValue = null;
     if ($oField instanceof oxField) {
         $mValue = $oField->getRawValue();
     } elseif (isset($oField->value)) {
         $mValue = $oField->value;
     }
     // Sarunas. check if this field value is null AND it can be null according to table description
     if (null === $mValue && $this->_canFieldBeNull($sFieldName)) {
         return 'null';
     }
     return oxDb::getDb()->quote($mValue);
 }
Beispiel #6
0
 /**
  * returns quoted field value for using in update statement
  *
  * @param string  $sFieldName name of field
  * @param oxField $oField     field object
  *
  * @return string
  */
 protected function _getUpdateFieldValue($sFieldName, $oField)
 {
     $mValue = null;
     if ($oField instanceof oxField) {
         $mValue = $oField->getRawValue();
     } elseif (isset($oField->value)) {
         $mValue = $oField->value;
     }
     $oDb = oxDb::getDb();
     //Check if this field value is null AND it can be null according if not returning default value
     if (null === $mValue) {
         if ($this->_canFieldBeNull($sFieldName)) {
             return 'null';
         } elseif ($mValue = $this->_getFieldDefaultValue($sFieldName)) {
             return $oDb->quote($mValue);
         }
     }
     return $oDb->quote($mValue);
 }
Beispiel #7
0
 public function testGetRawValueIfSetAsRaw()
 {
     $oField = new oxField();
     $oField->setValue("ssss<\n>", oxField::T_RAW);
     $this->assertEquals("ssss<\n>", $oField->value);
     $this->assertEquals("ssss<\n>", $oField->getRawValue());
 }