/** * Extend save method to add the image processing */ public function save($data) { // perform default save $save = parent::save($data); if (!$save) { return false; } // save or delete image $imageHelper = new JKitHelperImage(JComponentHelper::getParams('com_jkit')); $file = $_FILES['image']; if ($file['size']) { $imageHelper->uploadImage($file, $this->getState('user.id'), 'users'); } else { if (JRequest::getInt('image_delete')) { $imageHelper->deleteImage($this->getState('user.id'), 'users'); } } return true; }
/** * Extend save method to add the image and tag processing */ public function save($data) { // get tags data $tags = array_map('trim', explode(",", $data['tags'])); // save item (preventing joomla default operation with tags) $data['tags'] = null; $save = parent::save($data); if (!$save) { return false; } // get the item id $item_id = $this->getState('item.id'); if (!$item_id) { return false; } // save tags (only when saving in the same language or a new item) if (!JRequest::getString('original_language') || JRequest::getString('original_language') == $data['language']) { if (count($tags) > 0) { $this->saveTags($tags); } } // save or delete image $imageHelper = new JKitHelperImage(JComponentHelper::getParams('com_jkit')); $file = $_FILES['image']; if ($file['size']) { $imageHelper->uploadImage($file, $item_id, 'items'); } else { if (JRequest::getInt('image_delete')) { $imageHelper->deleteImage($item_id, 'items'); } } return true; }
/** * Extend save method to add J! User actions */ public function save($data) { // get the table $table = $this->getTable(); // check isNew $key = $table->getKeyName(); $pk = !empty($data[$key]) ? $data[$key] : (int) $this->getState($this->getName() . '.id'); $isNew = true; if ($pk > 0) { $table->load($pk); $isNew = false; } // bind if (!$table->bind($data)) { $this->setError($table->getError()); return false; } // check if (!$table->check()) { $this->setError($table->getError()); return false; } // check if the user exists $jid = $table->jid ? $table->jid : 0; // check, save or update joomla user before store $juser = $this->saveJoomlaUser($jid, $data); if (!$juser) { return false; } // save jkit user $table->jid = $juser->id; if (!$table->store()) { $this->setError($table->getError()); // TODO delete prev created joomla user return false; } // set state $pkName = $table->getKeyName(); if (isset($table->{$pkName})) { $this->setState($this->getName() . '.id', $table->{$pkName}); } $this->setState($this->getName() . '.new', $isNew); // save or delete image $imageHelper = new JKitHelperImage(JComponentHelper::getParams('com_jkit')); $file = $_FILES['image']; if ($file['size']) { $imageHelper->uploadImage($file, $this->getState('user.id'), 'users'); } else { if (JRequest::getInt('image_delete')) { $imageHelper->deleteImage($this->getState('user.id'), 'users'); } } return true; }