File indexing completed on 2025-02-09 07:14:34
0001 <?php 0002 /** 0003 * ocs-webserver 0004 * 0005 * Copyright 2016 by pling GmbH. 0006 * 0007 * This file is part of ocs-webserver. 0008 * 0009 * This program is free software: you can redistribute it and/or modify 0010 * it under the terms of the GNU Affero General Public License as 0011 * published by the Free Software Foundation, either version 3 of the 0012 * License, or (at your option) any later version. 0013 * 0014 * This program is distributed in the hope that it will be useful, 0015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 * GNU Affero General Public License for more details. 0018 * 0019 * You should have received a copy of the GNU Affero General Public License 0020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 **/ 0022 0023 class Default_Model_DbTable_ProjectWidgetDefault extends Local_Model_Table 0024 { 0025 protected $_key = 'widget_id'; 0026 0027 protected $_keyColumnsForRow = array('project_id'); 0028 0029 protected $_name = 'project_widget_default'; 0030 0031 protected $_primary = 'widget_id'; 0032 0033 /** 0034 * @param $projectId 0035 * @return mixed|stdClass returns default config if nothing found 0036 */ 0037 public function fetchConfig($projectId) 0038 { 0039 $defaultConfig = $this->fetchRow(array('project_id = ?' => $projectId)); 0040 0041 if (empty($defaultConfig)) { 0042 return $this->getDefaultConfig($projectId); 0043 } 0044 $temp = json_decode($defaultConfig->config); 0045 $temp->uuid = $defaultConfig['uuid']; 0046 $temp->project = $defaultConfig['project_id']; 0047 $temp->embedCode = ''; 0048 return $temp; 0049 } 0050 0051 private function getDefaultConfig($projectId) 0052 { 0053 $defaults = new stdClass(); 0054 $defaults->text = new stdClass(); 0055 $modelProject = new Default_Model_Project(); 0056 $dataProject = $modelProject->fetchRow(array('project_id = ?' => $projectId)); 0057 $modelMember = new Default_Model_Member(); 0058 $dataMember = $modelMember->fetchRow(array('member_id = ?' => $dataProject->member_id)); 0059 if ((false === empty($dataMember->paypal_mail)) OR (false === empty($dataMember->dwolla_id))) { 0060 $defaults->text->content = "I'm currently raising money through opendesktop.org . Click the donate button to help!"; 0061 } else { 0062 $defaults->text->content = "Discover more about my product on opendesktop.org ."; 0063 } 0064 $defaults->text->headline = $dataProject->title; 0065 $defaults->text->button = "Pling it!"; 0066 0067 $defaults->amounts = new stdClass(); 0068 $defaults->amounts->donation = 10; 0069 $defaults->amounts->showDonationAmount = true; 0070 $defaults->amounts->current = ''; 0071 $defaults->amounts->goal = ''; 0072 0073 $defaults->colors = new stdClass(); 0074 $defaults->colors->widgetBg = '#2673B0'; 0075 $defaults->colors->widgetContent = '#ffffff'; 0076 $defaults->colors->headline = '#ffffff'; 0077 $defaults->colors->text = '#000000'; 0078 $defaults->colors->button = '#428bca'; 0079 $defaults->colors->buttonText = '#ffffff'; 0080 0081 $defaults->showSupporters = true; 0082 $defaults->showComments = true; 0083 $defaults->logo = 'grey'; 0084 0085 $defaults->project = ''; 0086 $defaults->uuid = ''; 0087 $defaults->embedCode = ''; 0088 0089 return $defaults; 0090 } 0091 0092 public function insert(array $data) 0093 { 0094 if (empty($data['uuid'])) { 0095 $data['uuid'] = md5($data['config']); 0096 } 0097 0098 return parent::insert($data); 0099 } 0100 0101 public function save($data) 0102 { 0103 $data['uuid'] = $this->generateConfigUuid($data); 0104 0105 return parent::save($data); 0106 } 0107 0108 private function generateConfigUuid($data) 0109 { 0110 return md5($data['config']); 0111 } 0112 0113 0114 }