action = $action; $this->conf = $conf; //constas $this->set('client', $this->model->user_nick); $info = $action->getInfo(); $this->set('version', $info['date']); //common one $this->set('users', $this->action->get_model()->userFactory->get_all()); $this->set('groups', $this->action->get_model()->userFactory->get_groups()); } public function action($default=null) { $action = $this->action->get_action(); if ($action == '' && !is_null($default)) { return $default; } return $action; } public function param($id, $default='') { return $this->action->get_param($id, $default); } public function url() { return call_user_func_array(array($this->action, 'url'), func_get_args()); } public function mailto($to, $subject, $body) { return 'mailto:'.$to.'?subject='.rawurlencode($subject).'&body='.rawurlencode($body); } // public function get_dummy_of($name) { // return $this->action->get_model_of($name)->get_dummy_object(); // } public function static_acl($table, $field) { return $this->action->get_model()->acl->check_static_field($table, $field); } /*users info function for shorten the code*/ public function user_name($login=NULL) { $name = $this->action->get_model()->userFactory->get_user_full_name($login); if ($name === '') { return $login; } return $name; } public function user_email($login=NULL) { return $this->action->get_model()->userFactory->get_user_email($login); } /*end users info functions*/ public function prevent_rendering() { } public function set($id, $value) { $this->variables[$id] = $value; } public function get($id, $default='') { $arr = explode(' ', $id); $var = $this->variables; foreach($arr as $item) { if (isset($var[$item])) { $var = $var[$item]; } else { return $default; } } return $var; } public function set_values($values) { foreach ($values as $name => $value) { $this->values[$name] = $value; } } public function value($name) { return (isset($this->values[$name]) ? $this->values[$name] : ''); } public function getLang($id) { return $this->action->getLang($id); } /** * @return mixed */ public function current_user() { return $this->action->get_model()->user_nick; } public function user_acl_level() { return $this->action->get_model()->acl->get_level(); } public function date($date) { return dformat(strtotime($date), '%Y-%m-%d'); } public function datetime($datetime) { return dformat(strtotime($datetime), '%Y-%m-%d %H:%M'); } public function date_fuzzy_age($datetime) { return datetime_h(strtotime($datetime)); } public function date_diff_days($rDate, $lDate='now', $format='%R%a') { $interval = date_diff(date_create($lDate), date_create($rDate)); return $interval->format("$format ".$this->getLang('days')); } public function date_diff_hours($rDate, $lDate='now') { $interval = date_diff(date_create($lDate), date_create($rDate)); return $interval->format('%h:%I'); } // public function days($lDate, $rDate='now') { // $diff = strtotime($lDate) - strtotime($rDate); // // if ($diff >= 0 && $diff < 5) { // return $this->getLang('just_now'); // } // // $time_str = ''; // $minutes = floor($diff/60); // if ($minutes > 0) { // $hours = floor($minutes/60); // if ($hours > 0) { // $days = floor($hours/24); // if ($days > 0) { // $time_str = $days.' '.$this->getLang('days'); // } else { // $time_str = $hours.' '.$this->getLang('hours'); // } // } else { // $time_str = $minutes.' '.$this->getLang('minutes'); // } // } else { // $time_str = $diff.' '.$this->getLang('seconds'); // } // // if ($diff > 0) { // $time_str .= ' '.$this->getLang('ago'); // } // // return $time_str; // } // // public function days_left($date) { // $d = date_create($date); // $now = date_create('now'); // $interval = date_diff($now, $d); // return $interval->format('%R%a '.$this->getLang('days')); // } // public function string_time_to_now($value) { // $diff = time() - $value; // if ($diff < 5) { // return $this->getLang('just_now'); // } // return self::days($diff).' '.$this->getLang('ago'); // } }