Microweber\Providers\NotificationsManager::save PHP Method

save() public method

public save ( $params )
    public function save($params)
    {
        $params = parse_params($params);
        $table_orig = $this->table;
        $table = $this->app->database_manager->real_table_name($this->table);
        mw_var('FORCE_SAVE', $table);
        if (!isset($params['rel_type']) or !isset($params['rel_id'])) {
            return 'Error: invalid data you must send rel and rel_id as params for $this->save function';
        }
        $old = date('Y-m-d H:i:s', strtotime('-30 days'));
        $cleanup = "DELETE FROM {$table} WHERE created_at < '{$old}'";
        $this->app->database_manager->q($cleanup);
        if (isset($params['replace'])) {
            if (isset($params['module']) and isset($params['rel_type']) and isset($params['rel_id'])) {
                unset($params['replace']);
                $rel1 = $this->app->database_manager->escape_string($params['rel_type']);
                $module1 = $this->app->database_manager->escape_string($params['module']);
                $rel_id1 = $this->app->database_manager->escape_string($params['rel_id']);
                $cleanup = "DELETE FROM {$table} WHERE rel_type='{$rel1}' AND module='{$module1}' AND rel_id='{$rel_id1}'";
                $this->app->database_manager->q($cleanup);
            }
        }
        if (!isset($params['is_read'])) {
            $params['is_read'] = 0;
        }
        if (isset($params['notification_data'])) {
            $params['notification_data'] = @json_encode($params['notification_data']);
        }
        $this->app->cache_manager->delete('notifications' . DIRECTORY_SEPARATOR . 'global');
        $data = $this->app->database_manager->save($table_orig, $params);
        return $data;
    }