/**
  * Получить настройку по псевдониму или ключевому полю
  *
  * @param $key
  * @return CSetting
  */
 public static function getSetting($key)
 {
     if (is_string($key)) {
         $key = strtoupper($key);
     }
     $cacheKey = CACHE_APPLICATION_SETTINGS . '_' . $key;
     if (!CApp::getApp()->cache->hasCache($cacheKey)) {
         $found = false;
         if (is_string($key)) {
             foreach (CActiveRecordProvider::getWithCondition(TABLE_SETTINGS, "UPPER(alias) = '" . $key . "'")->getItems() as $item) {
                 $found = true;
                 $setting = new CSetting($item);
                 CApp::getApp()->cache->set(CACHE_APPLICATION_SETTINGS . '_' . $setting->getId(), $setting);
                 CApp::getApp()->cache->set($cacheKey, $setting);
             }
         } elseif (is_numeric($key)) {
             $item = CActiveRecordProvider::getById(TABLE_SETTINGS, $key);
             if (!is_null($item)) {
                 $found = true;
                 $setting = new CSetting($item);
                 CApp::getApp()->cache->set(CACHE_APPLICATION_SETTINGS . '_' . $setting->alias, $setting);
                 CApp::getApp()->cache->set($cacheKey, $setting);
             }
         }
         if (!$found) {
             CApp::getApp()->cache->set($cacheKey, null);
         }
     }
     return CApp::getApp()->cache->get($cacheKey);
 }
Пример #2
0
 /**
  * Магический метод получения любых классов
  *
  * @param $name
  * @param array $params
  * @throws Exception
  */
 public static function __callStatic($name, $params = array())
 {
     /**
      * Получаем имя класса из имени функции
      */
     $className = "C" . CUtils::strRight($name, "get");
     if (!class_exists($className)) {
         throw new Exception("В приложении не объявлен класс " . $className);
     }
     /**
      * @var CActiveModel $simpleClass
      */
     $simpleClass = new $className();
     $table = $simpleClass->getRecord()->getTable();
     $id = $params[0];
     /**
      * Попробуем сначала получить из кэша
      */
     $keySeek = $table . "_" . $id;
     if (CApp::getApp()->cache->hasCache($keySeek)) {
         return CApp::getApp()->cache->get($keySeek);
     }
     $ar = CActiveRecordProvider::getById($table, $id);
     if (!is_null($ar)) {
         $obj = new $className($ar);
         CApp::getApp()->cache->set($keySeek, $obj, 60);
         return $obj;
     }
 }
Пример #3
0
 /**
  * Ресурс, к которому календарь привязан
  *
  * @return CResource
  */
 public function getResource()
 {
     if (is_null($this->_resource)) {
         $ar = CActiveRecordProvider::getById(TABLE_RESOURCES, $this->getResourceId());
         $this->_resource = new CResource($ar);
     }
     return $this->_resource;
 }
 /**
  * @param $id
  * @return CWorkPlanCompetention
  */
 public static function getWorkplanCompetention($id)
 {
     $competention = null;
     $ar = CActiveRecordProvider::getById(TABLE_WORK_PLAN_COMPETENTIONS, $id);
     if (!is_null($ar)) {
         $competention = new CWorkPlanCompetention($ar);
     }
     return $competention;
 }
 /**
  * @static
  * @param $key
  * @return CSEBTicket
  */
 public static function getTicket($key)
 {
     if (!self::getCacheTickets()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_SEB_TICKETS, $key);
         if (!is_null($ar)) {
             $ticket = new CSEBTicket($ar);
             self::getCacheTickets()->add($ticket->getId(), $ticket);
         }
     }
     return self::getCacheTickets()->getItem($key);
 }
Пример #6
0
 /**
  * @param $key
  * @return CRate
  */
 public static function getRate($key)
 {
     if (!self::getCacheRates()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_RATES, $key);
         if (!is_null($ar)) {
             $rate = new CRate($ar);
             self::addToCache($rate);
         }
     }
     return self::getCacheRates()->getItem($key);
 }
Пример #7
0
 /**
  * @param $key
  * @return CNewsItem
  */
 public static function getNewsItem($key)
 {
     if (!self::getCacheNews()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_NEWS, $key);
         if (!is_null($ar)) {
             $newsItem = new CNewsItem($ar);
             self::getCacheNews()->add($newsItem->getId(), $newsItem);
         }
     }
     return self::getCacheNews()->getItem($key);
 }
 public static function getBiography($key)
 {
     if (!self::getCacheBiographys()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_BIOGRAPHY, $key);
         if (!is_null($ar)) {
             $biography = new CBiography($ar);
             self::getCacheBiographys()->add($biography->getId(), $biography);
         }
     }
     return self::getCacheBiographys()->getItem($key);
 }
 /**
  * Дисциплина с поиском и кэшем
  *
  * @static
  * @param $key
  * @return CDiscipline
  */
 public static function getDiscipline($key)
 {
     if (!self::getCacheDisciplines()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_DISCIPLINES, $key);
         if (!is_null($ar)) {
             $disc = new CDiscipline($ar);
             self::getCacheDisciplines()->add($disc->getId(), $disc);
         }
     }
     return self::getCacheDisciplines()->getItem($key);
 }
Пример #10
0
 /**
  * Пункт меню с кэшем
  *
  * @static
  * @param $key
  * @return CMenuItem
  */
 public static function getMenuItem($key)
 {
     if (!self::getCacheItems()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_MENU_ITEMS, $key);
         if (!is_null($ar)) {
             $item = new CMenuItem($ar);
             self::getCacheItems()->add($item->getId(), $item);
         }
     }
     return self::getCacheItems()->getItem($key);
 }
 public static function getQuestion($key)
 {
     if (!self::getCacheQuestion()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_QUESTION_TO_USERS, $key);
         if (!is_null($ar)) {
             $quest = new CQuestion($ar);
             self::getCacheQuestion()->add($quest->getId(), $quest);
         }
     }
     return self::getCacheQuestion()->getItem($key);
 }
 /**
  * @param $key
  * @return CDashboardReport
  */
 public static function getDashboardReport($key)
 {
     if (!self::getCacheDashboardReports()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_DASHBOARD_REPORTS, $key);
         if (!is_null($ar)) {
             $obj = new CDashboardReport($ar);
             self::getCacheDashboardReports()->add($key, $obj);
         }
     }
     return self::getCacheDashboardReports()->getItem($key);
 }
Пример #13
0
 public static function getPage($key)
 {
     if (!self::getCachePages()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_PAGES, $key);
         if (!is_null($ar)) {
             $page = new CPage($ar);
             self::getCachePages()->add($page->getId(), $page);
         }
     }
     return self::getCachePages()->getItem($key);
 }
 /**
  * Экзаменационный вопрос с учетом кэша
  *
  * @static
  * @param $key
  * @return CSebQuestion
  */
 public static function getQuestion($key)
 {
     if (!self::getCacheQuestions()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_SEB_QUESTIONS, $key);
         if (!is_null($ar)) {
             $q = new CSEBQuestion($ar);
             self::getCacheQuestions()->add($q->getId(), $q);
         }
     }
     return self::getCacheQuestions()->getItem($key);
 }
 /**
  * @param int $key
  * @return CDocumentFolder
  */
 public static function getFolder($key = 0)
 {
     if (!self::getCacheFolders()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_DOCUMENT_FOLDERS, $key);
         if (!is_null($ar)) {
             $obj = new CDocumentFolder($ar);
             self::getCacheFolders()->add($key, $obj);
         }
     }
     return self::getCacheFolders()->getItem($key);
 }
 /**
  * @param $key
  * @return CLibraryDocument
  */
 public static function getDocument($key)
 {
     if (!self::getCacheDocuments()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_LIBRARY_DOCUMENTS, $key);
         if (!is_null($ar)) {
             $doc = new CLibraryDocument($ar);
             self::getCacheDocuments()->add($doc->getId(), $doc);
             self::getCacheDocuments()->add("folder_" . $doc->getFolderId(), $doc);
         }
     }
     return self::getCacheDocuments()->getItem($key);
 }
 /**
  * @static
  * @param $key
  * @return CNotificationTemplate
  */
 public static function getTemplate($key)
 {
     if (!self::getCacheTemplates()->hasElement($key)) {
         if (is_numeric($key)) {
             $item = CActiveRecordProvider::getById(TABLE_NOTIFICATION_TEMPLATES, $key);
             if (!is_numeric($item)) {
                 $template = new CNotificationTemplate($item);
                 self::getCacheTemplates()->add($template->getId(), $template);
                 self::getCacheTemplates()->add($template->alias, $template);
             }
         } else {
             foreach (CActiveRecordProvider::getWithCondition(TABLE_NOTIFICATION_TEMPLATES, "alias='" . $key . "'")->getItems() as $item) {
                 $template = new CNotificationTemplate($item);
                 self::getCacheTemplates()->add($template->getId(), $template);
                 self::getCacheTemplates()->add($template->alias, $template);
             }
         }
     }
     return self::getCacheTemplates()->getItem($key);
 }
 /**
  * Получить настройку по псевдониму или ключевому полю
  *
  * @param $key
  * @return CSetting
  */
 public static function getSetting($key)
 {
     if (is_string($key)) {
         $key = strtoupper($key);
     }
     if (!self::getCacheSettings()->hasElement($key)) {
         if (is_string($key)) {
             foreach (CActiveRecordProvider::getWithCondition(TABLE_SETTINGS, "UPPER(alias) = '" . $key . "'")->getItems() as $item) {
                 $setting = new CSetting($item);
                 self::getCacheSettings()->add($setting->getId(), $setting);
                 self::getCacheSettings()->add($key, $setting);
             }
         } elseif (is_numeric($key)) {
             $item = CActiveRecordProvider::getById(TABLE_SETTINGS, $key);
             if (!is_null($item)) {
                 $setting = new CSetting($item);
                 self::getCacheSettings()->add(strtoupper($setting->alias), $setting);
                 self::getCacheSettings()->add($key, $setting);
             }
         }
     }
     return self::getCacheSettings()->getItem($key);
 }
 /**
  * @param $key
  * @return CIndPlanWorktype
  */
 public static function getWorktype($key)
 {
     if (!self::getCacheWorktypes()->hasElement($key)) {
         $ar = null;
         if (is_numeric($key)) {
             $ar = CActiveRecordProvider::getById(TABLE_IND_PLAN_WORKTYPES, $key);
         }
         if (!is_null($ar)) {
             $worktype = new CIndPlanWorktype($ar);
             self::getCacheWorktypes()->add($worktype->getId(), $worktype);
         }
     }
     return self::getCacheWorktypes()->getItem($key);
 }
 /**
  * @param $key
  * @return CCoreModelTask
  */
 public static function getCoreModelTask($key)
 {
     if (!self::getCacheModelTasks()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_CORE_MODEL_TASKS, $key);
         if (!is_null($ar)) {
             $task = new CCoreModelTask($ar);
             self::getCacheModelTasks()->add($task->getId(), $task);
         }
     }
     return self::getCacheModelTasks()->getItem($key);
 }
 /**
  * Ставка в часах
  *
  * @param $key
  * @return CHoursRate
  */
 public static function getHoursRate($key)
 {
     if (!self::getCacheHoursRate()->hasElement($key)) {
         $item = CActiveRecordProvider::getById(TABLE_HOURS_RATE, $key);
         if (!is_null($item)) {
             $rate = new CHoursRate($item);
             self::getCacheHoursRate()->add($rate->getId(), $rate);
         }
     }
     return self::getCacheHoursRate()->getItem($key);
 }
Пример #22
0
 /**
  * @param $key
  * @return CDiplomPreviewComission
  */
 public static function getPreviewCommission($key)
 {
     if (!self::getCachePreviewCommission()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_DIPLOM_PREVIEW_COMISSIONS, $key);
         if (!is_null($ar)) {
             $comm = new CDiplomPreviewComission($ar);
             self::getCachePreviewCommission()->add($comm->getId(), $comm);
         }
     }
     return self::getCachePreviewCommission()->getItem($key);
 }
Пример #23
0
 /**
  * Страница справочной системы
  *
  * @static
  * @param $key
  * @return CHelp
  */
 public static function getHelp($key)
 {
     if (!self::getCacheHelps()->hasElement($key)) {
         $help = null;
         if (is_numeric($key)) {
             $item = CActiveRecordProvider::getById(TABLE_HELP, $key);
             if (!is_null($item)) {
                 $help = new CHelp($item);
             }
         } elseif (is_string($key)) {
             /**
              * Это поиск справки по названию или адресу страницы. Сделаем допущение, что
              * в названии страницы обычно не упоминается ?, & и .php
              */
             if (strpos($key, "?") !== false || strpos($key, "&") !== false || strpos($key, ".php") !== false) {
                 // это адрес страницы
                 // сначала попробуем найти по полному совпадению
                 foreach (CActiveRecordProvider::getWithCondition(TABLE_HELP, "url = '" . $key . "'")->getItems() as $item) {
                     $help = new CHelp($item);
                 }
                 // если в строке запроса есть параметры, то попробуем по одному их отрубать
                 if (is_null($help)) {
                     while (strpos($key, "&") !== false) {
                         $key = substr($key, 0, strpos($key, "&"));
                         foreach (CActiveRecordProvider::getWithCondition(TABLE_HELP, "url = '" . $key . "'")->getItems() as $item) {
                             $help = new CHelp($item);
                         }
                         // если что-то нашли, то выходим из цикла убирания параметров
                         if (!is_null($help)) {
                             break;
                         }
                     }
                     if (is_null($help)) {
                         if (strpos($key, "php?action") === false || strpos($key, "/?action") === false || strpos($key, "php?action=index") !== false) {
                             $key = substr($key, 0, strpos($key, "?"));
                             foreach (CActiveRecordProvider::getWithCondition(TABLE_HELP, "url = '" . $key . "'")->getItems() as $item) {
                                 $help = new CHelp($item);
                             }
                         }
                     }
                     if (is_null($help)) {
                         foreach (CActiveRecordProvider::getWithCondition(TABLE_HELP, "url = '" . $key . "index.php'")->getItems() as $item) {
                             $help = new CHelp($item);
                         }
                     }
                 }
             } elseif (strpos($key, ".php") === false) {
                 foreach (CActiveRecordProvider::getWithCondition(TABLE_HELP, "url = '" . $key . "'")->getItems() as $item) {
                     $help = new CHelp($item);
                 }
                 if (is_null($help)) {
                     foreach (CActiveRecordProvider::getWithCondition(TABLE_HELP, "url = '" . $key . "index.php'")->getItems() as $item) {
                         $help = new CHelp($item);
                     }
                 }
             } else {
                 // это русское название куска справки
                 if (is_null($help)) {
                     foreach (CActiveRecordProvider::getWithCondition(TABLE_HELP, "title = '" . $key . "'")->getItems() as $item) {
                         $help = new CHelp($item);
                     }
                 }
             }
         }
         if (!is_null($help)) {
             self::getCacheHelps()->add($key, $help);
             self::getCacheHelps()->add($help->getId(), $help);
             self::getCacheHelps()->add($help->url, $help);
             self::getCacheHelps()->add($help->title, $help);
         }
     }
     return self::getCacheHelps()->getItem($key);
 }
 /**
  * @param $key
  * @return CProtocolOpinion
  */
 public static function getProtocolOpinion($key)
 {
     if (!self::getCacheProtocolOpinion()->hasElement($key)) {
         $ar = CActiveRecordProvider::getById(TABLE_PROTOCOL_OPINIONS, $key);
         if (!is_null($ar)) {
             $protocol = new CProtocolOpinion($ar);
             self::getCacheProtocolOpinion()->add($protocol->getId(), $protocol);
         }
     }
     return self::getCacheProtocolOpinion()->getItem($key);
 }
Пример #25
0
 /**
  * @param $key
  * @return CPrintField
  */
 public static function getField($key)
 {
     if (!self::getCacheField()->hasElement($key)) {
         $item = null;
         if (is_numeric($key)) {
             $item = CActiveRecordProvider::getById(TABLE_PRINT_FIELDS, $key);
         } elseif (is_string($key)) {
             foreach (CActiveRecordProvider::getWithCondition(TABLE_PRINT_FIELDS, "LCASE(alias) = '" . mb_strtolower($key) . "'")->getItems() as $i) {
                 $item = $i;
             }
         }
         if (!is_null($item)) {
             $field = new CPrintField($item);
             self::getCacheField()->add($field->getId(), $field);
             self::getCacheField()->add($field->alias, $field);
         }
     }
     return self::getCacheField()->getItem($key);
 }
Пример #26
0
 /**
  * Обновление существующей модели
  */
 private function updateModel()
 {
     // если эта модель поддерживает версионирование,
     // то сначала делаем копию текущей записи, а затем
     // сохраняем данные
     if (is_a($this, "IVersionControl")) {
         $currentAr = CActiveRecordProvider::getById($this->getTable(), $this->getId());
         $currentAr->setItemValue("_version_of", $this->getId());
         $currentAr->setItemValue("_created_at", date('Y-m-d G:i:s'));
         $currentAr->setItemValue("_created_by", CSession::getCurrentPerson()->getId());
         $currentAr->insert();
     }
     $this->getRecord()->update();
 }
Пример #27
0
 /**
  * @static
  * @param $key
  * @return CRatingIndexValue
  */
 public static function getRatingIndexValue($key)
 {
     if (!self::getCacheIndexValues()->hasElement($key)) {
         $item = CActiveRecordProvider::getById(TABLE_RATING_INDEX_VALUES, $key);
         if (!is_null($item)) {
             $obj = new CRatingIndexValue($item);
             self::getCacheIndexValues()->add($key, $obj);
         }
     }
     return self::getCacheIndexValues()->getItem($key);
 }
 /**
  * @param $key
  * @return CCorriculumDisciplineSection|null
  */
 public static function getDisciplineSection($key)
 {
     $ar = CActiveRecordProvider::getById(TABLE_CORRICULUM_DISCIPLINE_SECTIONS, $key);
     $obj = null;
     if (!is_null($ar)) {
         $obj = new CCorriculumDisciplineSection($ar);
     }
     return $obj;
 }
Пример #29
0
 /**
  * История изменений группы у студента
  *
  * @param $key
  * @return CStudentGroupChangeHistory|null
  */
 public static function getStudentGroupChangeHistory($key)
 {
     $history = null;
     $ar = CActiveRecordProvider::getById(TABLE_STUDENT_GROUP_HISTORY, $key);
     if (!is_null($ar)) {
         $history = new CStudentGroupChangeHistory($ar);
     }
     return $history;
 }
 /**
  * Получение данных модели по идентификатору
  */
 private function actionJSONGet()
 {
     // получим название класса модели, которую надо пользователю
     $modelClass = CRequest::getString("model");
     // идентификатор
     $id = CRequest::getInt("id");
     // создадим объект, посмотрим, в какой таблице он весь живет
     /**
      * @var $model CActiveModel
      */
     $model = new $modelClass();
     // проверим, может не реализует нужный интерфейс
     if (!is_a($model, "IJSONSerializable")) {
         throw new Exception("Класс " . $modelClass . " не реализует интерфейс IJSONSerializable");
     }
     $modelTable = $model->getRecord()->getTable();
     // получим из этой таблицы объект
     $ar = CActiveRecordProvider::getById($modelTable, $id);
     if (is_null($ar)) {
         echo json_encode(null);
         return;
     }
     // создадим новый объект указанного типа
     /**
      * @var $model IJSONSerializable
      */
     $model = new $modelClass($ar);
     // получим json объект модели
     $jsonObj = $model->toJsonObject();
     // добавим к json-объекту перевод
     $jsonObj->_translation = CCoreObjectsManager::getAttributeLabels($model);
     // сразу добавим штатную валидацию
     // может, чуть позже, пока нет
     echo json_encode($jsonObj);
 }