예제 #1
0
 /**
  * Method used to add a new project to the system.
  *
  * @return  integer 1 if the update worked, -1 or -2 otherwise
  */
 public static function insert()
 {
     if (Validation::isWhitespace($_POST['title'])) {
         return -2;
     }
     $stmt = 'INSERT INTO
                 {{%project}}
              (
                 prj_created_date,
                 prj_title,
                 prj_status,
                 prj_lead_usr_id,
                 prj_initial_sta_id,
                 prj_outgoing_sender_name,
                 prj_outgoing_sender_email,
                 prj_mail_aliases,
                 prj_remote_invocation,
                 prj_customer_backend,
                 prj_workflow_backend
              ) VALUES (
                  ?, ?, ?, ?, ?,
                  ?, ?, ?, ?, ?, ?
              )';
     try {
         DB_Helper::getInstance()->query($stmt, array(Date_Helper::getCurrentDateGMT(), $_POST['title'], $_POST['status'], $_POST['lead_usr_id'], $_POST['initial_status'], $_POST['outgoing_sender_name'], $_POST['outgoing_sender_email'], $_POST['mail_aliases'], $_POST['remote_invocation'], $_POST['customer_backend'], $_POST['workflow_backend']));
     } catch (DbException $e) {
         return -1;
     }
     $new_prj_id = DB_Helper::get_last_insert_id();
     foreach ($_POST['users'] as $user) {
         if ($user == $_POST['lead_usr_id']) {
             $role_id = User::getRoleID('Manager');
         } else {
             $role_id = User::getRoleID('Standard User');
         }
         self::associateUser($new_prj_id, $user, $role_id);
     }
     foreach ($_POST['statuses'] as $sta_id) {
         Status::addProjectAssociation($sta_id, $new_prj_id);
     }
     Display_Column::setupNewProject($new_prj_id);
     // insert default timetracking categories
     Time_Tracking::addProjectDefaults($new_prj_id);
     return 1;
 }