Example #1
0
 /**
  * Finds webhook configs by even
  *
  * @param   string   $eventName     Event type
  * @param   int      $farmId    The identifier of the farm
  * @param   int      $accountId The identifier of the client's account
  * @param   int      $envId     The identifier of the environment
  * @return  ArrayCollection Gets collection of the WebhookConfig objects
  */
 public static function findByEvent($eventName, $farmId, $accountId, $envId)
 {
     $ret = new ArrayCollection();
     $cfg = new self();
     $res = $cfg->db()->Execute("\n            SELECT " . $cfg->fields('c') . "\n            FROM " . $cfg->table() . " c\n            JOIN `webhook_config_events` ce ON ce.webhook_id = c.webhook_id\n            WHERE ce.event_type = ?\n            AND (\n                (c.account_id = ? AND c.env_id = ? AND `level` = 4) OR\n                (c.account_id = ? AND c.env_id IS NULL AND `level` = 2) OR\n                (c.account_id IS NULL AND c.env_id IS NULL AND `level` = 1)\n            )\n            AND EXISTS (\n                SELECT 1 FROM `webhook_config_farms` cf\n                WHERE cf.webhook_id = c.webhook_id\n                AND (cf.farm_id = 0 OR cf.farm_id = ?)\n            )\n        ", array($eventName, $accountId, $envId, $accountId, $farmId));
     while ($item = $res->FetchRow()) {
         $cfg = new self();
         $cfg->load($item);
         $ret->append($cfg);
         unset($cfg);
     }
     return $ret;
 }