public static function checkIn($number) { $bean = R::findOne('record', ' number = :number AND isnull(`in`) ', ['number' => $number]); if ($bean === null) { return null; } $bean->in = time(); $bean->checkInBy = App::user()->id; $record = new Record($number, $bean); R::store($bean); return $record; }
public function inShare() { $bean = $this->bean(); $user = App::user(); //owner if ($bean->userId === App::user()->id) { return true; } //shared to group foreach ($user->groups as $userGroup) { if (isset($bean->sharedGroupList[$userGroup->id])) { return true; } } //shared to specific user if (isset($bean->sharedUserList[$user->id])) { return true; } return false; }
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; }
<?php use Enpowi\App; use Enpowi\Users\User; use Enpowi\Modules\Module; Module::is(); $user = App::user(); $password = App::param('password'); $passwordRepeat = App::param('passwordRepeat'); $update = App::paramBool('update'); $stop = false; Module::paramRespond('password', ''); Module::paramRespond('passwordRepeat', ''); Module::paramRespond('passwordUpdated', ''); if (empty($password)) { $stop = true; } if (!$stop && $password !== $passwordRepeat) { Module::paramRespond('passwordRepeat', 'Passwords do not match'); $stop = true; } if (!$stop && !User::isValidPassword($password)) { Module::paramRespond('password', 'Invalid'); $stop = true; } if (!$stop) { if ($update) { if ($user->updatePassword($password)) { Module::paramRespond('passwordUpdated', 'Password updated'); } }
<?php use Enpowi\App; use Enpowi\Modules\Module; Module::is(); App::user()->logout(); echo json_encode([]);
public static function getUserFiles() { $id = App::user()->id; $beans = R::findAll('file', ' user_id = :userId ', ['userId' => $id]); $files = []; foreach ($beans as $bean) { $files[] = !empty($bean->classType) ? new $bean->classType($bean) : new File($bean); } return $files; }
public static function loadComponent($folder, $moduleName, $componentName = 'index') { $user = App::user(); if (empty($componentName)) { $componentName = 'index'; } App::log($moduleName, $componentName); if ($user->hasPerm($moduleName, $componentName)) { $module = new Modules\Module($folder, $moduleName); $component = new Modules\Component($module, $componentName); define('moduleName', $moduleName); define('componentName', $componentName); self::$module = $module; self::$component = $component; return $component; } return null; }
public function replace() { $user = App::user(); $existingBeans = R::findAll('territory', ' number = :number ', ['number' => $this->number]); foreach ($existingBeans as $bean) { $copy = R::dispense('territoryedit'); $copy->geoJson = $bean->geoJson; $copy->name = $bean->name; $copy->number = $bean->number; $copy->locality = $bean->locality; $copy->congregation = $bean->congregation; $copy->created = $bean->created; $copy->createdBy = $bean->createdBy; $copy->archived = time(); $copy->archivedBy = $user->id; R::store($copy); R::trash($bean); } $bean = R::dispense('territory'); $bean->geoJson = $this->geoJson; $bean->name = $this->name; $bean->number = $this->number; $bean->locality = $this->locality; $bean->congregation = $this->congregation; $bean->created = time(); $bean->createdBy = $user->id; R::store($bean); $this->_bean = $bean; return $this; }
<?php use Enpowi\App; use Enpowi\Blog\Post; use Enpowi\Modules\DataOut; use Enpowi\Modules\Module; Module::is(); $page = App::paramInt('page'); $showAll = App::user()->hasPerm('blog', 'edit'); $data = (new DataOut())->add('posts', Post::posts($page, $showAll))->add('pages', Post::pages($showAll))->add('page', $page)->out(); ?> <title>{{session.siteName }} - Blog</title> <div v-module data="<?php echo $data; ?> " class="container"> <!--TODO page name--> <h3><span v-t>Blog Posts</span> <a v-title="New Post" href="#/blog/edit"><span class="glyphicon glyphicon-plus-sign"></span></a> </h3> <nav class="pull-right"> <ul class="pagination"> <li v-show="page > 0"> <a href="#/" aria-label="Previous"> <span aria-hidden="true">«</span> </a> </li> <li v-show="pages.length > 0 && page < pages[pages.length - 1]">
<?php use Enpowi\App; use Enpowi\Files\Gallery; use Enpowi\Modules\Module; use Enpowi\Modules\DataOut; Module::is(); $galleryId = App::paramInt('g'); $gallery = null; $images = null; $galleries = null; $galleriesImages = null; if ($galleryId > 0) { $possibleGallery = new Gallery($galleryId); if ($possibleGallery->userId === App::user()->id) { $gallery = $possibleGallery; $images = $gallery->images(App::paramInt('page')); } } else { $galleriesImages = []; $galleries = Gallery::galleries(App::get()->user()->id, App::paramInt('page')); foreach ($galleries as $_gallery) { $images = $_gallery->images(1); if (isset($images[0])) { $galleriesImages[] = $images[0]->hash; } } } (new DataOut())->add('galleries', $galleries)->add('galleriesImages', $galleriesImages)->add('gallery', $gallery)->add('images', $images)->add('g', $galleryId)->bind(); ?> <title>{{session.siteName}} - Gallery</title>
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); }