/**
  * Получение экземпляра себя (Реализация синглетона)
  *
  * @return _Core_ObjectWatcher
  * @example $m = _Core_ObjectWatcher::getInstance();
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
示例#2
0
 public function __set($variable, $value)
 {
     if (array_key_exists($variable, $this->fields)) {
         $this->durty = true;
         _Core_ObjectWatcher::addDirty($this);
         $this->fields[$variable] = $value;
     }
 }
示例#3
0
        $templateEngine->display('index.html');
    } else {
        if (!IS_DEMO) {
            // Если пользователь зашёл с мобильного браузера
            if (_Core_Request::getCurrent()->host . '/' != HOST_ROOT_PDA && Helper_DetectBrowser::detectMobile() && !isset($_COOKIE['DO_WHANT_FULL_VERSION'])) {
                if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], HOST_ROOT_PDA) === false) {
                    header('Location: ' . URL_ROOT_PDA);
                    exit;
                } else {
                    setcookie('DO_WHANT_FULL_VERSION', true);
                }
            }
        }
        $templateEngine->display('index.html');
    }
    // Применение модификаций\удалений моделей
    _Core_ObjectWatcher::getInstance()->performOperations();
} catch (Exception $e) {
    // Вывод отладочной информации
    if (DEBUG) {
        if (strtolower(ini_get('html_errors')) == 'on') {
            highlight_string("<?php\n #" . $e->getMessage() . "\n\n in " . $e->getFile() . ':' . $e->getLine() . "\n\n" . $e->getTraceAsString());
        } else {
            print $e->getMessage() . "\n\n in " . $e->getFile() . ':' . $e->getLine() . "\n\n" . $e->getTraceAsString();
        }
    } elseif ('/notfound' == $request->uri) {
        //exit();
    } else {
        _Core_Router::redirect('/notfound', false, 404);
    }
}
示例#4
0
 /**
  * При завершении работы, контроллера
  */
 function __destruct()
 {
     if (!session_id()) {
         session_start();
     }
     // Применение модификаций\удалений моделей (после внедрения TemplateEngine_Json - удалить)
     _Core_ObjectWatcher::getInstance()->performOperations();
     $user = Core::getInstance()->user;
     $this->addToRes('errors', Core::getInstance()->errors);
     //@TODO Удалить потом
     $res = $this->getRes();
     if (isset($_SESSION['resultMessage'])) {
         if (isset($_SESSION['messageSend'])) {
             $res['result'] = array('text' => $_SESSION['resultMessage']);
             unset($_SESSION['resultMessage'], $_SESSION['messageSend']);
         } else {
             $_SESSION['messageSend'] = true;
         }
     }
     if (isset($_SESSION['errorMessage'])) {
         if (isset($_SESSION['errorMessage'])) {
             $res['result'] = array('text' => $_SESSION['errorMessage']);
             unset($_SESSION['errorMessage'], $_SESSION['messageSend']);
         } else {
             $_SESSION['messageSend'] = true;
         }
     }
     if (is_null($user->getId())) {
         $this->tpl->assign('res', $res);
         return false;
     }
     /**
      * Счета
      */
     $accountModel = new Account_Model();
     $accounts = $accountModel->loadAllWithStat($user->getId());
     //Подготавливаем Часто используемые счета
     $oftenAccounts = array();
     $oftenAccount = array();
     foreach ($accounts as $k => $v) {
         $op = new Operation_Model();
         $oftenAccounts[$k] = $op->getNumOfOperationOnAccount($k);
     }
     arsort($oftenAccounts);
     $num = 0;
     foreach ($oftenAccounts as $k => $v) {
         if ($num < 3) {
             $oftenAccount[$k] = $oftenAccounts[$k];
             $num++;
         }
     }
     // Подготавливаем фин.цели
     $targets = array();
     try {
         $targ = $user->getUserTargets();
     } catch (Exception $e) {
         $targ = 0;
     }
     try {
         $info = new Info_Model();
         $infoa = $info->get_data();
     } catch (Exception $e) {
         $infoa = array();
     }
     try {
         $category = new Category_Model();
         $cats = $category->getCategory();
         $cats['recent'] = get_recent_category(10, 0);
     } catch (Exception $e) {
         $cats = null;
     }
     /**
      * Валюты
      */
     $ex = sfConfig::get('ex');
     $userDefaultCurrency = $user->getUserProps('user_currency_default');
     $userCurrencies = array();
     // Все валюты пользователя по курсу к базовой
     foreach ($user->getUserCurrency() as $currencyItem) {
         $userCurrencies[$currencyItem['id']] = array('cost' => number_format($ex->getRate($currencyItem['id'], $userDefaultCurrency), 4, '.', ''), 'name' => $currencyItem['charCode'], 'text' => $currencyItem['abbr']);
     }
     $userCurrencies['default'] = (int) $userDefaultCurrency;
     //валюта по умолчанию
     /**
      * Res
      */
     $res = array_merge($res, array('getNotify' => @$_SESSION['user']['getNotify'], 'tags' => $user->getUserTags(), 'cloud' => $user->getUserTags(true), 'calendar' => array('overdue' => Core::getInstance()->user->getUserEvents('overdue'), 'calendar' => Core::getInstance()->user->getUserEvents('calendar'), 'future' => Core::getInstance()->user->getUserEvents('reminder')), 'accounts' => $accounts, 'accountsRecent' => $oftenAccount, 'user_targets' => $targ['user_targets'], 'popup_targets' => $targ['pop_targets'], 'currency' => $userCurrencies, 'flash' => array('title' => '', 'value' => isset($infoa[0][0]) ? $infoa[0][0] : 0), 'targets_category' => array('1' => 'Квартира', '2' => 'Автомобиль', '3' => 'Отпуск', '4' => 'Финансовая подушка', '6' => 'Свадьба', '7' => 'Бытовая техника', '8' => 'Компьютер', '5' => 'Прочее'), 'errors' => Core::getInstance()->errors, 'budget' => Core::getInstance()->user->getUserBudget(), 'category' => $cats, 'informers' => $infoa));
     if (Core::getInstance()->user->getId() > 0) {
         $res['user'] = array('name' => Core::getInstance()->user->getName());
     }
     $this->tpl->assign('res', $res);
 }