/**
  * @param Cruncher $cruncher
  * @param Node $node
  * @param string $locale
  * @param string $cacheKey
  * @param array $compilation
  * @return array
  */
 protected function compileTableLocaleStatistics(Cruncher $cruncher, Node $node, $locale, $cacheKey, array $compilation)
 {
     list($last_year_stats, $last_year_labels) = $cruncher->getCountPerMonth(Carbon::today()->subYear(), null, $locale, $node->trackerViews(), $cacheKey);
     $compilation = $this->compileYearStatistics($last_year_stats, $last_year_labels, $compilation, $locale);
     list($last_month_stats, $last_month_labels) = $cruncher->getCountPerWeek(Carbon::today()->subMonth(), null, $locale, $node->trackerViews(), $cacheKey);
     $compilation = $this->compileMonthStatistics($last_month_stats, $last_month_labels, $compilation, $locale);
     list($last_week_stats, $last_week_labels) = $cruncher->getCountPerDay(Carbon::today()->subWeek(), null, $locale, $node->trackerViews(), $cacheKey);
     $compilation = $this->compileWeekStatistics($last_week_stats, $last_week_labels, $compilation, $locale);
     return $compilation;
 }
Example #2
0
 /**
  * Gets or finds the node and sets by id
  *
  * @param int $id
  * @param bool $published
  * @return Node
  */
 public function getOrFind($id, $published = true)
 {
     $node = $this->get($id);
     if (is_null($node)) {
         $node = $published ? PublishedNode::find($id) : Node::find($id);
         $this->put($id, $node);
     }
     return $node;
 }
 /**
  * Shows the dashboard
  * @param DashboardStatisticsCompiler $compiler
  * @return view
  */
 public function index(DashboardStatisticsCompiler $compiler)
 {
     $params = ['recentlyCreated' => Node::recentlyCreated(10)->get(), 'recentlyEdited' => Node::recentlyEdited(10)->get()];
     if (tracker()->saveEnabled()) {
         $params['statistics'] = $compiler->compileStatistics();
         $params['mostVisited'] = Node::mostVisited(10)->get();
         $params['recentlyVisited'] = Node::recentlyVisited(10)->get();
     }
     return $this->compileView('dashboard.index', $params, trans('general.dashboard'));
 }
 /**
  * Registers view bindings
  *
  * @param NodeRepository $nodeRepository
  */
 protected function registerViewBindings(NodeRepository $nodeRepository)
 {
     if (!is_installed()) {
         return;
     }
     if (!is_request_reactor()) {
         $home = $nodeRepository->getHome(false);
         view()->share('home', $home);
     }
     view()->composer('*', function ($view) {
         $view->with('currentUser', auth()->user());
     });
     if (is_request_reactor()) {
         view()->composer('partials.navigation.nodes', function ($view) {
             $leafs = empty($id = auth()->user()->home) ? Node::whereIsRoot()->defaultOrder()->get() : [Node::find($id)];
             $view->with('leafs', $leafs);
         });
     }
 }
Example #5
0
 /** @test */
 function it_scopes_nodes_with_type()
 {
     $this->assertNull(Node::withType('project')->first());
     $this->assertNull(Node::withType('non-existing')->first());
     $node = $this->getNode();
     $node->fill(['en' => ['title' => 'English Title', 'description' => 'English Description', 'area' => 100000], 'tr' => ['title' => 'Türkçe Başlık', 'description' => 'Türkçe Açıklama', 'area' => 30000]]);
     $node->save();
     $this->assertInstanceOf('Nuclear\\Hierarchy\\Node', Node::withType('project')->first());
     $this->assertNull(Node::withType('non-existing')->first());
 }
Example #6
0
 /**
  * @param Request $request
  * @param Node $node
  * @param NodeSource $source
  */
 protected function validateEditForm(Request $request, Node $node, NodeSource $source)
 {
     $this->validateForm(source_form_name($node->getNodeTypeName(), true), $request, ['node_name' => 'max:255|alpha_dash|unique:node_sources,node_name,' . $source->getKey()]);
 }
 /**
  * Populates site information
  *
  * @param Request $request
  * @param InstallHelper $helper
  * @return redirect
  */
 public function postSite(Request $request, InstallHelper $helper)
 {
     $this->validate($request, ['meta_title' => 'required']);
     chronicle()->pauseRecording();
     $user = User::first();
     $home = Node::published()->whereHome(1)->firstOrFail();
     $home->associateOwner($user);
     $home->fill($request->only(['meta_title', 'meta_keywords', 'meta_description', 'meta_author']));
     $home->save();
     Artisan::call('key:generate');
     $helper->setEnvVariable('APP_STATUS', 'INSTALLED');
     return redirect()->route('install-complete');
 }
Example #8
0
 /**
  * Snippet for displaying node default content options
  *
  * @param Node $node
  * @param string $header
  * @param bool $table
  * @return string
  */
 public function nodeOptions(Node $node, $header = null, $table = true)
 {
     $id = $node->getKey();
     $sourceId = $node->translateOrFirst()->getKey();
     $html = '';
     if ($node->canHaveChildren()) {
         $html .= '<li class="dropdown-sub__item">
             <a href="' . route('reactor.nodes.create', $id) . '">
                 <i class="icon-plus"></i>' . trans('nodes.add_child') . '</a>
         </li>
         <li class="dropdown-sub__splitter"></li>';
     }
     $html .= '<li class="dropdown-sub__item">
         <a href="' . route('reactor.nodes.edit', [$id, $sourceId]) . '">
             <i class="icon-pencil"></i>' . trans('nodes.edit') . '</a>
     </li>';
     if ($node->canHaveMoreTranslations()) {
         $html .= '<li class="dropdown-sub__item">
             <a href="' . route('reactor.nodes.translation.create', [$id, $sourceId]) . '">
                 <i class="icon-language"></i>' . trans('general.add_translation') . '</a>
         </li>';
     }
     $html .= '<li class="dropdown-sub__item dropdown-sub__item--delete">' . delete_form(route('reactor.nodes.destroy', $id), trans('nodes.destroy')) . '</li>
     <li class="dropdown-sub__splitter"></li>
     <li class="dropdown-sub__item">' . $this->nodeOptionForm($node->isPublished() ? route('reactor.nodes.unpublish', $id) : route('reactor.nodes.publish', $id), $node->isPublished() ? 'icon-status-withheld' : 'icon-status-published', $node->isPublished() ? 'nodes.unpublish' : 'nodes.publish') . '</li>
     <li class="dropdown-sub__item">' . $this->nodeOptionForm($node->isLocked() ? route('reactor.nodes.unlock', $id) : route('reactor.nodes.lock', $id), $node->isLocked() ? 'icon-status-unlocked' : 'icon-status-locked', $node->isLocked() ? 'nodes.unlock' : 'nodes.lock') . '</li>';
     return content_options_open($header, $table) . $html . content_options_close($table);
 }
Example #9
0
 /**
  * Changes a nodes location in the tree
  *
  * @param Request $request
  * @return response
  */
 public function sortTree(Request $request)
 {
     $response = ['type' => 'danger', 'message' => trans('general.error_saving')];
     if (Gate::denies('EDIT_NODES')) {
         $response['message'] = trans('general.not_authorized');
         return response()->json($response);
     }
     $node = Node::find($request->input('node'));
     $sibling = Node::find($request->input('sibling'));
     if (is_null($node) || is_null($sibling)) {
         $response['message'] = trans('nodes.sort_invalid');
         return response()->json($response);
     }
     if ($node->isLocked()) {
         $response['message'] = trans('nodes.node_is_locked');
         return response()->json($response);
     }
     try {
         if ($request->input('action') === 'after') {
             $node->afterNode($sibling);
         }
         if ($request->input('action') === 'before') {
             $node->beforeNode($sibling);
         }
         // Touch the model so that model will be dirty and the
         // saving event will run. (We have to do this because saving event
         // do not fire in Translatable's save method if parent model is not dirty.
         $node->touch();
         if (!$node->save()) {
             return response()->json($response);
         }
     } catch (InvalidParentNodeTypeException $e) {
         $response['message'] = trans('nodes.invalid_parent');
         return response()->json($response);
     }
     $parentNode = request()->input('parent');
     $leafs = $parentNode !== '0' ? Node::findOrFail($parentNode)->getPositionOrderedChildren() : Node::whereIsRoot()->defaultOrder()->get();
     return response()->json(['type' => 'success', 'html' => view('partials.navigation.node_trees', ['leafs' => $leafs])->render()]);
 }
Example #10
0
 /**
  * Returns nodes by ids
  *
  * @param array|string $ids
  * @param bool $published
  * @return Collection
  */
 public function getNodesByIds($ids, $published = true)
 {
     if (empty($ids)) {
         return null;
     }
     if (is_string($ids)) {
         $ids = json_decode($ids, true);
     }
     if (is_array($ids) && !empty($ids)) {
         $placeholders = implode(',', array_fill(0, count($ids), '?'));
         $nodes = Node::whereIn('id', $ids)->orderByRaw('field(id,' . $placeholders . ')', $ids);
         if ($published) {
             $nodes->published();
         }
         $nodes = $nodes->get();
         return count($nodes) > 0 ? $nodes : null;
     }
     return null;
 }