예제 #1
0
 /**
  * Associate uploaded files to an "attachment".
  * Additionally cleanups stale uploads.
  *
  * @param int $attachment_id
  * @param int[] $iaf_ids
  */
 private static function associateFiles($attachment_id, $iaf_ids)
 {
     // TODO: verify that all $iaf_ids actually existed, not expired
     $list = DB_Helper::buildList($iaf_ids);
     $stmt = "UPDATE {{%issue_attachment_file}} SET iaf_iat_id=? WHERE iaf_id in ({$list})";
     $params = $iaf_ids;
     array_unshift($params, $attachment_id);
     DB_Helper::getInstance()->query($stmt, $params);
     // run cleanup of stale uploads
     $stmt = "DELETE FROM {{%issue_attachment_file}} WHERE iaf_iat_id=0 AND iaf_created_date>'0000-00-00 00:00:00' AND iaf_created_date < ?";
     $expire_date = time() - self::ATTACHMENT_EXPIRE_TIME;
     $params = array(Date_Helper::convertDateGMT($expire_date));
     DB_Helper::getInstance()->query($stmt, $params);
 }
예제 #2
0
 /**
  * Method used to add a new time entry in the system.
  *
  * @param int $iss_id issue id the time entry is associated with
  * @param int $ttc_id time tracking category id
  * @param int $time_spent time spent in minutes
  * @param array $date date structure
  * @param string $summary summary about time tracking entry
  * @return int 1 if the update worked, -1 otherwise
  */
 public static function addTimeEntry($iss_id, $ttc_id, $time_spent, $date, $summary)
 {
     if ($date) {
         // format the date from the form
         $created_date = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $date['Year'], $date['Month'], $date['Day'], $date['Hour'], $date['Minute'], 0);
         // convert the date to GMT timezone
         $created_date = Date_Helper::convertDateGMT($created_date . ' ' . Date_Helper::getPreferredTimezone());
     } else {
         $created_date = Date_Helper::getCurrentDateGMT();
     }
     $usr_id = Auth::getUserID();
     $stmt = 'INSERT INTO
                 {{%time_tracking}}
              (
                 ttr_ttc_id,
                 ttr_iss_id,
                 ttr_usr_id,
                 ttr_created_date,
                 ttr_time_spent,
                 ttr_summary
              ) VALUES (
                 ?, ?, ?, ?, ?, ?
              )';
     $params = array($ttc_id, $iss_id, $usr_id, $created_date, $time_spent, $summary);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     Issue::markAsUpdated($iss_id, 'time added');
     History::add($iss_id, $usr_id, 'time_added', 'Time tracking entry submitted by {user}', array('user' => User::getFullName($usr_id)));
     return 1;
 }
예제 #3
0
 /**
  * Method used to add a phone support entry using the user
  * interface form available in the application.
  *
  * @return  integer 1 if the insert worked, -1 or -2 otherwise
  */
 public static function insert()
 {
     $usr_id = Auth::getUserID();
     $iss_id = (int) $_POST['issue_id'];
     $date = $_POST['date'];
     // format the date from the form
     $created_date = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $date['Year'], $date['Month'], $date['Day'], $date['Hour'], $date['Minute'], 0);
     // convert the date to GMT timezone
     $created_date = Date_Helper::convertDateGMT($created_date . ' ' . Date_Helper::getPreferredTimezone());
     $stmt = 'INSERT INTO
                 {{%phone_support}}
              (
                 phs_iss_id,
                 phs_usr_id,
                 phs_phc_id,
                 phs_created_date,
                 phs_type,
                 phs_phone_number,
                 phs_description,
                 phs_phone_type,
                 phs_call_from_lname,
                 phs_call_from_fname,
                 phs_call_to_lname,
                 phs_call_to_fname
              ) VALUES (
                 ?, ?, ?, ?, ?,
                 ?, ?, ?, ?, ?,
                 ?, ?
              )';
     $params = array($iss_id, $usr_id, $_POST['phone_category'], $created_date, $_POST['type'], $_POST['phone_number'], $_POST['description'], $_POST['phone_type'], $_POST['from_lname'], $_POST['from_fname'], $_POST['to_lname'], $_POST['to_fname']);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     // enter the time tracking entry about this phone support entry
     $phs_id = DB_Helper::get_last_insert_id();
     $prj_id = Auth::getCurrentProject();
     $ttc_id = Time_Tracking::getCategoryId($prj_id, 'Telephone Discussion');
     $time_spent = (int) $_POST['call_length'];
     $summary = ev_gettext('Time entry inserted from phone call.');
     Time_Tracking::addTimeEntry($iss_id, $ttc_id, $time_spent, $date, $summary);
     $stmt = 'SELECT
                 max(ttr_id)
              FROM
                 {{%time_tracking}}
              WHERE
                 ttr_iss_id = ? AND
                 ttr_usr_id = ?';
     $ttr_id = DB_Helper::getInstance()->getOne($stmt, array($iss_id, $usr_id));
     Issue::markAsUpdated($iss_id, 'phone call');
     // need to save a history entry for this
     History::add($iss_id, $usr_id, 'phone_entry_added', 'Phone Support entry submitted by {user}', array('user' => User::getFullName($usr_id)));
     // XXX: send notifications for the issue being updated (new notification type phone_support?)
     // update phone record with time tracking ID.
     if (!empty($phs_id) && !empty($ttr_id)) {
         $stmt = 'UPDATE
                     {{%phone_support}}
                  SET
                     phs_ttr_id = ?
                  WHERE
                     phs_id = ?';
         try {
             DB_Helper::getInstance()->query($stmt, array($ttr_id, $phs_id));
         } catch (DbException $e) {
             return -1;
         }
     }
     return 1;
 }