示例#1
0
 /**
  * wrapper for ajax group selector.
  *
  * @param array $params
  *   Associated array for params record id.
  *
  * @return array
  *   associated array of group list
  *   -rp = rowcount
  *   -page= offset
  * @todo there seems little reason for the small number of functions that call this to pass in
  * params that then need to be translated in this function since they are coding them when calling
  */
 public static function getGroupListSelector(&$params)
 {
     // format the params
     $params['offset'] = ($params['page'] - 1) * $params['rp'];
     $params['rowCount'] = $params['rp'];
     $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
     // get groups
     $groups = CRM_Contact_BAO_Group::getGroupList($params);
     //skip total if we are making call to show only children
     if (empty($params['parent_id'])) {
         // add total
         $params['total'] = CRM_Contact_BAO_Group::getGroupCount($params);
         // get all the groups
         $allGroups = CRM_Core_PseudoConstant::allGroup();
     }
     // format params and add links
     $groupList = array();
     if (!empty($groups)) {
         foreach ($groups as $id => $value) {
             $groupList[$id]['group_id'] = $value['id'];
             $groupList[$id]['count'] = $value['count'];
             $groupList[$id]['group_name'] = $value['title'];
             // append parent names if in search mode
             if (empty($params['parent_id']) && !empty($value['parents'])) {
                 $groupIds = explode(',', $value['parents']);
                 $title = array();
                 foreach ($groupIds as $gId) {
                     $title[] = $allGroups[$gId];
                 }
                 $groupList[$id]['group_name'] .= '<div class="crm-row-parent-name"><em>' . ts('Child of') . '</em>: ' . implode(', ', $title) . '</div>';
                 $value['class'] = array_diff($value['class'], array('crm-row-parent'));
             }
             $value['class'][] = 'crm-entity';
             $groupList[$id]['class'] = $value['id'] . ',' . implode(' ', $value['class']);
             $groupList[$id]['group_description'] = CRM_Utils_Array::value('description', $value);
             if (!empty($value['group_type'])) {
                 $groupList[$id]['group_type'] = $value['group_type'];
             } else {
                 $groupList[$id]['group_type'] = '';
             }
             $groupList[$id]['visibility'] = $value['visibility'];
             $groupList[$id]['links'] = $value['action'];
             $groupList[$id]['org_info'] = CRM_Utils_Array::value('org_info', $value);
             $groupList[$id]['created_by'] = CRM_Utils_Array::value('created_by', $value);
             $groupList[$id]['is_parent'] = $value['is_parent'];
         }
         return $groupList;
     }
 }
 /**
  * This function is a wrapper for ajax group selector
  *
  * @param  array   $params associated array for params record id.
  *
  * @return array   $groupList associated array of group list
  * @access public
  */
 public function getGroupListSelector(&$params)
 {
     // format the params
     $params['offset'] = ($params['page'] - 1) * $params['rp'];
     $params['rowCount'] = $params['rp'];
     $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
     // get groups
     $groups = CRM_Contact_BAO_Group::getGroupList($params);
     // add total
     $params['total'] = CRM_Contact_BAO_Group::getGroupCount($params);
     // format params and add links
     $groupList = array();
     if (!empty($groups)) {
         foreach ($groups as $id => $value) {
             $groupList[$id]['group_id'] = $value['id'];
             $groupList[$id]['group_name'] = $value['title'];
             $groupList[$id]['group_description'] = CRM_Utils_Array::value('description', $value);
             $groupList[$id]['group_type'] = CRM_Utils_Array::value('group_type', $value);
             $groupList[$id]['visibility'] = $value['visibility'];
             $groupList[$id]['links'] = $value['action'];
             $groupList[$id]['org_info'] = $value['org_info'];
             $groupList[$id]['class'] = $value['class'];
         }
         return $groupList;
     }
 }