375 public function &
get($id)
380 if (!empty($this->_cachedModule_mid[$id])) {
381 return $this->_cachedModule_mid[$id];
383 $sql =
'SELECT * FROM '.$this->db->prefix(
'modules').
' WHERE mid = '.$id;
384 if ($result = $this->db->query($sql)) {
385 $numrows = $this->db->getRowsNum($result);
388 $myrow = $this->db->fetchArray($result);
389 $module->assignVars($myrow);
390 $this->_cachedModule_mid[$id] =& $module;
391 $this->_cachedModule_dirname[$module->getVar(
'dirname')] =& $module;
410 $dirname = trim($dirname);
411 $cache = &$this->_cachedModule_dirname;
412 if (!empty($cache[$dirname])) {
413 $ret = $cache[$dirname];
414 } elseif (0 == count($cache)) {
416 $sql =
'SELECT * FROM ' . $db->prefix(
'modules');
417 if ($result = $db->query($sql)) {
418 while ($myrow = $db->fetchArray($result)) {
420 $module->assignVars($myrow);
421 $cache[$myrow[
'dirname']] =& $module;
422 $this->_cachedModule_mid[$myrow[
'mid']] =& $module;
426 if (!empty($cache[$dirname])) {
427 $ret = $cache[$dirname];
448 $trust_dirname =
null;
455 $hasnotification =
null;
457 if (
'xoopsmodule' != strtolower(get_class($module))) {
461 if (!$module->isDirty()) {
464 if (!$module->cleanVars()) {
467 foreach ($module->cleanVars as $k => $v) {
470 if ($module->isNew()) {
472 $mid = $this->db->genId(
'modules_mid_seq');
474 $sql = sprintf(
'INSERT INTO %s (mid, name, version, last_update, weight, isactive, dirname, trust_dirname, role, hasmain, hasadmin, hassearch, hasconfig, hascomments, hasnotification) VALUES (%u, %s, %u, %u, %u, %u, %s, %s, %s, %u, %u, %u, %u, %u, %u)', $this->db->prefix(
'modules'), $mid, $this->db->quoteString($name), $version, time(), $weight, 1, $this->db->quoteString($dirname), $this->db->quoteString($trust_dirname), $this->db->quoteString($role), $hasmain, $hasadmin, $hassearch, $hasconfig, $hascomments, $hasnotification);
476 $sql = sprintf(
'UPDATE %s SET name = %s, dirname = %s, trust_dirname = %s, role = %s, version = %u, last_update = %u, weight = %u, isactive = %u, hasmain = %u, hasadmin = %u, hassearch = %u, hasconfig = %u, hascomments = %u, hasnotification = %u WHERE mid = %u', $this->db->prefix(
'modules'), $this->db->quoteString($name), $this->db->quoteString($dirname), $this->db->quoteString($trust_dirname), $this->db->quoteString($role), $version, time(), $weight, $isactive, $hasmain, $hasadmin, $hassearch, $hasconfig, $hascomments, $hasnotification, $mid);
478 if (!$result = $this->db->query($sql)) {
483 $mid = $this->db->getInsertId();
485 $module->assignVar(
'mid', $mid);
486 if (!empty($this->_cachedModule_dirname[$dirname])) {
487 unset($this->_cachedModule_dirname[$dirname]);
489 if (!empty($this->_cachedModule_mid[$mid])) {
490 unset($this->_cachedModule_mid[$mid]);
493 $this->_cachedModule_dirname[$dirname] = $module;
494 $this->_cachedModule_mid[$mid] =& $this->_cachedModule_dirname[$dirname];
496 if (XC_CLASS_EXISTS(
'Legacy_AdminSideMenu')) {
497 Legacy_AdminSideMenu::clearCache();
509 public function delete(&$module)
511 if (
'xoopsmodule' != strtolower(get_class($module))) {
514 $sql = sprintf(
'DELETE FROM %s WHERE mid = %u', $this->db->prefix(
'modules'), $module->getVar(
'mid'));
515 if (!$result = $this->db->query($sql)) {
519 $sql = sprintf(
"DELETE FROM %s WHERE gperm_name = 'module_admin' AND gperm_itemid = %u", $this->db->prefix(
'group_permission'), $module->getVar(
'mid'));
520 $this->db->query($sql);
522 $sql = sprintf(
"DELETE FROM %s WHERE gperm_name = 'module_read' AND gperm_itemid = %u", $this->db->prefix(
'group_permission'), $module->getVar(
'mid'));
523 $this->db->query($sql);
525 if (1 == $module->getVar(
'mid')) {
526 $sql = sprintf(
"DELETE FROM %s WHERE gperm_name = 'system_admin'", $this->db->prefix(
'group_permission'));
528 $sql = sprintf(
'DELETE FROM %s WHERE gperm_modid = %u', $this->db->prefix(
'group_permission'), $module->getVar(
'mid'));
530 $this->db->query($sql);
532 $sql = sprintf(
'SELECT block_id FROM %s WHERE module_id = %u', $this->db->prefix(
'block_module_link'), $module->getVar(
'mid'));
533 if ($result = $this->db->query($sql)) {
535 while ($myrow = $this->db->fetchArray($result)) {
536 array_push($block_id_arr, $myrow[
'block_id']);
540 if (isset($block_id_arr)) {
541 foreach ($block_id_arr as $i) {
542 $sql = sprintf(
'SELECT block_id FROM %s WHERE module_id != %u AND block_id = %u', $this->db->prefix(
'block_module_link'), $module->getVar(
'mid'), $i);
543 if ($result2 = $this->db->query($sql)) {
544 if (0 < $this->db->getRowsNum($result2)) {
546 $sql = sprintf(
'DELETE FROM %s WHERE (module_id = %u) AND (block_id = %u)', $this->db->prefix(
'block_module_link'), $module->getVar(
'mid'), $i);
547 $this->db->query($sql);
550 $sql = sprintf(
'UPDATE %s SET visible = 0 WHERE bid = %u', $this->db->prefix(
'newblocks'), $i);
551 $this->db->query($sql);
552 $sql = sprintf(
'UPDATE %s SET module_id = -1 WHERE module_id = %u', $this->db->prefix(
'block_module_link'), $module->getVar(
'mid'));
553 $this->db->query($sql);
559 if (!empty($this->_cachedModule_dirname[$module->getVar(
'dirname')])) {
560 unset($this->_cachedModule_dirname[$module->getVar(
'dirname')]);
562 if (!empty($this->_cachedModule_mid[$module->getVar(
'mid')])) {
563 unset($this->_cachedModule_mid[$module->getVar(
'mid')]);
575 public function &
getObjects($criteria =
null, $id_as_key =
false)
580 $sql =
'SELECT * FROM '.$db->prefix(
'modules');
581 if (isset($criteria) && $criteria instanceof \criteriaelement) {
582 $sql .=
' '.$criteria->renderWhere();
584 if (
null != $criteria->getSort()) {
585 $sql .=
' ORDER BY '.$criteria->getSort().
' '.$criteria->getOrder();
587 $sql .=
' ORDER BY weight '.$criteria->getOrder().
', mid ASC';
590 $limit = $criteria->getLimit();
591 $start = $criteria->getStart();
593 $result = $db->query($sql, $limit, $start);
597 while ($myrow = $db->fetchArray($result)) {
598 $mid = $myrow[
'mid'];
599 if (isset($this->_cachedModule_mid[$mid])) {
600 $module = $this->_cachedModule_mid[$mid];
603 $module->assignVars($myrow);
604 $this->_cachedModule_mid[$mid] = $module;
605 $this->_cachedModule_dirname[$myrow[
'dirname']] = $module;
610 $ret[$mid] =& $module;