Beispiel #1
0
 public function actionRemoveBind()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $request = \Yii::$app->request->post();
     $dgis_cat = Category2gis::findOne($request['id']);
     if (!$dgis_cat) {
         return ['error' => 'Error! Wrong 2gis category id!'];
     }
     $cats = explode(',', $dgis_cat->cats2dis);
     if (($key = array_search($request['catid'], $cats)) !== false) {
         unset($cats[$key]);
     } else {
         return ['result' => 'not deleted'];
     }
     $dgis_cat->cats2dis = count($cats) ? implode(',', $cats) : null;
     $dgis_cat->save();
     return ['result' => 'ok'];
 }
Beispiel #2
0
 private function _writeCats($cats, $parent_id = null)
 {
     foreach ($cats as $cat) {
         $record = Category2gis::findOne(['alias' => $cat->alias]);
         if (!$record) {
             $record = new Category2gis(['id' => $cat->id, 'name' => $cat->name, 'alias' => $cat->alias, 'parent_id' => $parent_id]);
             $record->save();
             echo "*";
         }
         if ($cat->type == 'general_rubric') {
             echo "  {$this->_t($cat->name)}\n";
             $this->_writeCats($cat->rubrics, $record->id);
         } else {
             echo "--  {$this->_t($cat->name)}\n";
         }
     }
 }
Beispiel #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory2gis()
 {
     return $this->hasMany(Category2gis::className(), ['parent_id' => 'id']);
 }