Пример #1
0
 /**
  * returns the default weight ( highest weight + 1 ) to be used.
  *
  * @param string $daoName full name of the DAO
  * @param array  $fieldValues field => value to be used in the WHERE
  * @param string $weightField field which contains the weight value,
  * defaults to 'weight'
  * @return integer
  */
 static function getDefaultWeight($daoName, $fieldValues = null, $weightField = 'weight')
 {
     $maxWeight = CRM_Utils_Weight::getMax($daoName, $fieldValues, $weightField);
     return $maxWeight + 1;
 }
Пример #2
0
 /**
  * make a copy of a profile, including
  * all the fields in the profile
  *
  * @param int $id
  *   The profile id to copy.
  *
  * @return \CRM_Core_DAO
  */
 public static function copy($id)
 {
     $fieldsFix = array('prefix' => array('title' => ts('Copy of ')));
     $copy =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFGroup', array('id' => $id), NULL, $fieldsFix);
     if ($pos = strrpos($copy->name, "_{$id}")) {
         $copy->name = substr_replace($copy->name, '', $pos);
     }
     $copy->name = CRM_Utils_String::munge($copy->name, '_', 56) . "_{$copy->id}";
     $copy->save();
     $copyUFJoin =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('uf_group_id' => $id), array('uf_group_id' => $copy->id), NULL, 'entity_table');
     $copyUFField =& CRM_Core_DAO::copyGeneric('CRM_Core_BAO_UFField', array('uf_group_id' => $id), array('uf_group_id' => $copy->id));
     $maxWeight = CRM_Utils_Weight::getMax('CRM_Core_DAO_UFJoin', NULL, 'weight');
     //update the weight
     $query = "\nUPDATE civicrm_uf_join\nSET    weight = %1\nWHERE  uf_group_id = %2\nAND    ( entity_id IS NULL OR entity_id <= 0 )\n";
     $p = array(1 => array($maxWeight + 1, 'Integer'), 2 => array($copy->id, 'Integer'));
     CRM_Core_DAO::executeQuery($query, $p);
     if ($copy->is_reserved) {
         $query = "UPDATE civicrm_uf_group SET is_reserved = 0 WHERE id = %1";
         $params = array(1 => array($copy->id, 'Integer'));
         CRM_Core_DAO::executeQuery($query, $params);
     }
     CRM_Utils_Hook::copy('UFGroup', $copy);
     return $copy;
 }
Пример #3
0
 /**
  * This function is to make a copy of a profile, including
  * all the fields in the profile
  *
  * @param int $id the profile id to copy
  *
  * @return void
  * @access public
  */
 static function copy($id)
 {
     $fieldsFix = array('prefix' => array('title' => ts('Copy of ')));
     $copy =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFGroup', array('id' => $id), null, $fieldsFix);
     $copyUFJoin =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('uf_group_id' => $id), array('uf_group_id' => $copy->id), null, 'entity_table');
     $copyUFField =& CRM_Core_DAO::copyGeneric('CRM_Core_BAO_UFField', array('uf_group_id' => $id), array('uf_group_id' => $copy->id));
     require_once "CRM/Utils/Weight.php";
     $maxWeight = CRM_Utils_Weight::getMax('CRM_Core_DAO_UFJoin', null, 'weight');
     //update the weight
     $query = "\nUPDATE civicrm_uf_join \nSET    weight = %1\nWHERE  uf_group_id = %2\nAND    ( entity_id IS NULL OR entity_id <= 0 )\n";
     $p = array(1 => array($maxWeight + 1, 'Integer'), 2 => array($copy->id, 'Integer'));
     CRM_Core_DAO::executeQuery($query, $p);
     if ($copy->is_reserved) {
         $query = "UPDATE civicrm_uf_group SET is_reserved = 0 WHERE id = %1";
         $params = array(1 => array($copy->id, 'Integer'));
         CRM_Core_DAO::executeQuery($query, $params);
     }
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::copy('UFGroup', $copy);
     return $copy;
 }