Ejemplo n.º 1
0
 public function actionView()
 {
     if (!empty($_GET['id'])) {
         $this->params['model'] = $model = Note::find()->where(['id' => $_GET['id']])->one();
     }
     if (empty($model)) {
         throw new NotFoundHttpException("Note not found");
     }
     Yii::$app->response->view = 'view';
     Yii::$app->response->task = 'dialog';
     Yii::$app->response->taskOptions = ['title' => 'Note', 'width' => '400px', 'isForm' => false];
 }
Ejemplo n.º 2
0
 public function getViewPackage($package)
 {
     $view = [];
     if (!empty($package['info'])) {
         $view['info'] = ['handler' => 'info', 'columns' => 4];
     }
     if ($this->hasNotes) {
         $view['notes'] = ['handler' => 'notes', 'items' => []];
         foreach (NoteModel::find()->where(['object_id' => $this->model->id])->all() as $model) {
             $view['notes']['items'][$model->id] = $model->attributes;
             $view['notes']['items'][$model->id]['date'] = date("F d, Y", strtotime($model->modified));
         }
         $view['notes']['urls'] = [];
         $view['notes']['urls']['create'] = Url::to(['/note/create', 'objectId' => '__objectId__']);
         $view['notes']['urls']['update'] = Url::to(['/note/update', 'id' => '__id__']);
         $view['notes']['urls']['delete'] = Url::to(['/note/delete', 'id' => '__id__']);
         $view['notes']['urls']['view'] = Url::to(['/note/view', 'id' => '__id__']);
     }
     if ($this->hasContacts) {
         $view['contacts'] = ['handler' => 'contacts', 'items' => []];
         foreach (ContactModel::find()->where(['object_id' => $this->model->id])->all() as $model) {
             $view['contacts']['items'][$model->id] = $model->attributes;
             $view['contacts']['items'][$model->id]['descriptor'] = $model->descriptor;
             $view['contacts']['items'][$model->id]['date'] = date("F d, Y", strtotime($model->modified));
         }
         $view['contacts']['urls'] = [];
         $view['contacts']['urls']['create'] = Url::to(['/contact/create', 'objectId' => '__objectId__']);
         $view['contacts']['urls']['update'] = Url::to(['/contact/update', 'id' => '__id__']);
         $view['contacts']['urls']['delete'] = Url::to(['/contact/delete', 'id' => '__id__']);
         $view['contacts']['urls']['view'] = Url::to(['/contact/view', 'id' => '__id__']);
     }
     $listableComponents = [];
     $listableComponents['services'] = ['item' => 'service-button', 'subitem' => 'services', 'label' => 'Services', 'viewUrl' => Url::to(['/service/view', 'id' => '__id__'])];
     $listableComponents['resources'] = ['item' => 'resource-button', 'subitem' => 'resources', 'label' => 'Provided Resources', 'viewUrl' => Url::to(['/resource/view', 'id' => '__id__'])];
     $listableComponents['sites'] = ['item' => 'site-button', 'label' => 'Sites', 'viewUrl' => Url::to(['/site/view', 'id' => '__id__'])];
     $listableComponents['sensors'] = ['item' => 'sensor-button', 'label' => 'Sensors', 'viewUrl' => Url::to(['/sensor/view', 'id' => '__id__'])];
     $n = 0;
     foreach ($listableComponents as $key => $component) {
         if (!empty($package['components'][$key]['items'][$component['item']]['subitems'])) {
             $items = $package['components'][$key]['items'][$component['item']]['subitems'];
             if (isset($component['subitem'])) {
                 if (!isset($items[$component['subitem']]) || !($items = $items[$component['subitem']]['subitems']) || empty($items)) {
                     continue;
                 }
             }
             $view[$key] = ['handler' => 'list', 'header' => $component['label'], 'priority' => 99999999 - $n, 'items' => $items, 'minColumns' => 6, 'urls' => ['view' => $component['viewUrl']]];
         }
         $n++;
     }
     return $view;
 }