/**
  * 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]);
 }
 /**
  * Build the Objects based on input & swagger
  *
  * @return boolean
  */
 public function BuildObjects()
 {
     // Create all Objects
     foreach ($this->resource->definitions as $keyObject => $valueObject) {
         // Try to Build the Object with its Parameter, if something goes wrong return false
         if (!$this->BuildObject($keyObject, $valueObject)) {
             return false;
         }
     }
     // Elastic Search Creation
     $esu = new ElasticSearchPut();
     $esu->setApi($this->api);
     $esu->MakeJSON();
     $esu->InsertUpdate();
     return true;
 }
Example #3
0
 /**
  * Votes Down an API.
  * Immediate return to index.
  * @param integer $id
  * @return mixed
  */
 public function actionVotedown($id, $redirect = 'index')
 {
     $model = $this->findModel($id);
     $curUser = Yii::$app->getUser();
     $curUser = User::findOne($curUser->id);
     $votes_up = explode(',', $curUser->votes_up_apis);
     $votes_down = explode(',', $curUser->votes_down_apis);
     if (in_array($id, $votes_down, null)) {
         return $this->redirect([$redirect]);
     }
     if (($key = array_search($id, $votes_up, null)) !== false) {
         unset($votes_up[$key]);
         $model->votes_up = $model->votes_up - 1;
         $curUser->votes_up_apis = implode(',', $votes_up);
     }
     $votes_down[] = $id;
     $curUser->votes_down_apis = implode(',', $votes_down);
     $curUser->save();
     $model->votes_down = $model->votes_down + 1;
     $model->save();
     $changeAPI = new NotifAPIHelper();
     $followersNotified = $changeAPI->apiChangedDownvotes($id);
     // Elastic Search Update
     $esu = new ElasticSearchPut();
     $esu->setApi($model);
     $esu->MakeJSON();
     $esu->InsertUpdate();
     $changeUser = new NotifUserHelper();
     $myId = \Yii::$app->user->id;
     $changeUser->userChangedDownvotesApis($myId);
     return $this->redirect([$redirect]);
 }
 /**
  * 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]);
 }