Exemplo n.º 1
0
 /**
  * Get category view content
  *
  * @param  mixed $id
  * @return array
  */
 public function getCategoryViewItems($id)
 {
     $items = [];
     $catItems = Table\CategoryItems::findBy(['category_id' => $id], ['order' => 'order ASC']);
     if ($catItems->hasRows()) {
         foreach ($catItems->rows() as $c) {
             if ($c->media_id != 0) {
                 $media = \Phire\Media\Table\Media::findById($c->media_id);
                 $title = isset($media->id) ? $media->title : '[N/A]';
                 $item_id = $c->media_id;
                 $type = 'media';
             } else {
                 $content = \Phire\Content\Table\Content::findById($c->content_id);
                 $title = isset($content->id) ? $content->title : '[N/A]';
                 $item_id = $c->content_id;
                 $type = 'content';
             }
             $items[] = ['title' => $title, 'item_id' => $item_id, 'type' => $type, 'order' => $c->order];
         }
     }
     return $items;
 }
Exemplo n.º 2
0
 /**
  * Check tree for status
  *
  * @param  array  $tree
  * @param  int    $roleId
  * @param  int    $depth
  * @return void
  */
 public static function checkTreeStatus(&$tree, $roleId = null, $depth = 0)
 {
     foreach ($tree as $i => &$branch) {
         if (isset($branch['item_id']) && isset($branch['type']) && $branch['type'] == 'content') {
             $content = \Phire\Content\Table\Content::findById($branch['item_id']);
             $allowed = true;
             if (null !== $content->roles) {
                 $roles = unserialize($content->roles);
                 if (count($roles) > 0 && (null === $roleId || !in_array($roleId, $roles))) {
                     $allowed = false;
                 }
             }
             if (isset($content->id) && ((int) $content->status != 1 || !$allowed)) {
                 unset($tree[$i]);
             }
         }
         if (isset($branch['children']) && count($branch['children']) > 0) {
             self::checkTreeStatus($branch['children'], $roleId, $depth + 1);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Get parental hierarchy
  *
  * @param  int $parentId
  * @return string
  */
 protected function getHierarchy($parentId = null)
 {
     $parents = [];
     while (null !== $parentId) {
         array_unshift($parents, $parentId);
         $category = Table\Content::findById($parentId);
         if (isset($category->id)) {
             $parentId = $category->parent_id;
         }
     }
     return count($parents) > 0 ? implode('|', $parents) : '';
 }
Exemplo n.º 4
0
 /**
  * Check tree for status
  *
  * @param  array  $tree
  * @param  int    $depth
  * @return void
  */
 public static function checkTreeStatus(&$tree, $depth = 0)
 {
     foreach ($tree as $i => &$branch) {
         if (isset($branch['id']) && isset($branch['type']) && $branch['type'] == 'content') {
             $content = \Phire\Content\Table\Content::findById($branch['id']);
             if (isset($content->id) && (int) $content->status != 1) {
                 unset($tree[$i]);
             }
         }
         if (isset($branch['children']) && count($branch['children']) > 0) {
             self::checkTreeStatus($branch['children'], $depth + 1);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * JSON action method
  *
  * @param  int $id
  * @return void
  */
 public function json($id)
 {
     $json = ['parent_uri' => ''];
     $content = Table\Content::findById($id);
     if (isset($content->id)) {
         $json['parent_uri'] = $content->uri;
     }
     $this->response->setBody(json_encode($json, JSON_PRETTY_PRINT));
     $this->send(200, ['Content-Type' => 'application/json']);
 }