CRM-14478 - CRM_Core_EntityReference - Move SQL construction

This anticipates polymorphic SQL construction -- where have different
classes for different types of references (eg conventional SQL FKs; dynamic
FK; option-value FKs) and where each class constructs slightly different
SQL.
CRM-14478 - Split CRM_Core_EntityReference into different classes
CRM-14478 - Add CRM_Core_Reference_OptionValue
CRM_Utils_Array::index() -- Allow indexing when some keys are NULL/undefined
CRM-14478 - Add CRM_Core_DAO::getReferenceCounts()
CRM-14478 - Add generic API, "getrefcount"
CRM-14478 - CRM_Case_XMLRepository - Add getActivityReferenceCount(), getRelationshipReferenceCount()
CRM-14478 - Allow components and hooks to influence refcounts
CRM-14478 - Count references to activity-types and relationship-types in CiviCase XML
Merge pull request #3322 from totten/master-refcount

CRM-14478 - Add generic API, "getrefcount"