/**
  * Add or update Contact SubTypes.
  *
  * @param array $params
  *   An assoc array of name/value pairs.
  *
  * @return object|void
  */
 public static function add(&$params)
 {
     // label or name
     if (empty($params['id']) && empty($params['label'])) {
         return NULL;
     }
     if (!empty($params['parent_id']) && !CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $params['parent_id'])) {
         return NULL;
     }
     $contactType = new CRM_Contact_DAO_ContactType();
     $contactType->copyValues($params);
     $contactType->id = CRM_Utils_Array::value('id', $params);
     $contactType->is_active = CRM_Utils_Array::value('is_active', $params, 0);
     $contactType->save();
     if ($contactType->find(TRUE)) {
         $contactName = $contactType->name;
         $contact = ucfirst($contactType->label);
         $active = $contactType->is_active;
     }
     if (!empty($params['id'])) {
         $params = array('name' => "New {$contactName}");
         $newParams = array('label' => "New {$contact}", 'is_active' => $active);
         CRM_Core_BAO_Navigation::processUpdate($params, $newParams);
     } else {
         $name = self::getBasicType($contactName);
         if (!$name) {
             return;
         }
         $value = array('name' => "New {$name}");
         CRM_Core_BAO_Navigation::retrieve($value, $navinfo);
         $navigation = array('label' => "New {$contact}", 'name' => "New {$contactName}", 'url' => "civicrm/contact/add?ct={$name}&cst={$contactName}&reset=1", 'permission' => 'add contacts', 'parent_id' => $navinfo['id'], 'is_active' => $active);
         CRM_Core_BAO_Navigation::add($navigation);
     }
     CRM_Core_BAO_Navigation::resetNavigation();
     // reset the cache after adding
     self::subTypeInfo(NULL, FALSE, FALSE, TRUE);
     return $contactType;
 }
Example #2
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['contact_type'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
 /**
  * Function to add or update Contact SubTypes 
  * 
  * @param  array $params  an assoc array of name/value pairs
  * @return object  
  * @access public
  * @static
  */
 static function add($params)
 {
     // null if empty params or doesn't contain parent_id
     if (!CRM_Utils_Array::value('parent_id', $params)) {
         return;
     }
     // label or name
     if (!CRM_Utils_Array::value('label', $params)) {
         return;
     }
     // parent_id
     if (!CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $params['parent_id'])) {
         return;
     }
     $contactType = new CRM_Contact_DAO_ContactType();
     $contactType->copyValues($params);
     $contactType->id = CRM_Utils_Array::value('id', $params);
     $contactType->is_active = CRM_Utils_Array::value('is_active', $params, 0);
     $contactType->save();
     if ($contactType->find(true)) {
         $contactName = $contactType->name;
         $contact = ucfirst($contactType->label);
         $active = $contactType->is_active;
     }
     if (CRM_Utils_Array::value('id', $params)) {
         $params = array('name' => "New {$contactName}");
         $newParams = array('label' => "New {$contact}", 'is_active' => $active);
         CRM_Core_BAO_Navigation::processUpdate($params, $newParams);
     } else {
         if (CRM_Utils_Array::value('parent_id', $params)) {
             $name = self::getBasicType($contactName);
             $value = array('name' => "New {$name}");
             CRM_Core_BAO_Navigation::retrieve($value, $navinfo);
             $navigation = array('label' => "New {$contact}", 'name' => "New {$contactName}", 'url' => "civicrm/contact/add&ct={$name}&cst={$contactName}&reset=1", 'permission' => "add contacts", 'parent_id' => $navinfo['id'], 'is_active' => $active);
             CRM_Core_BAO_Navigation::add($navigation);
         }
     }
     CRM_Core_BAO_Navigation::resetNavigation();
     // reset the cache after adding
     self::subTypeInfo(null, false, false, true);
     return $contactType;
 }