Ejemplo n.º 1
0
 public function buildParent()
 {
     if ($this->getModel()->getId() == 1) {
         return 'root';
     }
     $items = Service::renderList();
     return Util\Form::buildDropdown('parentId' . $this->unique, $items, $this->getModel()->getParentId(), false, [$this->getModel()->getId()]);
 }
Ejemplo n.º 2
0
 public static function buildTree()
 {
     $options = [];
     $options['where'][] = 'folder.status IN (0,1)';
     $options['order'][] = 'folder.display_order, folder.title';
     $folders = self::loadAll($options);
     return Service::buildNavRecursion($folders, 0, 0);
 }
Ejemplo n.º 3
0
 public function selectMedia()
 {
     if (!$this->hasPrivilege('admin.content.edit')) {
         return $this->noPrivilege('admin.content.edit');
     }
     $json = [];
     $json['result'] = ResultType::ERROR;
     // check
     $field = Converter::string('field', 'post');
     $hashParam = Converter::string('hash', 'post');
     $search = Converter::string('search', 'post');
     if (!isset($field) || !isset($hashParam)) {
         $json['message'] = Lang::lang('errorInvalidParameters');
         return json_encode($json);
     }
     $hash = explode('/', $hashParam);
     $hash = array_slice($hash, 1);
     $folderId = isset($hash[0]) && $hash[0] != '' ? (int) $hash[0] : 0;
     $page = isset($hash[1]) && $hash[1] != '' ? (int) $hash[1] : 1;
     $type = isset($hash[2]) && $hash[2] != '' ? $hash[2] : 'all';
     $order = isset($hash[3]) && $hash[3] != '' ? $hash[3] : 'modified_date';
     $orderType = isset($hash[4]) && $hash[4] != '' ? $hash[4] : 'desc';
     if (!in_array($type, ['all', 'images', 'videos', 'documents'])) {
         $type = 'all';
     }
     if (!in_array($order, ['title', 'extension', 'modified_date'])) {
         $order = 'modified_date';
     }
     if (!in_array($orderType, ['asc', 'desc'])) {
         $orderType = 'desc';
     }
     $options = [];
     $options['where'][] = 'media.status = 1';
     $options['where'][] = 'media.is_selectable = 1';
     if ($folderId != 0) {
         $options['where'][] = ['media.folder_id = ?', $folderId];
     }
     if (isset($search) && $search != '') {
         $options['where'][] = ['media.title LIKE ?', '%' . $search . '%'];
     }
     if ($type != 'all') {
         switch ($type) {
             case 'images':
                 $options['where'][] = 'media.extension IN ("jpg", "jpeg", "png")';
                 break;
             case 'videos':
                 $options['where'][] = 'media.extension IN ("avi", "mov")';
                 break;
             case 'documents':
                 $options['where'][] = 'media.extension IN ("pdf", "xls", "xlsx", "doc", "docx")';
                 break;
         }
     }
     $mediaCount = \Rebond\Core\Media\Data::count($options);
     // get user settings
     $userSettings = \Rebond\Cms\UserSettings\Data::loadByUserId($this->signedUser->getId());
     $mediaView = 'grid';
     $mediaListCount = 10;
     if (isset($userSettings)) {
         $mediaView = $userSettings->getMediaView() == 0 ? 'grid' : 'list';
         $mediaListCount = (int) $userSettings->getMediaPagingValue();
     }
     if ($page < 1) {
         $page = 1;
     }
     if ($page > ceil($mediaCount / $mediaListCount) && $mediaCount > 0) {
         $page = ceil($mediaCount / $mediaListCount);
     }
     $folders = \Rebond\Core\Folder\Service::renderList();
     // add paging and order
     $options['order'][] = 'media.' . $order . ' ' . $orderType;
     $options['limit'][] = ($page - 1) * $mediaListCount . ', ' . $mediaListCount;
     $media = \Rebond\Core\Media\Data::loadAll($options);
     $tpl = new Template(Template::MODULE, ['core', 'media']);
     $tpl->set('items', $media);
     $tpl->set('field', $field);
     $tplFilter = new Template(Template::MODULE, ['core', 'media']);
     $tplFilter->set('current', $page);
     $tplFilter->set('folders', $folders);
     $tplFilter->set('maxByPage', $mediaListCount);
     $tplFilter->set('count', $mediaCount);
     $tplFilter->set('mediaView', $mediaView);
     $tplFilter->set('order', $order . '_' . $orderType);
     $tplFilter->set('type', $type);
     $tplFilter->set('folderId', $folderId);
     $tplFilter->set('hash', '#!/' . $folderId . '/' . $page . '/' . $type . '/' . $order . '/' . $orderType);
     $tplFilter->set('search', $search);
     $json['result'] = ResultType::SUCCESS;
     $json['message'] = Lang::lang('listUpdated') . ' (' . count($media) . ')';
     $json['html'] = $tplFilter->render('select-filter');
     $json['html'] .= $tpl->render('select-' . $mediaView);
     return json_encode($json);
 }