public function newBean() { if ($this->bean !== null) { return $this->bean; } $bean = R::dispense('skemafield'); $bean->name = $this->name; $bean->cleanName = $this->cleanName; $bean->created = R::isoDateTime(); $bean->type = get_class($this); $bean->prerequisite = $this->prerequisite; return $this->bean = $bean; }
public function replace($content = '') { if (empty($this->name)) { throw new Exception('Page needs name before it can be saved'); } $userBean = Enpowi\App::user()->bean(); R::exec('UPDATE page SET is_revision = 1 WHERE name = ? and is_revision = 0', [$this->name]); $oldBean = $this->_bean; $originalUserBean = $userBean; //TODO: ensure createdBy is set once and contributors is an incremental list $bean = R::dispense('page'); $bean->name = $this->name; $bean->content = $content; $bean->created = R::isoDateTime(); $bean->user = $originalUserBean; $bean->isRevision = false; if ($oldBean !== null) { $bean->sharedUser = $oldBean->sharedUser; } $bean->sharedUser[] = $userBean; R::store($bean); return new Page($this->name, $bean); }
public static function create($name, $description) { $bean = R::dispense('gallery'); $bean->userId = App::user()->id; $bean->created = R::isoDateTime(); $gallery = new Gallery(null, $bean); return $gallery->setName($name)->setDescription($description)->save(); }
public function replace($content = '', $updateCache = true) { if (empty($this->name)) { throw new Exception('Blog post needs name before it can be saved'); } $bean = $this->_bean; if ($bean === null) { $this->_bean = $bean = R::dispense('blog'); } $bean->name = $this->name; $this->content = $bean->content = $content; $bean->edited = R::isoDateTime(); $bean->created = $this->created ?: R::isoDateTime(); $otherUserBean = App::user()->bean(); $bean->user = $this->_user !== null ? $this->_user->bean() : $otherUserBean; $this->contributorIds[] = $otherUserBean->getID(); $this->contributorIds = array_unique($this->contributorIds); $bean->contributorIds = implode(',', $this->contributorIds); if (!empty($this->publishedOn)) { $bean->publishedOn = R::isoDateTime($this->publishedOn); } else { $bean->publishedOn = null; } if ($updateCache) { if (Event\Blog\Cache::length() > 0) { Event\Blog\Cache::pub($this); } else { $this->cache = $rendered = $this->render(); $allowedTags = join('><', self::$cacheShortAllowedTagNames); if (strlen($allowedTags) > 0) { $allowedTags = '<' . $allowedTags . '>'; } else { $allowedTags = null; } $noTagsDirty = strip_tags($rendered, $allowedTags); $noTags = preg_replace('!\\s+!', ' ', $noTagsDirty); if (strlen($noTags) > self::$cacheShortLimit) { $noTags = substr($noTags, 0, self::$cacheShortLimit) . '...'; } $this->cacheShort = $noTags; } $bean->cache = $this->cache; $bean->cacheShort = $this->cacheShort; } $id = R::store($bean); Event\Blog\Replace::pub($this); return $id; }
public function canValidate() { return R::isoDateTime() - 60 * 60 * 24 < $this->_bean->validationDate; }
public function save() { $bean = $this->_bean; if ($bean === null) { $bean = $this->_bean = R::dispense('file'); $bean->userId = App::get()->user()->id; } $bean->classType = $this->classType; $bean->date = R::isoDateTime(); $bean->description = $this->description; $bean->name = $this->name; $bean->tags = $this->tags; $bean->hash = $this->hash; return $this->id = R::store($bean); }
public static function logError($detail = '') { $bean = R::dispense('error'); $bean->email = self::user()->email; $bean->ip = self::getApi()->request->getIp(); $bean->time = R::isoDateTime(); $bean->detail = $detail; R::store($bean); }
public function softTrash($bean) { $bean = $this->getBean($bean); $bean->deleted_at = R::isoDateTime(); return R::store($bean); }
return new Json($post->export()); }, 'POST')->route('edit-post', '/posts/:id', function ($id) use($auth) { $auth->authenticate(); $post = R::load('post', $id); if ($post->id != $id) { return new HttpStatus(HttpStatus::STATUS_204_NO_CONTENT); } $request = HttpContext::get()->getRequest(); if ($request->hasPost('post')) { $post->title = $request->getPost('post', 'title'); $post->summary = $request->getPost('post', 'summary'); $post->isactive = $request->getPost('post', 'isactive'); $post->content = $request->getPost('post', 'content'); $post->controller = $request->getPost('post', 'controller'); $post->slug = $request->getPost('post', 'slug'); $post->changed = R::isoDateTime(time()); // store tags $tags = $request->getPost('post', 'tags'); foreach ($tags as $tag) { $rbTag = R::findOne('tag', ' tag = ?', [$tag]); if (!$rbTag) { $rbTag = R::dispense('tag'); $rbTag->tag = $tag; R::store($rbTag); } $post->sharedTagList[] = $rbTag; } R::store($post); } return new Json($post->export()); }, 'PUT')->route('sitemap.xml', '/generate-sitemap', function () use($auth) {
public function replace($content = '') { if (empty($this->name)) { throw new Exception('Blog post needs name before it can be saved'); } $bean = $this->_bean; if ($bean === null) { $this->_bean = $bean = R::dispense('blog'); } $bean->name = $this->name; $this->content = $bean->content = $content; $bean->edited = R::isoDateTime(); $bean->created = $this->created ?: R::isoDateTime(); $otherUserBean = App::user()->bean(); $bean->user = $this->_user !== null ? $this->_user->bean() : $otherUserBean; $this->contributorIds[] = $otherUserBean->getID(); $this->contributorIds = array_unique($this->contributorIds); $bean->contributorIds = implode(',', $this->contributorIds); if (!empty($this->publishedOn)) { $bean->publishedOn = R::isoDateTime($this->publishedOn); } else { $bean->publishedOn = null; } R::store($bean); }
public function beforeStoreValue($valueFromUser) { return R::isoDateTime(strtotime($valueFromUser)); }
public function getBean() { if ($this->bean !== null) { return $this->bean; } $bean = R::findOne('skemaset', ' name = ? ', [$this->name]); if (empty($bean)) { $bean = R::dispense('skemaset'); $bean->name = $this->name; $bean->cleanName = Utility::cleanTableName($this->name); $bean->created = R::isoDateTime(); $bean->description = ''; $bean->ownFieldList; $bean->{'ownSkemarecord' . $this->cleanBaseName . 'List'}; } return $this->bean = $bean; }