/** * Get account for entity. * If the account doesn't exist it will be created. */ public static function getEntityAccount($entity_type, $entity_id) { if (!$entity_id) { throw new Exception("Expected entity id"); } $account = self::findOneByQuery("SELECT * FROM %t WHERE entity_type=%s AND entity_id=%s", $entity_type, $entity_id); if (!$account) { $account = new Account($entity_type, $entity_id); $account->save(); } return $account; }