Example #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;
 }
Example #2
0
 /**
  * Remove a media
  *
  * @param  array $fields
  * @return void
  */
 public function remove(array $fields)
 {
     if (isset($fields['rm_media'])) {
         foreach ($fields['rm_media'] as $id) {
             $media = Table\Media::findById((int) $id);
             if (isset($media->id)) {
                 $library = new MediaLibrary();
                 $library->getById($media->library_id);
                 $folder = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $library->folder;
                 if (file_exists($folder . DIRECTORY_SEPARATOR . $media->file) && !is_dir($folder . DIRECTORY_SEPARATOR . $media->file)) {
                     unlink($folder . DIRECTORY_SEPARATOR . $media->file);
                 }
                 foreach ($library->actions as $size => $action) {
                     if (file_exists($folder . DIRECTORY_SEPARATOR . $size . DIRECTORY_SEPARATOR . $media->file) && !is_dir($folder . DIRECTORY_SEPARATOR . $size . DIRECTORY_SEPARATOR . $media->file)) {
                         unlink($folder . DIRECTORY_SEPARATOR . $size . DIRECTORY_SEPARATOR . $media->file);
                     }
                 }
                 $media->delete();
             }
         }
     }
 }