Example #1
0
 public static function __init()
 {
     \minerva\models\Page::applyFilter('find', function ($self, $params, $chain) {
         /**
          * find() doens't do anything with a "request_params" key and you wouldn't typically see it...
          * However, all core Minerva code will pass the request params to all find() calls just for
          * this kind of flexibility. In this case, if it's not an admin action then we're adding to the
          * conditions the requirement of the document being published.
          *
          * Note that this filter is applied to the core Minerva Page model.
          * So as long as this model gets called, it will apply the published condition to all finds
          * for all pages. Keep in mind the order in which filters are applied and when libraries are added.
          * It's probably best to apply this sort of filter as self::applyFilter() instead so that we are
          * more certain of when it's used. The filter can also be defined below outside of the class.
          *
          * What else could we do here? We could say certain users could see it on non-admin actions too...
          * Or...whatever else that could be dreamed of.
          */
         if (!isset($params['options']['request_params']['admin']) || empty($params['options']['request_params']['admin'])) {
             $params['options']['conditions']['published'] = true;
         }
         return $chain->next($self, $params, $chain);
         // NOTE: could be applying access rules here and checking against them
         //$record = $chain->next($self, $params, $chain);
         // Here would be an "afterFind" don't forget to return $record; instead of to the chain
         //var_dump($record);
     });
     // Put any desired filters here
     parent::__init();
 }
Example #2
0
    public function getLatestPages($options=array()) {
	$defaults = array('conditions' => array(), 'limit' => 10);
	$options += $defaults;
	
	return Page::find('all', array('limit' => $options['limit'], 'conditions' => $options['conditions']));
    
    }
Example #3
0
</div>
<div class="clear"></div>

<div class="grid_8">
	<div class="box">
		<h2>Recently Created Pages</h2>
		<div class="block">
			<table>
				<thead>
					<tr>
						<th>Page Title</th>
						<th>Page Type</th>
					</tr>
				</thead>
				<?php
				$recent_pages = Page::getLatestPages();
				if($recent_pages) {
					foreach($recent_pages as $page) {
				?>
				<tr>
					<td>
						<?=$this->html->link($page->title, array('controller' => 'pages', 'action' => 'read', 'url' => $page->url)); ?>
					</td>
					<td>
						<?php if(!empty($page->page_type)) {
							echo '<em>(' . $page->page_type . ')</em>';
						} else {
							echo '<em>(page)</em>';
						} ?>
					</td>
				</tr>
Example #4
0
	public static function __init() {
		
		\minerva\models\Page::applyFilter('find', function($self, $params, $chain) {
		    
            /**
             * find() doens't do anything with a "request_params" key and you wouldn't typically see it...
             * However, all core Minerva code will pass the request params to all find() calls just for
             * this kind of flexibility. In this case, if it's not an admin action then we're adding to the
             * conditions the requirement of the document being published.
             *
             * What else could we do? We could say certain users could see it on non-admin actions too...
             * Or...whatever else that could be dreamed of.
            */
            if((isset($params['options']['request_params']['admin'])) && ($params['options']['request_params']['admin'] !== true)) {
                $params['options']['conditions']['published'] = true;
            }
		    
		    return $chain->next($self, $params, $chain);
		    
		    // NOTE: could be applying access rules here and checking against them
		    //$record = $chain->next($self, $params, $chain);
		    // Here would be an "afterFind" don't forget to return $record; instead of to the chain
		    //var_dump($record);
		    
		});
		
		// Put any desired filters here
		
		parent::__init();
	}