Ejemplo n.º 1
0
 /**
  * Do we have any unprocessed jobs scheduled for anytime in the future?
  * @return boolean
  */
 public function hasJobs()
 {
     $count = 0;
     Collection::model('\\Virge\\Cron\\Model\\Job')->filter(function () {
         Filter::isNull('started_on');
     })->count($count);
     return $count > 0;
 }
Ejemplo n.º 2
0
 /**
  * Load a model with it's primary key only
  * @param string $model
  * @param string $primary
  * @return \Virge\ORM\Component\Collection\Collection
  */
 public static function lazy($model, $primary = 'id')
 {
     $collection = new Collection();
     $collection->setModel(new $model());
     $collection->setLazy(true);
     $collection->setPrimary($primary);
     $collection->setLimit(NULL);
     $table = $collection->getModel()->getSqlTable();
     $collection->setTable($table);
     return $collection;
 }
Ejemplo n.º 3
0
 /**
  * Find a entity by filter callback
  * @param callable $filter
  * @param int $limit
  * @param int $start
  * @return array
  */
 public static function find($filter = NULL, $limit = 25, $start = 0)
 {
     if (is_callable($filter)) {
         $collection = Collection::model(get_called_class())->filter($filter);
     } else {
         $collection = Collection::model(get_called_class())->filter(function () use($filter) {
             Filter::start();
             Filter::eq('id', $filter);
             Filter::end();
         });
     }
     $collection->setLimit($limit);
     $collection->setStart($start);
     $collection = $collection->get();
     $results = array();
     while ($row = $collection->fetch()) {
         $results[] = $row;
     }
     if (empty($results)) {
         return array();
     }
     return $results;
 }