protected function afterSave() { parent::afterSave(); if ($this->isNewRecord) { $idObject = $this->id_object; if ($this->object_type == self::OBJECT_TYPE_TABLE && $this->table_name != "") { // Если создается объект у которого тип=Таблица, то создаем свойство Первичного ключа $p = ObjectParameter::newModel('ObjectParameter'); $p->id_object = $idObject; $p->id_parameter_type = DataType::PRIMARY_KEY; $p->caption = 'id'; $fieldName = 'id_' . str_replace(array('da_', 'pr_'), '', $this->table_name); $p->field_name = $fieldName; $p->id_parameter = $idObject . '-' . str_replace('_', '-', $fieldName); $p->setIsRequired(true); $p->save(); } } else { if ($this->id_object != $this->getPkBeforeSave()) { ObjectParameter::model()->updateAll(array('id_object' => $this->id_object), 'id_object=:obj', array(':obj' => $this->getPkBeforeSave())); ObjectParameter::model()->updateAll(array('add_parameter' => $this->id_object), 'id_parameter_type=7 AND add_parameter=:obj', array(':obj' => $this->getPkBeforeSave())); DaObjectView::model()->updateAll(array('id_object' => $this->id_object), 'id_object=:obj', array(':obj' => $this->getPkBeforeSave())); DaObjectViewColumn::model()->updateAll(array('id_object' => $this->id_object), 'id_object=:obj', array(':obj' => $this->getPkBeforeSave())); File::model()->updateAll(array('id_object' => $this->id_object), 'id_object=:obj', array(':obj' => $this->getPkBeforeSave())); Search::model()->updateAll(array('id_object' => $this->id_object), 'id_object=:obj', array(':obj' => $this->getPkBeforeSave())); } } }
public function processModel(CEvent $event) { /** * @var $model DaObject */ $model = $this->model; $idObject = $model->getIdInstance(); $idView = null; if (HU::post("create_rep") == 1) { //Создать представление с введённым именем $name = trim(HU::post("create_rep_name")); $view = null; if ($name != "") { $view = new DaObjectView(); $id = $idObject . '-view-main'; while (DaObjectView::model()->exists('id_object_view=:id', array(':id' => $id))) { $id = $idObject . '-view-view' . rand(1, 100); } $view->id_object_view = $id; $view->name = $name; $view->id_object = $idObject; $parent = $model->getFieldByType(DataType::ID_PARENT); if ($parent != null) { $view->id_parent = $parent; } //Сортировка $view->sql_order_by = $model->getOrderBy(); $view->save(); $idView = $view->getIdInstance(); } } $columnsForm = HU::post('column'); if (count($columnsForm)) { if (is_null($idView)) { //Свойства стоят, представления нет, приписываем имеющемуся //Если у объекта есть единственное представление, приписываем отмеченные галочки ему $view = DaObjectView::model()->findAll('id_object=:id', array(':id' => $idObject)); if (count($view) != 1) { return; } $idView = $view[0]->getIdInstance(); } //Уже приписанные представлению колонки $already = array(); $columns = DaObjectViewColumn::model()->findAll('id_object_view=:id', array(':id' => $idView)); foreach ($columns as $c) { $already[] = $c->id_object_parameter; } foreach ($columnsForm as $col) { if (in_array($col, $already)) { continue; } $p = $model->getParameterObjectByIdParameter($col); if ($p == null) { continue; } $column = new DaObjectViewColumn(); $column->id_object_view_column = $idView . '-' . str_replace('_', '-', $p->getFieldName()); $column->id_object_view = $idView; $column->id_object = $idObject; $column->id_object_parameter = $p->getIdParameter(); $column->caption = $p->getCaption(); $column->id_data_type = $p->getType(); $column->field_name = $p->getFieldName(); $column->save(); } } }
public function parseUrl($manager, $request, $pathInfo, $rawPathInfo) { $pathInfo .= '/'; if (preg_match('~^page/([\\da-zA-Z\\-\\_]+)(.*)~', $pathInfo, $matches)) { $idObject = $matches[1]; $remainUrl = $matches[2]; self::$_currentUrlParams[self::PARAM_OBJECT] = $idObject; $idInstance = null; $idView = null; if (preg_match('~^page/[\\da-zA-Z\\-\\_]+/([\\d\\-]+|[a-zA-Z\\d\\_]+\\-[a-zA-Z\\d\\-\\_]+)(/.*)~', $pathInfo, $matches)) { $idInstance = trim($matches[1]); $remainUrl = $matches[2]; if ($idInstance == '') { $idInstance = null; } } if ($idInstance != null) { self::$_currentUrlParams[self::PARAM_OBJECT_INSTANCE] = $idInstance; $_GET[self::PARAM_OBJECT_INSTANCE] = $idInstance; } preg_match_all('~([a-zA-z\\-\\_0-9]+)/(.+?)(?:/|$)~', $remainUrl, $matches); if (is_array($matches) && is_array($matches[1]) && count($matches[1]) > 0) { $count = count($matches[1]); for ($i = 0; $i < $count; $i++) { $param = $matches[1][$i]; if ($param == self::PARAM_OBJECT) { continue; } $value = $matches[2][$i]; self::$_currentUrlParams[$param] = $value; $_GET[$param] = $value; } $idView = HArray::val(self::$_currentUrlParams, self::PARAM_OBJECT_VIEW); } // пока тут определяем текущий объект и представление if ($idView != null) { $objectView = DaObjectView::model()->with('columns:onlyVisible')->findByPk($idView); if ($objectView == null) { throw new CHttpException(404); } Yii::app()->backend->objectView = $objectView; Yii::app()->backend->object = DaObject::getById($objectView->id_object); } else { $object = DaObject::getById($idObject); if ($object == null || $object->table_name == null) { throw new CHttpException(404); } Yii::app()->backend->object = $object; if ($object->object_type == DaObject::OBJECT_TYPE_CONTROLLER) { return $object->table_name; } $cr = new CDbCriteria(); $cr->addColumnCondition(array('t.id_object' => $idObject)); $cr->order = 't.order_no'; $objectView = DaObjectView::model()->with('columns:onlyVisible')->find($cr); if ($objectView == null) { return false; } $objectView->object = $object; Yii::app()->backend->objectView = $objectView; } if ($idInstance != null || isset(self::$_currentUrlParams[self::PARAM_ACTION_VIEW])) { return BackendModule::ROUTE_INSTANCE_VIEW; } if (isset(self::$_currentUrlParams[self::PARAM_GROUP_OBJECT])) { return BackendModule::ROUTE_INSTANCE_LIST_GROUP; } return BackendModule::ROUTE_INSTANCE_LIST; } return false; // не применяем данное правило }
public function init() { parent::init(); $arrayOfId = $this->grid->dataProvider->getKeys(); if (count($arrayOfId) == 0) { return; } $availableObjects = array(); $singleStatus = 0; foreach ($this->childData as $param) { if ($param->isRelation() == false) { continue; } $idObject = $param->getIdObjectParameter(); // Смотрим, может ли пользователь работать с подчинённым объектом if (isset($availableObjects[$idObject]) && $availableObjects[$idObject] === null) { continue; } if (!Yii::app()->authManager->checkObject(DaDbAuthManager::OPERATION_LIST, Yii::app()->user->id, $idObject)) { $availableObjects[$idObject] = null; continue; } else { $singleStatus = $singleStatus == 0 ? 1 : 2; $availableObjects[$idObject][$param->getIdParameter()]['field'] = $param->getFieldName(); } } if ($singleStatus == 2) { $this->single = false; $this->htmlOptions = array('class' => 'col-ref action-sub-data'); } else { $this->htmlOptions = array('class' => 'col-ref-one action-sub-data'); } foreach ($availableObjects as $idObject => $params) { if ($params === null) { unset($availableObjects[$idObject]); continue; } $object = null; if (count($params) == 1) { $object = DaObject::getById($idObject, false); foreach ($params as $idParameter => $caption) { $availableObjects[$idObject][$idParameter]['caption'] = $object->name; } } else { $object = DaObject::getById($idObject, true); foreach ($params as $idParameter => $caption) { $param = $object->getParameterObjectByIdParameter($idParameter); $availableObjects[$idObject][$idParameter]['caption'] = $object->name . ' (' . $param->caption . ')'; } } $model = $object->getModel(); foreach ($params as $idParameter => $config) { $cr = new CDbCriteria(); $cr->addColumnCondition(array('t.id_object' => $idObject)); $cr->order = 't.order_no'; $objectView = DaObjectView::model()->find($cr); $dataProvider = Yii::app()->controller->buildDataProvider($objectView, $model); $where = $dataProvider->criteria->condition; $params = $dataProvider->criteria->params; $whereConfig = array('and'); if ($where != null) { $whereConfig[] = $where; } $whereConfig[] = array('in', $config['field'], $arrayOfId); $data = Yii::app()->db->createCommand()->select($config['field'] . ' AS id, count(*) AS cnt')->from($model->tableName())->where($whereConfig, $params)->group($config['field'])->queryAll(); /* // многообъектая поддержка $iq = new InstanceQuery($where); $arrayOfIdObject = Object::getCommonObjectBySingle($idObjectTmp); if (count($arrayOfIdObject) > 1) { $iq->setUsedObjects(array($idObjectTmp)); }*/ $assocData = array(); foreach ($data as $row) { $assocData[$row['id']] = $row['cnt']; } $availableObjects[$idObject][$idParameter]['data'] = $assocData; } } $this->prepareData = $availableObjects; // TODO: Поменять скрипт, когда будет применяться PopOver if (!$this->single) { Yii::app()->clientScript->registerScript('admin.subData.init', '$(".action-sub-data").daSubData(); $(document).on("afterGridUpdate", function(e) { $(".action-sub-data").daSubData(); }); ', CClientScript::POS_READY); /* Yii::app()->clientScript->registerScript('admin.subData.init', ' $("[rel=\'popover-sub-data\']").popover({ placement: "left", trigger: "hover", template: "<div class=\'popover\'><div class=\'arrow\'></div><div class=\'popover-inner\'><div class=\'popover-content\'></div></div></div>" });', CClientScript::POS_READY); */ } }
/** * @param DaObjectView $view * @param DaActiveRecord $model * @return CActiveDataProvider */ public function buildDataProvider(DaObjectView $view, DaActiveRecord $model) { $pk = $model->getInstanceKeyName(); $criteria = new CDbCriteria(); $criteria->condition = $view->getWhere(); $dataProvider = new CActiveDataProvider($model, array('criteria' => $criteria, 'keyAttribute' => $pk)); $event = new ConfigureDataProviderEvent(Yii::app()->controller, $view->id_object, $dataProvider); Yii::app()->controller->raiseEvent(DefaultController::EVENT_ON_CONFIGURE_DATA_PROVIDER, $event); $dataProvider = $event->dataProvider; /***Ограничение по условию, сформированным программистом в классе***/ $event = new PermissionWhereEvent(Yii::app()->controller, $view->id_object, ''); $event->criteria = $criteria; Yii::app()->controller->raiseEvent(DefaultController::EVENT_ON_PROCESS_PERMISSION_WHERE, $event); $where = $event->where; if ($where != '') { $criteria->addCondition($where); } $criteria->params = array_merge($criteria->params, $event->params); return $dataProvider; }