* @since Version 2.0 */ class sysTranslationsModule { public $db; /** * Class constructor */ public function __construct() { $this->db = cDb::getInstance(); } /** * Function to get module records * * @author Mareks Keišs * @category sysTranslations Module * @param string $where - sql query * @param string $sort - sql query * @param int $offset - db table offset * @param int $limitPerPage - limit per page * @return array of data * @version 1.1 */ public function getModuleRecords($where, $sort, $offset = 0, $limitPerPage = 20){ $sSql = " SELECT SQL_CALC_FOUND_ROWS DISTINCT msg.id, msg.msg_message FROM site_cms_msg msg LEFT JOIN site_cms_msg_translations msgt ON msgt.msg_id = msg.id WHERE 1 {$where} ORDER BY {$sort} LIMIT {$offset}, {$limitPerPage} "; $this->db->query($sSql); return $this->db->getArray(); } /** * Function to add or save record data * * @author Mareks Keišs * @category sysTranslations Module * @param int $id - record id for update * @param array $data - record data * @return boot record new/old id * @version 1.1 */ public function saveRecordDataById($id, $data){ if($id){ if(!$this->db->_queryUpdate('site_menus', $data, array('id' => $id))){ return false; } }else{ if(!($id = $this->db->_queryInsert('site_menus', $data))){ return false; } } return $id; } /** * Function to get record data by id * * @author Mareks Keišs * @category sysTranslations Module * @param int $id - record id * @return array - record data * @version 1.1 */ public function getRecordDataById($id){ return $this->db->_querySelectRow('site_cms_msg', false, array('id' => $id)); } /** * Function to get system languages array * * @author Mareks Keišs * @category sysTranslations Module * @return array - record data * @version 1.1 */ public function getSysLanguages(){ return $this->db->_querySelect('site_languages', false, array('type' => 1), array('site_languages.order' => 'ASC')); } /** * Function to get record translation data * * @author Mareks Keišs * @category sysTranslations Module * @param int $msgId - message record id * @return array - record data * @version 1.1 */ public function getRecordTranslationsById($msgId){ $sSql = " SELECT msgt.msg_lang_id, msgt.msg_translation FROM site_cms_msg_translations msgt WHERE msgt.msg_id = " . $this->db->prepData($msgId) . " "; $this->db->query($sSql); return $this->db->getFieldBasedArray('msg_lang_id'); } /** * Function to delete all table records form db * * @author Mareks Keišs * @category sysTranslations Module * @return bool true / false * @version 1.1 */ public function deleteAllRecords(){ $this->db->execute("DELETE FROM `temp_cms_msg_links`"); $this->db->execute("DELETE FROM `site_cms_msg_translations`"); return $this->db->execute("DELETE FROM `site_cms_msg`"); } /** * Function to delete table records form db * * @author Mareks Keišs * @category sysTranslations Module * @param array $ids - record ids to delete * @return bool true / false * @version 1.1 */ public function deleteRecords($ids){ $ids = implode(',', $ids); $this->db->execute("DELETE FROM `temp_cms_msg_links` WHERE `msg_id` IN ({$ids})"); $this->db->execute("DELETE FROM `site_cms_msg_translations` WHERE `msg_id` IN ({$ids})"); return $this->db->execute("DELETE FROM `site_cms_msg` WHERE `id` IN ({$ids})"); } /** * Function to update message translations * * @author Mareks Keišs * @category sysTranslations Module * @param int $msgId - record id * @param array $translations - record translations * @return bool true / false * @version 1.1 */ public function updateTranslations($msgId, $translations){ $this->db->_queryDelete('site_cms_msg_translations', array('msg_id' => $msgId)); return $this->db->_queryInsertArray('site_cms_msg_translations', $translations, false, true); } /** * Function to change record status in db table * * @author Mareks Keišs * @category sysTranslations Module * @param array $ids - record ids to affect * @param string $field - field to update for status ENUM * @return bool true / false * @version 1.1 */ public function changeRecordsStatus($ids, $field){ $time = time(); $ids = implode(',', $ids); $status = $this->db->query("UPDATE site_menus msg SET {$field} = '1', menu_modified = '{$time}' WHERE {$field} = '0' AND id IN ({$ids})"); if(!$status) return $status; $status = $this->db->query("UPDATE site_menus msg SET {$field} = '0', menu_modified = '{$time}' WHERE {$field} = '1' AND id IN ({$ids}) AND menu_modified <> '{$time}'"); return $status; } public function getMaxId(){ $this->db->query("SELECT MAX(id) FROM site_cms_msg"); return $this->db->getOne(); } /** * Function to add or save classificator row record data * * @author Mareks Keišs * @category CMS cmsClassificators * @param array/string $msg * @return array * @version 1.1 */ public function getMsgIdsByMsg($msg){ $sSql = " SELECT id, msg_message FROM site_cms_msg WHERE msg_message IN ('" . implode("','", $this->db->prepData($msg, true)) . "') "; $this->db->query($sSql); return $this->db->getArray(); } public function truncateTable($table){ $this->db->execute("TRUNCATE TABLE {$table}"); } /** * Function to add or save classificator row record data * * @author Mareks Keišs * @category CMS cmsClassificators * @param string $table - table name * @param array $data - import data * @param array|bool $where - condition for removal * @return bool record new/old id * @version 1.1 */ public function saveTableImportData($table, $data, $where = false){ if(!!$where && is_array($where)) $this->db->_queryDelete($table, $where); $this->db->_queryInsertArray($table, $data, false, true); } /** * Function to get data by query and limit * * @author Mareks Keišs * @category APP pubLogistics * @param string $sQuery - route id * @param int $offset - route data * @param int $chunkSize - route data * @return array - record data * @version 1.1 */ public function getDataByQueryAndOffset($sQuery, $offset = 0, $chunkSize = 0){ if(!!$sQuery){ $this->db->query(" {$sQuery} LIMIT {$offset}, {$chunkSize} "); return $this->db->getArray(); } return false; } }