<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
class Video_Plugin_Core
{
  public function onStatistics($event)
  {
    $table   = Engine_Api::_()->getDbTable('videos', 'video');
    $select = new Zend_Db_Select($table->getAdapter());
    $select->from($table->info('name'), 'COUNT(*) AS count');
    $event->addResponse($select->query()->fetchColumn(0), 'video');
  }

  public function onUserDeleteBefore($event)
  {
    $payload = $event->getPayload();
    if( $payload instanceof User_Model_User ) {
      // Delete videos
      $videoTable = Engine_Api::_()->getDbtable('videos', 'video');
      $videoSelect = $videoTable->select()->where('owner_id = ?', $payload->getIdentity());
      foreach( $videoTable->fetchAll($videoSelect) as $video ) {
        Engine_Api::_()->getApi('core', 'video')->deleteVideo($video);
      }
    }
  }
}
