/*
Checking if a range of ids is already used

@param int $pageMinValue
@param int $pageMaxValue
@param int $tplMinValue
@param int $tplMaxValue
@param int $pids_id current platform id

@return boolean
979119
public function platformIdsRangeIsExist($pageMinValue, $pageMaxValue, $tplMinValue, 
	                                        $tplMaxValue, $pids_id)
	{
	    $select = $this->tableGateway->getSql()->select();
	    $select->where->between('pids_page_id_start', $pageMinValue, $pageMaxValue);
	    $select->where->OR->between('pids_page_id_end', $pageMinValue, $pageMaxValue);
        
	    $select->where->OR->between('pids_tpl_id_start', $tplMinValue, $tplMaxValue);
	    $select->where->OR->between('pids_tpl_id_end', $tplMinValue, $tplMaxValue);
	    
	    
	    $resultSet = $this->tableGateway->selectWith($select);
	    if (!empty($resultSet))
	    {
	        $result = $resultSet->toArray();
	        if (!empty($result))
	        {
	            // Checking the Number of Rows
	            if (count($result)==1)
	            {
	                // Checking if the ID is the current data that using updating
	                if ($result[0]['pids_id']==$pids_id)
	                    return true;
	            }
	        }
	        else
	            return true;
	    }
	    
	    return false;
	}
347284
public function getMaxId()
    {

        try {
            $result = app('db')->connection('mysql')->select("select max(id) maxid from " . config("database.mysql_workers"));

        } catch (\Exception $e) {
            Log::info('c=CopydataApiController f=getMaxId  msg=' . $e->getMessage());
            return false;
        }

        $max = $result[0]->maxid;
        return (int)$max;
    }
537657
public function clientPermAssign($cldbid, $permid, $permvalue, $permskip = FALSE)
  {
    if(!is_array($permid))
    {
      $permident = (is_numeric($permid)) ? "permid" : "permsid";
    }
    else
    {
      $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
    }

    $this->execute("clientaddperm", array("cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue, "permskip" => $permskip));
  }
1155717
private function setTerminator($dataValue, $dataCounter, $dataBits, $totalDataBits, $maxDataBits)
    {
        if ( $totalDataBits <= ($maxDataBits - 4) ) {
            $dataValue[$dataCounter]  = 0;
            $dataBits[$dataCounter]   = 4;
        }
        else {
            if ( $totalDataBits < $maxDataBits ) {
                $dataValue[$dataCounter]  = 0;
                $dataBits[$dataCounter]   = $maxDataBits - $totalDataBits;
            }
            else {
                if ( $totalDataBits > $maxDataBits ) {
                    throw new OverflowException('QRCode : Overflow error');
                }
            }
        }
        return array($dataValue, $dataBits);
    }
1164021
@Override
  public int setPageID(P page) {
    int pageID = page.getPageID();
    if(pageID == -1) {
      pageID = getNextEmptyPageID();
      if(pageID == -1) {
        pageID = nextPageID++;
      }
      page.setPageID(pageID);
    }
    return pageID;
  }
483919
public function isValidItem($mixValue){
		if($this->hasOption('max')){
			if(count($this->mixValue)>=$this->options()->max){
				throw new MaxException($this->options()->max);
				return false;
			}
		}

		return true;
	}
718790
protected function getValidatedPid(DataHandler $tceMain, $table, $uid)
    {
        $pid = $tceMain->getPID($table, $uid);
        if ($pid === false) {
            throw new NoPidException('Pid should not be false');
        }

        $pid = intval($pid);
        return $pid;
    }
594111
public function setWindowPage( $type_page_range, $value )
	{
		if ( !isset( $this->availables_page_range[$type_page_range] ) )
		{
			trigger_error( "Pagination setWindowPage: The type of page range ( $type_page_range ), not is valid. ( Availables: default, short and very_short )" );
			return false;
		}

		if ( !is_int( $value ) )
		{
			trigger_error( 'Pagination setWindowPage: The value to set page range must be an integer.' );
			return false;
		}

		$this->availables_page_range[$type_page_range] = $value;
	}
1014913
protected function processPageId($page_id) {
    $page_ids = array_keys($this->getVisiblePages());

    // Redirect to default page (first page) if no page or invalid page is
    // requested.
    if (empty($page_id) || !in_array($page_id, $page_ids)) {
      $page_id = reset($page_ids);
    }

    return $page_id;
  }
933256
private void checkLimitRange(int limit) {
    int minLimit = offsetPaginationConfiguration.allowZeroLimit() ? 0 : 1;

    if (limit < minLimit || limit > offsetPaginationConfiguration.maxLimit()) {
      throw InvalidParameterException.create(
          "Invalid value for '" + this.getParameterFieldName() + "': " + limit
              + "  - value between " + minLimit + " and " + offsetPaginationConfiguration.maxLimit()
              + " is required.");
    }
  }
968829
public static String padWithMax(final int numToPad, final int maxValue) {
    checkArgument(numToPad >= 0);
    checkArgument(numToPad <= maxValue);
    final int maxLength = Integer.toString(maxValue).length();
    final String baseString = Integer.toString(numToPad);
    final String padding = Strings.repeat("0", maxLength - baseString.length());
    return padding + numToPad;
  }
1065499
def check
      last_max = -1
      unless (min_id = @page_records.first.min_id) == 0
        raise RuntimeError, "min_id of first record (#{min_id}) " +
          "must be 0."
      end

      @page_records.each do |pr|
        unless pr.min_id == last_max + 1
          raise RuntimeError, "max_id of previous record (#{last_max}) " +
            "must be exactly 1 smaller than current record (#{pr.min_id})."
        end
        last_max = pr.max_id
        pr.check
      end

      unless last_max == 2 ** 64
        raise RuntimeError, "max_id of last records " +
          "(#{@page_records.last.max_id}) must be #{2 ** 64})."
      end
    end
1113330
static public function range($value, $minValue, $maxValue, $message = null, $propertyPath = null)
        {
            static::integer($value);

            if ($value < $minValue || $value > $maxValue) {
                $message = $message ?: sprintf(
                    'Number "%s" was expected to be at least "%d" and at most "%d".',
                    static::stringify($value),
                    static::stringify($minValue),
                    static::stringify($maxValue)
                );

                throw static::createException($value, $message, static::INVALID_RANGE, $propertyPath, array('min' => $minValue, 'max' => $maxValue));
            }
        }
805226
public function setIDRange($min, $max)
    {
        assert(is_numeric($min));
        assert(is_numeric($max));
        assert($min <= $max);
        $this->_min_id = $min;
        $this->_max_id = $max;

        return $this;
    }
473208
@Override
  public final void setItsId(final IdUserRoleJetty pId) {
    this.itsId = pId;
    if (this.itsId == null) {
      this.itsUser = null;
      this.itsRole = null;
    } else {
      this.itsUser = this.itsId.getItsUser();
      this.itsRole = this.itsId.getItsRole();
    }
  }
1141629
private boolean isBPDExpired() {
        Map<String, String> bpd = passport.getBPD();
        log.info("[BPD] max age: " + maxAge + " days");

        long maxMillis = -1L;
        try {
            int days = Integer.parseInt(maxAge);
            if (days == 0) {
                log.info("[BPD] auto-expiry disabled");
                return false;
            }

            if (days > 0)
                maxMillis = days * 24 * 60 * 60 * 1000L;
        } catch (NumberFormatException e) {
            log.error(e.getMessage(), e);
            return false;
        }

        long lastUpdate = 0L;
        if (bpd != null) {
            String lastUpdateProperty = bpd.get(BPD_KEY_LASTUPDATE);
            try {
                lastUpdate = lastUpdateProperty != null ? Long.parseLong(lastUpdateProperty) : lastUpdate;
            } catch (NumberFormatException e) {
                log.error(e.getMessage(), e);
                return false;
            }
            log.info("[BPD] last update: " + (lastUpdate == 0 ? "never" : new Date(lastUpdate)));
        }

        long now = System.currentTimeMillis();
        if (maxMillis < 0 || (now - lastUpdate) > maxMillis) {
            log.info("[BPD] expired, will be updated now");
            return true;
        }

        return false;
    }
1350249
public function checkIfpageShouldBeIndexed($uid, $language_uid)
    {
        $index = true;

        if ($this->cachedPageRecords[$language_uid][$uid]['hidden']) {
            $index = false;
        }

        if ($this->cachedPageRecords[$language_uid][$uid]['no_search']) {
            $index = false;
        }

        if (!in_array($this->cachedPageRecords[$language_uid][$uid]['doktype'], $this->indexDokTypes)) {
            $index = false;
        }

        return $index;
    }