Beispiel #1
0
 public function action_option()
 {
     $this->template->title = 'WSJ | RN Options Market';
     /*  Find options the user has bought and now can sell or execute  */
     $options_sell = Model_Option::find('all', array('where' => array(array('user_id', '=', $this->user->id), array('expiration_date', '>', DB::expr(time())), array('status', '=', 'Sold'), 'or' => array(array('user_id', '=', $this->_userId), array('expiration_date', '>', DB::expr(time())), array('status', '=', 'New')))));
     /*  Find options that do not belong to user and is allowed to buy  */
     $options_buy = Model_Option::find('all', array('where' => array(array('user_id', '!=', $this->_userId), array('expiration_date', '>', DB::expr(time())), array('status', '=', 'Sell'))));
     $data['optionsSell'] = $options_sell;
     $data['optionsBuy'] = $options_buy;
     /* set data info views and set views in template */
     $this->template->sell_option = View::forge('backend/index/option/sell', $data);
     $this->template->buy_option = View::forge('backend/index/option/buy', $data);
     $this->template->modal = View::forge('backend/index/option/modal');
 }
Beispiel #2
0
 public static function update($name = '', $value = '')
 {
     if (false === static::is_enabled()) {
         return false;
     }
     if (!isset(static::$_data[$name])) {
         static::insert($name, $value);
     }
     $data = \Model_Option::find(static::$_data[$name]['id']);
     $data->value = $value;
     $data->save();
     static::$_data[$name]['value'] = $data->value;
     return true;
 }
Beispiel #3
0
 /**
  * Set option(s)
  *
  * @param   mixed   Name of option or array in array('option' => 'value') style
  * @param   string  Value of the option
  * @param   bool    If true, not existing options will be created.
  * @return  void
  */
 public static function set($options, $value = null, $create = false)
 {
     is_array($options) or $options = array($options => $value);
     $fetched = Model_Option::find()->where('option', 'in', array_keys($options))->get();
     foreach ($fetched as $option) {
         static::$_cached[$option->option] = $option->value = $options[$option->option];
         $option->save();
         unset($options[$option->option]);
     }
     if ($create and count($options) > 0) {
         foreach ($options as $option => $value) {
             static::$_cached[$option] = $value;
             $opt = Model_Option::forge();
             $opt->option = $option;
             $opt->value = $value;
             $opt->save();
         }
     }
 }