Ejemplo n.º 1
0
 /**
  * Get list of encoders and conservators available if at least conservator
  * Get the list of himself if encoder ... Otherwise sends nothing
  * @param myUser $user A doctrine myUser class object containing informations about the current user
  * @return mixed[] A collection of users entries
  */
 public function getRestrictedEncodersList(myUser $user)
 {
     $result = array();
     $q = Doctrine_Query::create()->select('u.id')->addSelect('u.formated_name')->from('Users u')->where('u.db_user_type >= 2')->orderBy('u.formated_name_indexed');
     if ($user->isA(Users::ENCODER)) {
         $q->addWhere('u.id = ?', array($user->getId()));
     } elseif (!$user->isAtLeast(Users::MANAGER)) {
         return $result;
     } else {
         $result[] = $this->getI18N()->__('All');
     }
     $results = $q->fetchArray();
     foreach ($results as $results_item) {
         $result[$results_item['id']] = $results_item['formated_name'];
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Get all loans related to an Array of id
  * @param myUser $user object The user that serves at filtering the list of loans we can get access to
  * @param array $specIds Array of id of related record
  * @return Doctrine_Collection Collection of loans
  */
 public function getLoansRelatedArray($user, $specIds = array())
 {
     $specimenIds = '';
     if (is_array($specIds)) {
         if (empty($specIds) || count($specIds) === 0) {
             return array();
         }
         $specimenIds = implode(',', $specIds);
     } else {
         $specimenIds = $specIds;
     }
     $conn_MGR = Doctrine_Manager::connection();
     $conn = $conn_MGR->getDbh();
     $sql = '';
     $sqlSelect = "select li.specimen_ref as specimen_id,\n                           count(distinct li.loan_ref) as loans_count,\n                           array_to_string(array_agg(li.loan_ref), CHR(10)) as loans_ref,\n                           array_to_string(array_agg((select name from loans where id = li.loan_ref)), CHR(10)) as loans_name,\n                           array_to_string(array_agg((select case when status = 'closed' then '(C)' when status = 'rejected' then '(!)' else '(O)' end as status from loan_status as ls where ls.loan_ref = li.loan_ref and ls.is_last = true limit 1)), CHR(10)) as loans_status,\n                           array_to_string(array_agg((select status from loan_status as ls where ls.loan_ref = li.loan_ref and ls.is_last = true limit 1)), CHR(10)) as loans_status_tooltip,\n                           array_to_string(array_agg((select case when status = 'closed' then 'loan_closed' when status = 'rejected' then 'loan_rejected' else 'loan_opened' end as status from loan_status as ls where ls.loan_ref = li.loan_ref and ls.is_last = true limit 1)), CHR(10)) as loans_status_class ";
     $sqlFrom = " from loan_items as li ";
     $sqlWhere = " where li.specimen_ref  = any('{ {$specimenIds} }'::int[])";
     $sqlGroupAndOrderBy = " group by li.specimen_ref\n                            order by li.specimen_ref";
     $params = array();
     if ($user->isA(Users::ADMIN)) {
         $sqlSelect .= " , array_to_string(array_agg((select 1)), CHR(10)) as loans_right ";
     } else {
         $sqlSelect .= " , array_to_string(array_agg((select count(id) from loan_rights as lr where lr.loan_ref = li.loan_ref and lr.user_ref = :user_id)), CHR(10)) as loans_right ";
         $params[':user_id'] = $user->getId();
     }
     $sql .= $sqlSelect . $sqlFrom . $sqlWhere . $sqlGroupAndOrderBy;
     $statement = $conn->prepare($sql);
     $statement->execute($params);
     $results = $statement->fetchAll(PDO::FETCH_ASSOC);
     return $results;
 }