File indexing completed on 2024-12-22 05:33:27
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class Backend_ProjectController extends Local_Controller_Action_Backend 0024 { 0025 0026 const RESULT_OK = "OK"; 0027 const RESULT_ERROR = "ERROR"; 0028 const DATA_ID_NAME = 'project_id'; 0029 0030 const PARAM_FEATURED = 'featured'; 0031 const PARAM_APPROVED = 'ghns_excluded'; 0032 const PARAM_PLING_EXCLUDED = 'pling_excluded'; 0033 const PARAM_PRODUCT_DANGEROUS = 'product_dangerous'; 0034 const PARAM_PRODUCT_DEPRECATED = 'product_deprecated'; 0035 0036 const PARAM_MSG ='msg'; 0037 /** @var Default_Model_Project */ 0038 protected $_model; 0039 0040 protected $_modelName = 'Default_Model_Project'; 0041 protected $_pageTitle = 'Manage Products'; 0042 0043 public function init() 0044 { 0045 $this->_model = new $this->_modelName(); 0046 0047 $this->view->pageTitle = $this->_pageTitle; 0048 0049 parent::init(); 0050 } 0051 0052 public function indexAction() 0053 { 0054 } 0055 0056 public function listAction() 0057 { 0058 $startIndex = (int)$this->getParam('jtStartIndex'); 0059 $pageSize = (int)$this->getParam('jtPageSize'); 0060 $sorting = $this->getParam('jtSorting'); 0061 $filter['title'] = $this->getParam('filter_title'); 0062 $filter['project_id'] = $this->getParam('filter_project_id'); 0063 $filter['member_id'] = $this->getParam('filter_member_id'); 0064 $filter['claimable'] = $this->getParam('filter_claimable'); 0065 $filter['type_id'][1] = $this->getParam('filter_project_page'); 0066 $filter['type_id'][2] = $this->getParam('filter_personal_page'); 0067 $filter['type_id'][3] = $this->getParam('filter_updates'); 0068 0069 $select = $this->_model->select()->order($sorting)->limit($pageSize, $startIndex); 0070 0071 $metadata = $this->_model->info(Zend_Db_Table_Abstract::METADATA); 0072 0073 foreach ($filter as $key => $value) { 0074 if (is_array($value)) { 0075 $list = ''; 0076 foreach ($value as $element) { 0077 if (isset($element)) { 0078 $list = $list . ',' . $element; 0079 } 0080 } 0081 0082 if (empty($list)) { 0083 continue; 0084 } 0085 0086 $list = substr($list, 1); 0087 0088 $select->where("{$key} in ({$list})"); 0089 0090 continue; 0091 } 0092 if (false === empty($value)) { 0093 $data_type = $metadata[$key]['DATA_TYPE']; 0094 if (($data_type == 'varchar') OR ($data_type == 'text')) { 0095 $select->where("{$key} like ?", '%' . $value . '%'); 0096 } else { 0097 $select->where("{$key} = ?", $value); 0098 } 0099 } 0100 } 0101 0102 $auth = Zend_Auth::getInstance(); 0103 if ($auth->hasIdentity()) { 0104 $identity = $auth->getIdentity(); 0105 $roleName = $identity->roleName; 0106 0107 switch ($roleName) { 0108 case Default_Plugin_AclRules::ROLENAME_STAFF: 0109 $select->where('status >= ?', Default_Model_DbTable_Project::PROJECT_ILLEGAL); 0110 break; 0111 } 0112 } 0113 0114 $reports = $this->_model->fetchAll($select); 0115 0116 $reportsAll = $this->_model->fetchAll($select->limit(null, null)->reset('columns') 0117 ->columns(array('countAll' => new Zend_Db_Expr('count(*)')))); 0118 0119 $jTableResult = array(); 0120 $jTableResult['Result'] = self::RESULT_OK; 0121 $jTableResult['Records'] = $reports->toArray(); 0122 $jTableResult['TotalRecordCount'] = $reportsAll->current()->countAll; 0123 0124 $this->_helper->json($jTableResult); 0125 } 0126 0127 public function createAction() 0128 { 0129 $jTableResult = array(); 0130 try { 0131 $newRow = $this->_model->createRow($this->getAllParams()); 0132 $result = $newRow->save(); 0133 0134 $jTableResult['Result'] = self::RESULT_OK; 0135 $jTableResult['Record'] = $newRow->toArray(); 0136 } catch (Exception $e) { 0137 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0138 $translate = Zend_Registry::get('Zend_Translate'); 0139 $jTableResult['Result'] = self::RESULT_ERROR; 0140 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0141 } 0142 0143 $this->_helper->json($jTableResult); 0144 } 0145 0146 public function updateAction() 0147 { 0148 $jTableResult = array(); 0149 try { 0150 $filterInput = new Zend_Filter_Input(array( 0151 '*' => 'StringTrim', 0152 'project_id' => 'digits', 0153 'member_id' => 'digits', 0154 'project_category_id' => 'digits', 0155 'status' => 'digits', 0156 'pid' => 'digits', 0157 'type_id' => 'digits', 0158 'creator_id' => 'digits', 0159 'validated' => 'digits', 0160 'featured' => 'digits', 0161 'amount' => 'digits', 0162 'spam_checked' => 'digits', 0163 'claimable' => 'digits', 0164 'claimed_by_member' => 'digits', 0165 ), array('*' => array()), $this->getAllParams()); 0166 0167 $record = $this->_model->save($filterInput->getEscaped()); 0168 0169 $jTableResult = array(); 0170 $jTableResult['Result'] = self::RESULT_OK; 0171 $jTableResult['Record'] = $record->toArray(); 0172 } catch (Exception $e) { 0173 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0174 $translate = Zend_Registry::get('Zend_Translate'); 0175 $jTableResult['Result'] = self::RESULT_ERROR; 0176 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0177 } 0178 0179 $this->_helper->json($jTableResult); 0180 } 0181 0182 public function deleteAction() 0183 { 0184 $identity = Zend_Auth::getInstance()->getIdentity(); 0185 $dataId = (int)$this->getParam(self::DATA_ID_NAME, null); 0186 0187 $this->_model->setDeleted($identity->member_id, $dataId); 0188 0189 $product = $this->_model->find($dataId)->current(); 0190 0191 0192 Default_Model_ActivityLog::logActivity($dataId, $dataId, $identity->member_id, 0193 Default_Model_ActivityLog::BACKEND_PROJECT_DELETE, $product); 0194 0195 $jTableResult = array(); 0196 $jTableResult['Result'] = self::RESULT_OK; 0197 0198 $this->_helper->json($jTableResult); 0199 } 0200 0201 public function togglestatusAction() 0202 { 0203 $jTableResult = array(); 0204 try { 0205 $projectId = (int)$this->getParam('project_id'); 0206 0207 $record = $this->_model->find($projectId)->current(); 0208 $record->status = ($record->status ? 0 : 10); 0209 $record->save(); 0210 0211 $jTableResult = array(); 0212 $jTableResult['Result'] = self::RESULT_OK; 0213 $jTableResult['Record'] = $record->toArray(); 0214 } catch (Exception $e) { 0215 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0216 $translate = Zend_Registry::get('Zend_Translate'); 0217 $jTableResult['Result'] = self::RESULT_ERROR; 0218 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0219 } 0220 0221 $this->_helper->json($jTableResult); 0222 } 0223 0224 public function dospamcheckedAction() 0225 { 0226 $id = (int)$this->getParam(self::DATA_ID_NAME); 0227 $product = $this->_model->fetchRow(array('project_id = ?' => $id)); 0228 if (empty($product)) { 0229 $jsonResult = array(); 0230 $jsonResult['Result'] = self::RESULT_ERROR; 0231 0232 $this->_helper->json($jsonResult); 0233 } 0234 0235 $checked = (int)$this->getParam('checked'); 0236 $sql = "UPDATE project SET spam_checked = :spam_checked, changed_at = :changed_at WHERE project_id = :project_id"; 0237 $this->_model->getAdapter() 0238 ->query($sql, array('spam_checked' => $checked, 'changed_at' => $product->changed_at, 'project_id' => $id)) 0239 ; 0240 0241 $jsonResult = array(); 0242 $jsonResult['Result'] = self::RESULT_OK; 0243 $jsonResult['spam_checked'] = $checked; 0244 0245 $this->_helper->json($jsonResult); 0246 } 0247 0248 public function dofeatureAction() 0249 { 0250 $projectId = (int)$this->getParam(self::DATA_ID_NAME, null); 0251 $product = $this->_model->find($projectId)->current(); 0252 $featured = (int)$this->getParam(self::PARAM_FEATURED, null); 0253 0254 $sql = "UPDATE project SET featured = :featured, changed_at = :changed_at WHERE project_id = :project_id"; 0255 $this->_model->getAdapter() 0256 ->query($sql, array('featured' => $featured, 'changed_at' => $product->changed_at, 'project_id' => $projectId)) 0257 ; 0258 0259 $auth = Zend_Auth::getInstance(); 0260 $identity = $auth->getIdentity(); 0261 Default_Model_ActivityLog::logActivity($projectId, $projectId, $identity->member_id, 0262 Default_Model_ActivityLog::BACKEND_PROJECT_FEATURE, $product); 0263 0264 $jTableResult = array(); 0265 $jTableResult['Result'] = self::RESULT_OK; 0266 0267 $this->_helper->json($jTableResult); 0268 } 0269 0270 public function doghnsexcludeAction() 0271 { 0272 $projectId = (int)$this->getParam(self::DATA_ID_NAME, null); 0273 $product = $this->_model->find($projectId)->current(); 0274 $ghns_excluded = (int)$this->getParam(self::PARAM_APPROVED, null); 0275 0276 $tableTags = new Default_Model_Tags(); 0277 $tableTags->saveGhnsExcludedTagForProject($projectId, $ghns_excluded); 0278 0279 0280 /** ronald 20180611 now as tag 0281 $sql = "UPDATE project SET ghns_excluded = :ghns_excluded WHERE project_id = :project_id"; 0282 $this->_model->getAdapter()->query($sql, array('ghns_excluded' => $ghns_excluded, 'project_id' => $projectId)); 0283 */ 0284 0285 $auth = Zend_Auth::getInstance(); 0286 $identity = $auth->getIdentity(); 0287 Default_Model_ActivityLog::logActivity($projectId, $projectId, $identity->member_id, 0288 Default_Model_ActivityLog::BACKEND_PROJECT_GHNS_EXCLUDED, $product); 0289 0290 0291 $moderationModel = new Default_Model_ProjectModeration(); 0292 0293 $note =$this->getParam(self::PARAM_MSG, null); 0294 0295 0296 $moderationModel->createModeration($projectId 0297 ,Default_Model_ProjectModeration::M_TYPE_GET_HOT_NEW_STUFF_EXCLUDED 0298 ,$ghns_excluded 0299 ,$identity->member_id 0300 ,$note 0301 ); 0302 0303 $jTableResult = array(); 0304 $jTableResult['Result'] = self::RESULT_OK; 0305 0306 $this->_helper->json($jTableResult); 0307 } 0308 0309 0310 public function doexcludeAction() 0311 { 0312 $projectId = (int)$this->getParam(self::DATA_ID_NAME, null); 0313 $product = $this->_model->find($projectId)->current(); 0314 $exclude = (int)$this->getParam(self::PARAM_PLING_EXCLUDED, null); 0315 0316 $sql = "UPDATE project SET pling_excluded = :exclude WHERE project_id = :project_id"; 0317 $this->_model->getAdapter()->query($sql, array('exclude' => $exclude, 'project_id' => $projectId)); 0318 0319 $auth = Zend_Auth::getInstance(); 0320 $identity = $auth->getIdentity(); 0321 Default_Model_ActivityLog::logActivity($projectId, $projectId, $identity->member_id, 0322 Default_Model_ActivityLog::BACKEND_PROJECT_PLING_EXCLUDED, $product); 0323 0324 $jTableResult = array(); 0325 $jTableResult['Result'] = self::RESULT_OK; 0326 0327 $this->_helper->json($jTableResult); 0328 } 0329 0330 public function dodeprecatedAction() 0331 { 0332 $projectId = (int)$this->getParam(self::DATA_ID_NAME, null); 0333 $product = $this->_model->find($projectId)->current(); 0334 $deprecated = (int)$this->getParam(self::PARAM_PRODUCT_DEPRECATED, null); 0335 0336 $tableTags = new Default_Model_Tags(); 0337 $tableTags->saveDeprecatedModeratorTagForProject($projectId, $deprecated); 0338 0339 $auth = Zend_Auth::getInstance(); 0340 $identity = $auth->getIdentity(); 0341 Default_Model_ActivityLog::logActivity($projectId, $projectId, $identity->member_id, 0342 Default_Model_ActivityLog::BACKEND_PROJECT_DEPREACTED, $product); 0343 0344 0345 $jTableResult = array(); 0346 $jTableResult['Result'] = self::RESULT_OK; 0347 0348 $this->_helper->json($jTableResult); 0349 } 0350 0351 public function dodangerousAction() 0352 { 0353 $projectId = (int)$this->getParam(self::DATA_ID_NAME, null); 0354 $product = $this->_model->find($projectId)->current(); 0355 $dangerous = (int)$this->getParam(self::PARAM_PRODUCT_DANGEROUS, null); 0356 0357 $tableTags = new Default_Model_Tags(); 0358 $tableTags->saveDangerosuTagForProject($projectId, $dangerous); 0359 0360 $auth = Zend_Auth::getInstance(); 0361 $identity = $auth->getIdentity(); 0362 Default_Model_ActivityLog::logActivity($projectId, $projectId, $identity->member_id, 0363 Default_Model_ActivityLog::BACKEND_PROJECT_DANGEROUS, $product); 0364 0365 0366 $jTableResult = array(); 0367 $jTableResult['Result'] = self::RESULT_OK; 0368 0369 $this->_helper->json($jTableResult); 0370 } 0371 0372 0373 public function changecatAction() 0374 { 0375 $projectId = (int)$this->getParam(self::DATA_ID_NAME, null); 0376 $catId = (int)$this->getParam('project_category_id', null); 0377 0378 $product = $this->_model->find($projectId)->current(); 0379 $sql = "UPDATE project SET project_category_id = :cat_id, changed_at = :changed_at WHERE project_id = :project_id"; 0380 $this->_model->getAdapter() 0381 ->query($sql, array('cat_id' => $catId, 'changed_at' => $product->changed_at, 'project_id' => $projectId)) 0382 ; 0383 0384 $identity = Zend_Auth::getInstance()->getIdentity(); 0385 Default_Model_ActivityLog::logActivity($projectId, $projectId, $identity->member_id, 0386 Default_Model_ActivityLog::BACKEND_PROJECT_CAT_CHANGE, $product); 0387 0388 $jTableResult = array(); 0389 $jTableResult['Result'] = self::RESULT_OK; 0390 0391 $this->_helper->json($jTableResult); 0392 } 0393 0394 public function unsplashAction() 0395 { 0396 $command = new Backend_Commands_DeleteProductUnsplash(); 0397 $result = $command->doCommand(); 0398 0399 $this->view->result = "total projects: {$result['total']} => deleted projects: " . ((int)$result['total']-(int)$result['errors']); 0400 } 0401 }