public function up() { //we'll need some places where the events can take place $locations = array('Rīga', 'Valmiera', 'Ventspils'); foreach ($locations as $location) { $loc = \Model_Orm_Location::forge(); $loc->title = $location; $loc->save(); } //and let's create at least one event as well $demo_event = \Model_Orm_Event::forge(); $demo_event->title = "Notikums pēc nedēļas"; $demo_event->description = "Kaut kas, kam jānotiek nedēļu vēlāk nekā šī skripta izpilde."; $startdate = \Fuel\Core\Date::forge(time() + 7 * 24 * 60 * 60); $demo_event->start = $startdate->format('mysql', false); //'2013-11-27 07:00:00'; $demo_event->location_id = 1; //pieņemsim, ka Rīgā; $demo_event->save(); //the event shouldn't be empty - some agenda items $agenda_items = array('Notikuma pats, pats sākums', 'Kaut kad drusku vēlāk', 'Vēl mazliet vēlāk', 'Un nu jau arī beigas'); foreach ($agenda_items as $agenda_item) { $demo_agenda = \Model_Orm_Agenda::forge(); $demo_agenda->title = $agenda_item; $demo_agenda->event = $demo_event; $demo_agenda->save(); } //we also need some users. at least two. \Auth::instance()->create_user("*****@*****.**", "fuel_dev", "*****@*****.**", 100, array("verified" => true, "verification_key" => md5(mt_rand(0, mt_getrandmax())))); \Auth::instance()->create_user("*****@*****.**", "fuel_dev", "*****@*****.**", 1, array("verified" => true, "verification_key" => md5(mt_rand(0, mt_getrandmax())))); }
public function action_index() { echo '<pre>'; echo 'FuelPHP Version: ' . Fuel::VERSION . "\n"; echo ' locale: ' . setlocale(LC_ALL, '0') . "\n"; echo ' date: ' . Date::forge()->format('mysql') . "\n"; echo 'default_charset: ' . ini_get('default_charset') . "\n"; echo '</pre>'; }
public static function update($id, $data) { try { $data['updated_at'] = date('Y-m-d H:i:s', Date::forge()->get_timestamp()); $query = Model_Category::find($id); $query->set($data); $query->save(); } catch (Exception $e) { Log::write('ERROR', $e->getMessage()); return false; } return true; }
public static function run($speech = null) { echo 'hello can you hear me?'; $mongo = new MongoClient(); $database = $mongo->selectDB("UNWDMI"); $collection = new MongoCollection($database, "measurements"); $start = new MongoDate(Date::time()->get_timestamp()); $end = new MongoDate(Date::time()->get_timestamp()); $cursor = $collection->find(array('measurement.STN' => '476290', 'measurement.DATETIME' => array('$gte' => $start, '$lt' => $end))); $cursor->sort(array('measurement.DATETIME' => -1)); var_dump($cursor); foreach ($cursor as $document) { echo date('Y-M-d h:i:s', $document['measurement']['DATETIME']->sec); echo '<br />'; var_dump($document); } }
public function action_edit($id = null) { $pass = Model_Pass::find($id); $val = Model_Pass::validate('edit'); if ($val->run()) { $pass->name = Input::post('name'); $pass->description = Input::post('description'); $pass->logo_text = Input::post('logo_text'); $pass->barcode_message = Input::post('barcode_message'); $pass->barcode_format = Input::post('barcode_format'); $relevant_date = \Fuel\Core\Input::post('relevant_date', 0); if ($relevant_date != 0) { $pass->relevant_date = \Fuel\Core\Date::create_from_string($relevant_date, 'mysql')->get_timestamp(); } else { $pass->relevant_date = 0; } if ($pass->save()) { Session::set_flash('success', e('Updated pass #' . $id)); Response::redirect('admin/pass'); } else { Session::set_flash('error', e('Could not update pass #' . $id)); } } else { if (Input::method() == 'POST') { $pass->name = $val->validated('name'); $pass->description = $val->validated('description'); $pass->logo_text = $val->validated('logo_text'); $pass->barcode_message = $val->validated('barcode_message'); $pass->barcode_format = $val->validated('barcode_format'); $pass->relevant_date = \Fuel\Core\Date::create_from_string($val->validated('relevant_date'), 'mysql')->get_timestamp(); Session::set_flash('error', $val->error()); } $this->template->set_global('pass', $pass, false); } $this->template->title = "Passes"; $this->template->content = View::forge('admin/pass/edit'); }
/** * Takes a Date instance and transforms it into a DB timestamp * * @param \Fuel\Core\Date value * @param array any options to be passed * * @throws InvalidContentType * * @return int|string */ public static function type_time_encode(\Fuel\Core\Date $var, array $settings) { if (!$var instanceof \Fuel\Core\Date) { throw new InvalidContentType('Value must be an instance of the Date class.'); } if ($settings['data_type'] == 'time_mysql') { return $var->format('mysql'); } return $var->get_timestamp(); }
echo Form::label('Barcode format', 'barcode_format'); ?> <div class="input"> <?php echo \Fuel\Core\Form::select('barcode_format', Input::post('barcode_format', isset($pass) ? $pass->barcode_format : 0), array('QR', 'PDF417', 'Aztec'), array('class' => 'span2')); ?> </div> </div> <div class="clearfix"> <?php echo Form::label('Relevant date', 'relevant_date'); ?> <div class="input"> <?php echo \Fuel\Core\Form::input('relevant_date', Input::post('relevant_date', isset($pass) && $pass->relevant_date > 0 ? \Fuel\Core\Date::forge($pass->relevant_date)->format('mysql') : ''), array('class' => 'span2', 'placeholder' => '2012-11-01 10:10:10')); ?> </div> </div> <div class="actions"> <?php echo Form::submit('submit', 'Save', array('class' => 'btn btn-primary')); ?> </div> </fieldset> <?php echo Form::close();
?> </td> <td><?php echo number_format($item->target_billable, 2); ?> HRS P/M</td> <td><?php echo number_format($item->target_unbillable, 2); ?> HRS P/M</td> <td><?php echo isset($groups[$item->group]) ? $groups[$item->group] : $item->group; ?> </td> <td><?php echo $item->last_login > 0 ? \Fuel\Core\Date::forge($item->last_login)->format('%d/%m/%Y %H:%M:%S ') : 'Never'; ?> </td> <td> <div class="pull-right"> <small> <?php echo Html::anchor('admin/users/view/' . $item->id, 'View'); ?> | <?php echo Html::anchor('admin/users/edit/' . $item->id, 'Edit'); ?> | <?php echo Html::anchor('admin/users/delete/' . $item->id, 'Delete', array('onclick' => "return confirm('Are you sure?')"));
public function action_logtimes($timestamp = null) { if (!Auth\Auth::has_access('timesheets.read')) { Fuel\Core\Session::set_flash('error', 'You do not have access to view timesheets'); Fuel\Core\Response::redirect('user'); } if (!$timestamp) { $timestamp = \Fuel\Core\Date::forge()->get_timestamp(); // today } if (Fuel\Core\Input::method() == 'POST') { try { // start a db transaction \Fuel\Core\DB::start_transaction(); // find all logs for this task for this day $date = date('Y-m-d', $timestamp); $starts = date('Y-m-d 00:00:00', $timestamp); $ends = date('Y-m-d 23:59:59', $timestamp); $project_task_logs = Model_Projecttasklog::find('all', array('related' => array('project_task'), 'where' => array(array('project_task.user_id', $this->current_user->id), array('task_started', 'BETWEEN', array($starts, $ends))))); foreach ($project_task_logs as $log) { $date_starts = date('Y-m-d', $timestamp); $date_ends = date('Y-m-d 23:59:59', $timestamp); if ($log->get_project_task()->user_id == $this->current_user->id) { if (in_array(strtotime($log->task_started), range(strtotime($date_starts), strtotime($date_ends)))) { // delete the logs $log->delete(); } } } // insert new logs if (Fuel\Core\Input::post('timeslots')) { $date = date('Y-m-d', $timestamp); $last_comment = ''; $last_task_id = ''; foreach (Fuel\Core\Input::post('timeslots') as $str) { $times = explode('_', $str); $is_billable = 0; $task_started = $date . ' ' . $times[0] . ':00'; $task_completed = $date . ' ' . $times[1] . ':00'; $project_task_id_array = Fuel\Core\Input::post('project_task_id'); $task_id = $project_task_id_array["'{$str}'"]; if (Fuel\Core\Input::post('comment_' . $str) != '') { $last_comment = Fuel\Core\Input::post('comment_' . $str); } if (intval(Fuel\Core\Input::post('is_billable_' . $str, '0')) == 1) { $is_billable = 1; } if (empty($task_id)) { $task_id = $last_task_id; } else { $last_task_id = $task_id; } if (empty($task_id)) { continue; // todo - display error } $task_log = Model_Projecttasklog::forge(array('project_task_id' => $task_id, 'comment' => $last_comment, 'task_started' => $task_started, 'task_completed' => $task_completed, 'is_billable' => $is_billable)); $task_log->save(); } } // commit to database \Fuel\Core\DB::commit_transaction(); \Fuel\Core\Session::set_flash('success', 'Time logs saved successfully.'); Fuel\Core\Response::redirect('user/timesheets/index/' . $timestamp); } catch (Exception $ex) { // rollback on error \Fuel\Core\DB::rollback_transaction(); \Fuel\Core\Session::set_flash('error', $ex->getMessage()); Fuel\Core\Response::redirect('user/timesheets/advanced/logtimes/' . $timestamp); } } $now = \Fuel\Core\Date::forge($timestamp)->format('mysql'); $day_starts = date('Y-m-d 00:00:00', strtotime($now)); $day_ends = date('Y-m-d 23:59:59', strtotime($now)); $today_logs = Model_Projecttasklog::find('all', array('related' => array('project_task', 'project_task.project', 'project_task.project_task_name', 'project_task.user'), 'where' => array(array('task_started', 'BETWEEN', array($day_starts, $day_ends)), array('project_task.user_id', $this->current_user->id)), 'order_by' => array(array('task_started', 'asc')))); // todo: use DB::query() instead $this->template->set_global('today_logs', $today_logs); $this->template->set_global('projects', Model_Project::find('all', array('order_by' => array(array('name', 'asc'))))); $this->template->set_global('timezones', Model_Timezone::find('all', array('order_by' => array(array('starts', 'asc'))))); $this->template->set_global('my_tasks', Model_Projecttask::find('all', array('where' => array(array('user_id', $this->current_user->id)), 'related' => array('project_task_name'), 'order_by' => array(array('project_task_description', 'asc'))))); $this->template->set_global('timestamp', $timestamp); $this->template->set_global('date', \Fuel\Core\Date::forge($timestamp)->format('mysql_date')); $this->template->title = 'Timesheets'; $this->template->content = View::forge('user/timesheets/advanced/_advanced_form'); }
?> </p> <p> <strong>Barcode format:</strong> <?php echo $pass->barcode_format_readable(); ?> </p> <?php } ?> <p> <strong>Relevant date:</strong> <?php if ($pass->relevant_date > 0) { echo \Fuel\Core\Date::forge($pass->relevant_date)->format('mysql'); } ?> </p> <div class="container"> <div class="row"> <button class="btn btn-large span2" onclick="location.href = '<?php echo \Fuel\Core\Uri::create('admin/pass/cert/' . $pass->id); ?> ';"> Certificate </button> <button class="btn btn-large span2"
public static function link_provider($user_id) { if ($authentication = Session::get('auth-strategy.authentication', [])) { $opauth = Auth_Opauth::forge(false); $insert_id = $opauth->link_provider(['parent_id' => $user_id, 'provider' => $authentication['provider'], 'uid' => $authentication['uid'], 'access_token' => $authentication['access_token'], 'secret' => $authentication['secret'], 'refresh_token' => $authentication['refresh_token'], 'expires' => $authentication['expires'], 'created_at' => date('Y-m-d H:i:s', Date::forge()->get_timestamp())]); } }
public static function add_user() { $user_props = ['username' => 'wjshop', 'email' => '*****@*****.**', 'password' => Model_Service_Util::hash_password('11111111'), 'group' => 100, 'customer_name' => 'wjshop', 'created_at' => date('Y-m-d H:i:s', Date::forge()->get_timestamp())]; $user = Model_User::forge($user_props); $user->save(); }