Getting requests to show on the Schedule and other problems
Posted: Fri Jan 23, 2009 9:03 am
Basically the requests in my self-customized timetrex implementation and environment are requests for specific days off. So the way it would work is an employee might look at the schedule decide they can't work a specific day(s) in the future and then submit a request to have that day(s) off. Now for ease of the administrator, I would like to have the day range of the pending requests show up on the schedule by say making some notation (a background color change or something) on those dates. This would help the administrator be able to determine the trouble spots on the schedule just by looking at it. And when no more notations (trouble spots) exist, they would know that the schedule is suitable.
In order to achieve what I described above, I had to add in another field in the user_date table which I called date_stamp_end. Basically the date_stamp field is being used as the start date of the request and the date_stamp_end is being used as the end date. I added the required functions into UserDateFactory.class.php and the ability to record an end date of request into EditRequest.php and EditRequest.tpl.
Everything seems to work fine. When a request is made a start and end time get added to the user_date table for the user_date Id that is referenced in the request table. Great! Till I go to delete a request and realize that it only deletes (puts a 1 in the deleted column) out of the request table and doesn't do so for the related record in the user_date table. I went looking through the code and found this in UserRequestList.php :
foreach ($ids as $id) {
$rlf->getByIdAndCompanyId( $id, $current_company->getId() );
foreach ($rlf as $r_obj) {
$r_obj->setDeleted($delete);
$r_obj->Save();
}
}
That takes care of the deleting from the request table but doesn't touch the user_date table. So I added this to RequestListFactory.class.php:
function getMyUserDateID($id) {
if ( $id == '') {
return FALSE;
}
$ph = array(
'id' => $id,
);
$query = '
select user_date_id
from '. $this->getTable() .'
where id = ? AND deleted = 0';
$this->rs = $this->db->Execute($query, $ph);
return $this;
}
Then I edited UserRequestList.php :
foreach ($ids as $id) {
$rlf->getByIdAndCompanyId( $id, $current_company->getId() );
foreach ($rlf as $r_obj) {
$udlf = new UserDateListFactory();
$udlf->getById( $rlf->getMyUserDateID($id), NULL, NULL );
foreach ($udlf as $u_obj) {
$u_obj->setDeleted($delete);
$u_obj->Save();
}
$r_obj->setDeleted($delete);
$r_obj->Save();
}
}
However this doesn't work. The idea was to get the user_date_id from the request table and then find that record in the user_date table and set the record to deleted.
If some one could tell me where I went wrong that would be greatly appreciated.
Also I am looking for a way to look at all the records in the user_date table that have requests (that have not been deleted) related to them and pull out the date_stamp (start date) and date_stamp_end (end date). Then I would put a notation on the schedule for all the dates that have request pending on them.
Thank you so much for reading this small book I have written and all your help with this endeavor. And I would be happy to give you any code that I written if you would like to add this feature to your product.
In order to achieve what I described above, I had to add in another field in the user_date table which I called date_stamp_end. Basically the date_stamp field is being used as the start date of the request and the date_stamp_end is being used as the end date. I added the required functions into UserDateFactory.class.php and the ability to record an end date of request into EditRequest.php and EditRequest.tpl.
Everything seems to work fine. When a request is made a start and end time get added to the user_date table for the user_date Id that is referenced in the request table. Great! Till I go to delete a request and realize that it only deletes (puts a 1 in the deleted column) out of the request table and doesn't do so for the related record in the user_date table. I went looking through the code and found this in UserRequestList.php :
foreach ($ids as $id) {
$rlf->getByIdAndCompanyId( $id, $current_company->getId() );
foreach ($rlf as $r_obj) {
$r_obj->setDeleted($delete);
$r_obj->Save();
}
}
That takes care of the deleting from the request table but doesn't touch the user_date table. So I added this to RequestListFactory.class.php:
function getMyUserDateID($id) {
if ( $id == '') {
return FALSE;
}
$ph = array(
'id' => $id,
);
$query = '
select user_date_id
from '. $this->getTable() .'
where id = ? AND deleted = 0';
$this->rs = $this->db->Execute($query, $ph);
return $this;
}
Then I edited UserRequestList.php :
foreach ($ids as $id) {
$rlf->getByIdAndCompanyId( $id, $current_company->getId() );
foreach ($rlf as $r_obj) {
$udlf = new UserDateListFactory();
$udlf->getById( $rlf->getMyUserDateID($id), NULL, NULL );
foreach ($udlf as $u_obj) {
$u_obj->setDeleted($delete);
$u_obj->Save();
}
$r_obj->setDeleted($delete);
$r_obj->Save();
}
}
However this doesn't work. The idea was to get the user_date_id from the request table and then find that record in the user_date table and set the record to deleted.
If some one could tell me where I went wrong that would be greatly appreciated.
Also I am looking for a way to look at all the records in the user_date table that have requests (that have not been deleted) related to them and pull out the date_stamp (start date) and date_stamp_end (end date). Then I would put a notation on the schedule for all the dates that have request pending on them.
Thank you so much for reading this small book I have written and all your help with this endeavor. And I would be happy to give you any code that I written if you would like to add this feature to your product.