Jump to content
Sign in to follow this  
hellomoto

How to add fields matching each pg of tpl in module config & add to pg created by?

Recommended Posts

Need your kindly tips and guidance:

So I need for the configuration to have a field for every existing [template=]supplier, for matching with a dir (not already matched) within the module directory which contains the import & update scripts for that supplier.
Then on the admin page created by this module under Admin > Setup, all of the Suppliers need to be listed with corresponding links to Import or Update where available (for those matched to a directory);
and when one of those actions is executed it should load the results log in an iframe.

But, how?

Here is what I have so far, yet to try activated:

<?php
/**
 * Process Products Data (0.0.1)
 * Scrapes  imports products, and updates pricing, availability  variations synchronized with data feeds. Process tailored per source account/supplier.
 *
 * @author
 *
 * ProcessWire 3.x
 * Copyright (C) 2011 by Ryan Cramer
 * Licensed under GNU/GPL v2, see LICENSE.TXT
 *
 * http://www.processwire.com
 * http://www.ryancramer.com
 *
 */

class ImportProductsData extends Process implements ConfigurableModule {

	public static function getModuleInfo() {
		return array(
			'title' => "Process Products Data",
			'version' => "0.0.1",
			'summary' => "Scrapes &amp; imports products, and updates pricing, availability &amp; variations synchronized with data feeds. Process tailored per source account/supplier.",

			'permission' => array(""),
			'autoload' => false,
			'singular' => true,
			'permanent' => false,
			'permission' => 'products-impupd',

			'requires' => array("PHP>=5.4.0", "ProcessWire>=2.5.28", ""),
			//'installs' => array(""),

		);
	}

	const PAGE_NAME = 'products-impupd';

	static public function getDefaults() {
		return array(
		);
	}

	public function init() {
		// $this->addStyle("custom.css");
		// $this->addScript("custom.js");
		// $this->addHookAfter("class::function", $this, "yourFunction");
	}

	public function ___install() {
		// Create page "Product Data ImpUpd" under Setup
		$page = $this->pages->get('template=admin, name='.self::PAGE_NAME);
		if (!$page->id) {
				$page = new Page();
				$page->template = 'admin';
				$page->parent = $this->pages->get($this->config->adminRootPageID)->child('name=setup');
				$page->title = 'Products Import&amp;Update';
				$page->name = self::PAGE_NAME;
				$page->process = $this;
				$page->save();

			// tell the user we created this page
			$this->message("Created Page: {$page->path}");

		}

	}

	public function ___uninstall() {
		// Del page ImpUpd under Setup
		//$moduleID = $this->modules->getModuleID($this);
		$page = $this->pages->get('template=admin, name='.self::PAGE_NAME);

		if($page->id) {
			// if we found the page, let the user know and delete it
			$this->wire('pages')->delete($page, true);
			$this->message($this->_('Deleted Page: ') . $page->path);
		}
	}

	static public function getModuleConfigInputfields(array $data) {
		$inputfields = new InputfieldWrapper();

		$defaults = self::getDefaults();
		$data = array_merge($defaults, $data);

		return $inputfields;
		// foreach supplier select data set dir (each w/ import & update fct)
		// defaults = supplier.name
		// once selected execute import or update & log
		// in iframe & display results [log]
	}

}

 

Edited by hellomoto
more descriptive title

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By VeiJari
      Hello forum,
      This is really a weird one, because front end editing works in a earlier website we did to a customer. 
      When I check the source code for current website it does initiate front end edit: 
      <span id=pw-edit-1 class='pw-edit pw-edit-InputfieldPageTitle' data-name=title data-page=1021 data-lang='1017' style='position:relative'><span class=pw-edit-orig>Tekijät</span><span class=pw-edit-copy id=pw-editor-title-1021 style='display:none;-webkit-user-select:text;user- select:text;' contenteditable>Tekijät</span></span>  But when I double click nothing happens (yes I'm 100% sure I'm superuser and logged in)
      I also tried to apply the front end with other methods than:
      $page->edit('title'); But didn't work either.
      We are using jquery 2.2.4, so it should not be a problem.
      Is this a bug related to current master or something else?
      Someone else having this problem as well?
    • By jom
      Hi everyone
      It seems that I don't fully understand the wireTempPath() function and I need some help.
      I use wireTempPath() to create a new location in assets/cache/WireTempDir and than copy a pdf from the assets/files/page folder to the new folder. I want the file to be accessible only for a limited time, that's why I use wireTempPath.
      The file seems to be copied to the right location, but gets deleted right afterwards, according to 
      As mentioned in the topic above, 
      $wireTempDir->setRemove(false); prevents the file to be deleted. But I like the file to be automatically deleted after a few days. So, how can I do that?
      My code so far (everything works, but the automatic removal of the tempDir folder):
      //generate and show download link $folder = time(); // timestamp as temporary folder $maxAge = (int) $settings->options_downloadlink_valid_hours * 3600; //tempDir wants maxAge as seconds $options = array( 'maxAge' => $maxAge ); $wireTempDir = wireTempDir($folder, $options); $wireTempDir->setRemove(false); $src_file = $page->ebook_download->filename; // Create a new directory in ProcessWire's cache dir if(wire('files')->mkdir($wireTempDir, $recursive = true)) { if(wire('files')->copy($src_file, $wireTempDir)){ //get subdirs from tempDir: $pos = strpos($wireTempDir, "WireTempDir"); $subdir = substr($wireTempDir, $pos, 100); $out .= "<p><a href='" . wire('pages')->get('template=passthrough')->httpUrl . "?file=" . $subdir . $page->ebook_download->basename . "' target='_blank'>$page->title</a></p>"; } } I appreciate any ideas - thanks!
      Oliver
    • By maba
      Hello,
      I need to import regularly - every 15 or 30 days - a big .xslx file into my PW installation.
      This file now has 14 columns, 5.000 rows and grows every month.
      I'll need to group, order and work with these data to:
      analyse User monthly costs analyse User costs per Asset ... User (real AD account) has to match with a PW user - I can't join to the domain - but as you can see I have some services users (start with sca_*) or no user at all. Those rows have to be assigned to a specific user, e.g. account100.
      And:
      I would like to be able to have a kind of diff function to compare User assets between this and last month (and so on) other request is to have a notification when something change for a User between actual and latest import First request: which is the best solution to store those data in your opinion? Page, Table, Repeater Matrix, ...?
      Those are very repetitive data and I think a page reference is better than to import all the data every time but I have to understand how to manage those "dynamic" groups of software (AccType Det), hardware (Asset), ... For example Price will be imported and not stored with the description because it could be change in the future and I'll not have any control on it.
      Thanks!
      User,OE,productNmr,AccType1,AccType Det,Count,Price (€),Sum,ASNA,CC,AccType Info,Asset,AccGroup,,,,,,,,,,,,,
    • By dragan
      Is it by design that a site/ready.php is not included when creating a new site profile? Is it possible to include it with a hook? Or are there any security thoughts? (I don't want to redistribute it in public, it's just so I have my own boilerplate)
    • By VeiJari
      Hello forum, this is my first security related post, so I'm a bit of a newbie.
      I understand that when I have direct front-input from user I should sanitize the input, but how about when I use a secret key for showing a API for a third-party supplier? Should I sanitize the input->get() key?
      I've tested this issue and I tried ?key=<?php echo $page->field; ?> And without adding any sanitization it comes back: /?key=<?php%20echo%20$page->field;%20?>
      So can I rely on this, or should I still use $sanitizer just in case?
       
      Thanks for the help!
×
×
  • Create New...