* @return CRM_Core_DAO_Navigation
*/
public static function add(&$params) {
- $navigation = new CRM_Core_DAO_Navigation();
if (empty($params['id'])) {
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['has_separator'] = CRM_Utils_Array::value('has_separator', $params, FALSE);
$params['permission'] = implode(',', $params['permission']);
}
- $navigation->copyValues($params);
-
- $navigation->save();
- return $navigation;
+ return self::writeRecord($params);
}
/**
break;
case "rename":
- self::processRename($nodeID, $label);
+ self::writeRecord(['id' => $nodeID, 'label' => $label]);
break;
case "delete":
- self::processDelete($nodeID);
+ self::deleteRecord(['id' => $nodeID]);
break;
}
$incrementOtherNodes = FALSE;
}
- $transaction = new CRM_Core_Transaction();
-
// now update the existing nodes to weight + 1, if required.
if ($incrementOtherNodes) {
$query = "UPDATE civicrm_navigation SET weight = weight + 1
CRM_Core_DAO::executeQuery($query);
}
- // finally set the weight of current node
- $query = "UPDATE civicrm_navigation SET weight = {$newWeight}, parent_id = {$newParentID} WHERE id = {$nodeID}";
- CRM_Core_DAO::executeQuery($query);
-
- $transaction->commit();
+ // finally set the weight and parent of current node
+ self::writeRecord(['id' => $nodeID, 'weight' => $newWeight, 'parent_id' => $newParentID]);
}
/**
*
* @param int $nodeID
* @param $label
+ * @deprecated - use API
*/
public static function processRename($nodeID, $label) {
- CRM_Core_DAO::setFieldValue('CRM_Core_DAO_Navigation', $nodeID, 'label', $label);
+ self::writeRecord(['id' => $nodeID, 'label' => $label]);
}
/**
* Process delete action for tree.
*
* @param int $nodeID
+ * @deprecated - use API
*/
public static function processDelete($nodeID) {
- $query = "DELETE FROM civicrm_navigation WHERE id = {$nodeID}";
- CRM_Core_DAO::executeQuery($query);
+ self::deleteRecord(['id' => $nodeID]);
}
/**