]> git.mxchange.org Git - friendica.git/commitdiff
Create new ProfileField classes
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 20 Jan 2020 00:21:30 +0000 (19:21 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 23 Jan 2020 00:42:34 +0000 (19:42 -0500)
- Create ProfileField model class
- Remove obsolete BaseCollection->models property

src/BaseCollection.php
src/Collection/ProfileFields.php [new file with mode: 0644]
src/Model/ProfileField.php [new file with mode: 0644]
src/Repository/ProfileField.php [new file with mode: 0644]

index 4d5803d58524e1b8dccfdba00a9b056c2fccef8a..5a20acee7f4f2a0f1ccf6e34fd6d2a6e03330d64 100644 (file)
@@ -24,7 +24,6 @@ abstract class BaseCollection extends \ArrayIterator
        {
                parent::__construct($models);
 
-               $this->models = $models;
                $this->totalCount = $totalCount ?? count($models);
        }
 
diff --git a/src/Collection/ProfileFields.php b/src/Collection/ProfileFields.php
new file mode 100644 (file)
index 0000000..e171b83
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+
+namespace Friendica\Collection;
+
+use Friendica\BaseCollection;
+
+class ProfileFields extends BaseCollection
+{
+
+}
diff --git a/src/Model/ProfileField.php b/src/Model/ProfileField.php
new file mode 100644 (file)
index 0000000..51b43e3
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+namespace Friendica\Model;
+
+use Friendica\BaseModel;
+
+/**
+ * Custom profile field model class.
+ *
+ * Custom profile fields are user-created arbitrary profile fields that can be assigned a permission set to restrict its
+ * display to specific Friendica contacts as it requires magic authentication to work.
+ *
+ * @property int    uid
+ * @property int    order
+ * @property int    psid
+ * @property string label
+ * @property string value
+ * @property string created
+ * @property string edited
+ */
+class ProfileField extends BaseModel
+{
+
+}
diff --git a/src/Repository/ProfileField.php b/src/Repository/ProfileField.php
new file mode 100644 (file)
index 0000000..21fd2da
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+
+namespace Friendica\Repository;
+
+use Friendica\BaseModel;
+use Friendica\BaseRepository;
+use Friendica\Collection;
+use Friendica\Model;
+use Friendica\Model\PermissionSet;
+use Friendica\Util\DateTimeFormat;
+
+class ProfileField extends BaseRepository
+{
+       protected static $table_name = 'profile_field';
+
+       protected static $model_class = Model\ProfileField::class;
+
+       protected static $collection_class = Collection\ProfileFields::class;
+
+       /**
+        * @param array $data
+        * @return Model\ProfileField
+        */
+       protected function create(array $data)
+       {
+               return new Model\ProfileField($this->dba, $this->logger, $data);
+       }
+
+       /**
+        * @param array $condition
+        * @return Model\ProfileField
+        * @throws \Friendica\Network\HTTPException\NotFoundException
+        */
+       public function selectFirst(array $condition)
+       {
+               return parent::selectFirst($condition);
+       }
+
+       /**
+        * @param array $condition
+        * @param array $params
+        * @return Collection\ProfileFields
+        * @throws \Exception
+        */
+       public function select(array $condition = [], array $params = [])
+       {
+               return parent::select($condition, $params);
+       }
+
+       /**
+        * @param array $condition
+        * @param array $params
+        * @param int|null $max_id
+        * @param int|null $since_id
+        * @param int $limit
+        * @return Collection\ProfileFields
+        * @throws \Exception
+        */
+       public function selectByBoundaries(array $condition = [], array $params = [], int $max_id = null, int $since_id = null, int $limit = self::LIMIT)
+       {
+               return parent::selectByBoundaries($condition, $params, $max_id, $since_id, $limit);
+       }
+
+       /**
+        * @param int $uid Field owner user Id
+        * @return Collection\ProfileFields
+        * @throws \Exception
+        */
+       public function selectByUserId(int $uid)
+       {
+               return $this->select(
+                       ['uid' => $uid],
+                       ['order' => ['order']]
+               );
+       }
+
+       /**
+        * Retrieve all custom profile field a given contact is able to access to, including public profile fields.
+        *
+        * @param int $cid Private contact id, must be owned by $uid
+        * @param int $uid Field owner user id
+        * @return Collection\ProfileFields
+        * @throws \Exception
+        */
+       public function selectByContactId(int $cid, int $uid)
+       {
+               $psids = PermissionSet::get($uid, $cid);
+
+               // Includes public custom fields
+               $psids[] = 0;
+
+               return $this->select(
+                       ['uid' => $uid, 'psid' => $psids],
+                       ['order' => ['order']]
+               );
+       }
+
+       /**
+        * @param array $fields
+        * @return Model\ProfileField|bool
+        * @throws \Exception
+        */
+       public function insert(array $fields)
+       {
+               $fields['created'] = DateTimeFormat::utcNow();
+               $fields['edited']  = DateTimeFormat::utcNow();
+
+               return parent::insert($fields);
+       }
+
+       /**
+        * @param Model\ProfileField $model
+        * @return bool
+        * @throws \Exception
+        */
+       public function update(BaseModel $model)
+       {
+               $model->edited = DateTimeFormat::utcNow();
+
+               return parent::update($model);
+       }
+}