For a very basic operation you will need to monitor at least three switches (possibly four) .... two for the limits, and one or two for the request. (Open or Close (two), or a single push button (one) for toggling the Open/Close request.
Another two I/O's will be necessary to drive an H-Bridge controller or to drive Relays to control the direction of the gate motor.
Aside from that it should be just conditional software programming ... If this is pressed do that unless you are already here