<?php 

namespace common\modules\support\models\redmine;

use common\models\Settings;

class IssueHelper 
{
	public static function sort($issues = null)
	{
        if($issues)
        {
    		$settings = [
                [
                    'statuses' => explode(',', Settings::getValue('support-status-work')),
                    'title' => 'Задачи в работе',
                ],
                [
                    'statuses' => explode(',', Settings::getValue('support-status-new')),
                    'title' => 'Задачи на оценке',
                ],
                [
                    'statuses' => explode(',', Settings::getValue('support-status-test')),
                    'title' => 'Задачи на тестировании',
                ],
                [
                    'statuses' => explode(',', Settings::getValue('support-status-approve')),
                    'title' => 'Задачи ожидающие проверки',
                ],
                [
                    'statuses' => explode(',', Settings::getValue('support-status-accepted')),
                    'title' => 'Закрытые задачи',
                    'close' => true
                ],
            ];

            foreach ($issues as $issue) 
            {
                foreach ($settings as &$setting) 
                {
                    if(in_array($issue['status']['id'], $setting['statuses']))
                    {
                        $setting['models'][] = $issue;
                    }
                }
            }

            unset($setting);

            return $settings;
        }

        return null;
	}
}