| 1 | <?php |
| 2 | /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 3 | /* |
| 4 | # ***** BEGIN LICENSE BLOCK ***** |
| 5 | # This file is part of InDefero, an open source project management application. |
| 6 | # Copyright (C) 2008 Céondo Ltd and contributors. |
| 7 | # |
| 8 | # InDefero is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | # InDefero is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with this program; if not, write to the Free Software |
| 20 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | # |
| 22 | # ***** END LICENSE BLOCK ***** */ |
| 23 | |
| 24 | /** |
| 25 | * Storage of the SSH keys. |
| 26 | * |
| 27 | */ |
| 28 | class IDF_Key extends Pluf_Model |
| 29 | { |
| 30 | public $_model = __CLASS__; |
| 31 | |
| 32 | function init() |
| 33 | { |
| 34 | $this->_a['table'] = 'idf_keys'; |
| 35 | $this->_a['model'] = __CLASS__; |
| 36 | $this->_a['cols'] = array( |
| 37 | // It is mandatory to have an "id" column. |
| 38 | 'id' => |
| 39 | array( |
| 40 | 'type' => 'Pluf_DB_Field_Sequence', |
| 41 | //It is automatically added. |
| 42 | 'blank' => true, |
| 43 | ), |
| 44 | 'user' => |
| 45 | array( |
| 46 | 'type' => 'Pluf_DB_Field_Foreignkey', |
| 47 | 'model' => 'Pluf_User', |
| 48 | 'blank' => false, |
| 49 | 'verbose' => __('user'), |
| 50 | ), |
| 51 | 'content' => |
| 52 | array( |
| 53 | 'type' => 'Pluf_DB_Field_Text', |
| 54 | 'blank' => false, |
| 55 | 'verbose' => __('ssh key'), |
| 56 | ), |
| 57 | ); |
| 58 | // WARNING: Not using getSqlTable on the Pluf_User object to |
| 59 | // avoid recursion. |
| 60 | $t_users = $this->_con->pfx.'users'; |
| 61 | $this->_a['views'] = array( |
| 62 | 'join_user' => |
| 63 | array( |
| 64 | 'join' => 'LEFT JOIN '.$t_users |
| 65 | .' ON '.$t_users.'.id='.$this->_con->qn('user'), |
| 66 | 'select' => $this->getSelect().', ' |
| 67 | .$t_users.'.login AS login', |
| 68 | 'props' => array('login' => 'login'), |
| 69 | ) |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | function showCompact() |
| 74 | { |
| 75 | return Pluf_Template::markSafe(Pluf_esc(substr($this->content, 0, 25)).' [...] '.Pluf_esc(substr($this->content, -55))); |
| 76 | } |
| 77 | |
| 78 | function postSave($create=false) |
| 79 | { |
| 80 | /** |
| 81 | * [signal] |
| 82 | * |
| 83 | * IDF_Key::postSave |
| 84 | * |
| 85 | * [sender] |
| 86 | * |
| 87 | * IDF_Key |
| 88 | * |
| 89 | * [description] |
| 90 | * |
| 91 | * This signal allows an application to perform special |
| 92 | * operations after the saving of a SSH Key. |
| 93 | * |
| 94 | * [parameters] |
| 95 | * |
| 96 | * array('key' => $key, |
| 97 | * 'created' => true/false) |
| 98 | * |
| 99 | */ |
| 100 | $params = array('key' => $this, 'created' => $create); |
| 101 | Pluf_Signal::send('IDF_Key::postSave', |
| 102 | 'IDF_Key', $params); |
| 103 | } |
| 104 | |
| 105 | function preDelete() |
| 106 | { |
| 107 | /** |
| 108 | * [signal] |
| 109 | * |
| 110 | * IDF_Key::preDelete |
| 111 | * |
| 112 | * [sender] |
| 113 | * |
| 114 | * IDF_Key |
| 115 | * |
| 116 | * [description] |
| 117 | * |
| 118 | * This signal allows an application to perform special |
| 119 | * operations before a key is deleted. |
| 120 | * |
| 121 | * [parameters] |
| 122 | * |
| 123 | * array('key' => $key) |
| 124 | * |
| 125 | */ |
| 126 | $params = array('key' => $this); |
| 127 | Pluf_Signal::send('IDF_Key::preDelete', |
| 128 | 'IDF_Key', $params); |
| 129 | } |
| 130 | |
| 131 | } |
| 132 | |