Example #1
0
 public function getRelatedPosts($limit = 12)
 {
     $model = new static();
     $model->setState('filter.published_today', true)->setState('filter.publication_status', 'published');
     $conditions = $model->conditions();
     // convert the set states to conditions
     $model->setCondition('_id', array('$ne' => new \MongoId((string) $this->id)))->setParam('limit', $limit);
     $categories = array();
     if (!empty($this->{'categories'})) {
         $categories = \Dsc\ArrayHelper::getColumn((array) $this->{'categories'}, 'id');
     }
     if (!empty($categories)) {
         $model->setCondition('categories', array('$elemMatch' => array('id' => array('$in' => $categories))));
     }
     return $model->getItems();
 }
Example #2
0
 public static function getList()
 {
     $class = new static();
     return $class->getItems();
 }
Example #3
0
 /**
  * Finds items in the collection based on set conditions
  * 
  * @param unknown $conditions
  * @param unknown $fields
  */
 public static function find($conditions = array(), $fields = array())
 {
     $model = new static();
     $sort = $model->__config['default_sort'];
     if (isset($conditions['sort'])) {
         $sort = $conditions['sort'];
         unset($conditions['sort']);
     }
     $model->setParam('sort', $sort);
     if (isset($conditions['limit'])) {
         $limit = $conditions['limit'];
         unset($conditions['limit']);
         $model->setParam('limit', $limit);
     }
     if (isset($conditions['skip'])) {
         $skip = $conditions['skip'];
         unset($conditions['skip']);
         $model->setParam('skip', $skip);
     }
     $model->setParam('conditions', $conditions);
     $model->setParam('fields', $fields);
     return $model->getItems();
 }