* @since Version 2.0 */ class sysSiteModulesModule { public $db; /** * Class constructor */ public function __construct() { $this->db = cDb::getInstance(); } /** * Function to get module records * * @author Aivars Žukovskis * @category sysSiteModules * @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 sm.id, sm.mod_class_name, sm.mod_title, sm.mod_db_name, sm.mod_type, sm.mod_modified, sm.mod_created, CONCAT(su.user_name, ' ', su.user_surname) as mod_modified_by, CONCAT(su2.user_name, ' ', su2.user_surname) as mod_created_by FROM sys_modules sm LEFT JOIN site_users su ON sm.mod_modified_by = su.id LEFT JOIN site_users su2 ON sm.mod_created_by = su2.id HAVING 1 {$where} ORDER BY {$sort} LIMIT {$offset}, {$limitPerPage} "; $this->db->query($sSql); return $this->db->getArray(); } /** * Function to add or save data * * @author Aivars Žukovskis * @category sysSiteModules * @param int $id - record id for update * @param array $vData - data to save * @return bool record new/old id * @version 1.1 */ public function saveModuleData($id, $vData){ if($id){ if(!$this->db->_queryUpdate('sys_modules', $vData, array('id' => $id), true)) return false; }else{ if(!($id = $this->db->_queryInsert('sys_modules', $vData, false, true))) return false; } return $id; } /** * Function to check if db table exists * * @author Aivars Žukovskis * @category sysSiteModules * @param string $sName - table name to check * @return bool/string table name * @version 1.1 */ public function checkDbTableExists($sName){ return $this->db->_querySelectOne('INFORMATION_SCHEMA.TABLES', array('TABLE_NAME'), array('TABLE_SCHEMA' => DB_NAME, 'TABLE_NAME' => $sName)); } /** * Function to check if db table exists * * @author Aivars Žukovskis * @category sysSiteModules * @param int $id - record id * @return bool|array - module type * @version 1.1 */ public function getModuleDataById($id){ return $this->db->_querySelectRow('sys_modules', array('mod_title','mod_class_name','mod_db_name', 'mod_p_name','mod_type', 'mod_permission_sql', 'mod_table_sql'), array('id' => $id)); } /** * Function to get record data by id * * @author Aivars Žukovskis * @category sysSiteModules * @param int $id - record id for update * @return bool record new/old id * @version 1.1 */ public function getRecordDataById($id){ return $this->db->_querySelectRow('sys_modules', false, array('id' => $id)); } /** * Function to get records data by ids * * @author Aivars Žukovskis * @category sysSiteModules * @param array $vIds - records ids * @return bool record new/old id * @version 1.1 */ public function getRecordsDataByIds($vIds){ return $this->db->_querySelect('sys_modules', array('mod_class_name', 'mod_type'), array('id' => $vIds)); } /** * Function to get records data by ids * * @author Aivars Žukovskis * @category sysSiteModules * @param array $vIds - records ids * @return bool * @version 1.1 */ public function deleteRecordsByIds($vIds){ return $this->db->_queryDelete('sys_modules', array('id' => $vIds)); } /** * Function to reserve next x ids in table * * @author Aivars Žukovskis * @category sysSiteModules * @param int $resRowsCount - how many rows + 1 dummy * @param string $sTable - table * @param string $sFields - fields * @return bool record highest id to work with * @version 1.1 */ public function rsvTableRows($resRowsCount, $sTable, $sFields){ if($resRowsCount && $resRowsCount > 0 && strlen($sTable) && strlen($sFields)){ $this->db->query(" INSERT INTO {$sTable} ({$sFields}) VALUES ( ( SELECT COALESCE(MAX(tt.id),0)+{$resRowsCount} FROM {$sTable} tt ), -1) "); return $this->db->lastInsertedId(); } return false; } /** * Function to delete table temp data rows * * @author Aivars Žukovskis * @category sysSiteModules * @param $sTable - table * @param $sField - field * @return bool * @version 1.1 */ public function deleteTempRows($sTable, $sField){ if(strlen($sTable) && strlen($sField)) $this->db->_queryDelete($sTable, array($sField => -1)); } /** * Function to insert group * * @author Aivars Žukovskis * @category sysSiteModules * @param array $vData - data to insert * @return bool true / false * @version 1.1 */ public function insertGroup($vData) { return $this->db->_queryInsert('mod_permissions_groups', $vData); } /** * Function to insert multi array in db * * @author Aivars Žukovskis * @category sysSiteModules * @param array $vData - data to insert * @param string $sTable - table, by default its mod permissions * @return bool true / false * @version 1.1 */ public function insertMulti($vData, $sTable = 'mod_permissions') { return $this->db->_queryInsertArray($sTable, $vData); } }