| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2019-08-08 15:08:23 +01:00
										 |  |  | // This file is part of GNU social - https://www.gnu.org/software/social
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or
 | 
					
						
							|  |  |  | // (at your option) any later version.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is distributed in the hope that it will be useful,
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU Affero General Public License for more details.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License
 | 
					
						
							|  |  |  | // along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2019-08-08 15:08:23 +01:00
										 |  |  |  * Allows administrators to define additional profile fields for the users of a GNU social installation. | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @category  Widget | 
					
						
							| 
									
										
										
										
											2020-06-29 01:41:46 +03:00
										 |  |  |  * @package   GNUsocial | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  |  * @author    Max Shinn <trombonechamp@gmail.com> | 
					
						
							| 
									
										
										
										
											2019-08-08 15:08:23 +01:00
										 |  |  |  * @author    Diogo Cordeiro <diogo@fc.up.pt> | 
					
						
							|  |  |  |  * @copyright 2011-2019 Free Software Foundation, Inc http://www.fsf.org | 
					
						
							|  |  |  |  * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 15:08:23 +01:00
										 |  |  | defined('GNUSOCIAL') || die(); | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-18 12:10:44 +02:00
										 |  |  | class GNUsocialProfileExtensionField extends Managed_DataObject | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-08-21 14:12:18 +02:00
										 |  |  |     public $__table = 'gnusocialprofileextensionfield'; | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  |     public $id;          // int(11)
 | 
					
						
							|  |  |  |     public $systemname;  // varchar(64)
 | 
					
						
							| 
									
										
										
										
											2015-02-12 18:18:55 +01:00
										 |  |  |     public $title;       // varchar(191)   not 255 because utf8mb4 takes more space
 | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  |     public $description; // text
 | 
					
						
							| 
									
										
										
										
											2015-02-12 18:18:55 +01:00
										 |  |  |     public $type;        // varchar(191)   not 255 because utf8mb4 takes more space
 | 
					
						
							| 
									
										
										
										
											2020-06-29 01:41:46 +03:00
										 |  |  |     public $created;     // datetime()
 | 
					
						
							|  |  |  |     public $modified;    // timestamp()    not_null default_CURRENT_TIMESTAMP
 | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 15:08:23 +01:00
										 |  |  |     public static function schemaDef(): array | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-08-08 15:08:23 +01:00
										 |  |  |         return [ | 
					
						
							|  |  |  |             'fields' => [ | 
					
						
							|  |  |  |                 'id' => ['type' => 'serial', 'not null' => true, 'description' => 'Unique ID for extension field'], | 
					
						
							|  |  |  |                 'systemname' => ['type' => 'varchar', 'not null' => true, 'length' => 64, 'description' => 'field systemname'], | 
					
						
							|  |  |  |                 'title' => ['type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'field title'], | 
					
						
							|  |  |  |                 'description' => ['type' => 'text', 'not null' => true, 'description' => 'field description'], | 
					
						
							|  |  |  |                 'type' => ['type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'field type'], | 
					
						
							| 
									
										
										
										
											2020-06-29 01:41:46 +03:00
										 |  |  |                 'created' => ['type' => 'datetime', 'description' => 'date this record was created'], | 
					
						
							|  |  |  |                 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'], | 
					
						
							| 
									
										
										
										
											2019-08-08 15:08:23 +01:00
										 |  |  |             ], | 
					
						
							|  |  |  |             'primary key' => ['id'], | 
					
						
							|  |  |  |             'indexes' => [ | 
					
						
							|  |  |  |                 'gnusocialprofileextensionfield_title_idx' => ['title'], | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 15:08:23 +01:00
										 |  |  |     public static function newField($title, $description = null, $type = 'str', $system_name = null): GNUsocialProfileExtensionField | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  |     { | 
					
						
							|  |  |  |         $field = new GNUsocialProfileExtensionField(); | 
					
						
							|  |  |  |         $field->title = $title; | 
					
						
							|  |  |  |         $field->description = $description; | 
					
						
							|  |  |  |         $field->type = $type; | 
					
						
							| 
									
										
										
										
											2019-08-08 15:08:23 +01:00
										 |  |  |         if (empty($system_name)) { | 
					
						
							|  |  |  |             $field->systemname = 'field' . $field->id; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $field->systemname = $system_name; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  |         $field->id = $field->insert(); | 
					
						
							| 
									
										
										
										
											2019-08-08 15:08:23 +01:00
										 |  |  |         if (!$field->id) { | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  |             common_log_db_error($field, 'INSERT', __FILE__); | 
					
						
							|  |  |  |             throw new ServerException(_m('Error creating new field.')); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return $field; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 15:08:23 +01:00
										 |  |  |     public static function allFields(): array | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  |     { | 
					
						
							|  |  |  |         $field = new GNUsocialProfileExtensionField(); | 
					
						
							| 
									
										
										
										
											2019-08-08 15:08:23 +01:00
										 |  |  |         $fields = []; | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  |         if ($field->find()) { | 
					
						
							| 
									
										
										
										
											2019-08-08 15:08:23 +01:00
										 |  |  |             while ($field->fetch()) { | 
					
						
							| 
									
										
										
										
											2010-12-31 16:36:51 -06:00
										 |  |  |                 $fields[] = clone($field); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return $fields; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |