Jump to content
Дизайн и модификация IPS Community IPBSkinsBETA
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
TemKa_SD

Помогите записать правильно в массив

Recommended Posts

Здравствуйте. Мне необходимо получить историю изменения группы пользователя в IPS, на сколько я понял, эта информация хранится только в core_member_history.

		$dates = [];
		$date = $old = $new = null;

		foreach( \IPS\Db::i()->select( '*', 'core_member_history', array( 'log_app=? and log_member=? and log_type=?', 'core', 6, 'group' ) ) as $row  )
		{
			$data = json_decode( $row['log_data'], TRUE );

			if ($new == $data['old'] && $date != $finish = $row['log_date']) {
				$dates[] = ['start' => $date, 'finish' => $finish];
			}

			$date = $row['log_date'];
			$old = $data['old'];
			$new = $data['new'];
		}

В моем примере я должен получить вот такой массив в итоге:

Array
(
    [0] => Array
        (
            [start] => 1597760738.50
            [finish] => 1601474591.76
        )

    [1] => Array
        (
            [start] => 1608299241.36
            [finish] => null
        )

)

а получаю вот такой:

Array
(
    [0] => Array
        (
            [start] => 1597760738.50
            [finish] => 1601474591.76
        )

    [1] => Array
        (
            [start] => 1601474591.76
            [finish] => 1608299241.36
        )

)

Т.е 

Edited by TemKa_SD

Share this post


Link to post
Share on other sites

Какое-то запудренное условие, хотя задача вроде элементарная

		$dates = [];
		$finish = null;

		foreach( \IPS\Db::i()->select( '*', 'core_member_history', array( 'log_app=? and log_member=? and log_type=?', 'core', 6, 'group' ) ) as $row  )
		{
			$data = json_decode( $row['log_data'], TRUE );

			$dates[] = [
				'start' => $data['log_date'],
				'finish' => $finish
			];

			$finish = $row['log_date'];
		}

 

  • Upvote 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...