Beispiel #1
0
 public function getAll($maxDepth = false, $objectType = false, $parentObjectTypes = false)
 {
     if ($objectType !== false && !is_array($objectType)) {
         $objectType = [$objectType];
     }
     $objects = [];
     foreach ($this->_objects as $key => $item) {
         if ($maxDepth !== false) {
             if (is_numeric($maxDepth)) {
                 if ($maxDepth < $item[0]) {
                     continue;
                 }
             } elseif (is_array($maxDepth) && isset($maxDepth[$item[1]])) {
                 if ($maxDepth[$item[1]] < $item[0]) {
                     continue;
                 }
             }
         }
         if ($objectType !== false && !in_array($item[1], $objectType)) {
             continue;
         }
         if ($parentObjectTypes && (!isset($item[3]['parentType']) || !in_array($item[3]['parentType'], $parentObjectTypes))) {
             continue;
         }
         if (empty($item[2])) {
             $item[2] = $this->_objects[$key][2] = Registry::getObject($key);
         }
         $objects[$key] = $item[2];
     }
     return $objects;
 }
Beispiel #2
0
 public function getObjectModel()
 {
     if (!isset($this->_cache['object_model'])) {
         $this->_cache['object_model'] = false;
         if (!empty($this->model->object_id)) {
             $this->_cache['object_model'] = Registry::getObject($this->model->object_id);
         }
     }
     return $this->_cache['object_model'];
 }
Beispiel #3
0
 public function actionCreate()
 {
     if (!empty($_GET['objectId'])) {
         $this->params['objectModel'] = $objectModel = Registry::getObject($_GET['objectId']);
     }
     if (empty($objectModel)) {
         throw new NotFoundHttpException("Object not found");
     }
     $this->params['model'] = $model = new Note();
     $model->object_id = $objectModel->id;
     if (!empty($_POST)) {
         $this->params['model']->load($_POST);
         if ($this->params['model']->save()) {
             Yii::$app->response->success = 'Note \'' . $model->descriptor . '\' created!';
             Yii::$app->response->trigger = [['refresh', '.sensor-viewer']];
         }
     }
     Yii::$app->response->view = 'create';
     Yii::$app->response->task = 'dialog';
     Yii::$app->response->labels['submit'] = 'Create';
     Yii::$app->response->taskOptions = ['title' => 'Add Note', 'width' => '800px'];
 }
Beispiel #4
0
 public function getInfo()
 {
     $info = $this->object->getInfo();
     $collections = $this->collectChildModels();
     $provides = [];
     $references = [];
     $boundIps = [];
     foreach ($collections['service']->getAll() as $serviceObj) {
         if ($serviceObj instanceof Service) {
             $service = $serviceObj;
             $provides[] = $service->descriptor;
         } else {
             $service = Service::get($serviceObj->service_id);
             $provider = Registry::getObject($service->object_id);
             $serviceDescription = $service->descriptor;
             //\d(get_class($serviceObj->dataObject->object));exit;
             if ($serviceObj->dataObject->object instanceof ServiceBinding) {
                 if (!empty($serviceObj->dataObject->object->binding['ip'])) {
                     $boundIps[] = $serviceObj->dataObject->object->binding['ip'];
                 }
                 if (!empty($serviceObj->dataObject->object->binding['hostname'])) {
                     $serviceDescription .= ', ' . $serviceObj->dataObject->object->binding['hostname'];
                 }
             }
             $references[] = $provider->descriptor . ' (' . $serviceDescription . ')';
         }
     }
     if (!empty($references)) {
         $info['Connected Services'] = implode('; ', array_unique($references));
     }
     if (!empty($provides)) {
         $info['Provides Services'] = implode('; ', array_unique($provides));
     }
     if (!empty($boundIps)) {
         $info['IP(s)'] = implode('; ', array_unique($boundIps));
     }
     return $info;
 }
Beispiel #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getObject()
 {
     return Registry::getObject($this->object_id);
 }
Beispiel #6
0
 public function childModels($careAboutActive = true)
 {
     if ($careAboutActive) {
         $active = 1;
     } else {
         $active = [0, 1];
     }
     $models = [];
     $models['Resource'] = Resource::find()->where(['id' => $this->resource_id, 'active' => $active])->all();
     if ($resourceProvider = Registry::getObject($this->object_id)) {
         if (!$careAboutActive || !empty($resourceProvider->active)) {
             $models['ResourceProvider'] = [$resourceProvider];
         }
     }
     return $models;
 }
 public function actionView()
 {
     if (empty($_GET['id']) || !($objectModel = Registry::getObject($_GET['id']))) {
         throw new \yii\web\NotFoundHttpException("Object not found");
     }
     $parentModel = false;
     if (!empty($_GET['parent']) && !($parentModel = Registry::getObject($_GET['parent']))) {
         throw new \yii\web\NotFoundHttpException("Object not found");
     }
     Yii::$app->response->params['objectModel'] = $objectModel;
     Yii::$app->response->params['parentModel'] = $parentModel;
     $object = $objectModel->dataObject;
     $children = $object->collectChildModels();
     $initial = [];
     $initial['object'] = $objectModel->dataObject->getPackage(true);
     $initial['parentObject'] = false;
     $parentId = null;
     if ($parentModel) {
         $parentId = $_GET['parent'];
         $initial['parentObject'] = $parentModel->dataObject->getPackage();
     }
     $this->params['parentId'] = $parentId;
     $this->params['initial'] = $initial;
     if (!empty($_GET['package'])) {
         Yii::$app->response->data = $initial;
     }
     if (!empty($_GET['bare'])) {
         $this->layout = false;
     } else {
         Yii::$app->response->taskOptions = ['title' => $objectModel->descriptor, 'modalClass' => 'modal-xl', 'isForm' => false];
         Yii::$app->response->task = 'dialog';
     }
     Yii::$app->response->view = '@psesd/sensorHub/views/base/view';
 }
Beispiel #8
0
 public function internalCollectFromModels($event)
 {
     if ($event->type === 'children') {
         $models = $this->model->getChildIds();
     } else {
         $models = $this->model->getParentIds();
     }
     foreach ($models as $modelId) {
         $model = Registry::getObject($modelId);
         if (!isset($model->dataObject) || !isset($model->dataObject->object) || !$model->dataObject->object instanceof \psesd\sensors\base\BaseInterface) {
             continue;
         }
         if ($model->hasAttribute('active') && empty($model->active)) {
             continue;
         }
         $event->pass($model);
         $recurse[] = $model;
     }
 }