/** * @param CActiveModel $model * @param bool $exportTasks * @param bool $isMain * @return SolrInputDocument */ private static function createSolrInputDocument(CActiveModel $model, $exportTasks = false, $isMain = false) { $doc = new SolrInputDocument(); $doc->addField("id", $model->getRecord()->getTable() . "_" . $model->getId()); $doc->addField("_doc_id_", $model->getId()); /** * Выгружаем дополнительные выгружаемые поля */ $metaModel = CCoreObjectsManager::getCoreModel(get_class($model)); if (!is_null($metaModel)) { foreach ($metaModel->fields->getItems() as $field) { if ($field->isExportable()) { $name = $field->field_name; $doc->addField($name, $model->{$name}); } } } /** * Выгружаем список задач, с которыми связана модель */ if ($exportTasks) { foreach ($metaModel->tasks->getItems() as $task) { $doc->addField("_tasks_", $task->getId()); } } /** * Класс модели */ $doc->addField("_class_", $metaModel->class_name); /** * Модель является основной */ if ($isMain) { $doc->addField("_is_main_", "1"); } else { $doc->addField("_is_main_", "0"); } return $doc; }
public function actionIndex() { $selectedType = null; $set = new CRecordSet(true, true); $query = new CQuery(); $set->setQuery($query); /** * Исходный запрос */ $query->select("person.*")->from(TABLE_PERSON . " as person")->leftJoin(TABLE_PERSON_BY_TYPES . " as types", "types.kadri_id = person.id")->leftJoin(TABLE_TYPES . " as person_types", "types.person_type_id = person_types.id")->leftJoin(TABLE_GENDERS . " as pol", "person.pol = pol.id")->leftJoin(TABLE_TAXONOMY_TERMS . " as term", "person.department_role_id = term.id")->leftJoin(TABLE_LANGUAGES . " as lang", "person.language1 = lang.id")->leftJoin(TABLE_POSTS . " as post", "person.dolgnost = post.id")->leftJoin(TABLE_TITLES . " as zvanie", "person.zvanie = zvanie.id")->leftJoin(TABLE_DEGREES . " as stepen", "person.stepen = stepen.id")->order("person.fio asc"); $isAll = false; if (CRequest::getInt("isAll") == "1") { $isAll = true; } if (CRequest::getInt("type") != 0) { $selectedType = CRequest::getInt("type"); } elseif (!$isAll and is_null(CRequest::getString("filterClass"))) { $query->condition("(types.person_type_id = 1 or types.person_type_id = 3)"); } $typesQuery = new CQuery(); $typesQuery->select("types.*")->from(TABLE_TYPES . " as types")->order("types.name asc"); $types = array(); foreach ($typesQuery->execute()->getItems() as $ar) { $type = new CActiveModel(new CActiveRecord($ar)); $types[$type->getId()] = $type->name; } /** * Набираем выборку */ $persons = new CArrayList(); foreach ($set->getPaginated()->getItems() as $ar) { $person = new CPerson($ar); $persons->add($person->getId(), $person); } $this->setData("paginator", $set->getPaginator()); $this->setData("persons", $persons); $this->setData("types", $types); $this->setData("isAll", $isAll); $this->setData("selectedType", $selectedType); /** * Генерация меню */ $this->addActionsMenuItem(array(array("title" => "Добавить сотрудника", "link" => "index.php?action=add", "icon" => "actions/list-add.png"), array("title" => "Печать по шаблону", "link" => "#", "icon" => "devices/printer.png", "template" => "formset_person"))); /** * Отображение представления */ $this->renderView("_staff/person/index.tpl"); }
public function actionUpdate() { $plan = CWorkPlanManager::getWorkplan(CRequest::getInt("plan_id")); if (!is_null($plan->corriculumDiscipline)) { foreach (CActiveRecordProvider::getWithCondition(TABLE_CORRICULUM_DISCIPLINE_SECTIONS, "discipline_id=" . $plan->corriculumDiscipline->getId())->getItems() as $ar) { $term = new CActiveModel($ar); $object = new CWorkPlanTerm(); $object->plan_id = $plan->getId(); $object->number = $term->getId(); $object->save(); } } $this->redirect("workplanterms.php?action=index&plan_id=" . $plan->getId()); }
/** * Обновление прав доступа к таблице по умолчанию * * @param CActiveModel $model * @param array $entries * @param int $level */ private function updateDefaultAccess(CActiveModel $model, array $entries, $level = 1) { // 1. удаляем старые записи доступа foreach (CActiveRecordProvider::getWithCondition(TABLE_ACL_DEFAULTS, "table_id=" . $model->getId())->getItems() as $item) { $obj = new CActiveModel($item); $obj->remove(); } // 2. создаем новые записи уровня сущностей foreach ($entries["id"] as $key => $value) { $entry = new CActiveModel(); $entry->getRecord()->setTable(TABLE_ACL_DEFAULTS); $entry->table_id = $model->getId(); $entry->level = $level; $entry->entry_type = $entries["type"][$key]; $entry->entry_id = $value; $entry->save(); } }