saglabā valūtas kursus DB
@param type $aRate
@param type $dDate
@return boolean
425345
private function _saveRate($aRate, $date, $source) {


        $base = $this->getSourceBaseCurrency($source);

        //for base currency rate always is 1
        $aRate[$base] = 1;
        /**
         * iet cauri kursiem un saglabā tos
         */
        foreach ($aRate as $fcrn_code => $rate) {
            $id = $this->getCurrencyIdByCode($fcrn_code);
            if (!$id) {
                $this->sError = false;
                /**
                 * valūta nav starp vajadzīgajām valūtam
                 */
                continue;
            }

            /**
             * vai tāds ieraksts jau nav tabulā
             */
            if ($this->_getRateFromDb($source, $base, $id, $date)) {
                continue;
            }

            $sql = "
                INSERT INTO fcrt_currency_rate (
                  fcrt_fcsr_id,
                  fcrt_base_fcrn_id,
                  fcrt_fcrn_id,
                  fcrt_date,
                  fcrt_rate
                ) 
                VALUES
                  (
                    :fcrt_fcsr_id,
                    :fcrt_base_fcrn_id,
                    :fcrt_fcrn_id,
                    :fcrt_date,
                    :fcrt_rate
                  )                
                ";

            $parameters = array(
                ':fcrt_fcsr_id' => $source,
                ':fcrt_base_fcrn_id' => $base, 
                ':fcrt_fcrn_id' => $id,
                ':fcrt_date' => $date,
                ':fcrt_rate' => $rate,
            );

            Yii::log("Save rates to db: ".  json_encode($parameters));
            Yii::app()->db->createCommand($sql)->execute($parameters);
        }
        return true;
    }
1232848
public function fetch($resultSet){
		$row = @sqlite_fetch_array($resultSet, SQLITE_ASSOC);
		if($row){
			$charset = $this->charset === null ? null : $this->charset . '//TRANSLIT';

			$fields = array();
			foreach($row as $key => $val){
				if($charset !== null && is_string($val))
					$val = iconv($this->dbcharset, $charset, $val);
				$key = str_replace(array('[', ']'), '', $key);
				$pos = strpos($key, '.');
				if($pos !== false)
					$key = substr($key, $pos + 1);
				$fields[$key] = $val;
			}
			$row = $fields;
		}
		return $row;
	}
940787
public static function put($arTags, $sKeys, &$arValue, $iMinute)
    {
        $obDate = Carbon::now()->addMinute($iMinute);

        $sCacheDriver = config('cache.default');
        if(!empty($arTags)) {
            if($sCacheDriver == 'redis') {
                Cache::tags($arTags)->put($sKeys, $arValue, $obDate);
                return;
            } else {
                $sKeys = implode('_', $arTags).'_'.$sKeys;
            }
        }

        Cache::put($sKeys, $arValue, $obDate);
    }
352712
public function copy( Table $src, Table $dest ) {

		$this->copy_structure( $src, $dest );
		$src_table  = $this->database->quote_identifier( $src->name() );
		$dest_table = $this->database->quote_identifier( $dest->name() );
		$query      = "INSERT INTO {$dest_table} SELECT * FROM {$src_table}";

		return (bool) $this->database->query( $query );
	}
117272
private function insert($validate = true)
	{
		$this->verifyNotReadonly('insert');

		// Check if validation or beforeCreate returns false.
		if (($validate && !$this->_validate() || !$this->invokeCallback('beforeCreate',false))) {
			return false;
		}

		$table = static::table();

		// Get dirty attributes, or when nothing is dirty we just take all atrributes
		if (!($attributes = $this->dirtyAttributes())) { 
			$attributes = $this->_attributes;
		}

		$pk = $this->getPrimaryKey(true);
		$useSequence = false;

		if ($table->sequence && !isset($attributes[$pk]))
		{
			if (($conn = static::connection()) instanceof OciAdapter) {

				// terrible oracle makes us select the nextval first
				$attributes[$pk] = $conn->getNextSequenceValue($table->sequence);
				$table->insert($attributes);
				$this->_attributes[$pk] = $attributes[$pk];
				
			} else {
				// unset pk that was set to null
				if (array_key_exists($pk, $attributes)) {
					unset($attributes[$pk]);
				}

				$table->insert($attributes, $pk, $table->sequence);
				$useSequence = true;
			}
		} else {

			// Simple insert
			$table->insert($attributes);

		}
			

		// if we've got an autoincrementing/sequenced pk set it
		// don't need this check until the day comes that we decide to support composite pks
		// if (count($pk) == 1)
		{
			$column = $table->getColumnByInflectedName($pk);

			if ($column->autoIncrement || $useSequence) {
				$this->_attributes[$pk] = static::connection()->insertId($table->sequence);
			}
		}

		$this->_newRecord = false;
		$this->invokeCallback('afterCreate', false);
		return true;
	}
1021223
public function read ($pkValue = FALSE, &$db = FALSE)
	{
		
		try
		{
			
			// If there is a key value passed set it

			if ($pkValue !== FALSE)
			{
				$this->iset (static::$pk, $pkValue);
			}
			
			// Get database slave for read

			if ($db === FALSE)
			{
				$db	=& $this->getDbSlave ();
			}

			// Prepare query

			$query = $db->prepare ('
			SELECT * FROM `' . static::$dbTable . '`
			WHERE ' . static::$pk . ' = :pk
			');

			// Bind paramater

			$query->bindValue (':pk',	$this->iget (static::$pk));

			// Execute

			$query->execute ();

			// Set row

			$row	= $query->fetch (\PDO::FETCH_ASSOC);

			// If no data was returned return FALSE

			if (!$row)
			{
				return FALSE;
			}

			// Set each attribute value

			foreach ($row as $name => $val)
			{

				if ($this->attributeExists ($name))
				{
					$this->iset ($name, $val, FALSE, TRUE);
				}

			}
			
		}
		
		// Set errors as framework messages

		catch (Resource\Parser\Exception $e)
		{
			new Message ('error', $e->getMessage ());
			return FALSE;
		}
		
		// Return TRUE

		return TRUE;
		
	}
184595
protected function is0VatRate($vatRate)
    {
        if (is_array($vatRate) && isset($vatRate)) {
            $vatRate = isset($vatRate[Tag::VatRate]) ? $vatRate[Tag::VatRate] : null;
        }
        return isset($vatRate) && (Number::isZero($vatRate) || Number::floatsAreEqual($vatRate, -1.0));
    }
36758
protected function getCountCommon(array $aData = [])
    {
        //  Define the selects
        $oDb = Factory::service('Database');
        $oDb->select($this->tableAlias . '.*');
        $oDb->select([
            $this->tableEmailAlias . '.email',
            $this->tableEmailAlias . '.code email_verification_code',
            $this->tableEmailAlias . '.is_verified email_is_verified',
            $this->tableEmailAlias . '.date_verified email_is_verified_on',
        ]);
        $oDb->select($this->getMetaColumns($this->tableMetaAlias));
        $oDb->select([
            $this->tableGroupAlias . '.slug group_slug',
            $this->tableGroupAlias . '.label group_name',
            $this->tableGroupAlias . '.default_homepage group_homepage',
            $this->tableGroupAlias . '.acl group_acl',
        ]);

        // --------------------------------------------------------------------------

        //  Define the joins
        $oDb->join(
            $this->tableEmail . ' ' . $this->tableEmailAlias,
            $this->tableAlias . '.id = ' . $this->tableEmailAlias . '.user_id AND ' . $this->tableEmailAlias . '.is_primary = 1',
            'LEFT'
        );

        $oDb->join(
            $this->tableMeta . ' ' . $this->tableMetaAlias,
            $this->tableAlias . '.id = ' . $this->tableMetaAlias . '.user_id',
            'LEFT'
        );

        $oDb->join(
            $this->tableGroup . ' ' . $this->tableGroupAlias,
            $this->tableAlias . '.group_id = ' . $this->tableGroupAlias . '.id',
            'LEFT'
        );

        //  Let the parent method handle sorting, etc
        parent::getCountCommon($aData);
    }
648113
public function valid_date($sDate, $sFormat)
    {
        //  If blank, then assume the date is not required
        if (empty($sDate)) {
            return true;
        }

        if (empty($sFormat)) {
            $sFormat = 'Y-m-d';
        }

        if (!array_key_exists('valid_date', $this->_error_messages)) {
            $this->set_message('valid_date', lang('fv_valid_date_field'));
        }

        try {

            $oDate = \DateTime::createFromFormat($sFormat, $sDate);

            if (empty($oDate)) {
                return false;
            }

            return $oDate->format($sFormat) == $sDate;

        } catch (\Exception $e) {

            return false;
        }
    }
814205
public function save($new = false, $validate=true,$validateFields=[])
    {
        $this->isNewRecord = $new;

        if($validate){
            if(!$this->validate($validateFields)){
                return false;
            }
        }
        if(!static::beforeSave()) return false;
        $db = X::app()->db->table(self::tableName());
        $tableFields = $db->getFields(self::tableName());
        foreach($this->_modelData as $k=>$v){
            //删除数据库没有的字段
            if(!in_array($k,$tableFields)) unset($this->_modelData[$k]);
        }
        if ($new) {
            return $db->add($this->_modelData);
        } else {
            $id = $this->{self::$pk};
            unset($this->_modelData[self::$pk]);
            return $db->update([self::$pk => $id], $this->_modelData);
        }
    }
410464
public function german2English($sDate)
    {
        $aDate = explode(".", $sDate);

        if (isset($aDate) && count($aDate) > 1) {
            if (count($aDate) == 2) {
                $sDate = $aDate[1] . "-" . $aDate[0];
            } else {
                $sDate = $aDate[2] . "-" . $aDate[1] . "-" . $aDate[0];
            }
        }

        return $sDate;
    }
851118
public function validate ($validate_rule = null, $data_set = [], $force_source = false) {
		//結果の初期化
		$result = [];

		//現在のバリデーションルールを取得
		$validate_rule = $validate_rule ?? $this->rule->validate ?? null;
		if (is_callable($validate_rule)) {
			$validate_rule = $validate_rule();
		}

		//実行対象のバリデーションがあるか確認、なければ対象はなかったとして終了
		if (is_null($validate_rule)) {
			$this->hasValidator = false;
			return [];
		}
		$this->hasValidator = true;

		//外部入力値を取得
		$request_access = LazyArrayObject::Create([
			'parameter'	=> Request::GetParameters(),
			'data'		=> Request::GetPostData(),
			'post'		=> Request::GetPost(),
			'upload'	=> Request::GetUploadFileData(),
			'cookie'	=> Request::GetCookies(),
			'route'		=> $this->route,
			'direct'	=> $data_set,
		]);

		//検証の実行：入力一要素ごとに処理を行う
		foreach (array_filter(($validate_rule instanceof \ArrayObject) ? $validate_rule->getArrayCopy() : $validate_rule) as $target => $rules) {
			//短縮設定を掬い取る
			$rule_length = count($rules);
			for ($i = 0;$i < $rule_length;$i++) {
				$data_set = array_slice($rules, $i, 1);
				$idx = key($data_set);
				$rule = current($data_set);
				if (is_int($idx) && is_string($rule)) {
					$rules = array_merge(array_slice($rules, 0, $i), [$rule => true], array_slice($rules, $i + 1));
				}
			}

			//先行する検証の結果を参照するかどうか
			$premise = $rules['premise'] ?? null;
			if ($premise) {
				foreach (Arrays::AdjustArray($premise) as $error_name) {
					//一つでもエラーとなっている先行検証結果がある場合、処理そのものをスキップ
					if (isset($result[$error_name])) {
						continue 2;
					}
				}
			}

			//データ取得対象ソースの指定
			$source = $force_source ?: ($rules['rules']['source'] ?? $rules['source'] ?? (Request::IsPostMethod() ? 'data' : 'parameter'));
			$data = $request_access->$source;

			//先行確認値があった場合、突合チェック
			$pre_check_pattern = null;
			if (($position = strpos($target, '@value=')) !== false) {
				$pre_check_pattern = substr($target, $position + strlen('@value='));
				$target = substr($target, 0, $position);

				//先行入力値とマッチしなかった場合はスキップ
				if ($pre_check_pattern !== null && preg_match(sprintf("/^%s$/u", str_replace('/', "\\/", $pre_check_pattern)), $data->$target) !== 1) {
					continue;
				}
			}

			//指定があった場合、値の取得先を差し替え
			$name = $rules['name'] ?? $target;

			//検証実行：結果はどんどん末尾に追加していく
			$ret = Validator::BulkCheck($data, [$name => $rules], $result) ?? [];
			if (!empty($ret)) {
				foreach ($ret as $target => $error_message_list) {
					$result += $result + [$target => $error_message_list];
				}

				//入力要素レベルのis_lastが存在した場合、ここで処理終了となる
				if ($rules['is_last'] ?? null) {
					break;
				}
			}
		}

		//処理の終了
		return $result;
	}
982201
static function isValidISODateString( $sDate )
	{
		if ( ! CLib::IsExistingString( $sDate ) )
		{
			return false;
		}

		$nTime	= strtotime( $sDate );
		return ( false !== $nTime &&
			0 == strcasecmp( $sDate, date( "Y-m-d", $nTime ) ) );
	}
1268786
public function fetch($fetchMode = NULL, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) {
        $fetchMode = empty($fetchMode) ? $this->fetchMode : $fetchMode;
        Assertions::assertSupportedFetchMode($fetchMode);

        return count($this->result) === 0 ? false : array_pop($this->result);
    }
805997
public static function IPTE2CodigoBarras($ipte)
    {
        $ipte = self::onlyNumbers($ipte);

        $barras = substr($ipte, 0, 4);
        $barras .= substr($ipte, 32, 1) ;
        $barras .= substr($ipte, 33, 14) ;
        $barras .= substr($ipte, 4,1) ;
        $barras .= substr($ipte, 5, 4) ;
        $barras .= substr($ipte, 10, 10) ;
        $barras .= substr($ipte, 21, 8) ;
        $barras .= substr($ipte, 29, 2);

        return $barras;
    }
67110
public function rset()
    {
        if (PEAR::isError($error = $this->put('RSET'))) {
            return $error;
        }
        if (PEAR::isError($error = $this->parseResponse(250, $this->pipelining))) {
            return $error;
        }

        return true;
    }
1297868
public function isEmptyDate($sDate)
    {
        if (!empty($sDate)) {
            $sDate = preg_replace("/[^0-9a-z]/i", "", $sDate);
            if (!is_numeric($sDate) || $sDate != 0) {
                return false;
            }
        }

        return true;
    }