/** * Resolve the correct order for a savedWorkflow. If it is a new savedWorkflow then set the order to max * plus 1. 'Max' is a calculation of the existing workflows that are for the specific moduleClassName. * If the workflow is an existing workflow, then if moduleClassName has changed, the 'max' plus 1 should be * used. Otherwise if it is new and the moduleClassName has not changed, then leave it alone * @param SavedWorkflow $savedWorkflow * @param bool $isBeingCopied * @throws NotSupportedException if the moduleClassName has not been defined yet */ public static function resolveOrder(SavedWorkflow $savedWorkflow, $isBeingCopied = false) { assert('is_bool($isBeingCopied)'); if ($savedWorkflow->moduleClassName == null) { throw new NotSupportedException(); } $q = DatabaseCompatibilityUtil::getQuote(); $sql = "select max({$q}order{$q}) maxorder from " . SavedWorkflow::getTableName(); $sql .= " where moduleclassname = '" . $savedWorkflow->moduleClassName . "'"; if ($isBeingCopied || $savedWorkflow->id < 0 || array_key_exists('moduleClassName', $savedWorkflow->originalAttributeValues)) { $maxOrder = ZurmoRedBean::getCell($sql); $savedWorkflow->order = (int) $maxOrder + 1; } }