ShareModel.php 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<?php

/**
 * Copyright (c) by the ACP3 Developers.
 * See the LICENSE file at the top-level module directory for licensing details.
 */

namespace ACP3\Modules\ACP3\Share\Model;

use ACP3\Core\Model\AbstractModel;
use ACP3\Core\Model\DataProcessor;
12
use ACP3\Modules\ACP3\Share\Installer\Schema;
13 14 15 16 17 18 19 20 21 22

class ShareModel extends AbstractModel
{
    const EVENT_PREFIX = Schema::MODULE_NAME;

    /**
     * {@inheritdoc}
     */
    public function save(array $data, $entryId = null)
    {
23
        $data = \array_merge($data, $this->getData($data));
24 25 26 27

        return parent::save($data, $entryId);
    }

28 29 30 31 32 33 34 35 36 37 38
    /**
     * @param array $data
     *
     * @return array
     */
    private function getData(array $data): array
    {
        $newData = [];
        $keys = [
            'active' => 'share_active',
            'services' => 'share_services',
39
            'ratings_active' => 'share_ratings_active',
40 41 42 43 44 45 46 47 48 49
        ];
        foreach ($keys as $column => $formField) {
            if (isset($data[$formField])) {
                $newData[$column] = $data[$formField];
            }
        }

        return $newData;
    }

50 51 52 53 54 55 56
    /**
     * {@inheritdoc}
     */
    protected function getAllowedColumns()
    {
        return [
            'uri' => DataProcessor\ColumnTypes::COLUMN_TYPE_RAW,
57
            'active' => DataProcessor\ColumnTypes::COLUMN_TYPE_BOOLEAN,
58
            'services' => DataProcessor\ColumnTypes::COLUMN_TYPE_SERIALIZABLE,
59
            'ratings_active' => DataProcessor\ColumnTypes::COLUMN_TYPE_BOOLEAN,
60 61 62
        ];
    }
}