<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/

class Browserpush_Installer extends Engine_Package_Installer_Module
{

  public function onInstall()
  {

    $db = $this->getDb();

    //Place widget in header
    $parent_content_id = $db->select()
      ->from('engine4_core_content', 'content_id')
      ->where('type = ?', 'container')
      ->where('page_id = ?', '1')
      ->where('name = ?', 'main')
      ->limit(1)
      ->query()
      ->fetchColumn();
    if ($parent_content_id) {


      $select = new Zend_Db_Select($db);
      $select_content = $select
        ->from('engine4_core_content')
        ->where('page_id = ?', 1)
        ->where('type = ?', 'widget')
        ->where('name = ?', 'browserpush.notification-button')
        ->limit(1);
      $content_id = $select_content->query()->fetchObject()->content_id;
      if (empty($content_id)) {
        $db->insert('engine4_core_content', array(
          'type' => 'widget',
          'name' => 'browserpush.notification-button',
          'page_id' => 1,
          'parent_content_id' => $parent_content_id,
          'order' => 20,
        ));
      }

      $select = new Zend_Db_Select($db);
      $select_content = $select
        ->from('engine4_core_content')
        ->where('page_id = ?', 1)
        ->where('type = ?', 'widget')
        ->where('name = ?', 'browserpush.push')
        ->limit(1);
      $content_id = $select_content->query()->fetchObject()->content_id;
      if (empty($content_id)) {
        $db->insert('engine4_core_content', array(
          'type' => 'widget',
          'name' => 'browserpush.push',
          'page_id' => 1,
          'parent_content_id' => $parent_content_id,
          'order' => 21,
        ));
      }
    }

    parent::onInstall();
  }
}
