/**
  * Return related time records
  *
  * @param void
  * @param integer $visibility
  * @return array
  */
 function getTimeRecords($visibility = VISIBILITY_NORMAL)
 {
     $ids = $this->getTimeRecordIds();
     return is_foreachable($ids) ? TimeRecords::findByIds($ids, STATE_VISIBLE, $visibility) : null;
 }
 /**
  * Update multiple time records
  *
  * @param void
  * @return null
  */
 function mass_update()
 {
     if ($this->request->isSubmitted()) {
         $updated = 0;
         // number of successfully update records
         $message = 'No records has been updatede or moved to trash';
         $action = $this->request->post('action');
         $time_record_ids = $this->request->post('time_record_ids');
         if (is_foreachable($time_record_ids)) {
             $time_records = TimeRecords::findByIds($time_record_ids, STATE_VISIBLE, $this->logged_user->getVisibility());
             if (is_foreachable($time_records)) {
                 db_begin_work();
                 switch ($action) {
                     // Mark as billable
                     case 'mark_as_billable':
                         $message = ':count records marked as billable';
                         foreach ($time_records as $time_record) {
                             if ($time_record->canChangeBillableStatus($this->logged_user)) {
                                 $time_record->setBillableStatus(BILLABLE_STATUS_BILLABLE);
                                 $save = $time_record->save();
                                 if ($save && !is_error($save)) {
                                     $updated++;
                                 }
                                 // if
                             }
                             // if
                         }
                         // foreach
                         break;
                         // Mark as non-billable
                     // Mark as non-billable
                     case 'mark_as_not_billable':
                         $message = ':count records marked as non-billable';
                         foreach ($time_records as $time_record) {
                             if ($time_record->canChangeBillableStatus($this->logged_user)) {
                                 $time_record->setBillableStatus(BILLABLE_STATUS_NOT_BILLABLE);
                                 $save = $time_record->save();
                                 if ($save && !is_error($save)) {
                                     $updated++;
                                 }
                                 // if
                             }
                             // if
                         }
                         // foreach
                         break;
                         // Mark as billed
                     // Mark as billed
                     case 'mark_as_billed':
                         $message = ':count records marked as billed';
                         foreach ($time_records as $time_record) {
                             if ($time_record->canChangeBillableStatus($this->logged_user)) {
                                 $time_record->setBillableStatus(BILLABLE_STATUS_BILLED);
                                 $save = $time_record->save();
                                 if ($save && !is_error($save)) {
                                     $updated++;
                                 }
                                 // if
                             }
                             // if
                         }
                         // foreach
                         break;
                         // Mark as not billed
                     // Mark as not billed
                     case 'mark_as_not_billed':
                         $message = ':count records marked as not billed';
                         foreach ($time_records as $time_record) {
                             if ($time_record->canChangeBillableStatus($this->logged_user)) {
                                 $time_record->setBillableStatus(BILLABLE_STATUS_BILLABLE);
                                 $save = $time_record->save();
                                 if ($save && !is_error($save)) {
                                     $updated++;
                                 }
                                 // if
                             }
                             // if
                         }
                         // foreach
                         break;
                         // Move to trash
                     // Move to trash
                     case 'move_to_trash':
                         $message = ':count records moved to trash';
                         foreach ($time_records as $time_record) {
                             if ($time_record->canDelete($this->logged_user)) {
                                 $trash = $time_record->moveToTrash();
                                 if ($trash && !is_error($trash)) {
                                     $updated++;
                                 }
                                 // if
                             }
                             // if
                         }
                         // foreach
                         break;
                 }
                 // switch
                 db_commit();
             }
             // if
         }
         // if
         flash_success($message, array('count' => $updated));
         $this->redirectToReferer(timetracking_module_url($this->active_project));
     } else {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
     // if
 }