private function approveDocument() { $update_product_only = (bool) Tools::getValue('update_product_only'); if ($update_product_only) { $error_message = $this->l('Product data could not be updated'); $success_message = $this->l('Product data was successfully updated'); } else { $error_message = $this->l('Document could not be approved'); $success_message = $this->l('Document was successfully approved'); } $id_document = (int) Tools::getValue('id_document'); $id_product = (int) Tools::getValue('id_product'); $document = new TextMasterDocument((int) $id_document); if (!Validate::isLoadedObject($document)) { return $this->displayError($error_message); } $document_data = $document->getApiData(); if (!$document_data || !isset($document_data['author_work']) || !isset($document_data['project_id'])) { return $this->displayError($error_message); } $product = new Product((int) $id_product); if (!Validate::isLoadedObject($product)) { return $this->displayError($error_message); } $project = TextMasterProject::getProjectByApiId($document_data['project_id'], true); if (!Validate::isLoadedObject($project)) { return $this->displayError($error_message); } $project_data = $project->getProjectData(); if (!isset($project_data['language_to'])) { return $this->displayError($error_message); } $id_lang = Language::getIdByIso($project_data['language_to']); if (!$id_lang) { return $this->displayError($error_message); } if (!$update_product_only) { if (!$document->approve()) { return $this->displayError($error_message); } } if (!$this->updateProductData($document_data, $product, $id_lang)) { return $this->displayError($error_message); } $this->addFlashMessage($success_message); Tools::redirectAdmin(self::CURRENT_INDEX . Tools::getValue('token') . '&configure=' . $this->name . '&menu=' . Tools::getValue('menu') . '&id_project=' . Tools::getValue('id_project') . '&viewproject&token=' . Tools::getAdminTokenLite('AdminModules')); }
public function getProjects($type, $filter = array()) { if ($this->{'projects_' . $type}) { return $this->{'projects_' . $type}; } // return projects from cache if exists $all_projects = $this->request('projects?per_page=5000', false, true); // all projects data //$all_projects['projects'] = $this->module_instance->getProjectsListDataByType($type); /* divides all projects into specific arrays of translation, copywriting and proofreading */ foreach ($all_projects['projects'] as $project) { $project_local_data = TextMasterProject::getProjectByApiId($project['id']); if (!$project_local_data->id) { continue; } // lets go through only if project has been created from within PrestaShop $project['id_project'] = $project_local_data->id; $project['date_add'] = $project_local_data->date_add; $project['date_upd'] = $project_local_data->date_upd; $project['show_launch_button'] = 1; //always show button but displayLaunchButton function does the final decision according status. Kinda workaraund here. $projectsData = $this->{'projects_' . $project['ctype']}; // copy of specific projects array $projectsData[] = $project; // appends project data into copy of specific projects array $this->{'projects_' . $project['ctype']} = $projectsData; // updated array is assigned back to original specific projects array } return $this->{'projects_' . $type}; }