public function savecompanyfeatureAction() { $actionIds = $this->getRequest()->getPost('actionIds'); $companyId = $this->getRequest()->getPost('companyId'); $jsonModel = new JsonModel(); if (!$companyId) { $jsonModel->setVariables(['code' => 0, 'messages' => ['Dữ liệu không hợp lệ']]); return $jsonModel; } $companyFeature = new \Company\Model\Feature(); $companyFeature->setCompanyId($companyId); $companyFeatureMapper = $this->getServiceLocator()->get('\\Company\\Model\\FeatureMapper'); $companyFeatureMapper->deleteCompanyFeature($companyFeature); if ($actionIds) { $actionIds = explode(',', $actionIds); foreach ($actionIds as $actionId) { $companyFeature->setActionId($actionId); if (!$companyFeatureMapper->isExisted($companyFeature)) { $companyFeatureMapper->save($companyFeature); } } } $jsonModel->setVariables(['code' => 1]); return $jsonModel; }
public function clonecompanyfeatureAction() { $fromCompanyId = $this->getRequest()->getQuery('fromCompanyId'); $toCompanyId = $this->getRequest()->getQuery('toCompanyId'); $dbSql = $this->getServiceLocator()->get('dbSql'); $dbAdapter = $this->getServiceLocator()->get('dbAdapter'); $select = $dbSql->select(['f' => \Company\Model\FeatureMapper::TABLE_NAME]); $select->where(['companyId' => $fromCompanyId]); $query = $dbSql->buildSqlString($select); $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); $actionIds = []; if ($rows->count()) { foreach ($rows->toArray() as $row) { $actionIds[$row['actionId']] = $row['actionId']; } } $toCompanyIds = explode(',', $toCompanyId); $digitFilter = new \Zend\Filter\Digits(); $featureMapper = $this->getServiceLocator()->get('\\Company\\Model\\FeatureMapper'); if (count($toCompanyIds)) { foreach ($toCompanyIds as $companyId) { $companyId = $digitFilter->filter($companyId); foreach ($actionIds as $actionId) { $feature = new \Company\Model\Feature(); $feature->setCompanyId($companyId); $feature->setActionId($actionId); if (!$featureMapper->isExisted($feature)) { $featureMapper->save($feature); } } echo 'done ' . $companyId . '<br/>'; } } die; }