Operation createTemplateAsync

Upload a new PDF template with a file upload

@param  \SplFileObject $template_document (required)
@param  string $template_name (required)

@throws \InvalidArgumentException
@return \GuzzleHttp\Promise\PromiseInterface
332364
public function createTemplateAsync($template_document, $template_name)
    {
        return $this->createTemplateAsyncWithHttpInfo($template_document, $template_name)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }
300517
public function get(Request $request, $template)
    {
        try
        {
            /**
             * Set workspace identifier
             */
            \PDFGeneratorAPI::setWorkspace($this->userRepository->getWorkspaceIdentifier(Auth::user()));

            $template = \PDFGeneratorAPI::get($template);
        }
        catch(Exception $e)
        {
            return response()->json([
                'error' => $e->getMessage()
            ], $e->getCode());
        }

        return response()->json($template);
    }
1045220
public function addTemplate($name, $filename)
    {
        if (!is_string($name) || !is_string($filename) || empty($name) || empty($filename)) {
            throw new \InvalidArgumentException('Template name and filename must be a not empty string');
        }

        $this->templateMap[$name] = $filename;
    }
238886
public static function create_template_cohort($templateorid, $cohortorid) {
        global $DB;
        static::require_enabled();

        $template = $templateorid;
        if (!is_object($template)) {
            $template = new template($template);
        }
        require_capability('moodle/competency:templatemanage', $template->get_context());

        $cohort = $cohortorid;
        if (!is_object($cohort)) {
            $cohort = $DB->get_record('cohort', array('id' => $cohort), '*', MUST_EXIST);
        }

        // Replicate logic in cohort_can_view_cohort() because we can't use it directly as we don't have a course context.
        $cohortcontext = context::instance_by_id($cohort->contextid);
        if (!$cohort->visible && !has_capability('moodle/cohort:view', $cohortcontext)) {
            throw new required_capability_exception($cohortcontext, 'moodle/cohort:view', 'nopermissions', '');
        }

        $tplcohort = template_cohort::get_relation($template->get('id'), $cohort->id);
        if (!$tplcohort->get('id')) {
            $tplcohort->create();
        }

        return $tplcohort;
    }
1286963
function SmartTemplateDebugger ( $template_filename )
		{
			$this->filename  =  $template_filename;

			//	Load Template
	        if ($hd  =  @fopen($template_filename,  "r"))
	        {
		        $this->template  =  fread($hd,  filesize($template_filename));
		        fclose($hd);
		    }
		    else
		    {
		    	$this->template  =  "SmartTemplate Debugger Error: File not found: '$template_filename'";
		    }
			$this->tab[0]  =  '';
			for ($i=1;  $i < 10;  $i++) {
				$this->tab[$i]  =  str_repeat('    ', $i);
			}
		}
1039714
public function upload()
    {
        try {
            $templatecontent = $this->getBase64Contents();
            $filename        = basename($this->getName());
        } catch ( FileExistException $ex ) {
            throw new FileExistException('Template file does not exist or is not readable' , $ex);
        }

        try {
            $this->getSoapClient()->UploadTemplate([
                'template' => $templatecontent ,
                'filename' => $filename ,
            ]);

            $remoteTemplate = new Remote($this->getSoapClient());
            $remoteTemplate->setName($this->getName());

            return $remoteTemplate;
        } catch ( SoapException $ex ) {
            throw new UploadException('Error while uploading the template' , $ex);
        }
    }
855111
public function saveTemplateFromRevision($template_name, $revision_id) {
        $revision_id = (int) $revision_id;
        return $this->saveTemplate($template_name, [ 'revision' => $revision_id ]);
    }
608030
def _get_template(self, template_name, template_file):
        
        template = os.path.join(self.location, 'templates',
                                template_name, template_file)
        return jinja2.Template(open(template).read())
918025
function loadTemplate( $templateFile )
    {
        // this function will load the requested template ($file includes full or relative pathname)
        // the code for the template will be modified to make it name safe, and then stored in
        // an array for later use
        // The id of the template will be returned for the user to operate on it later
        if ( !file_exists( $templateFile ) )
        {
            return -1;
        }

        $code = implode( '', file( $templateFile ) );
        if ( !strlen( $code ) )
        {
            return;
        }

        $code = trim( $code );
        if ( substr( $code, 0, 5 ) == '<?php' )
        {
            $code = substr( $code, 5 );
        }
        if ( substr( $code, -2 ) == '?>' )
        {
            $code = substr( $code, 0, strlen( $code ) - 2 );
        }
        if ( isset( $this->ez['numTemplates'] ) )
        {
            $newNum = $this->ez['numTemplates'];
            $this->ez['numTemplates']++;
        }
        else
        {
            $newNum = 0;
            $this->ez['numTemplates'] = 1;
            $this->ez['templates'] = array();
        }

        $this->ez['templates'][$newNum]['code'] = $code;

        return $newNum;
    }
276422
public function createTemplate(Template &$template)
		{
			$form_data = array(
				'template_name' => $template->getName(),
				'template_subject' => $template->getSubject(),
				'template_body_plain' => $template->getBodyPlain(),
				'template_body_html' => $template->getBodyHtml(),
				'template_body_mobile' => $template->getBodyMobile(),
				'charset' => $template->getCharacterSet(),
				'encoding' => $template->getCharacterEncoding(),
				'folder_id' => $template->getFolderId()
			);
			$data = $this->call('createtemplate', $form_data);

			$template->setTemplateId(trim($data[1]));

			//return $template;
		}
302820
def __getTemplate(template_file_name):
        
        with open(template_file_name) as template_file:
            template_raw = template_file.read()

        template = parse(template_raw)
        return template
446085
public function useTemplate($template_name = false)
    {
        $templates = $this->getTemplates();

        // set the default template
        if ($template_name == false) {
            $template_name = $templates[0]->name;
        }

        // actually use the template
        if ($template_name) {
            $this->{$template_name}();
        }
    }
844507
public function findTemplate($template_name)
    {
        /*
         * Find template location inside search directory path
         */
        if (!$this->app) {
            throw new Exception_InitError('You should use add() to add objects!');
        }
        $f = $this->app->locatePath(
            $this->template_type ?: $this->settings['template_type'],
            $template_name.$this->settings['extension']
        );

        return $this->origin_filename = $f;
    }
1215944
function appendTemplateToStatistics( $templateName, $templateFileName )
    {
        $actualTemplateName = preg_replace( "#^[\w/]+templates/#", '', $templateFileName );
        $requestedTemplateName = preg_replace( "#^[\w/]+templates/#", '', $templateName );

        $tpl = eZTemplate::instance();
        $needToAppend = true;

        // don't add template info if it is a duplicate of previous.
        $statsSize = count( $tpl->TemplatesUsageStatistics );
        if ( $statsSize > 0 )
        {
            $lastTemplateInfo = $tpl->TemplatesUsageStatistics[$statsSize-1];
            if ( $lastTemplateInfo['actual-template-name'] === $actualTemplateName &&
                 $lastTemplateInfo['requested-template-name'] === $requestedTemplateName &&
                 $lastTemplateInfo['template-filename'] === $templateFileName )
            {
                $needToAppend = false;
            }
        }

        if ( $needToAppend )
        {
            $templateInfo = array( 'actual-template-name' => $actualTemplateName,
                                   'requested-template-name' => $requestedTemplateName,
                                   'template-filename' => $templateFileName );

            $tpl->TemplatesUsageStatistics[] = $templateInfo;
        }
    }
381880
private function validateTemplate($template, $templateList)
    {
        if (empty($template)) {
            throw new \Exception('The template name is required.');
        }

        if (!in_array($template, $templateList)) {
            throw new \InvalidArgumentException(
                sprintf('The template "%s" does not exist, use: %s', $template, implode(', ', $templateList))
            );
        }
    }
1025719
def create_template(properties)
      template_dir_path = Pathname.new(File.dirname(__FILE__)).join(NEW_TEMPLATE_FOLDER)
      rambaspec_template_file_path = template_dir_path.join(RAMBASPEC_TEMPLATE_NAME)
      code_file_path = template_dir_path.join(CODE_FOLDER)
      tests_file_path = template_dir_path.join(TESTS_FOLDER)

      file_source = IO.read(rambaspec_template_file_path)

      template = Liquid::Template.parse(file_source)
      output = template.render(properties)

      result_name = properties[TEMPLATE_NAME_KEY] + RAMBASPEC_EXTENSION
      result_dir_path = Pathname.new(properties[TEMPLATE_NAME_KEY])

      FileUtils.mkdir_p result_dir_path
      FileUtils.cp_r(code_file_path, result_dir_path)
      FileUtils.cp_r(tests_file_path, result_dir_path)

      File.open(result_dir_path.join(result_name), 'w+') {|f|
        f.write(output)
      }
    end
1218309
public function setTemplate($template, array $template_variables = [])
	{
		$this->template = $template;
		$this->template_variables = $template_variables;

		return $this;
	}