2011-01-01 07:36:51 +09:00
|
|
|
<?php
|
2019-08-08 23:08:23 +09: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/>.
|
|
|
|
|
2011-01-01 07:36:51 +09:00
|
|
|
/**
|
2019-08-08 23:08:23 +09:00
|
|
|
* Allows administrators to define additional profile fields for the users of a GNU social installation.
|
2011-01-01 07:36:51 +09:00
|
|
|
*
|
|
|
|
* @category Widget
|
2019-08-08 23:08:23 +09:00
|
|
|
* @package GNU social
|
2011-01-01 07:36:51 +09:00
|
|
|
* @author Max Shinn <trombonechamp@gmail.com>
|
2019-08-08 23:08:23 +09: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
|
2011-01-01 07:36:51 +09:00
|
|
|
*/
|
|
|
|
|
2019-08-08 23:08:23 +09:00
|
|
|
defined('GNUSOCIAL') || die();
|
2011-01-01 07:36:51 +09:00
|
|
|
|
2013-08-18 19:10:44 +09:00
|
|
|
class GNUsocialProfileExtensionField extends Managed_DataObject
|
2011-01-01 07:36:51 +09:00
|
|
|
{
|
2013-08-21 21:12:18 +09:00
|
|
|
public $__table = 'gnusocialprofileextensionfield';
|
2011-01-01 07:36:51 +09:00
|
|
|
public $id; // int(11)
|
|
|
|
public $systemname; // varchar(64)
|
2015-02-13 02:18:55 +09:00
|
|
|
public $title; // varchar(191) not 255 because utf8mb4 takes more space
|
2011-01-01 07:36:51 +09:00
|
|
|
public $description; // text
|
2015-02-13 02:18:55 +09:00
|
|
|
public $type; // varchar(191) not 255 because utf8mb4 takes more space
|
2019-08-08 23:08:23 +09:00
|
|
|
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
|
|
|
|
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
|
2011-01-01 07:36:51 +09:00
|
|
|
|
2019-08-08 23:08:23 +09:00
|
|
|
public static function schemaDef(): array
|
2011-01-01 07:36:51 +09:00
|
|
|
{
|
2019-08-08 23:08:23 +09: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'],
|
|
|
|
'created' => ['type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'],
|
|
|
|
'modified' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
|
|
|
|
],
|
|
|
|
'primary key' => ['id'],
|
|
|
|
'indexes' => [
|
|
|
|
'gnusocialprofileextensionfield_title_idx' => ['title'],
|
|
|
|
],
|
|
|
|
];
|
2011-01-01 07:36:51 +09:00
|
|
|
}
|
|
|
|
|
2019-08-08 23:08:23 +09:00
|
|
|
public static function newField($title, $description = null, $type = 'str', $system_name = null): GNUsocialProfileExtensionField
|
2011-01-01 07:36:51 +09:00
|
|
|
{
|
|
|
|
$field = new GNUsocialProfileExtensionField();
|
|
|
|
$field->title = $title;
|
|
|
|
$field->description = $description;
|
|
|
|
$field->type = $type;
|
2019-08-08 23:08:23 +09:00
|
|
|
if (empty($system_name)) {
|
|
|
|
$field->systemname = 'field' . $field->id;
|
|
|
|
} else {
|
|
|
|
$field->systemname = $system_name;
|
|
|
|
}
|
|
|
|
|
2011-01-01 07:36:51 +09:00
|
|
|
$field->id = $field->insert();
|
2019-08-08 23:08:23 +09:00
|
|
|
if (!$field->id) {
|
2011-01-01 07:36:51 +09:00
|
|
|
common_log_db_error($field, 'INSERT', __FILE__);
|
|
|
|
throw new ServerException(_m('Error creating new field.'));
|
|
|
|
}
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
2019-08-08 23:08:23 +09:00
|
|
|
public static function allFields(): array
|
2011-01-01 07:36:51 +09:00
|
|
|
{
|
|
|
|
$field = new GNUsocialProfileExtensionField();
|
2019-08-08 23:08:23 +09:00
|
|
|
$fields = [];
|
2011-01-01 07:36:51 +09:00
|
|
|
if ($field->find()) {
|
2019-08-08 23:08:23 +09:00
|
|
|
while ($field->fetch()) {
|
2011-01-01 07:36:51 +09:00
|
|
|
$fields[] = clone($field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
}
|