NodesController::term PHP Method

term() public method

Term
public term ( ) : void
return void
    public function term()
    {
        $Node = $this->{$this->modelClass};
        $term = $Node->Taxonomy->Term->find('first', array('conditions' => array('Term.slug' => $this->request->params['named']['slug']), 'cache' => array('name' => 'term_' . $this->request->params['named']['slug'], 'config' => 'nodes_term')));
        if (!isset($term['Term']['id'])) {
            $this->Session->setFlash(__d('croogo', 'Invalid Term.'), 'flash', array('class' => 'error'));
            return $this->redirect('/');
        }
        if (!isset($this->request->params['named']['type'])) {
            $this->request->params['named']['type'] = 'node';
        }
        if (isset($this->request->params['named']['limit'])) {
            $limit = $this->request->params['named']['limit'];
        } else {
            $limit = Configure::read('Reading.nodes_per_page');
        }
        $this->paginate[$Node->alias]['order'] = $Node->escapeField('created') . ' DESC';
        $visibilityRolesField = $Node->escapeField('visibility_roles');
        $this->paginate[$Node->alias]['conditions'] = array($Node->escapeField('status') => $Node->status(), $Node->escapeField('terms') . ' LIKE' => '%"' . $this->request->params['named']['slug'] . '"%', 'OR' => array($visibilityRolesField => '', $visibilityRolesField . ' LIKE' => '%"' . $this->Croogo->roleId() . '"%'));
        $this->paginate[$Node->alias]['contain'] = array('Meta', 'Taxonomy' => array('Term', 'Vocabulary'), 'User');
        if (isset($this->request->params['named']['type'])) {
            $type = $Node->Taxonomy->Vocabulary->Type->find('first', array('conditions' => array('Type.alias' => $this->request->params['named']['type']), 'cache' => array('name' => 'type_' . $this->request->params['named']['type'], 'config' => 'nodes_term')));
            if (!isset($type['Type']['id'])) {
                $this->Session->setFlash(__d('croogo', 'Invalid content type.'), 'flash', array('class' => 'error'));
                return $this->redirect('/');
            }
            if (isset($type['Params']['nodes_per_page']) && empty($this->request->params['named']['limit'])) {
                $limit = $type['Params']['nodes_per_page'];
            }
            $this->paginate[$Node->alias]['conditions'][$Node->escapeField('type')] = $type['Type']['alias'];
            $this->set('title_for_layout', $term['Term']['title']);
        }
        $this->paginate[$Node->alias]['limit'] = $limit;
        if ($this->usePaginationCache) {
            $cacheNamePrefix = 'nodes_term_' . $this->Croogo->roleId() . '_' . $this->request->params['named']['slug'] . '_' . Configure::read('Config.language');
            if (isset($type)) {
                $cacheNamePrefix .= '_' . $type['Type']['alias'];
            }
            $this->paginate['page'] = isset($this->request->params['named']['page']) ? $this->request->params['named']['page'] : 1;
            $cacheName = $cacheNamePrefix . '_' . $this->paginate['page'] . '_' . $limit;
            $cacheNamePaging = $cacheNamePrefix . '_' . $this->paginate['page'] . '_' . $limit . '_paging';
            $cacheConfig = 'nodes_term';
            $nodes = Cache::read($cacheName, $cacheConfig);
            if (!$nodes) {
                $nodes = $this->paginate($Node->alias);
                Cache::write($cacheName, $nodes, $cacheConfig);
                Cache::write($cacheNamePaging, $this->request->params['paging'], $cacheConfig);
            } else {
                $paging = Cache::read($cacheNamePaging, $cacheConfig);
                $this->request->params['paging'] = $paging;
            }
        } else {
            $nodes = $this->paginate($Node->alias);
        }
        $this->set(compact('term', 'type', 'nodes'));
        $this->Croogo->viewFallback(array('term_' . $term['Term']['id'], 'term_' . $term['Term']['slug'], 'term_' . $type['Type']['alias'] . '_' . $term['Term']['slug'], 'term_' . $type['Type']['alias']));
    }