/** * Like the same method as defined in Content, this method will create a * ContentGroupElement based on the content type specified by * getNewContentUI OR get an existing element by getSelectExistingContentUI * * @param string $user_prefix A identifier provided by the programmer to * recognise it's generated form * @param string $content_group Must be present * @param bool $associate_existing_content If set to true, will get an * existing element instead of creating a * new content. * * @return object The ContentGroup object, or null if the user didn't greate one * @static */ public static function processNewContentUI($user_prefix, ContentGroup $content_group, $associate_existing_content = false) { $db = AbstractDb::getObject(); // Init values $content_group_element_object = null; $max_display_order_row = null; if ($associate_existing_content == true) { $displayed_content_object = Content::processSelectExistingContentUI($user_prefix); } else { $displayed_content_object = Content::processNewContentUI($user_prefix); } if ($displayed_content_object) { /* Get the display order to add the GontentGroupElement at the end */ $sql = "SELECT MAX(display_order) as max_display_order FROM content_group_element WHERE content_group_id='" . $content_group->getId() . "'"; $db->execSqlUniqueRes($sql, $max_display_order_row, false); $display_order = $max_display_order_row['max_display_order'] + 1; $content_id = get_guid(); $content_type = 'ContentGroupElement'; $sql = "INSERT INTO content (content_id, content_type) VALUES ('{$content_id}', '{$content_type}');"; if (!$db->execSqlUpdate($sql, false)) { throw new Exception(_('Unable to insert new content group element into database!')); } $sql = "INSERT INTO content_group_element (content_group_element_id, content_group_id, display_order) VALUES ('{$content_id}', '" . $content_group->GetId() . "', {$display_order});"; if (!$db->execSqlUpdate($sql, false)) { throw new Exception(_('Unable to insert new content group element into database!')); } $content_group_element_object = self::getObject($content_id); $content_group_element_object->replaceDisplayedContent($displayed_content_object); } return $content_group_element_object; }