public function getDistinctStatus()
 {
     $status = array('' => 'All', 'opened' => 'Opened');
     $all_status = LoanStatus::getAvailableStatus();
     foreach ($this->createFlatDistinct('loan_status', 'status', 'status')->execute() as $record) {
         $status[$record->getStatus()] = $all_status[$record->getStatus()];
     }
     return $status;
 }
 /**
  * getMyLoans
  *
  * Get the loans for a user that are not Closed/Returned/Rejected
  *
  * @param int $user_id The user id to look for
  * @param int $max_items a number loans to get
  *
  * @return Doctrine_Query Query with loans ordered by from_date desc
  */
 public function getMyLoans($user_id, $max_items = FALSE)
 {
     $status_group = LoanStatus::getClosedStatus('closed');
     $status_group_params = implode(',', array_fill(0, count($status_group), '?'));
     $q = Doctrine_Query::create()->from('Loans l')->where('EXISTS (SELECT lr.id FROM LoanRights lr WHERE lr.loan_ref = l.id AND lr.user_ref = ? )', $user_id)->andWhere("EXISTS (SELECT ls.id FROM LoanStatus ls WHERE loan_ref = l.id AND ls.status NOT IN (" . $status_group_params . ") AND is_last = TRUE )", $status_group)->orderBy('l.from_date desc');
     if ($max_items) {
         $q->limit($max_items);
     }
     return $q;
 }
 public function executeLoanStatus()
 {
     $this->defineForm();
     $this->loanstatus = Doctrine::getTable('LoanStatus')->getLoanStatus($this->eid);
     $this->form = new informativeWorkflowForm(null, array('available_status' => LoanStatus::getAvailableStatus()));
 }
示例#4
0
 public function executeAddStatus(sfWebRequest $request)
 {
     if ($request->isXmlHttpRequest()) {
         $form = new LoanStatusForm(null, array('available_status' => LoanStatus::getAvailableStatus()));
         $form->bind(array('comment' => $request->getParameter('comment'), 'status' => $request->getParameter('status')));
         if ($form->isValid()) {
             $data = array('loan_ref' => $request->getParameter('id'), 'status' => $request->getParameter('status'), 'comment' => $request->getParameter('comment'), 'user_ref' => $this->getUser()->getId());
             $loanstatus = new LoanStatus();
             $loanstatus->fromArray($data);
             $loanstatus->save();
             return $this->renderText('ok');
         } else {
             return $this->renderText('notok' . $form->getErrorSchema());
         }
         // else : nothing append, and it's a good thing
     }
     $this->redirect('board/index');
 }