コード例 #1
0
ファイル: default.php プロジェクト: kosmosby/medicine-prof
    /**
     * Constructor
     *
     * @param KConfig $config Configuration options
     */
    public function __construct(KConfig $config)
    {
        parent::__construct($config);

        self::$_pages_model = $this->getService('com://site/docman.model.pages');

        $this->_state
            ->insert('page', 'int')
            ->insert('page_conditions', 'raw', array())
            ->insert('current_user', 'int')
            ->insert('access', 'int')
            ->insert('status', 'cmd')
        ;
    }
コード例 #2
0
ファイル: documents.php プロジェクト: kosmosby/medicine-prof
 protected function _buildQueryWhere(KDatabaseQuery $query)
 {
     $state = $this->_state;
     $query->where('1 = 1');
     if (is_array($state->page_conditions)) {
         $where = array();
         foreach ($state->page_conditions as $condition) {
             if ($condition[0] === 'categories') {
                 $cats = array_map('intval', (array) $condition[1]);
                 $where[] = sprintf('tbl.docman_category_id IN (%s)', implode(', ', $cats));
             }
             if ($condition[0] === 'documents') {
                 $q = array();
                 if (!empty($condition[1]['categories'])) {
                     $cats = array_map('intval', (array) $condition[1]['categories']);
                     $q[] = sprintf('tbl.docman_category_id IN (%s)', implode(', ', $cats));
                 }
                 if (!empty($condition[1]['created_by'])) {
                     $created_by = array_map('intval', (array) $condition[1]['created_by']);
                     $q[] = sprintf('tbl.created_by IN (%s)', implode(', ', $created_by));
                 }
                 if ($q) {
                     $where[] = '(' . implode(' AND ', $q) . ')';
                 }
             }
         }
         if ($where) {
             $where = '(' . implode(' OR ', $where) . ')';
             $query->where[] = array('property' => '', 'condition' => 'AND ' . $where);
         }
     }
     $query->where('1 = 1');
     $this->_buildQuerySearchKeyword($query);
     parent::_buildQueryWhere($query);
     $categories = (array) $state->category;
     if ($categories) {
         $include_children = $state->category_children;
         if ($include_children) {
             $query->join('inner', 'docman_category_relations AS r', 'r.descendant_id = tbl.docman_category_id')->where('r.ancestor_id', 'IN', $categories)->group('tbl.docman_document_id');
         } else {
             $query->where('tbl.docman_category_id', 'IN', $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 = sprintf('(tbl.created_by = %d) OR', $state->current_user);
         }
         $enabled = implode(', ', (array) $state->enabled);
         $query->where[] = array('property' => '', 'condition' => sprintf('AND (%s (tbl.enabled IN (%d)))', $user_enabled_clause, $enabled));
     }
     if ($state->search_date || $state->day_range) {
         $date = $state->search_date ? "'" . $state->search_date . "'" : 'NOW()';
         if ($state->day_range) {
             $query->where[] = array('property' => '', 'condition' => 'AND tbl.created_on BETWEEN ' . sprintf('DATE_SUB(%1$s, INTERVAL %2$d DAY) AND DATE_ADD(%1$s, INTERVAL %2$d DAY)', $date, $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 = sprintf('(tbl.created_by = %d) OR', $state->current_user);
         }
         $now = JFactory::getDate()->toSql();
         $query->where[] = array('property' => '', 'condition' => sprintf('AND (%s (tbl.publish_on = 0 OR tbl.publish_on <= \'%s\'))', $user_status_clause, $now));
         $query->where[] = array('property' => '', 'condition' => sprintf('AND (%s (tbl.unpublish_on = 0 OR tbl.unpublish_on >= \'%s\'))', $user_status_clause, $now));
     } elseif ($state->status === 'pending') {
         $now = JFactory::getDate()->toSql();
         $query->where[] = array('property' => '', 'condition' => 'AND ' . sprintf('(tbl.publish_on <> 0 AND tbl.publish_on >= \'%s\')', $now));
     } elseif ($state->status === 'expired') {
         $now = JFactory::getDate()->toSql();
         $query->where[] = array('property' => '', 'condition' => 'AND ' . sprintf('(tbl.unpublish_on <> 0 AND tbl.unpublish_on <= \'%s\')', $now));
     }
     if ($state->access) {
         $user_clause = '';
         // Logged in users see their documents regardless of the access level
         if ($state->current_user) {
             $user_clause = sprintf('(tbl.created_by = %d) OR', $state->current_user);
         }
         $access = implode(', ', (array) $state->access);
         $query->where[] = array('property' => '', 'condition' => sprintf('AND (%s ((CASE tbl.access WHEN -1 THEN COALESCE(c.access, 1) ELSE tbl.access END) IN (%s)))', $user_clause, $access));
         $query->where[] = array('property' => '', 'condition' => sprintf('AND (%s (c.access IN (%s)))', $user_clause, $access));
     }
     if ($state->created_by) {
         $query->where('tbl.created_by', 'IN', $state->created_by);
     }
     if ($state->storage_type) {
         $query->where('tbl.storage_type', 'IN', $state->storage_type);
     }
     if ($state->storage_path) {
         $query->where('tbl.storage_path', 'IN', $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);
     }
 }
コード例 #3
0
ファイル: nodes.php プロジェクト: kosmosby/medicine-prof
 protected function _buildQueryHaving(KDatabaseQuery $query)
 {
     // If we have a parent id level is set using the where clause
     if (!$this->_state->parent_id && $this->_state->level !== null) {
         // Query object does not support operators in having clauses
         // So we need to build the string ourselves
         $query->having('level IN (' . implode(',', (array) $this->_state->level) . ')');
     }
     parent::_buildQueryHaving($query);
 }