function BuildProperty($name, $desc, $type, $object)
 {
     $model = new Properties();
     $model->name = $name;
     $model->description = $desc;
     // If APIS_addressmodel keep only addressmodel and make it Addressmodel
     // If Checkin_openicheckin keep only checkin and make it Checkin
     $model->type = $type;
     $pos = strpos($model->type, '_');
     if ($pos !== false) {
         $model->type = substr($model->type, $pos + 1);
     }
     $model->type = str_replace("openi", "", $model->type);
     $model->type = ucfirst($model->type);
     $model->object = $object;
     $model->save();
 }
 /**
  * Duplicates a Property model under this Object and API.
  * If duplication is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDuplicate($id)
 {
     $model = new Properties();
     $objectModel = $this->findObjectModel($id);
     $apiModel = $this->findAPIModel($objectModel->api);
     if ($model->load(Yii::$app->request->post()) && $model->inherited != '') {
         $parentModel = $this->findModel($model->inherited);
         $model->inherited = $parentModel->id;
         $model->object = $id;
         $model->name = $parentModel->name . '_for_' . $objectModel->name;
         $model->description = $parentModel->description;
         $model->privacy = $parentModel->privacy;
         $model->methods = $parentModel->methods;
         if ($model->save()) {
             // 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, 'object' => $objectModel]);
 }
Esempio n. 3
0
 private function saveProperties($model)
 {
     if ($properties = Yii::$app->request->post('ExclusivesProperties', false)) {
         foreach ($properties as $property) {
             if ($propertyName = Properties::find()->where(['name' => $property['name']])->one()) {
                 if ($propertyVal = ExclusivesProperties::find()->where(['property_id' => $propertyName['id'], 'exclusive_id' => $model->id])->one()) {
                     $propertyVal->value = $property['value'];
                     $propertyVal->save();
                 } else {
                     $propertyVal = new ExclusivesProperties();
                     $propertyVal->exclusive_id = $model->id;
                     $propertyVal->property_id = $propertyName->id;
                     $propertyVal->value = $property['value'];
                     $propertyVal->save();
                 }
             } else {
                 $propertyName = new Properties();
                 $propertyName->name = $property['name'];
                 $propertyName->save();
                 $propertyVal = new ExclusivesProperties();
                 $propertyVal->exclusive_id = $model->id;
                 $propertyVal->property_id = $propertyName->id;
                 $propertyVal->value = $property['value'];
                 $propertyVal->save();
             }
         }
     }
 }
Esempio n. 4
0
 /**
  * Build a Property
  *
  * @param string $name
  * @param object $value
  * @param integer $objectId
  *
  * @return boolean
  */
 private function BuildProperty($name, $value, $objectId)
 {
     $property = new Properties();
     $property->name = $name;
     $property->description = property_exists($value, 'description') ? $value->description : '';
     $property->object = $objectId;
     // Check if there is a type definition, cases have been based on https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#dataTypeFormat
     // There is also a possibility for an array type, which is a 1-* reference for another Object
     // Another case is that of $ref as an 1-1 reference to another Object
     if (property_exists($value, 'type')) {
         switch ($value->type) {
             case 'integer':
                 if (property_exists($value, 'format')) {
                     switch ($value->format) {
                         case 'int32':
                             $property->type = 'integer';
                             break;
                         case 'int64':
                             $property->type = 'long';
                             break;
                     }
                 }
                 break;
             case 'number':
                 if (property_exists($value, 'format')) {
                     switch ($value->format) {
                         case 'float':
                             $property->type = 'float';
                             break;
                         case 'double':
                             $property->type = 'double';
                             break;
                     }
                 }
                 break;
             case 'string':
                 $property->type = 'string';
                 if (property_exists($value, 'format')) {
                     switch ($value->format) {
                         case 'byte':
                             $property->type = 'byte';
                             break;
                         case 'date':
                             $property->type = 'date';
                             break;
                         case 'date-time':
                             $property->type = 'dateTime';
                             break;
                         case 'password':
                             $property->type = 'password';
                             break;
                     }
                     $property->type = 'byte';
                 }
                 break;
             case 'boolean':
                 $property->type = 'boolean';
                 break;
             case 'array':
                 if (property_exists($value, 'items')) {
                     $items = $value->items;
                     if (property_exists($items, '$ref')) {
                         // Get the last item out of the array produced from the $ref string exploded at '/', with capitalized first letter
                         $property->type = '[' . ucfirst(end(explode('/', $items->{'$ref'}))) . ']';
                     } elseif (property_exists($items, 'type')) {
                         if (property_exists($items, 'xml') and property_exists($items->xml, 'name')) {
                             $property->type = '[' . $items->xml->name . ' (' . $items->type . ')]';
                         } else {
                             $property->type = '[' . $items->type . ']';
                         }
                     }
                 }
                 break;
             default:
                 $property->type = 'string';
         }
     }
     if (property_exists($value, '$ref')) {
         // Get the last item out of the array produced from the $ref string exploded at '/', with capitalized first letter
         $property->type = ucfirst(end(explode('/', $value->{'$ref'})));
     }
     return $property->save();
 }
 /**
  * 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]);
 }