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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By jploch
      Hey folks,
      Iam working on a module that extends InputfieldPageTable. I use PageTableExtended as a starting point and all went well so far, except I can't access my config values outside of the module file. The config values allways return the defaults, and not the values in the pw field settings. 

      Here is the code that sets the defaults inside my inputfield module file:
      public function init() { parent::init(); // defaults $this->set('gridMaxWidth', '1600'); $this->set('gridColumns', '12'); } Here is how I add the config field:
      public function ___getConfigInputfields() { $inputfields = parent::___getConfigInputfields(); $fieldsetGrid = $this->modules->get('InputfieldFieldset'); $fieldsetGrid->label = $this->_('Default Grid Settings'); $f = $this->wire('modules')->get('InputfieldText'); $f->attr('name', 'gridMaxWidth'); $f->attr('value', $this->gridMaxWidth); $f->label = $this->_('Container max width'); $f->description = $this->_('Grid container max width in px'); // page name format description $f->notes = $this->_('default is 1600'); // page name format notes $fieldsetGrid->append($f); $inputfields->append($fieldsetGrid); return $inputfields; } Accessing the values outside my module files like this (this gives me the default: 1600, even if I insert another value in the backend field settings):
      $default = $this->wire('modules')->get('InputfieldPageGrid'); $default->gridMaxWidth; Any Ideas?
    • By ngrmm
      My clients wants a modal to show up on every page. But when a user clicks inside the modal -> a session-cookie is set and the modal gets a class.
      // user clicks on modal button $('.modal_button').click(function(){ // 1. set PW session cookie // 2. toggle class $('.modal').toggleClass('off'); }); I know how to set a cookie on page-load via PW-API. But the click on the modal button does not force a page-load. So i have to set the cookie through javascript. Is there a way to do that?
    • By VeiJari
      Hello,
      I'm trying to create a page via api and populate values to it. I can populate everything except user pages to a page reference array.
      Code: 
      $dataUsers = $data->project->users; foreach($dataUsers as $dataUser) { $newProject->projectUsers->add(wire()->pages->find('template=user, id=' . $dataUser->id)); } I'm receiving my data via JSON.
      Is there something I'm missing?
      Thanks for help
    • By VeiJari
      Hi, this is the first we are trying to make a page that has only one type of user that has access to every page. 
      The other users should only have a given access to specific pages, not to the whole template.
      My structure
      -Field -Organisation -Project -Report I want that the "measurer" role only has access to "project x" and it's children, but no view access to every project, organisation or field. I've tried to do this with https://modules.processwire.com/modules/page-edit-per-user/ but it still needs a view access to the whole tree to see the "project x" page. Or is there something I haven't figured out?
      Maybe I have to make it via the API: a select field in the "organisation" template where the admins could add the users and then I use hook to update the privileges?
      Have you done something like this and how did you accomplish it?
      Any help would be appreciated.
       
    • By cosmicsafari
      Hi all,
      Before I go potentially wasting time trying to achieve the impossible.
      Can anyone confirm if its possible to have a Page Reference field on a modules config page?
      I'm wanting to essentially just output a list of select able pages based on the a given selector (likely by template at this stage), wherein the select is the pages that the module should apply to etc. I was thinking a simple checkbox list would suffice is asmSelect isn't available.
      Essentially have it display the same way a Page Reference field would display on a template, where you can easily select a bunch of them.
      public function getInputfields() { $inputfields = parent::getInputfields(); $f = $this->modules->get('InputfieldPage'); $f->attr('name', 'testSelect'); $f->setAttribute('multiple', 'checkboxes'); $f->setAttribute('findPagesSelector', 'template=development'); $f->label = 'Test'; $inputfields->add($f); return $inputfields; } Figured something akin to the above would work but can't seem to get rid of this warning on the modules config screen though.

×
×
  • Create New...