예제 #1
0
 public function __construct($id = null)
 {
     parent::__construct($id);
     if (!$this->loaded()) {
         // Set reasonable defaults
         $this->created = time();
         $this->rand_key = random::percent();
         $this->thumb_dirty = 1;
         $this->resize_dirty = 1;
         $this->sort_column = "created";
         $this->sort_order = "ASC";
         $this->owner_id = identity::active_user()->id;
     }
 }
예제 #2
0
파일: item.php 프로젝트: qboy1987/mooiyou
 /**
  * Return a query to get a random Item_Model, with optional filters.
  * Usage: item::random_query()->execute();
  *
  * Note: You can add your own ->where() clauses but if your Gallery is
  * small or your where clauses are over-constrained you may wind up with
  * no item.  You should try running this a few times in a loop if you
  * don't get an item back.
  */
 static function random_query()
 {
     // Pick a random number and find the item that's got nearest smaller number.
     // This approach works best when the random numbers in the system are roughly evenly
     // distributed so this is going to be more efficient with larger data sets.
     return ORM::factory("item")->viewable()->where("rand_key", "<", random::percent())->order_by("rand_key", "DESC");
 }