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

class Core_Model_DbTable_Emailtemplates extends Core_Model_Item_DbTable_Abstract
{

  protected $_rowClass = "Core_Model_Emailtemplate";

  public function getTemplates($params)
  {
    $tableName = $this->info('name');

    $select = $this->select()->from($tableName);

    if ($params['is_active'] == '1')
      $select->where('is_active = ?', '0');
    elseif ($params['is_active'] == '0')
      $select->where('is_active = ?', '1');

    $select->where('predefined = ?', '0')
            ->order('creation_date ASC');

    if (isset($params['fetchAll'])) {
      return $this->fetchAll($select);
    } else {
      return Zend_Paginator::factory($select);
    }
  }

  public function isEnableTemplate()
  {
    return $this->select()
      ->from($this->info('name'), 'emailtemplate_id')
      ->where('is_active =?', 1)
      ->limit(1)
      ->query()
      ->fetchColumn();
  }
}
