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

class Stories_Plugin_Core extends Zend_Controller_Plugin_Abstract
{

  public function onUserCreateAfter($event)
  {

    $user = $event->getPayload();

    if (Engine_Api::_()->getApi('settings', 'core')->getSetting('stories.pluginactivated')) {
      $userTable = Engine_Api::_()->getItemTable('user');
      $userinfoTable = Engine_Api::_()->getItemTable('stories_userinfo');

      //Enter privacy into userinfoTable
      Engine_Api::_()->stories()->isExist($user->user_id, 'owner_member');

      $dbGetInsert = Engine_Db_Table::getDefaultAdapter();

      //View privacy
      $dbGetInsert->query('INSERT INTO `engine4_authorization_allow` (`resource_type`, `resource_id`, `action`, `role`, `role_id`, `value`, `params`) VALUES ("user", "' . $user->user_id . '", "story_view", "owner_member", "0", "1", NULL);');

      //Comment Privacy
      $dbGetInsert->query('INSERT INTO `engine4_authorization_allow` (`resource_type`, `resource_id`, `action`, `role`, `role_id`, `value`, `params`) VALUES ("user", "' . $user->user_id . '", "story_comment", "owner_member", "0", "1", NULL);');
    }
  }
}
