src/bbn/appui/history.php
private static function _insert(array $cfg): int
  {
    if (
      isset($cfg['column'], $cfg['line'], $cfg['chrono']) &&
      self::check() &&
      ($db = self::_get_db())
    ){
      // Recording the last ID
      $id = $db->last_id();
      $last = self::$db->last();
      $last_params = self::$db->last_params;
      self::disable();
      if ( !array_key_exists('old', $cfg) ){
        $cfg['ref'] = null;
        $cfg['val'] = null;
      }
      else if (
        bbn\str::is_uid($cfg['old']) &&
        self::$db->count(self::$table_uids, ['bbn_uid' => $cfg['old']])
      ){
        $cfg['ref'] = $cfg['old'];
        $cfg['val'] = null;
      }
      else{
        $cfg['ref'] = null;
        $cfg['val'] = $cfg['old'];
      }
      // New row in the history table
      if ( $res = $db->insert(self::$table, [
        'opr' => $cfg['operation'],
        'uid' => $cfg['line'],
        'col' => $cfg['column'],
        'val' => $cfg['val'],
        'ref' => $cfg['ref'],
        'tst' => self::$date ?: $cfg['chrono'],
        'usr' => self::$user
      ]) ){
        // Set back the original last ID
        $db->set_last_insert_id($id);
      }
      self::$db->last_query = $last;
      self::$db->last_params = $last_params;
      self::enable();
      return $res;
    }
    return 0;
  }
private static function _insert(array $cfg): int
  {
    if (
      isset($cfg['column'], $cfg['line'], $cfg['chrono']) &&
      self::check() &&
      ($db = self::_get_db())
    ){
      // Recording the last ID
      $id = $db->last_id();
      $last = self::$db->last();
      $last_params = self::$db->last_params;
      self::disable();
      if ( !array_key_exists('old', $cfg) ){
        $cfg['ref'] = null;
        $cfg['val'] = null;
      }
      else if (
        bbn\str::is_uid($cfg['old']) &&
        self::$db->count(self::$table_uids, ['bbn_uid' => $cfg['old']])
      ){
        $cfg['ref'] = $cfg['old'];
        $cfg['val'] = null;
      }
      else{
        $cfg['ref'] = null;
        $cfg['val'] = $cfg['old'];
      }
      // New row in the history table
      if ( $res = $db->insert(self::$table, [
        'opr' => $cfg['operation'],
        'uid' => $cfg['line'],
        'col' => $cfg['column'],
        'val' => $cfg['val'],
        'ref' => $cfg['ref'],
        'tst' => self::$date ?: $cfg['chrono'],
        'usr' => self::$user
      ]) ){
        // Set back the original last ID
        $db->set_last_insert_id($id);
      }
      self::$db->last_query = $last;
      self::$db->last_params = $last_params;
      self::enable();
      return $res;
    }
    return 0;
  }
private static function _insert ( array $ cfg ) : int { if ( isset ( $ cfg [ 'column' ] , $ cfg [ 'line' ] , $ cfg [ 'chrono' ] ) && self :: check ( ) && ( $ db = self :: _get_db ( ) ) ) { // Recording the last ID $ id = $ db -> last_id ( ) ; $ last = self :: $ db -> last ( ) ; $ last_params = self :: $ db -> last_params ; self :: disable ( ) ; if ( ! array_key_exists ( 'old' , $ cfg ) ) { $ cfg [ 'ref' ] = null ; $ cfg [ 'val' ] = null ; } else if ( bbn \ str :: is_uid ( $ cfg [ 'old' ] ) && self :: $ db -> count ( self :: $ table_uids , [ 'bbn_uid' => $ cfg [ 'old' ] ] ) ) { $ cfg [ 'ref' ] = $ cfg [ 'old' ] ; $ cfg [ 'val' ] = null ; } else { $ cfg [ 'ref' ] = null ; $ cfg [ 'val' ] = $ cfg [ 'old' ] ; } // New row in the history table if ( $ res = $ db -> insert ( self :: $ table , [ 'opr' => $ cfg [ 'operation' ] , 'uid' => $ cfg [ 'line' ] , 'col' => $ cfg [ 'column' ] , 'val' => $ cfg [ 'val' ] , 'ref' => $ cfg [ 'ref' ] , 'tst' => self :: $ date ? : $ cfg [ 'chrono' ] , 'usr' => self :: $ user ] ) ) { // Set back the original last ID $ db -> set_last_insert_id ( $ id ) ; } self :: $ db -> last_query = $ last ; self :: $ db -> last_params = $ last_params ; self :: enable ( ) ; return $ res ; } return 0 ; }
Adds a row in the history table

@param array $cfg
@return int
Adds a row in the history table