Scalr\UI\Controller\Admin\Analytics\NotificationTrait::saveReports PHP Метод

saveReports() защищенный Метод

Saves/modifies/deletes reports
protected saveReports ( array $settings, string $projectId = null )
$settings array Array of reports to create/modify
$projectId string optional Projects id.
    protected function saveReports($settings, $projectId = null)
    {
        $uuids = [];
        foreach ($settings['items'] as $item) {
            $report = new ReportEntity();
            if ($item['uuid']) {
                $report->findPk($item['uuid']);
                if (!$report->hasAccessPermissions($this->getUser())) {
                    continue;
                }
            }
            $report->subjectType = $item['subjectType'];
            $subject = null;
            if ($report->subjectType == ReportEntity::SUBJECT_TYPE_CC && $item['subjectId']) {
                $subject = $this->getContainer()->analytics->ccs->get($item['subjectId']);
            } elseif ($report->subjectType == ReportEntity::SUBJECT_TYPE_PROJECT && $item['subjectId']) {
                $subject = $this->getContainer()->analytics->projects->get($item['subjectId']);
            } elseif ($item['subjectType'] == -1) {
                $report->subjectType = null;
                $report->subjectId = null;
            }
            if ($report->subjectType) {
                if ($item['subjectId'] && !$subject) {
                    throw new Scalr_UI_Exception_NotFound();
                }
                $report->subjectId = $item['subjectId'] ? $item['subjectId'] : null;
            }
            $report->period = $item['period'];
            $report->emails = $item['emails'];
            $report->status = $item['status'];
            $report->save();
            $uuids[] = $report->uuid;
        }
        $criteria = [['accountId' => null]];
        if ($projectId) {
            $criteria[] = ['subjectId' => $projectId];
        }
        foreach (ReportEntity::find($criteria) as $report) {
            /* @var $report ReportEntity */
            if (!in_array($report->uuid, $uuids) && $report->hasAccessPermissions($this->getUser())) {
                $report->delete();
            }
        }
    }