aboutsummaryrefslogtreecommitdiff
path: root/app/class/Page.php
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-01-10 15:28:29 +0100
committervincent-peugnet <v.peugnet@free.fr>2020-01-10 15:28:29 +0100
commit7001272f4e8b683cbc64564c5798d85a34ab9026 (patch)
tree01f52cca7f8013b3b66bfbd29c2d4a1538b097b4 /app/class/Page.php
parent7eb6ec32c4313a7456370e47d3878ff961ec56d0 (diff)
downloadwcms-7001272f4e8b683cbc64564c5798d85a34ab9026.tar.gz
wcms-7001272f4e8b683cbc64564c5798d85a34ab9026.zip
refact : ptime pdate added inside of page
Diffstat (limited to 'app/class/Page.php')
-rw-r--r--app/class/Page.php67
1 files changed, 54 insertions, 13 deletions
diff --git a/app/class/Page.php b/app/class/Page.php
index 2fa4060..1daa240 100644
--- a/app/class/Page.php
+++ b/app/class/Page.php
@@ -114,8 +114,6 @@ class Page
$this->seteditby([]);
}
-
-
public static function classvarlist()
{
$classvarlist = [];
@@ -484,18 +482,10 @@ class Page
public function settag($tag)
{
- if (is_string($tag)) {
-
- if (strlen($tag) < self::LEN) {
- $tag = strip_tags(trim(strtolower($tag)));
- $tag = str_replace('*', '', $tag);
- $tag = str_replace(' ', '', $tag);
-
- $taglist = explode(",", $tag);
- $taglist = array_filter($taglist);
- $this->tag = $taglist;
+ if (is_string($tag) && strlen($tag) < self::LEN) {
+ $tag = $this->tagtoarray($tag);
}
- } elseif (is_array($tag)) {
+ if (is_array($tag)) {
$this->tag = $tag;
}
}
@@ -509,6 +499,22 @@ class Page
}
}
+ public function setptime($ptime)
+ {
+ if(is_string($ptime) && DateTime::createFromFormat('H:i', $ptime) !== FALSE) {
+ $time = explode(':', $ptime);
+ $this->date = $this->date->setTime($time[0], $time[1]);
+ }
+ }
+
+ public function setpdate($pdate)
+ {
+ if(is_string($pdate) && DateTime::createFromFormat('Y-m-d', $pdate) !== FALSE) {
+ $date = explode('-', $pdate);
+ $this->date = $this->date->setDate($date[0], $date[1], $date[2]);
+ }
+ }
+
public function setdatecreation($datecreation)
{
if ($datecreation instanceof DateTimeImmutable) {
@@ -813,6 +819,41 @@ class Page
return count($this->editby) > 0;
}
+ /**
+ * Merge new tag with actual tags
+ *
+ * @param string|array $tag Could be tags as string or array
+ */
+
+ public function addtag($tag)
+ {
+ if (is_string($tag)) {
+ $tag = $this->tagtoarray($tag);
+ }
+ if(is_array($tag)) {
+ $this->tag = array_unique(array_merge($this->tag, $tag));
+ }
+ }
+
+
+ // _________________________________ T O O L S ______________________________________
+
+ /**
+ * Convert a tag string to an array ready to be stored
+ *
+ * @param string $tagstring Tag as string separated by commas
+ * @return array Tags stored as an array
+ */
+
+ private function tagtoarray(string $tagstring) : array
+ {
+ $tag = strip_tags(trim(strtolower($tagstring)));
+ $tag = str_replace('*', '', $tag);
+ $tag = str_replace(' ', '', $tag);
+ $taglist = explode(",", $tag);
+ $taglist = array_filter($taglist);
+ return $taglist;
+ }
}