コード例 #1
0
ファイル: categories.php プロジェクト: kosmosby/medicine-prof
 protected function _getPageConditions($pages)
 {
     $pages = (array) KObjectConfig::unbox($pages);
     $document_pages = array_intersect($pages, array_keys($this->_getDocumentPages()->toArray()));
     // Return an empty list of categories if the model is filtered against single document pages only.
     if (count($document_pages) === count($pages)) {
         $conditions = array(array('categories', array(-1)));
     } else {
         $conditions = parent::_getPageConditions($pages);
     }
     return $conditions;
 }
コード例 #2
0
ファイル: abstract.php プロジェクト: kosmosby/medicine-prof
    public function getPagesModel()
    {
        if (!self::$_pages_model) {
            self::$_pages_model = $this->getObject('com://admin/docman.model.pages');

            $view = $this->getObject('request')->query->view;
            if (JFactory::getApplication()->isAdmin() || $view === 'doclink' || $view === 'documents') {
                self::$_pages_model->language('all');
            }
        }

        return self::$_pages_model;
    }
コード例 #3
0
ファイル: documents.php プロジェクト: kosmosby/medicine-prof
    protected function _buildQueryWhere(KDatabaseQueryInterface $query)
    {
        $state = $this->getState();

        if ($this->_page_conditions)
        {
            $categories = array();
            $where = array();
            $i = 0;

            foreach ($this->_page_conditions as $condition)
            {
                if ($condition[0] === 'categories') {
                    $categories = array_merge($categories, (array) $condition[1]);
                }

                if ($condition[0] === 'documents')
                {
                    $str = '';

                    if (!empty($condition[1]['categories']))
                    {
                        $str[] = "tbl.docman_category_id IN :category_id$i";
                        $query->bind(array("category_id$i" => (array) $condition[1]['categories']));
                    }

                    if (!empty($condition[1]['created_by'])
                        || $condition[1]['created_by'] === 0 || $condition[1]['created_by'] === '0')
                    {
                        $str[] = "tbl.created_by IN :created_by$i";
                        $query->bind(array("created_by$i" => (array) $condition[1]['created_by']));
                    }

                    if ($str) {
                        $where[] = '('.implode(' AND ', $str).')';
                    }
                }

                if ($condition[0] === 'document')
                {
                    $where[] = "(tbl.slug = :slug$i)";
                    $query->bind(array("slug$i" => $condition[1]['slug']));
                }

                $i++;
            }

            if ($categories)
            {
                $where[] = '(tbl.docman_category_id IN :page_categories)';
                $query->bind(array('page_categories' => (array) $categories));
            }

            if ($where) {
                $where = '('.implode(' OR ', $where).')';

                $query->where($where);
            }
        }

        $this->_buildQuerySearchKeyword($query);

        parent::_buildQueryWhere($query);

        $categories = (array) $state->category;
        if ($categories)
        {
            $include_children = $state->category_children;

            if ($include_children)
            {
                $query->join(array('r' => 'docman_category_relations'), 'r.descendant_id = tbl.docman_category_id')
                    ->where('r.ancestor_id IN :include_children_categories')
                    ->bind(array('include_children_categories' => $categories))
                    ->group('tbl.docman_document_id');
            }
            else {
                $query->where('tbl.docman_category_id IN :include_children_categories')
                    ->bind(array('include_children_categories' => $categories));
            }
        }

        if (is_numeric($state->enabled))
        {
            $user_enabled_clause = '';
            // Logged in users see their documents regardless of the access level
            if ($state->current_user) {
                $user_enabled_clause = 'tbl.created_by = :current_user OR';
            }

            $query->where(sprintf('(%s tbl.enabled IN :enabled)', $user_enabled_clause))->bind(array(
                'enabled' => (array) $state->enabled,
                'current_user' => $state->current_user
            ));
        }

        if ($state->search_date || $state->day_range) 
        {
        	$date      = $state->search_date ? ':date' : 'NOW()';
            $date_bind = $state->search_date ? $state->search_date : null;
            if ($state->day_range) {
            	$query->where("(tbl.created_on BETWEEN DATE_SUB($date, INTERVAL :days DAY) AND DATE_ADD($date, INTERVAL :days DAY))")
            		  ->bind(array('date' => $date_bind, 'days' => $state->day_range));
            }
        }

        if ($state->status === 'published') 
        {
            $user_status_clause = '';
            // Logged in users see their documents regardless of the published status
            if ($state->current_user) {
                $user_status_clause = 'tbl.created_by = :current_user OR';
            }

            $now = JFactory::getDate()->toSql();

            $query->where(sprintf('(%s (tbl.publish_on = 0 OR tbl.publish_on <= :publish_date))', $user_status_clause))
              	  ->where(sprintf('(%s (tbl.unpublish_on = 0 OR tbl.unpublish_on >= :publish_date))', $user_status_clause))
            	  ->bind(array(
                      'publish_date' => $now,
                      'current_user' => $state->current_user
                  ));
        } 
        elseif ($state->status === 'pending') 
        {
            $now = JFactory::getDate()->toSql();

            $query->where('(tbl.publish_on <> 0 AND tbl.publish_on >= :publish_date)')
	            ->bind(array('publish_date' => $now));
        } 
        elseif ($state->status === 'expired') 
        {
            $now = JFactory::getDate()->toSql();

            $query->where('(tbl.unpublish_on <> 0 AND tbl.unpublish_on <= :publish_date)')
	            ->bind(array('publish_date' => $now));
        }

        if ($state->access)
        {
            $user_access_clause = '';
            // Logged in users see their documents regardless of the published status
            if ($state->current_user) {
                $user_access_clause = 'tbl.created_by = :current_user OR';
            }

            $query->where(sprintf('(%s c.access IN :access)', $user_access_clause))
                  ->where(sprintf('(%s (CASE tbl.access WHEN -1 THEN COALESCE(c.access, 1) ELSE tbl.access END) IN :access)', $user_access_clause))
                  ->bind(array(
                        'access' => (array) $state->access,
                        'current_user' => $state->current_user
                    ));
        }

        if (is_numeric($state->created_by) || !empty($state->created_by)) {
            $query->where('tbl.created_by IN :created_by')->bind(array('created_by' => (array) $state->created_by));
        }

        if ($state->storage_type) {
            $query->where('tbl.storage_type IN :storage_type')->bind(array('storage_type' => (array) $state->storage_type));
        }

        if ($image = $state->image) {
            $query->where('tbl.image IN :image')->bind(array('image' => (array) $image));
        }

        if ($state->storage_path) {
            $query->where('tbl.storage_path IN :storage_path')->bind(array('storage_path' => (array) $state->storage_path));
        }

        if ($state->search_path !== null)
        {
            if ($state->search_path === '')
            {
                $operation = 'NOT LIKE';
                $path = "%/%";
            }
            else
            {
                $operation = 'LIKE';
                $path = $state->search_path;
            }

            $query->where('tbl.storage_path '.$operation. ' :path')->bind(array('path' => $path));
        }
    }