/** * sampleAutoTweetNGIntegration * * @param int $productId Param * @param array &$data Param * * Example of how to save AutoTweetNG Request * Copy-paste into your extension, and customize freely * * @return void */ private static function sampleAutoTweetNGIntegration($productId, &$data) { // If product is not published, nothing else to do if (!$data['published']) { return; } $typeinfo = 99; $native_object = json_encode($data); // Product Url $viewProductUrl = EshopRoute::getProductRoute($productId, EshopHelper::getProductCategory($productId)); // Image Url $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->clear(); $query->select('image')->from('#__eshop_productimages')->where('product_id = ' . intval($productId))->order('ordering'); $db->setQuery($query); $product_image = $db->loadResult(); $image_url = null; if ($product_image && JFile::exists(JPATH_ROOT . '/media/com_eshop/products/' . $product_image)) { $image_url = 'media/com_eshop/products/' . $product_image; } $langmgmt_default_language = EParameter::getComponentParam(CAUTOTWEETNG, 'langmgmt_default_language'); if ($langmgmt_default_language) { $key = 'product_name_' . $langmgmt_default_language; if (array_key_exists($key, $data)) { $title = $data[$key]; } $key = 'product_desc_' . $langmgmt_default_language; if (array_key_exists($key, $data)) { $description = TextUtil::cleanText($data[$key]); } } if (empty($title)) { $title = $data['product_name']; } if (empty($description)) { $description = TextUtil::cleanText($data['product_desc']); } if (empty($title)) { return; } // Saving Advanced Attributes $autotweet_advanced = $data['autotweet_advanced_attrs']; $advanced_attrs = AdvancedattrsHelper::retrieveAdvancedAttrs($autotweet_advanced); AdvancedattrsHelper::saveAdvancedAttrs($advanced_attrs, $productId); // AutotweetAPI $id = self::insertRequest($productId, 'autotweetpost', JFactory::getDate()->toSql(), $title, $typeinfo, $viewProductUrl, $image_url, $native_object, $advanced_attrs); // Adding more information to the request $requestsModel = F0FModel::getTmpInstance('Requests', 'AutoTweetModel'); $request = $requestsModel->getItem($id); $request = (array) $request; $request['xtform']->set('title', $title); $request['xtform']->set('fulltext', $description); $request['xtform']->set('author', JFactory::getUser()->username); $requestsModel->save($request); }
/** * This method runs after the data is saved to the $table. * * @param F0FTable &$table The table which was saved * * @return boolean */ protected function onAfterSave(&$table) { $result = parent::onAfterSave($table); if (isset($this->advanced_attrs)) { $this->advanced_attrs->ref_id = $table->ref_id; AdvancedattrsHelper::saveAdvancedAttrs($this->advanced_attrs, $table->ref_id); } return $result; }
/** * applyAjaxPluginAction * * @return void */ public function applyAjaxPluginAction() { try { // CSRF prevention if ($this->csrfProtection) { $this->_csrfProtection(); } $data = $this->_getAjaxData(); if ($data['id'] == 0 || $data['ref_id'] == 0) { throw new Exception('Unknown Plugin Action (id/ref_id)'); } $attr_id = null; // Autotweet_advanced_attrs if (AUTOTWEETNG_JOOCIAL && $data['autotweet_advanced_attrs']) { $advanced_attrs = AdvancedattrsHelper::retrieveAdvancedAttrs($data['autotweet_advanced_attrs']); if (isset($advanced_attrs->ref_id)) { if (($agenda = $advanced_attrs->agenda) && count($agenda) > 0) { // The first date, it's the next date $publish_up = AdvancedattrsHelper::getNextAgendaDate($agenda); if (!empty($publish_up)) { $publish_up = EParameter::convertUTCLocal($publish_up); $data['publish_up'] = $publish_up; } } // Safe to save $attr_id = AdvancedattrsHelper::saveAdvancedAttrs($advanced_attrs, $advanced_attrs->ref_id); unset($data['autotweet_advanced_attrs']); } } // Load the model $model = $this->getThisModel(); if (!$model->getId()) { $model->setIDsFromRequest(); } $id = $model->getId(); if (!$this->onBeforeApplySave($data)) { return false; } // Set the layout to form, if it's not set in the URL if (is_null($this->layout)) { $this->layout = 'form'; } // Do I have a form? $model->setState('form_name', 'form.' . $this->layout); $status = $model->save($data); if ($status && $id != 0) { F0FPlatform::getInstance()->setHeader('Status', '201 Created', true); // Try to check-in the record if it's not a new one $status = $model->checkin(); } if ($status) { $status = $this->onAfterApplySave(); } $req_id = $model->getId(); if ($attr_id) { AdvancedattrsHelper::assignRequestId($attr_id, $req_id); } $this->input->set('id', $req_id); $message = json_encode(array('status' => $status, 'request_id' => $status ? $model->getId() : false, 'message' => $status ? JText::_('COM_AUTOTWEET_COMPOSER_MESSAGE_SAVED') : implode('', $model->getErrors()), 'messageType' => $status ? 'success' : 'error', 'hash' => AutotweetBaseHelper::getHash())); } catch (Exception $e) { $message = json_encode(array('status' => false, 'message' => $e->getMessage(), 'messageType' => 'error', 'hash' => AutotweetBaseHelper::getHash())); } echo EJSON_START . $message . EJSON_END; }
/** * saveAdvancedAttrs * * @param int $id Param * * @return void */ public function saveAdvancedAttrs($id) { if (!AUTOTWEETNG_JOOCIAL) { return; } if ($this->advanced_attrs && !$this->saved_advanced_attrs) { // Safe to save AdvancedattrsHelper::saveAdvancedAttrs($this->advanced_attrs, $id); $this->saved_advanced_attrs = true; } }