Ejemplo n.º 1
0
 /**
  * Creates a new Object model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Objects();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect('create');
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 2
0
 function BuildObject($objectName, $objectDescription)
 {
     $model = Objects::find()->where(['name' => $objectName])->one();
     if ($model === null) {
         $model = new Objects();
     } else {
         Properties::deleteAll(['object' => $model->id]);
     }
     // If APIS_addressmodel keep only addressmodel and make it Addressmodel
     // If Checkin_openicheckin keep only checkin and make it Checkin
     $model->name = $objectName;
     $pos = strpos($model->name, '_');
     if ($pos !== false) {
         $model->name = substr($model->name, $pos + 1);
     }
     $model->name = str_replace("openi", "", $model->name);
     $model->name = ucfirst($model->name);
     $model->description = $objectDescription;
     $model->api = $this->_apiID;
     $model->privacy = 'public';
     $model->save();
     $this->_objectID = $model->id;
 }
Ejemplo n.º 3
0
 /**
  * Build a new Object
  *
  * @param string $titleFromKey
  * @param object $value
  *
  * @return boolean
  */
 public function BuildObject($titleFromKey, $value)
 {
     $object = new Objects();
     $object->name = property_exists($value, 'title') ? $value->title : $titleFromKey;
     $object->description = property_exists($value, 'description') ? $value->description : '';
     $object->api = $this->api->id;
     $object->privacy = $this->api->privacy;
     if ($object->save()) {
         if (property_exists($value, 'properties')) {
             return $this->BuildProperties($value->properties, $object->id);
         }
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 4
0
 /**
  * Duplicates an Object model under this API.
  * If duplication is successful, the browser will be redirected to the 'view' page.
  * If the Object has inheritance then retrieve all the Properties and Methods of the parent.
  * @param integer $id
  * @return mixed
  */
 public function actionDuplicate($id)
 {
     $model = new Objects();
     $apiModel = $this->findAPIModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->inherited != '') {
         $parentModel = $this->findModel($model->inherited);
         $model->inherited = $parentModel->id;
         $model->api = $id;
         $model->description = $parentModel->description;
         $model->privacy = $parentModel->privacy;
         $model->methods = $parentModel->methods;
         if ($model->save()) {
             // Link all CBS that the parent model had
             $cbss = ObjectCBS::find()->where(['object' => $model->inherited])->all();
             if ($cbss) {
                 foreach ($cbss as $cbs) {
                     $objectCbs = new ObjectCBS();
                     $objectCbs->object = $model->id;
                     $objectCbs->cbs = $cbs->cbs;
                     $objectCbs->save();
                 }
             }
             $properties = Properties::findAll(['object' => $parentModel->id]);
             foreach ($properties as $property) {
                 $prop = new Properties();
                 $prop->name = $property->name;
                 $prop->description = $property->description;
                 $prop->type = $property->type;
                 $prop->object = $model->id;
                 $prop->save();
             }
             $change = new NotifAPIHelper();
             $followersNotified = $change->apiChangedObjectsNumber($id);
             // Elastic Search Update
             $esu = new ElasticSearchPut();
             $esu->setApi($apiModel);
             $esu->MakeJSON();
             $esu->InsertUpdate();
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('duplicate', ['model' => $model, 'api' => $apiModel]);
 }