gergo85 / oc-news

This is the simple news and newsletter plugin for October CMS and Winter CMS.
http://octobercms.com/plugin/indikator-news
MIT License
42 stars 29 forks source link

Author of the post to always be automatically only the user who publishes the post. #139

Closed Thominho closed 4 years ago

Thominho commented 4 years ago

Hi,

I want the author of the post to always be automatically only the user who publishes the post. Can this be achieved here?

Big thank you!

Idea - https://ibb.co/VM2Rrr3

    public function getUserOptions()
    {
        $result = [0 => 'indikator.news::lang.form.select_user'];
        $users = Db::table('backend_users')->orderBy('login', 'asc')->get()->all();

        foreach ($users as $user) {
            $name = trim($user->first_name.' '.$user->last_name);
            $name = ($name != '') ? ' ('.$name.')' : '';
            $result[$user->id] = $user->login.$name;
        }

        return $result;
    }
Thominho commented 4 years ago

For others..

use BackendAuth;

public function getUserOptions()
{
    // placeholder
    $result = [0 => 'indikator.news::lang.form.select_user'];

    // only back-end user which is currently logged in
    // it will be available always as we are in back-end :)
    $user = BackendAuth::getUser();
    $result[$user->id] = $user->login; // or $user->email;    

    return $result;
}