public function update_meta($fire_events = true) { $data = array(); if ($this->catParentID() !== '0' && $this->catParentID() !== 'null') { $Categories = new PerchCategories_Categories(); $ParentCat = $Categories->find($this->catParentID()); $data['catPath'] = $ParentCat->catPath() . $this->catSlug() . '/'; $data['catTreePosition'] = $ParentCat->catTreePosition() . '-' . str_pad($this->catOrder(), 3, '0', STR_PAD_LEFT); } else { $Sets = new PerchCategories_Sets(); $Set = $Sets->find($this->setID()); $data['catPath'] = $Set->setSlug() . '/' . $this->catSlug() . '/'; $data['catTreePosition'] = str_pad($this->setID(), 3, '0', STR_PAD_LEFT) . '-' . str_pad($this->catOrder(), 3, '0', STR_PAD_LEFT); } $data['catDisplayPath'] = $this->get_display_path(); if (count($data)) { parent::update($data); if ($fire_events) { $Perch = Perch::fetch(); $Perch->event($this->event_prefix . '.update', $this); } } }
<?php $API = new PerchAPI('categories', 1.0); $HTML = $API->get('HTML'); $Sets = new PerchCategories_Sets(); $Categories = new PerchCategories_Categories(); $setID = false; $Set = false; if (isset($_GET['id']) && $_GET['id'] != '') { $setID = (int) $_GET['id']; $Set = $Sets->find($setID); } if ($setID == false) { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/categories/'); } $cats = $Categories->get_tree($setID);
$catID = false; $Category = false; $Set = false; $ParentCat = false; // Success or failure message $message = false; $details = array(); /* Figure out what mode we're in by testing what's on the query string. Load up instances of the Category and Set where appropriate. */ if (PerchUtil::get('id')) { // Edit mode $catID = (int) PerchUtil::get('id'); $Category = $Categories->find($catID); $Set = $Sets->find($Category->setID()); $details = $Category->to_array(); } else { // New category mode if (PerchUtil::get('sid')) { // New in set $Set = $Sets->find((int) PerchUtil::get('sid')); } if (PerchUtil::get('pid')) { // New based on parent category $ParentCat = $Categories->find((int) PerchUtil::get('pid')); $Set = $Sets->find($ParentCat->setID()); } } /* Check permissions and that we have enough data to proceed.