Created
October 28, 2014 11:58
-
-
Save gayanvirajith/244da4b43db1cb3e4c75 to your computer and use it in GitHub Desktop.
Car classified process module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"car-condition": { | |
"id": 44, | |
"name": "car-condition", | |
"fieldgroups_id": "car-condition", | |
"flags": 0, | |
"cache_time": 0, | |
"useRoles": 0, | |
"childrenTemplatesID": 0, | |
"sortfield": "", | |
"noChildren": 1, | |
"noParents": "", | |
"childTemplates": [], | |
"parentTemplates": [ | |
"car-conditions" | |
], | |
"allowPageNum": 0, | |
"allowChangeUser": 0, | |
"redirectLogin": 0, | |
"urlSegments": 0, | |
"https": 0, | |
"slashUrls": 1, | |
"altFilename": "", | |
"guestSearchable": 0, | |
"pageClass": "", | |
"childNameFormat": "", | |
"pageLabelField": "", | |
"noGlobal": 0, | |
"noMove": 0, | |
"noTrash": 0, | |
"noSettings": 0, | |
"noChangeTemplate": 0, | |
"noShortcut": 0, | |
"noUnpublish": 0, | |
"nameContentTab": 0, | |
"noCacheGetVars": "", | |
"noCachePostVars": "", | |
"useCacheForUsers": 0, | |
"cacheExpire": 0, | |
"cacheExpirePages": [], | |
"label": "", | |
"tags": "-car-classified", | |
"titleNames": 0, | |
"noPrependTemplateFile": 0, | |
"noAppendTemplateFile": 0, | |
"prependFile": "", | |
"appendFile": "", | |
"_exportMode": true, | |
"fieldgroupFields": [ | |
"title" | |
], | |
"fieldgroupContexts": { | |
"title": [] | |
} | |
}, | |
"car-conditions": { | |
"id": 43, | |
"name": "car-conditions", | |
"fieldgroups_id": "car-conditions", | |
"flags": 0, | |
"cache_time": 0, | |
"useRoles": 0, | |
"childrenTemplatesID": 0, | |
"sortfield": "", | |
"noChildren": "", | |
"noParents": "", | |
"childTemplates": [ | |
"car-condition" | |
], | |
"parentTemplates": [], | |
"allowPageNum": 0, | |
"allowChangeUser": 0, | |
"redirectLogin": 0, | |
"urlSegments": 0, | |
"https": 0, | |
"slashUrls": 1, | |
"altFilename": "", | |
"guestSearchable": 0, | |
"pageClass": "", | |
"childNameFormat": "", | |
"pageLabelField": "", | |
"noGlobal": 0, | |
"noMove": 0, | |
"noTrash": 0, | |
"noSettings": 0, | |
"noChangeTemplate": 0, | |
"noShortcut": 0, | |
"noUnpublish": 0, | |
"nameContentTab": 0, | |
"noCacheGetVars": "", | |
"noCachePostVars": "", | |
"useCacheForUsers": 0, | |
"cacheExpire": 0, | |
"cacheExpirePages": [], | |
"label": "", | |
"tags": "-car-classified", | |
"titleNames": 0, | |
"noPrependTemplateFile": 0, | |
"noAppendTemplateFile": 0, | |
"prependFile": "", | |
"appendFile": "", | |
"_exportMode": true, | |
"fieldgroupFields": [ | |
"title" | |
], | |
"fieldgroupContexts": { | |
"title": [] | |
} | |
}, | |
"fuel-type": { | |
"id": 46, | |
"name": "fuel-type", | |
"fieldgroups_id": "fuel-type", | |
"flags": 0, | |
"cache_time": 0, | |
"useRoles": 0, | |
"childrenTemplatesID": 0, | |
"sortfield": "", | |
"noChildren": 1, | |
"noParents": "", | |
"childTemplates": [], | |
"parentTemplates": [ | |
"fuel-types" | |
], | |
"allowPageNum": 0, | |
"allowChangeUser": 0, | |
"redirectLogin": 0, | |
"urlSegments": 0, | |
"https": 0, | |
"slashUrls": 1, | |
"altFilename": "", | |
"guestSearchable": 0, | |
"pageClass": "", | |
"childNameFormat": "", | |
"pageLabelField": "", | |
"noGlobal": 0, | |
"noMove": 0, | |
"noTrash": 0, | |
"noSettings": 0, | |
"noChangeTemplate": 0, | |
"noShortcut": 0, | |
"noUnpublish": 0, | |
"nameContentTab": 0, | |
"noCacheGetVars": "", | |
"noCachePostVars": "", | |
"useCacheForUsers": 0, | |
"cacheExpire": 0, | |
"cacheExpirePages": [], | |
"label": "", | |
"tags": "-car-classified", | |
"titleNames": 0, | |
"noPrependTemplateFile": 0, | |
"noAppendTemplateFile": 0, | |
"prependFile": "", | |
"appendFile": "", | |
"_exportMode": true, | |
"fieldgroupFields": [ | |
"title" | |
], | |
"fieldgroupContexts": { | |
"title": [] | |
} | |
}, | |
"fuel-types": { | |
"id": 45, | |
"name": "fuel-types", | |
"fieldgroups_id": "fuel-types", | |
"flags": 0, | |
"cache_time": 0, | |
"useRoles": 0, | |
"childrenTemplatesID": 0, | |
"sortfield": "", | |
"noChildren": "", | |
"noParents": "", | |
"childTemplates": [ | |
"fuel-type" | |
], | |
"parentTemplates": [], | |
"allowPageNum": 0, | |
"allowChangeUser": 0, | |
"redirectLogin": 0, | |
"urlSegments": 0, | |
"https": 0, | |
"slashUrls": 1, | |
"altFilename": "", | |
"guestSearchable": 0, | |
"pageClass": "", | |
"childNameFormat": "", | |
"pageLabelField": "", | |
"noGlobal": 0, | |
"noMove": 0, | |
"noTrash": 0, | |
"noSettings": 0, | |
"noChangeTemplate": 0, | |
"noShortcut": 0, | |
"noUnpublish": 0, | |
"nameContentTab": 0, | |
"noCacheGetVars": "", | |
"noCachePostVars": "", | |
"useCacheForUsers": 0, | |
"cacheExpire": 0, | |
"cacheExpirePages": [], | |
"label": "", | |
"tags": "-car-classified", | |
"titleNames": 0, | |
"noPrependTemplateFile": 0, | |
"noAppendTemplateFile": 0, | |
"prependFile": "", | |
"appendFile": "", | |
"_exportMode": true, | |
"fieldgroupFields": [ | |
"title" | |
], | |
"fieldgroupContexts": { | |
"title": [] | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ul.menu { | |
padding: 2em 0; | |
width: 100%; | |
} | |
ul.menu li { | |
display: inline; | |
margin-right: 10px; | |
} | |
ul.menu li a { | |
border: 1px solid #db1174; | |
padding: 5px; | |
display: inline-block; | |
border-radius: .4em; | |
} | |
ul.menu li.current a { | |
background: #db1174; | |
color: #FFF; | |
} | |
.Inputfields .InputfieldMarkup .InputfieldContent { | |
margin-top: 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
/* | |
* Toggle all checkboxes in th for 'car-condition' tables | |
*/ | |
$('input.toggle_all').click(function(){ | |
if ($(this).prop('checked')) { | |
$('.toggle').prop('checked', true); | |
} else { | |
$('.toggle').prop('checked', false); | |
} | |
}); | |
// If we are NOT on the widgets or authors tables, then disable sorting on first column | |
if (!$('table').hasClass('noDisable')) { | |
if ($.tablesorter != undefined) $.tablesorter.defaults.headers = {0:{sorter:false}};//works but requires two clicks to kick-in! | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Car Classified Process Module | |
* | |
* | |
* Copyright [2014] by [Gayan Virajith] | |
* | |
* | |
* ProcessWire 2.x | |
* Copyright (C) 2012 by Ryan Cramer | |
* Licensed under GNU/GPL v2, see LICENSE.TXT | |
* | |
* http://processwire.com | |
* | |
*/ | |
class ProcessCarClassified extends Process { | |
/** | |
* Return information about this module (required) | |
* | |
*/ | |
public static function getModuleInfo() { | |
return array( | |
// Your module's title | |
'title' => 'Car Classified', | |
// A 1 sentence description of what your module does | |
'summary' => 'Car classified process module to manage classifieds', | |
// Module version number: use 1 for 0.0.1 or 100 for 1.0.0, and so on | |
'version' => 1, | |
// Name of person who created this module (change to your name) | |
'author' => 'Gayan Virajith', | |
// URL to more info: change to your full modules.processwire.com URL (if available), or something else if you prefer | |
'href' => 'http://modules.processwire.com/', | |
// name of permission required of users to execute this Process (optional) | |
'permission' => 'page-edit', | |
); | |
} | |
/** | |
* The name that will be used for the page this module creates | |
* | |
* It should be unique and the same (or similar) to the module name, but all lowercase. | |
* It should not be the same as any other ProcessWire admin page name. | |
* | |
*/ | |
const pageName = 'car-classified'; | |
// Car conditions page | |
private $carCondtionParent; | |
// Car condition template name | |
private $carConditionTemplate; | |
// Fuel types page | |
private $fuelTypesParent; | |
// Fuel type template name | |
private $fuelTypeTemplate; | |
/** | |
* This is an optional initialization function called before any execute functions. | |
* | |
*/ | |
public function init() { | |
parent::init(); // required | |
$this->carConditionParent = wire('pages')->findOne("template=car-conditions"); | |
$this->carConditionTemplate = 'car-condition'; | |
$this->fuelTypesParent = wire('pages')->findOne("template=fuel-types"); | |
$this->fuelTypeTemplate = 'fuel-type'; | |
} | |
/** | |
* This function is executed when a page with your Process assigned is accessed. | |
* | |
* This can be seen as your main or index function. You'll probably want to replace | |
* everything in this function. | |
* | |
*/ | |
public function ___execute() { | |
// set a new headline, replacing the one used by our page (optional) | |
Wire::setFuel('processHeadline', 'My dashboard'); | |
// add a breadcrumb that returns to our main page | |
//CREATE A NEW FORM | |
$form = $this->modules->get('InputfieldForm'); | |
$form->attr('id', 'dashboard'); | |
$form->action = './'; | |
$form->method = 'post'; | |
$w = new InputfieldWrapper(); | |
$w->attr('title', $this->_('Overview')); | |
$fs1 = $this->modules->get("InputfieldFieldset"); | |
$fs1->label = $this->_('Dashboard'); | |
$fs1->setAttribute('id', 'dashboard'); | |
$m = $this->modules->get('InputfieldMarkup'); | |
$m->columnWidth = 50; | |
$m->label = $this->_('Quick view'); | |
//$m->description = $this->_('At a glance'); | |
$m->attr('value', '<div>Hello</div>'); | |
$m->skipLabel = Inputfield::skipLabelHeader;//we don't want a label displayed here | |
$fs1->add($m);//add post stats inputfield to fieldset | |
$w->add($fs1); | |
$form->add($w); | |
$form->attr('value', $this->mainNav()); | |
return $form->render(); | |
} | |
/** | |
* Called when the URL is this module's page URL + "/carConditions/" | |
* | |
*/ | |
public function ___executeCarConditions() { | |
// set a new headline, replacing the one used by our page (optional) | |
Wire::setFuel('processHeadline', 'Manage car conditions'); | |
// add a breadcrumb that returns to our main page | |
$this->breadcrumbs->add(new Breadcrumb('../', 'Car conditions')); | |
//CREATE A NEW FORM | |
$form = $this->modules->get('InputfieldForm'); | |
$form->attr('id', self::pageName); | |
$form->action = './carConditions'; | |
$form->method = 'post'; | |
//CREATE A NEW WRAPPER | |
$w = new InputfieldWrapper; | |
//CREATE THE FIRST FIELDSET | |
$fs1 = $this->modules->get("InputfieldFieldset"); | |
$fs1->label = $this->_('Add new car condition'); | |
$m = $this->modules->get('InputfieldMarkup'); | |
//$m->columnWidth = 35; | |
$m->label = $this->_('Add new'); | |
$m->description = $this->_('One item per line.'); | |
$m->collapsed = Inputfield::collapsedYes; | |
$txa = $this->modules->get('InputfieldTextarea'); | |
$txa->attr('id+name', 'conditions_add_text'); | |
$txa->skipLabel = Inputfield::skipLabelHeader;//we don't want a label displayed here | |
$m->add($txa); | |
//submit button to save quick post [save unpublished!] | |
$s = $this->modules->get('InputfieldSubmit'); | |
$s->attr('id+name', 'conditions_save_unpublished_btn'); | |
$s->attr('value', $this->_('Save Unpublished')); | |
$s->class .= " conditions_save_unpublished";//add a custom class to this submit button | |
$m->add($s); | |
//submit button to save AND publish quick post | |
$s = $this->modules->get('InputfieldSubmit'); | |
$s->attr('id+name', 'conditions_publish_btn'); | |
$s->attr('value', $this->_('Publish')); | |
$s->class .= " conditions_publish";//add a custom class to this submit button | |
$m->add($s); | |
$fs1->add($m); | |
$w->add($fs1);//first fieldset added to wrapper | |
//CREATE THE SECOND FIELDSET (because I want the two fs separate!) | |
$fs2 = $this->modules->get("InputfieldFieldset"); | |
$fs2->label = sprintf(__('List / Edit car conditions')); | |
//$fs2->removeAttr('id'); | |
$fs2->setAttribute('id', 'categories_edit');//here I set my own ID since I will want to target this <li>; otherwise, PW will set its own. Note, there is no method setAttr! | |
$fs2->addClass('edit_fieldsets'); | |
//CREATE AN INPUTFIELD MARKUP | |
$m = $this->modules->get('InputfieldMarkup'); | |
$fs2->add($m); | |
$form->add($w); | |
$form->attr('value', $this->mainNav()); | |
//CREATE AN INPUTFIELD MARKUP | |
$m = $this->modules->get('InputfieldMarkup'); | |
//CREATE A NEW TABLE | |
$t = $this->modules->get('MarkupAdminDataTable'); | |
$t->setEncodeEntities(false); | |
$t->setClass('carConditionsTable'); | |
// Set header rows | |
$t->headerRow(array( | |
// '<input type="checkbox" class="toggle_all">', | |
$this->_('Title'), | |
$this->_('Published'), | |
)); | |
$carConditions = wire('pages')->find("template=car-condition, include=all, sort=sort, limit=10"); | |
if ($carConditions){ | |
foreach ($carConditions as $condition) { | |
// Check if tag is published or not | |
$condition->is(Page::statusUnpublished) ? $status = "<span class='unpublished'>" . $this->_('No') . "</span>" : $status = $this->_("Yes"); | |
$t->row(array( | |
// "<input type='checkbox' name='car_condition_delete[]' value='{$condition->id}' class='toggle'>",//sorting disable in .js file | |
"<a href='{$this->config->urls->admin}page/edit/?id={$condition->id}' class='edit iframe'>$condition->title</a>", | |
$status,//tag published or not | |
)); | |
} | |
$start = $carConditions->getStart()+1; | |
$end = $start + count($carConditions)-1; | |
$total = $carConditions->getTotal(); | |
if($total) $conditionCount = "<h4>" . sprintf(__('%1$s %2$d to %3$d of %4$d'), 'Listing ', $start, $end, $total) . "</h4>"; | |
//add a description to tags dashboard {tagsCount, limitSelect and instruction OR no tags found status} | |
// $m->description = $total == 0 ? $this->_('No items found.') : $conditionCount . $this->_('Click on a title to edit the item.'); | |
$currentUrl = wire('page')->url . wire('input')->urlSegmentsStr."/"; | |
$pagination = $carConditions->renderPager(array('baseUrl' => $currentUrl)); | |
$m->attr('value', $pagination . $t->render() . $pagination);//wrap our table with pagination | |
$fs2->add($m); | |
//$w->add($m); | |
$w->add($fs2);//second fieldset added to wrapper | |
$form->add($w); | |
} | |
$post = $this->input->post; | |
//send input->post values to the Method save(); | |
if($post->conditions_save_unpublished_btn || $post->conditions_publish_btn) | |
$this->saveCarCondtions($form); | |
return $form->render(); | |
} | |
public function ___executeFuelTypes() { | |
// sSet a new headline, replacing the one used by our page (optional) | |
Wire::setFuel('processHeadline', 'Manage fuel types'); | |
//CREATE A NEW FORM | |
$form = $this->modules->get('InputfieldForm'); | |
$form->attr('id', self::pageName); | |
$form->action = './fuelTypes'; | |
$form->method = 'post'; | |
//CREATE THE FIRST FIELDSET | |
$fs1 = $this->modules->get("InputfieldFieldset"); | |
$fs1->label = $this->_('Add new fuel type'); | |
$w = new InputfieldWrapper(); | |
$w->attr('title', $this->_('Overview')); | |
$m = $this->modules->get('InputfieldMarkup'); | |
//$m->columnWidth = 35; | |
$m->label = $this->_('Add new'); | |
$m->description = $this->_('One item per line.'); | |
$m->collapsed = Inputfield::collapsedYes; | |
$txa = $this->modules->get('InputfieldTextarea'); | |
$txa->attr('id+name', 'fuel_add_text'); | |
$txa->skipLabel = Inputfield::skipLabelHeader;//we don't want a label displayed here | |
$m->add($txa); | |
//submit button to save quick post [save unpublished!] | |
$s = $this->modules->get('InputfieldSubmit'); | |
$s->attr('id+name', 'fuel_save_unpublished_btn'); | |
$s->attr('value', $this->_('Save Unpublished')); | |
$s->class .= " fuel_save_unpublished";//add a custom class to this submit button | |
$m->add($s); | |
//submit button to save AND publish quick post | |
$s = $this->modules->get('InputfieldSubmit'); | |
$s->attr('id+name', 'fuel_publish_btn'); | |
$s->attr('value', $this->_('Publish')); | |
$s->class .= " fuel_publish";//add a custom class to this submit button | |
$m->add($s); | |
$fs1->add($m); | |
$w->add($fs1); | |
$form->add($w); | |
$form->attr('value', $this->mainNav()); | |
//CREATE THE SECOND FIELDSET (because I want the two fs separate!) | |
$fs2 = $this->modules->get("InputfieldFieldset"); | |
$fs2->label = sprintf(__('List / Edit fuel types')); | |
//$fs2->removeAttr('id'); | |
$fs2->setAttribute('id', 'fuel_types_edit');//here I set my own ID since I will want to target this <li>; otherwise, PW will set its own. Note, there is no method setAttr! | |
$fs2->addClass('edit_fieldsets'); | |
//CREATE AN INPUTFIELD MARKUP | |
$m = $this->modules->get('InputfieldMarkup'); | |
//CREATE A NEW TABLE | |
$t = $this->modules->get('MarkupAdminDataTable'); | |
$t->setEncodeEntities(false); | |
$t->setClass('fuelTypesTable'); | |
// Set header rows | |
$t->headerRow(array( | |
// '<input type="checkbox" class="toggle_all">', | |
$this->_('Title'), | |
$this->_('Published'), | |
)); | |
$fuelTypes = wire('pages')->find("template=fuel-type, include=all, sort=sort, limit=10"); | |
if ($fuelTypes){ | |
foreach ($fuelTypes as $type) { | |
// Check if tag is published or not | |
$type->is(Page::statusUnpublished) ? $status = "<span class='unpublished'>" . $this->_('No') . "</span>" : $status = $this->_("Yes"); | |
$t->row(array( | |
// "<input type='checkbox' name='car_condition_delete[]' value='{$condition->id}' class='toggle'>",//sorting disable in .js file | |
"<a href='{$this->config->urls->admin}page/edit/?id={$type->id}' class='edit iframe'>$type->title</a>", | |
$status,//tag published or not | |
)); | |
} | |
$currentUrl = wire('page')->url . wire('input')->urlSegmentsStr."/"; | |
$pagination = $fuelTypes->renderPager(array('baseUrl' => $currentUrl)); | |
$m->attr('value', $pagination . $t->render() . $pagination);//wrap our table with pagination | |
$fs2->add($m); | |
//$w->add($m); | |
$w->add($fs2);//second fieldset added to wrapper | |
$form->add($w); | |
} | |
$post = $this->input->post; | |
//send input->post values to the Method save(); | |
if($post->fuel_publish_btn || $post->fuel_save_unpublished_btn) | |
$this->saveFuelTypes($form); | |
return $form->render(); | |
} | |
private function mainNav() { | |
//Create delegate template | |
$template = new TemplateFile(__DIR__ . "/markup/navigation.inc"); | |
//assign the rendered view to content variable to show up on articles.php | |
$template->set('mainPage', self::pageName); | |
return $template->render(); | |
} | |
/** | |
* | |
* Save new fuel types entries. | |
* | |
*/ | |
private function saveFuelTypes($form) { | |
$form->processInput($this->input->post); | |
//addFuelTypes will be a string of text separated by a new line (\n). | |
$addFuelTypes = $this->input->post->fuel_add_text; | |
if (!$addFuelTypes) { | |
$this->error($this->_("You need to add some car fuel types.")); | |
$this->session->redirect(wire('page')->url . "fuelTypes/"); | |
} | |
// $fuelTypes Array will be populated by splitting up using \n (newline) | |
$fuelTypes = explode("\n", $addFuelTypes); | |
$count = 0; // $counter for counting up fuel types | |
foreach ($fuelTypes as $type) { | |
// Save new fuel type page; | |
$p = new Page(); | |
if ($this->fuelTypesParent) { | |
$p->parent = $this->fuelTypesParent; | |
} | |
$p->template = wire('templates')->get($this->fuelTypeTemplate); | |
$p->title = $this->sanitizer->text($type); | |
// Skip to next if no title provided | |
if (!$p->title) continue; | |
// Sanitize and convert to a URL | |
if ($p->title) $p->name = $this->sanitizer->pageName($p->title); | |
//check if name already taken | |
if($p->parent->child("name={$p->name}, include=all")->id) { | |
$failed [] = $p->title; | |
continue; | |
} | |
if ($this->input->post->fuel_save_unpublished_btn) $p->addStatus(Page::statusUnpublished); | |
$p->save(); | |
$count++; | |
} | |
// Create a string of "failed" category titles to add to error message | |
$failedTitles = implode(', ', $failed); | |
// Tell user how many categories were added | |
if($count > 0) $this->message(sprintf(_n("Added %d new fuel type.", "Added %d new fuel types.", $count), $count)); | |
// Notifiy failed items to user | |
if($failedTitles) $this->error($this->_("Some fuel types not added because names already in use. These are: {$failedTitles}.")); | |
$this->session->redirect(wire('page')->url . "fuelTypes/"); | |
} | |
/** | |
* | |
* Save new car condition entries. | |
* | |
*/ | |
private function saveCarCondtions($form) { | |
$form->processInput($this->input->post); | |
//$addConditions will be a string of text separated by a new line (\n). | |
$addConditions = $this->input->post->conditions_add_text; | |
if (!$addConditions) { | |
$this->error($this->_("You need to add some car conditions.")); | |
$this->session->redirect(wire('page')->url . "carConditions/"); | |
} | |
// $conditions Array will be populated by splitting up using \n (newline) | |
$conditions = explode("\n", $addConditions); | |
$count = 0; // $counter for counting up conditions | |
foreach ($conditions as $condition) { | |
// Save new car condition page; | |
$p = new Page(); | |
if ($this->carConditionParent) { | |
$p->parent = $this->carConditionParent; | |
} | |
$p->template = wire('templates')->get($this->carConditionTemplate); | |
$p->title = $this->sanitizer->text($condition); | |
// Skip to next if no title provided | |
if (!$p->title) continue; | |
// Sanitize and convert to a URL | |
if ($p->title) $p->name = $this->sanitizer->pageName($p->title); | |
//check if name already taken | |
if($p->parent->child("name={$p->name}, include=all")->id) { | |
$failed [] = $p->title; | |
continue; | |
} | |
if ($this->input->post->conditions_save_unpublished_btn) $p->addStatus(Page::statusUnpublished); | |
$p->save(); | |
$count++; | |
} | |
// Create a string of "failed" category titles to add to error message | |
$failedTitles = implode(', ', $failed); | |
// Tell user how many categories were added | |
if($count > 0) $this->message(sprintf(_n("Added %d new car condition.", "Added %d new conditions.", $count), $count)); | |
// Notifiy failed items to user | |
if($failedTitles) $this->error($this->_("Some car conditions not added because names already in use. These are: {$failedTitles}.")); | |
$this->session->redirect(wire('page')->url . "carConditions/"); | |
} | |
/** | |
* Called only when your module is installed | |
* | |
* This version creates a new page with this Process module assigned. | |
* | |
*/ | |
public function ___install() { | |
// create the page our module will be assigned to | |
$page = new Page(); | |
$page->template = 'admin'; | |
$page->name = self::pageName; | |
// installs to the admin "Setup" menu ... change as you see fit | |
// $page->parent = $this->pages->get($this->config->adminRootPageID)->child('name=setup'); | |
$page->parent = $this->pages->get($this->config->adminRootPageID); | |
$page->process = $this; | |
// we will make the page title the same as our module title | |
// but you can make it whatever you want | |
$info = self::getModuleInfo(); | |
$page->title = $info['title']; | |
// save the page | |
$page->save(); | |
// tell the user we created this page | |
$this->message("Created Page: {$page->path}"); | |
} | |
/** | |
* Called only when your module is uninstalled | |
* | |
* This should return the site to the same state it was in before the module was installed. | |
* | |
*/ | |
public function ___uninstall() { | |
// find the page we installed, locating it by the process field (which has the module ID) | |
// it would probably be sufficient just to locate by name, but this is just to be extra sure. | |
$moduleID = $this->modules->getModuleID($this); | |
$page = $this->pages->get("template=admin, process=$moduleID, name=" . self::pageName); | |
if($page->id) { | |
// if we found the page, let the user know and delete it | |
$this->message("Deleting Page: {$page->path}"); | |
$page->delete(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment