Пример #1
0
 public function sortLayers($request)
 {
     $layers = $request->input('layer');
     foreach ($layers as $order => $id) {
         $layer = Layer::findOrFail($id);
         $layer->order = $order;
         $layer->save();
     }
     return true;
 }
Пример #2
0
 public function touch($schema, $table, $gid, $user)
 {
     $primeryKey = $this->getPrimeryKey("{$schema}.{$table}");
     $layerObj = new Layer();
     $roleObj = $layerObj->getRole($schema, $table, $user);
     $roles = $roleObj["data"];
     $role = $roles[$user];
     if (!$role) {
         $response['success'] = false;
         $response['message'] = "You don't have a role in the workflow";
         $response['code'] = 401;
         return $response;
     }
     $this->begin();
     $query = "SELECT * FROM \"{$schema}\".\"{$table}\" WHERE {$primeryKey['attname']}=:gid";
     $res = $this->prepare($query);
     try {
         $res->execute(array("gid" => $gid));
     } catch (\PDOException $e) {
         $this->rollback();
         $response['success'] = false;
         $response['message'] = $e->getMessage();
         $response['code'] = 401;
         return $response;
     }
     $originalFeature = $this->fetchRow($res);
     $gc2_version_gid = $originalFeature["gc2_version_gid"];
     $gc2_status = $originalFeature["gc2_status"];
     $gc2_workflow = $originalFeature["gc2_workflow"];
     switch ($role) {
         case "author":
             $workflow = "'{$gc2_workflow}'::hstore || hstore('author', '{$user}')";
             if ($gc2_status > 1) {
                 $this->rollback();
                 $response['success'] = false;
                 $response['message'] = "This feature has been " . ($gc2_status == 2 ? "reviewed" : "published") . ", so an author can't update it.";
                 $response['code'] = 401;
                 return $response;
             }
             $status = 1;
             break;
         case "reviewer":
             $workflow = "'{$gc2_workflow}'::hstore || hstore('reviewer', '{$user}')";
             if ($gc2_status > 2) {
                 $this->rollback();
                 $response['success'] = false;
                 $response['message'] = "This feature has been published so a reviewer can't update it.";
                 $response['code'] = 401;
                 return $response;
             }
             $status = 2;
             break;
         case "publisher":
             $workflow = "'{$gc2_workflow}'::hstore || hstore('publisher', '{$user}')";
             $status = 3;
             break;
         default:
             $workflow = "'{$gc2_workflow}'::hstore";
             $status = $gc2_status;
             break;
     }
     // Check if feature is ended
     if ($originalFeature["gc2_version_end_date"]) {
         $this->rollback();
         $response['success'] = false;
         $response['message'] = "You can't change the history!";
         $response['code'] = 401;
         return $response;
     }
     // Clone original feature for ended version
     $intoArr = array();
     $selectArr = array();
     foreach ($originalFeature as $k => $v) {
         if ($k != $primeryKey['attname']) {
             if ($k == "gc2_version_end_date") {
                 $intoArr[] = $k;
                 $selectArr[] = "now()";
             } else {
                 $intoArr[] = $selectArr[] = $k;
             }
         }
     }
     $sql = "INSERT INTO \"{$schema}\".\"{$table}\"(";
     $sql .= implode(",", $intoArr);
     $sql .= ")";
     $sql .= " SELECT ";
     $sql .= implode(",", $selectArr);
     $sql .= " FROM \"{$schema}\".\"{$table}\"";
     $sql .= " WHERE {$primeryKey['attname']}=:gid";
     $res = $this->prepare($sql);
     try {
         $res->execute(array("gid" => $gid));
     } catch (\PDOException $e) {
         $this->rollback();
         $response['success'] = false;
         $response['message'] = $e->getMessage();
         $response['code'] = 401;
         return $response;
     }
     // Update feature
     $query = "UPDATE \"{$schema}\".\"{$table}\" SET gc2_version_user='******', gc2_status = {$status}, gc2_workflow = {$workflow} WHERE {$primeryKey['attname']}=:gid";
     $res = $this->prepare($query);
     try {
         $res->execute(array("gid" => $gid));
     } catch (\PDOException $e) {
         $this->rollback();
         $response['success'] = false;
         $response['message'] = $e->getMessage();
         $response['code'] = 401;
         return $response;
     }
     $query = "INSERT INTO settings.workflow (f_schema_name,f_table_name,gid,status,gc2_user,roles,workflow,version_gid,operation)";
     $query .= " VALUES('{$schema}','{$table}',{$gid},{$status},'{$user}'," . \app\inc\PgHStore::toPg($roles) . ",{$workflow},{$gc2_version_gid},'update')";
     //die($query);
     $res = $this->prepare($query);
     try {
         $res->execute();
     } catch (\PDOException $e) {
         $this->rollback();
         $response['success'] = false;
         $response['message'] = $e->getMessage();
         $response['code'] = 401;
         return $response;
     }
     $this->commit();
     // Bust the cache
     \app\controllers\Tilecache::bust($schema . "." . $table);
     $response['success'] = true;
     $response['message'] = "Workflow updated";
     return $response;
 }