<?php
/* This file has been auto-generated. Do not edit this file directly. */
namespace SabaiApps\Directories\Component\Notification\Model\Base;

use SabaiApps\Framework\Model\Model;

abstract class NotificationGateway extends \SabaiApps\Framework\Model\AbstractGateway {

	public function getName() {
		return 'notification_notification';
	}

	public function getFields() {
		return array(
			'notification_event'   => Model::KEY_TYPE_VARCHAR,
			'notification_system'  => Model::KEY_TYPE_INT,
			'notification_active'  => Model::KEY_TYPE_INT,
			'notification_data'    => Model::KEY_TYPE_TEXT,
			'notification_id'      => Model::KEY_TYPE_INT,
			'notification_created' => Model::KEY_TYPE_INT,
			'notification_updated' => Model::KEY_TYPE_INT,
		);
	}

	protected function _getIdFieldName() {
		return 'notification_id';
	}

	protected function _getSelectByIdQuery( $id, $fields ) {
		return sprintf(
			'SELECT %s FROM %snotification_notification WHERE notification_id = %d',
			empty( $fields ) ? '*' : implode( ', ', $fields ),
			$this->_db->getResourcePrefix(),
			$id
		);
	}

	protected function _getSelectByIdsQuery( $ids, $fields ) {
		return sprintf(
			'SELECT %s FROM %snotification_notification WHERE notification_id IN (%s)',
			empty( $fields ) ? '*' : implode( ', ', $fields ),
			$this->_db->getResourcePrefix(),
			implode( ', ', array_map( 'intval', $ids ) )
		);
	}

	protected function _getSelectByCriteriaQuery( $criteriaStr, $fields ) {
		return sprintf(
			'SELECT %1$s FROM %2$snotification_notification notification_notification WHERE %3$s',
			empty( $fields ) ? '*' : implode( ', ', $fields ),
			$this->_db->getResourcePrefix(),
			$criteriaStr
		);
	}

	protected function _getInsertQuery( &$values ) {
		$values['notification_created'] = time();
		$values['notification_updated'] = 0;
		return sprintf( 'INSERT INTO %snotification_notification(notification_event, notification_system, notification_active, notification_data, notification_id, notification_created, notification_updated) VALUES(%s, %d, %d, %s, %s, %d, %d)', $this->_db->getResourcePrefix(), $this->_db->escapeString( $values['notification_event'] ), $values['notification_system'], $values['notification_active'], $this->_db->escapeString( serialize( $values['notification_data'] ) ), empty( $values['notification_id'] ) ? 'NULL' : intval( $values['notification_id'] ), $values['notification_created'], $values['notification_updated'] );
	}

	protected function _getUpdateQuery( $id, $values ) {
		$last_update                    = $values['notification_updated'];
		$values['notification_updated'] = time();
		return sprintf( 'UPDATE %snotification_notification SET notification_event = %s, notification_system = %d, notification_active = %d, notification_data = %s, notification_updated = %d WHERE notification_id = %d AND notification_updated = %d', $this->_db->getResourcePrefix(), $this->_db->escapeString( $values['notification_event'] ), $values['notification_system'], $values['notification_active'], $this->_db->escapeString( serialize( $values['notification_data'] ) ), $values['notification_updated'], $id, $last_update );
	}

	protected function _getDeleteQuery( $id ) {
		return sprintf( 'DELETE FROM %1$snotification_notification WHERE notification_id = %2$d', $this->_db->getResourcePrefix(), $id );
	}

	protected function _getUpdateByCriteriaQuery( $criteriaStr, $sets ) {
		$sets['notification_updated'] = 'notification_updated=' . time();
		return sprintf( 'UPDATE %snotification_notification notification_notification SET %s WHERE %s', $this->_db->getResourcePrefix(), implode( ', ', $sets ), $criteriaStr );
	}

	protected function _getDeleteByCriteriaQuery( $criteriaStr ) {
		return sprintf( 'DELETE notification_notification FROM %1$snotification_notification notification_notification WHERE %2$s', $this->_db->getResourcePrefix(), $criteriaStr );
	}

	protected function _getCountByCriteriaQuery( $criteriaStr ) {
		return sprintf( 'SELECT COUNT(*) FROM %1$snotification_notification notification_notification WHERE %2$s', $this->_db->getResourcePrefix(), $criteriaStr );
	}
}
