Files
crm.clientright.ru/modules/Settings/ITS4YouQuickReminder/models/Integration.php

104 lines
2.8 KiB
PHP
Raw Normal View History

<?php
/* * *******************************************************************************
* The content of this file is subject to the ITS4YouQuickReminder license.
* ("License"); You may not use this file except in compliance with the License
* The Initial Developer of the Original Code is IT-Solutions4You s.r.o.
* Portions created by IT-Solutions4You s.r.o. are Copyright(C) IT-Solutions4You s.r.o.
* All Rights Reserved.
* ****************************************************************************** */
class Settings_ITS4YouQuickReminder_Integration_Model extends Vtiger_Base_Model
{
/**
* @var string
*/
public $moduleName;
/**
* @var PearDatabase
*/
public $db;
/**
* @param string $module
* @return Settings_ITS4YouQuickReminder_Integration_Model
* @throws Exception
*/
public static function getInstance($module)
{
$self = new self();
$self->db = PearDatabase::getInstance();
$self->setModuleName($module);
$self->retrieveData();
return $self;
}
public static function isInstalled()
{
$adb = PearDatabase::getInstance();
$result = $adb->query('SELECT * FROM its4you_reminder_settings');
return $adb->num_rows($result);
}
/**
* @throws Exception
*/
public function retrieveData()
{
$result = $this->db->pquery('SELECT * FROM its4you_reminder_settings WHERE module_name=?', array($this->getModuleName()));
$row = $this->db->query_result_rowdata($result);
$this->setData($row);
$this->set('module_name', $this->getModuleName());
}
/**
* @return string
*/
public function getModuleName()
{
return $this->moduleName;
}
/**
* @param string $value
*/
public function setModuleName($value)
{
$this->moduleName = $value;
}
public function save()
{
$params = array($this->get('module_name'), $this->get('active'));
if (!$this->isEmpty('id')) {
array_push($params, $this->get('id'));
$this->db->pquery('UPDATE its4you_reminder_settings SET module_name=?,active=? WHERE id=?', $params);
} else {
$this->db->pquery('INSERT INTO its4you_reminder_settings (module_name, active) VALUES (?,?)', $params);
}
}
public static $activeModules = [];
public static function getActiveModules()
{
if (empty(self::$activeModules)) {
$adb = PearDatabase::getInstance();
$result = $adb->pquery('SELECT module_name FROM its4you_reminder_settings WHERE active=?',
array('1')
);
while ($row = $adb->fetchByAssoc($result)) {
self::$activeModules[] = $row['module_name'];
}
}
return self::$activeModules;
}
}