Example #1
0
 public function edit(Request $req, Response $res)
 {
     $name = $req->info->local->name;
     $entity = isset($req->id) ? $this->em($req->info)->id($req->id) : $this->em($req->info)->create();
     $req->view->{$name} = $wrap = $this->em->wrap($entity);
     if (!$req->isPost()) {
         return;
     }
     $wrap->graphFromArray($req->bodyParams());
     if (!$wrap->graphIsValid()) {
         $this->notify("{$req->info->singular} <strong>{$entity->name}</strong> could not be saved, please check the messages below", 'negative');
         return;
     }
     if (!$this->em->isPersisted($entity)) {
         $this->em->persist($entity);
     }
     try {
         $this->em->flush();
     } catch (UniqueConstraintViolationException $e) {
         $this->notify("{$req->info->singular} could not be saved because <strong>{$entity->name}</strong> already exists", 'negative');
         return;
     }
     $this->notify("{$req->info->singular} <strong>{$entity->name}</strong> was saved successfully", 'positive');
     return $res->redirect($this->url(array('action' => null, 'id' => null)));
 }
Example #2
0
 public function merge(Request $req, Response $res)
 {
     $merge = new Merge();
     $req->view->merge = $wrap = $this->em->wrap($merge);
     if (!$req->isPost()) {
         return;
     }
     $wrap->graphFromArray($req->bodyParams());
     if (!$wrap->graphIsValid()) {
         $this->notify("{$req->info->plural} could not be merged, please check the messages below", 'negative');
         return;
     }
     $sourceTag = $this->em('core_tag')->id($merge->sourceTag->id);
     $targetTag = $this->em('core_tag')->id($merge->targetTag->id);
     $entities = $this->em('core_content')->all(['tags' => [$sourceTag]]);
     foreach ($entities as $entity) {
         $entity->tags->removeElement($sourceTag);
         if (!$entity->tags->contains($targetTag)) {
             $entity->tags->add($targetTag);
         }
     }
     $this->em->remove($sourceTag);
     $this->em->flush();
     $this->notify("{$req->info->plural} were merged successfully", 'positive');
     return $res->redirect($this->url(array('action' => null, 'id' => null)));
 }
Example #3
0
 public function edit(Request $req, Response $res)
 {
     $class = $req->info->class;
     $widget = new $class();
     $req->view->widget = $wrap = $this->em->wrap($widget);
     $wrap->graphFromArray($req->bodyParams());
     if (!$req->post) {
         return;
     }
     if (!$wrap->isValid()) {
         return;
     }
     $req->data->entity = $req->info->name;
     $req->data->params = array_map(function ($value) {
         return is_object($value) ? $value->id : $value;
     }, $widget->toArray());
     $req->data->html = $this->view->render('widget/card', ['widget' => $widget], 'core')->toString();
 }
Example #4
0
 public function edit(Request $req, Response $res)
 {
     $name = $req->info->local->name;
     $entity = isset($req->id) ? $this->em($req->info)->id($req->id) : $this->em($req->info)->create();
     $req->view->{$name} = $wrap = $this->em->wrap($entity);
     if (!$req->isPost()) {
         return;
     }
     $wrap->graphFromArray($req->bodyParams());
     if (!$wrap->graphIsValid()) {
         return;
     }
     if (!$this->em->isPersisted($entity)) {
         $this->em->persist($entity);
     }
     $this->em->flush();
     $this->notify("{$req->info->singular} <strong>{$entity->name}</strong> was saved successfully", 'positive');
     return $res->redirect($this->url([]));
 }
Example #5
0
 public function passwordReset(Request $req, Response $res)
 {
     $user = $this->em('core_user')->one(['token' => $req->token]);
     if (!isset($user)) {
         $this->notify('Sorry, your password reset link has expired, please request a new one', 'negative');
         return $res->redirect($this->url([], 'core_passwordRequest', true));
     }
     $req->view->passwordReset = $wrap = $this->em->wrap($passwordReset = new \Chalk\Core\Model\PasswordReset());
     if (!$req->isPost()) {
         return;
     }
     $wrap->graphFromArray($req->bodyParams());
     if (!$wrap->graphIsValid()) {
         return;
     }
     $user->passwordPlain = $passwordReset->password;
     $user->token = null;
     $user->tokenDate = null;
     $this->em->flush();
     $this->notify('Your password has been reset successfully', 'positive');
     return $res->redirect($this->url([], 'core_login', true));
 }
Example #6
0
 public function select(Request $req, Response $res)
 {
     $filters = $this->chalk->module('core')->contentList($req->filters);
     $info = isset($req->type) ? Chalk::info($req->type) : $filters->first();
     $req->queryParam('type', $info->name);
     $class = "\\{$info->module->class}\\Model\\{$info->local->class}\\Index";
     if (!class_exists($class)) {
         $class = "\\Chalk\\Core\\Model\\Content\\Index";
     }
     $index = new $class();
     $wrap = $this->em->wrap($index);
     $wrap->graphFromArray($req->queryParams());
     $req->view->index = $wrap;
     $req->view->filters = $filters;
     if (!$req->isPost() && !$index->contentNew) {
         return;
     }
     $wrap->graphFromArray($req->bodyParams());
     $contents = [];
     foreach ($index->contents as $content) {
         $contents[] = ['id' => $content->id, 'name' => $content->name, 'card' => $this->view->render('content/card', ['content' => $content], 'core')->toString()];
     }
     $req->data->contents = $contents;
 }
Example #7
0
 public function edit(Request $req, Response $res)
 {
     if (isset($req->node)) {
         $node = $this->em('Chalk\\Core\\Structure\\Node')->id($req->node);
     } else {
         $node = $this->em('Chalk\\Core\\Structure\\Node')->create();
         $node->parent = $this->em('Chalk\\Core\\Structure\\Node')->id($req->parent);
         $node->content = $this->em($req->type)->create();
     }
     $req->view->node = $wrap = $this->em->wrap($node);
     if (!$req->isPost()) {
         return;
     }
     $wrap->graphFromArray($req->bodyParams());
     if (!$wrap->graphIsValid()) {
         return;
     }
     if (!$this->em->isPersisted($node)) {
         $this->em->persist($node);
     }
     $this->em->flush();
     $this->notify(Chalk::info($node->content)->singular . " <strong>{$node->content->name}</strong> was saved successfully", 'positive');
     return $res->redirect($this->url(['node' => $node->id]));
 }
Example #8
0
 public function quick(Request $req, Response $res)
 {
     if (!$req->isPost()) {
         throw new \Chalk\Exception("Upload action only accepts POST requests");
     }
     $quick = new \Chalk\Core\Model\Url\Quick();
     $wrap = $this->em->wrap($quick);
     $wrap->graphFromArray($req->bodyParams());
     if (!$wrap->graphIsValid()) {
         $this->notify("{$req->info->singular} could not be added, please try again", 'negative');
         return $res->redirect($this->url(array('action' => 'index')));
         return;
     }
     $redirect = new Url($req->redirect);
     $content = $this->em($req->info)->one(['url' => $quick->url]);
     if ($content) {
         $redirect->queryParam('contentNew', $content->id);
         return $res->redirect($redirect);
     }
     $content = $this->em($req->info)->create();
     $content->status = \Chalk\App::STATUS_PUBLISHED;
     $content->fromArray($quick->toArray());
     $this->em->persist($content);
     $this->em->flush();
     $redirect->queryParam('contentNew', $content->id);
     return $res->redirect($redirect);
 }