'ets_rv_activity', 'primary' => 'id_ets_rv_activity', 'fields' => array( 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'id_guest' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'employee' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'type' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 54), 'action' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 54), 'id_ets_rv_product_comment' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'id_ets_rv_comment' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'id_ets_rv_reply_comment' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'read' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'content' => array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml', 'size' => '65535'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), ), ); public static function getActivitiesFromID($from_id = 0, $exclude_id_employee = 0) { if ($from_id == '' || !Validate::isUnsignedInt($from_id)) { $from_id = 0; } $dq = new DbQuery(); $dq ->select('COUNT(id_ets_rv_activity)') ->from('ets_rv_activity') ->where('id_ets_rv_activity > ' . (int)$from_id); if ($exclude_id_employee > 0) { $dq ->where('employee!=' . (int)$exclude_id_employee); } return Db::getInstance()->getValue($dq); } public static function getLastID() { $dq = new DbQuery(); $dq->select('id_ets_rv_activity') ->from('ets_rv_activity') ->orderBy('id_ets_rv_activity DESC'); return Db::getInstance()->getValue($dq); } public static function makeRead($id_employee, $id) { return Db::getInstance()->execute('INSERT IGNORE INTO `' . _DB_PREFIX_ . 'ets_rv_staff_activity` VALUES(' . (int)$id_employee . ', ' . (int)$id . ', 1);'); } public static function makeReadAll($id_employee, $ids) { $queries = []; if ($ids) { foreach ($ids as $id) $queries[] = '(' . (int)$id_employee . ', ' . (int)$id . ', 1)'; } return count($queries) > 0 && Db::getInstance()->execute('INSERT IGNORE INTO `' . _DB_PREFIX_ . 'ets_rv_staff_activity` VALUES' . implode(',', $queries) . ';'); } public static function makeReadLastViewer($id_employee, $id_ets_rv_activity) { if (!$id_ets_rv_activity || !Validate::isUnsignedInt($id_ets_rv_activity) || !$id_employee || !Validate::isUnsignedInt($id_employee)) return false; return Db::getInstance()->execute(' INSERT IGNORE INTO `' . _DB_PREFIX_ . 'ets_rv_staff_activity` (`id_employee`, `id_ets_rv_activity`, `read`) SELECT \'' . (int)$id_employee . '\' as `id_employee`, a.`id_ets_rv_activity`, \'1\' as `read` FROM `' . _DB_PREFIX_ . 'ets_rv_activity` a LEFT JOIN `' . _DB_PREFIX_ . 'ets_rv_staff_activity` sa ON (sa.`id_ets_rv_activity` = a.`id_ets_rv_activity` AND sa.`id_employee` = ' . (int)$id_employee . ') WHERE a.`id_ets_rv_activity` <= ' . (int)$id_ets_rv_activity . ' AND sa.`id_ets_rv_activity` is NULL '); } public static function deleteAll($question = 0) { return Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'ets_rv_activity` WHERE `id_ets_rv_product_comment` IN (SELECT `id_ets_rv_product_comment` FROM `' . _DB_PREFIX_ . 'ets_rv_product_comment` WHERE `question`=' . (int)$question . ')'); } }