File indexing completed on 2025-05-04 05:29:13
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 Default_Model_ProjectLicense 0024 { 0025 0026 /** @var string */ 0027 protected $_dataTableName; 0028 /** @var Local_Model_Table */ 0029 protected $_dataTable; 0030 0031 /** 0032 * PHP 5 allows developers to declare constructor methods for classes. 0033 * Classes which have a constructor method call this method on each newly-created object, 0034 * so it is suitable for any initialization that the object may need before it is used. 0035 * 0036 * Note: Parent constructors are not called implicitly if the child class defines a constructor. 0037 * In order to run a parent constructor, a call to parent::__construct() within the child constructor is required. 0038 * 0039 * param [ mixed $args [, $... ]] 0040 * 0041 * @link http://php.net/manual/en/language.oop5.decon.php 0042 * 0043 * @param string $_dataTableName 0044 */ 0045 function __construct($_dataTableName = 'Default_Model_DbTable_ProjectCcLicense') 0046 { 0047 $this->_dataTableName = $_dataTableName; 0048 $this->_dataTable = new $this->_dataTableName; 0049 } 0050 0051 /** 0052 * @param int $project_id 0053 * 0054 * @return bool 0055 */ 0056 public function hasLicense($project_id) 0057 { 0058 $resultRow = $this->_dataTable->fetchRow(array('project_id = ?' => $project_id)); 0059 if (empty($resultRow)) { 0060 return false; 0061 } 0062 0063 return true; 0064 } 0065 0066 /** 0067 * @param int $_projectId 0068 * @param array $values 0069 */ 0070 public function saveLicenseData($_projectId, $values) 0071 { 0072 $row = $this->findOneProject($_projectId); 0073 $row->setFromArray($values); 0074 $row->project_id = $_projectId; 0075 $row->save(); 0076 } 0077 0078 /** 0079 * @param $project_id 0080 * 0081 * @return Default_Model_DbRow_ProjectCcLicense 0082 */ 0083 public function findOneProject($project_id) 0084 { 0085 $resultRow = $this->_dataTable->fetchRow(array('project_id = ?' => $project_id)); 0086 if (empty($resultRow)) { 0087 $resultRow = $this->_dataTable->createRow(array(), Default_Model_DbTable_ProjectCcLicense::DEFAULT_CLASS); 0088 } 0089 0090 return $resultRow; 0091 } 0092 0093 /** 0094 * @param int $_projectId 0095 * 0096 * @throws Zend_Db_Table_Row_Exception 0097 */ 0098 public function deleteLicenseData($_projectId) 0099 { 0100 $row = $this->findOneProject($_projectId); 0101 if ($row->isStoredLicense()) { 0102 $row->delete(); 0103 } 0104 } 0105 0106 }