Commit d23a0e62 authored by Tim Diels's avatar Tim Diels
Browse files

Issue #3274453 by tim-diels, trickfun: Attempt to read property "total" on...

Issue #3274453 by tim-diels, trickfun: Attempt to read property "total" on string in Drupal\activecampaign_dashboard
parent 2bf8ed94
Loading
Loading
Loading
Loading
+21 −16
Original line number Diff line number Diff line
@@ -13,10 +13,6 @@ class ActiveCampaignCampaigns extends ActiveCampaignDashboard {
   * {@inheritDoc}
   */
  protected function getTableData(int $page = 0, int $limit = 20): array {

    $response = $this->api->getCampaigns([], $page, $limit);
    $data['total'] = $response->total;

    $data['table_fields'] = [
      $this->t('Name'),
      $this->t('Date send'),
@@ -27,6 +23,14 @@ class ActiveCampaignCampaigns extends ActiveCampaignDashboard {
      $this->t('Unsubscribe rate'),
    ];

    // Check if we have an object containing our data instead of an error
    // message.
    $response = $this->api->getCampaigns([], $page, $limit);
    if (is_string($response)) {
      $this->messenger()->addError($response);
    }
    else {
      $data['total'] = $response->total;
      foreach ($response->rows as $key => $campaign) {
        // Check if the row is actual data or metadata from the api.
        if (is_numeric($key)) {
@@ -42,6 +46,7 @@ class ActiveCampaignCampaigns extends ActiveCampaignDashboard {

        }
      }
    }

    return $data;
  }
+19 −14
Original line number Diff line number Diff line
@@ -13,10 +13,6 @@ class ActiveCampaignContacts extends ActiveCampaignDashboard {
   * {@inheritDoc}
   */
  protected function getTableData(int $page = 0, int $limit = 20): array {

    $response = $this->api->getContacts([], $page, $limit);
    $data['total'] = $response->total;

    $data['table_fields'] = [
      $this->t('Email'),
      $this->t('First Name'),
@@ -24,6 +20,14 @@ class ActiveCampaignContacts extends ActiveCampaignDashboard {
      $this->t('Created'),
    ];

    // Check if we have an object containing our data instead of an error
    // message.
    $response = $this->api->getContacts([], $page, $limit);
    if (is_string($response)) {
      $this->messenger()->addError($response);
    }
    else {
      $data['total'] = $response->total;
      foreach ($response->rows as $key => $contact) {
        // Check if the row is actual data or metadata from the api.
        if (is_numeric($key)) {
@@ -36,6 +40,7 @@ class ActiveCampaignContacts extends ActiveCampaignDashboard {

        }
      }
    }

    return $data;
  }
+17 −14
Original line number Diff line number Diff line
@@ -14,16 +14,18 @@ class ActiveCampaignLists extends ActiveCampaignDashboard {
   * {@inheritDoc}
   */
  protected function getTableData(int $page = 0, int $limit = 20): array {

    $response = $this->api->getLists([], $page, $limit);
    $data['total'] = $response->total;

    $data['table_fields'] = [
      $this->t('Name'),
      $this->t('Subscribers'),
      $this->t('Active Subscribers'),
    ];

    $response = $this->api->getLists([], $page, $limit);
    if (is_string($response)) {
      $this->messenger()->addError($response);
    }
    else {
      $data['total'] = $response->total;
      foreach ($response->rows as $key => $list) {
        // Check if the row is actual data or metadata from the api.
        if (is_numeric($key)) {
@@ -36,6 +38,7 @@ class ActiveCampaignLists extends ActiveCampaignDashboard {

        }
      }
    }

    return $data;
  }