Exemplo n.º 1
0
 public function mysql_delete()
 {
     $ws = $this->get_UserWorkspace();
     $shares = UserShare::from_property(array("UserWorkspace_id" => $this->UserWorkspace_id, "invitee_id" => $this->invitee_id));
     if ($ws != null && count($shares) <= 1) {
         $ws->revoke_privileges_db_user($this->invitee_id);
     }
     parent::mysql_delete();
 }
Exemplo n.º 2
0
 public function remove_shares()
 {
     foreach (UserShare::from_property(array("UserWorkspace_id" => $this->id)) as $share) {
         $share->mysql_delete();
     }
 }
Exemplo n.º 3
0
 public function mysql_save_from_post($post)
 {
     $is_new = $this->id == 0;
     if (array_key_exists("superuser", $post)) {
         $logged_user = User::get_logged_user();
         if ($logged_user == null || $logged_user->superuser == 0) {
             $post['superuser'] = 0;
         }
     }
     $post['oid'] = parent::mysql_save_from_post($post);
     $obj = User::from_mysql_id($post['oid']);
     if ($post['modify_password'] == 1) {
         $obj->password = $obj->calculate_password_hash($post['password_hash']);
         $obj->mysql_save();
     }
     if (array_key_exists("deleteShare", $post)) {
         $rows = json_decode($post["deleteShare"]);
         foreach ($rows as $row) {
             $share = UserShare::from_mysql_id($row);
             if ($share != null) {
                 $share->mysql_delete();
             }
         }
     }
     if (array_key_exists("updateShare", $post)) {
         $rows = json_decode($post["updateShare"], true);
         foreach ($rows as $row) {
             if ($row["id"] != 0) {
                 $share = UserShare::from_mysql_id($row['id']);
                 $share->invitee_id = $row['invitee_id'];
                 $share->UserWorkspace_id = $row['workspace_id'];
                 $share->mysql_save();
             } else {
                 $share = new UserShare();
                 $share->invitee_id = $row['invitee_id'];
                 $share->UserWorkspace_id = $row['workspace_id'];
                 $share->mysql_save();
             }
         }
     }
     if ($is_new) {
         $ws = new UserWorkspace();
         $ws->owner_id = $post['oid'];
         $ws->main = 1;
         $ws->name = "main";
         $ws->mysql_save();
     } else {
         if (array_key_exists("deleteWorkspace", $post)) {
             $rows = json_decode($post["deleteWorkspace"]);
             foreach ($rows as $row) {
                 $ws = UserWorkspace::from_mysql_id($row);
                 if ($ws != null) {
                     $ws->mysql_delete();
                 }
             }
         }
         if (array_key_exists("updateWorkspace", $post)) {
             $rows = json_decode($post["updateWorkspace"], true);
             foreach ($rows as $row) {
                 if ($row["id"] != 0) {
                     $ws = UserWorkspace::from_mysql_id($row['id']);
                     $ws->name = $row['name'];
                     $ws->owner_id = $this->id;
                     $ws->mysql_save();
                 } else {
                     $ws = new UserWorkspace();
                     $ws->name = $row['name'];
                     $ws->owner_id = $this->id;
                     $ws->mysql_save();
                 }
             }
         }
     }
     return $post['oid'];
 }