function updategroupmembers_POST(Web &$w)
{
    // populate input array with preliminary membership details pertaining to target task group
    // these details will be the same for all new members to be added to the group
    $arrdb = array();
    $arrdb['task_group_id'] = $_REQUEST['task_group_id'];
    $arrdb['role'] = $_REQUEST['role'];
    $arrdb['priority'] = 1;
    $arrdb['is_active'] = 1;
    // for each selected member, complete population of input array
    //	foreach ($_REQUEST['member'] as $member) {
    $arrdb['user_id'] = $w->request('member');
    // check to see if member already exists in this group
    $mem = $w->Task->getMemberGroupById($arrdb['task_group_id'], $arrdb['user_id']);
    // if no membership, create it
    if (!$mem) {
        $mem = new TaskGroupMember($w);
        $mem->fill($arrdb);
        $mem->insert();
    } else {
        // if membership does exists, update the record - only the role will be updated
        $mem->fill($arrdb);
        $mem->update();
    }
    // prepare input array for next selected member to insert/update
    unset($arrdb['user_id']);
    //	}
    // return
    $w->msg("Task Group updated", "/task-group/viewmembergroup/" . $_REQUEST['task_group_id']);
}
Beispiel #2
0
 /**
  * Create a new Taskgroup using all the form details of the taskgroup form
  * 
  * @param task_group_type, eg. "TaskGroupType_TaskTodo"
  * @param title, the task group title
  * @param description, a description
  * @param default_assignee_id, a user_id or null
  * @param can_assign, OWNER|MEMBER|GUEST
  * @param can_view, OWNER|MEMBER|GUEST
  * @param can_create, OWNER|MEMBER|GUEST
  * @param is_active, 0|1
  * @param is_deleted, 0|1
  *  
  * @return TaskGroup
  */
 function createTaskGroup($type, $title, $description, $default_assignee_id, $can_assign = "OWNER", $can_view = "OWNER", $can_create = "OWNER", $is_active = 1, $is_deleted = 0)
 {
     // title should be unique!
     $taskgroup = $this->getTaskGroupByUniqueTitle($title);
     if (null != $taskgroup) {
         return $taskgroup;
     }
     // insert newly created task group into the task_group database
     $taskgroup = new TaskGroup($this->w);
     $taskgroup->task_group_type = $type;
     $taskgroup->title = $title;
     $taskgroup->description = $description;
     $taskgroup->can_assign = $can_assign;
     $taskgroup->can_view = $can_view;
     $taskgroup->can_create = $can_create;
     $taskgroup->is_active = $is_active;
     $taskgroup->is_deleted = $is_deleted;
     $taskgroup->default_assignee_id = $default_assignee_id;
     $response = $taskgroup->insert();
     // Check the validation
     if ($response !== true) {
         $this->w->errorMessage($taskgroup, "Taskgroup", $response, false, "/task-group/viewtaskgrouptypes#create");
     }
     // if created succcessfully, create default notify matrix: all on
     if ($taskgroup->id) {
         $arr['guest']['creator'] = 1;
         $arr['member']['creator'] = 1;
         $arr['member']['assignee'] = 1;
         $arr['owner']['creator'] = 1;
         $arr['owner']['assignee'] = 1;
         $arr['owner']['other'] = 1;
         // so foreach role/type lets put the values in the database
         foreach ($arr as $role => $types) {
             foreach ($types as $type => $value) {
                 $notify = new TaskGroupNotify($this->w);
                 $notify->task_group_id = $taskgroup->id;
                 $notify->role = $role;
                 $notify->type = $type;
                 $notify->value = $value;
                 $notify->insert();
             }
         }
     }
     // if task group is successfully created and a default assignee is defined
     // create a task group membership list and set this person as the task group owner
     // if no default assignee, a task group membership list can be created at any time
     if ($taskgroup->id && $default_assignee_id != "") {
         $arrdb = array();
         $arrdb['task_group_id'] = $taskgroup->id;
         $arrdb['user_id'] = $default_assignee_id;
         $arrdb['role'] = "OWNER";
         $arrdb['priority'] = 1;
         $arrdb['is_active'] = 1;
         $mem = new TaskGroupMember($this->w);
         $mem->fill($arrdb);
         $mem->insert();
     }
     return $taskgroup;
 }