/** * generate_new_templates * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will automatically create the defaults for the event. The user would then be redirected to edit the default context for the event. * * @access protected * @param string $messenger the messenger we are generating templates for * @param array $message_types array of message types that the templates are generated for. * @param int $GRP_ID If a non global template is being generated then it is expected we'll have a GRP_ID to use as the base for the new generated template. * @param bool $global true indicates generating templates on messenger activation. false requires GRP_ID for event specific template generation. * @throws \EE_Error * @return array @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array for templates * that are generated. If this is an empty array then it means no templates were generated which usually * means there was an error. Anything in the array with an empty value for `MTP_context` means that it * was not a new generated template but just reactivated (which only happens for global templates that * already exist in the database. */ public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) { //make sure message_type is an array. $message_types = (array) $message_types; $templates = array(); if (empty($messenger)) { throw new EE_Error(__('We need a messenger to generate templates!', 'event_espresso')); } //if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files. if (empty($message_types)) { throw new EE_Error(__('We need at least one message type to generate templates!', 'event_espresso')); } EEH_MSG_Template::_set_autoloader(); foreach ($message_types as $message_type) { //if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty. if ($global && empty($GRP_ID)) { $GRP_ID = EEM_Message_Template_Group::instance()->get_one(array(array('MTP_messenger' => $messenger, 'MTP_message_type' => $message_type, 'MTP_is_global' => true))); $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0; } // if this is global template generation. // First let's determine if we already HAVE global templates for this messenger and message_type combination. // If we do then NO generation!! if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) { $templates[] = array('GRP_ID' => $GRP_ID, 'MTP_context' => ''); //we already have generated templates for this so let's go to the next message type. continue; } $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); if (!$new_message_template_group) { continue; } $templates[] = $new_message_template_group; } return $templates; }
/** * @deprecated 4.9.0 * @param $messenger * @param string $message_type message type that the templates are being created for * @param int $GRP_ID * @param bool $is_global * @return array|object if creation is successful then we return an array of info, otherwise an error_object is returned. * @throws \EE_Error */ public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) { // EE_messages has been deprecated $this->_class_is_deprecated(__FUNCTION__); EE_Registry::instance()->load_helper('MSG_Template'); return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global); }