The code computes the field/link ap further down.  

It first gets the AP gain for destroying + building the portal.  It then evaluates the team the portal belongs to and makes a unique array (by GUID) of all the links/fields that have end points in view.