Habari\Posts::reassign PHP Метод

reassign() публичный статический Метод

Reassigns the author of a specified set of posts
public static reassign ( integer | User | string $user, array | Posts $posts ) : boolean
$user integer | User | string a user ID or name
$posts array | Posts an array of post IDs, an array of Post objects, or an instance of Posts
Результат boolean Whether the rename operation succeeded or not
    public static function reassign($user, $posts)
    {
        if (!is_int($user)) {
            $u = User::get($user);
            $user = $u->id;
        }
        // safety checks
        if ($user == 0 || empty($posts)) {
            return false;
        }
        switch (true) {
            case is_integer(reset($posts)):
                break;
            case reset($posts) instanceof Post:
                $ids = array();
                foreach ($posts as $post) {
                    $ids[] = $post->id;
                }
                $posts = $ids;
                break;
            default:
                return false;
        }
        $ids = implode(',', $posts);
        // allow plugins the opportunity to prevent the reassignment now that we've verified the user and posts
        $allow = true;
        $allow = Plugins::filter('posts_reassign_allow', $allow, $user, $posts);
        if (!$allow) {
            return false;
        }
        // actually perform the reassignment
        Plugins::act('posts_reassign_before', array($user, $posts));
        $results = DB::query("UPDATE {posts} SET user_id=? WHERE id IN ({$ids})", array($user));
        Plugins::act('posts_reassign_after', array($user, $posts));
        return $results;
    }