本文整理汇总了PHP中CakeTime::convert方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeTime::convert方法的具体用法?PHP CakeTime::convert怎么用?PHP CakeTime::convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CakeTime
的用法示例。
在下文中一共展示了CakeTime::convert方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit_post
public function edit_post()
{
if ($this->request->is('post')) {
// get uuid
$guid = String::uuid();
// get todays datetime in seconds
$time_in_seconds = CakeTime::convert(time(), new DateTimeZone('Asia/Calcutta'));
// set final id for array
$id = "ad_" . $time_in_seconds . '_' . $guid;
$final_aray['timestamp']['created'] = $time_in_seconds;
$final_aray['timestamp']['modified'] = $time_in_seconds;
$item_data = $this->data;
// pr($item_data);
// final Array for cloudant
$final_aray = array();
$final_aray['id'] = $id;
$final_aray['doc_type'] = 'ad';
$final_aray['i_want_to'] = $item_data['i_want_to'];
$final_aray['job_type'] = $item_data['job_type'];
$final_aray['condition'] = $item_data['condition'];
$final_aray['you_are/i_am'] = $item_data['youare'];
$final_aray['item_type']['id'] = $item_data['ItemType']['id'];
$final_aray['item_type']['name'] = $item_data['ItemType']['name'];
// for resume
if (!$item_data['ItemType']['resume_file']['size'] <= 0) {
$filename = array();
$filename['resume_file']['name'] = $item_data['ItemType']['resume_file']['name'];
$filename['resume_file']['type'] = $item_data['ItemType']['resume_file']['type'];
$filename['resume_file']['tmp_name'] = $item_data['ItemType']['resume_file']['tmp_name'];
$filename['resume_file']['size'] = $item_data['ItemType']['resume_file']['size'];
$filename['resume_file']['error'] = $item_data['ItemType']['resume_file']['error'];
$filename['guid'] = $id;
if (!$this->ItemPhoto->save($filename)) {
$this->Session->setFlash('Sorry, an error occurred.', 'default', array('class' => 'alert alert-danger'), 'error');
$this->redirect(array('controller' => 'ad_posts', 'action' => 'index'));
} else {
$last_uploaded_resume = $this->ItemPhoto->findByGuid($id);
$final_aray['resume'] = $last_uploaded_resume['ItemPhoto']['id'] . "/" . $last_uploaded_resume['ItemPhoto']['resume_file'];
}
}
// end of resume
// check photo uploaded or not
if (!$item_data['ItemType']['image_files'][0]['size'] <= 0) {
// save images in sql database
$item_photo_details = array();
// loop each uploaded images
foreach ($item_data['ItemType']['image_files'] as $key => $value) {
$filename = array();
$filename['image_file']['name'] = $value['name'];
$filename['image_file']['type'] = $value['type'];
$filename['image_file']['tmp_name'] = $value['tmp_name'];
$filename['image_file']['size'] = $value['size'];
$filename['image_file']['error'] = $value['error'];
$filename['guid'] = $id;
array_push($item_photo_details, $filename);
}
if ($this->ItemPhoto->saveMany($item_photo_details)) {
// get current uploaded photos
$last_uploaded_images = $this->ItemPhoto->find('all', array('conditions' => array('guid' => $id), 'order' => 'created'));
$count = 0;
//pr(json_encode($last_uploaded_images));die();
$primary_photo = array();
// for save primary photo
$photos = array();
// for save other photos
$tmp_photo = array();
foreach ($last_uploaded_images as $value) {
// for photos
if ($count == 0) {
$primary_photo['filename'] = $value['ItemPhoto']['image_file'];
$primary_photo['dir'] = $value['ItemPhoto']['id'];
// add photos array into final_aray
$final_aray['primary_photo'] = $primary_photo;
//array_push($final_aray, $primary_photo);
} else {
$tmp_photo['filename'] = $value['ItemPhoto']['image_file'];
$tmp_photo['dir'] = $value['ItemPhoto']['id'];
array_push($photos, $tmp_photo);
}
$count++;
}
$final_aray['photo'] = $photos;
} else {
$this->Session->setFlash('Sorry, an error occurred.', 'default', array('class' => 'alert alert-danger'), 'error');
$this->redirect(array('controller' => 'ad_posts', 'action' => 'index'));
}
}
// end of photo
//pr($final_aray);
$final_aray['item_category']['id'] = $item_data['ItemCategory']['id'];
$final_aray['item_category']['name'] = $item_data['ItemCategory']['name'];
$final_aray['brand']['id'] = $item_data['brand']['id'];
$final_aray['brand']['name'] = $item_data['brand']['name'];
// find included item name
if (isset($item_data['included'])) {
$included = 0;
$item = "";
foreach ($item_data['included'] as $key => $value) {
if ($key === 'charger') {
$item = 'Charger';
//.........这里部分代码省略.........
示例2: convert
/**
* Converts given time (in server's time zone) to user's local time, given his/her timezone.
*
* @param string $serverTime UNIX timestamp
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
*
* @return int UNIX timestamp
* @see CakeTime::convert()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function convert($serverTime, $timezone)
{
return $this->_engine->convert($serverTime, $timezone);
}
示例3: uploadImage
/**
* Upload your file
*
* @param array $file file detail
* @param string $path upload path
* @param string $name file name when update file
* @param boolean $edit check edit upload mode
* @return array
* @author Chaiwut <ichaiwut.s@gmail.com>
* @since 12 July 2015
*/
public function uploadImage($file = null, $path = null, $name = null, $edit = false)
{
//status to return, 0 mean `false`.
$status = array('status' => 0, 'message' => __('ข้อมูลไม่ถูกต้อง'));
//Check user data.
if ($file == null || $path == null) {
return $status;
}
//Alowed only `jpg`, `jpeg` and `png` only
//to avoid large file.
if (!in_array($file['type'], Configure::read('typeImg'))) {
$status['message'] = __('ไม่อนุญาตให้ไฟล์ไฟล์นี้');
return $status;
}
//Set file extendtion.
$fileExtention = '';
switch ($file['type']) {
case 'image/png':
$fileExtention = '.png';
break;
case 'image/jpeg':
$fileExtention = '.jpg';
break;
}
$fileName = CakeTime::convert(time(), new DateTimeZone('Asia/Bangkok')) . $fileExtention;
//Set file name
//I use timestamp for file name.
//If user send the name to us use thier name
if ($name != null && !$edit) {
$fileName = $name . $fileExtention;
} else {
if ($name != null && $edit) {
$fileName = $name;
}
}
//Upload file
if (is_uploaded_file($file['tmp_name'])) {
move_uploaded_file($file['tmp_name'], $path . $fileName);
$status['status'] = 1;
$status['message'] = __('เพิ่มข้อมูลสำเร็จ');
$status['file_name'] = $fileName;
return $status;
}
$status['message'] = __('เพิ่มข้อมูลไม่สำเร็จ');
return $status;
}
示例4: admin_add
/**
* Added new Blog Content
*
* @return void
* @author Alongkot <aszee.web@gmail.com>
* @since 21 June 2015
*/
public function admin_add($preview = NULL)
{
$this->layout = 'dashboard';
$this->set('bloggroups', $this->Blog->Bloggroup->find('list'));
if ($this->request->is('post')) {
// User
if ($preview == "preview") {
// preview Blog
$this->set('data', $this->request->data);
$this->render('admin_preview');
} else {
// Insert to Blog Table
$this->request->data['Blog']['user_id'] = AuthComponent::user('id');
$this->request->data['Blog']['image_dir'] = CakeTime::convert(time(), new DateTimeZone('Asia/Bangkok'));
// change path temp -> foder
$temp_folder = AuthComponent::user('username') . '_temp';
$this->request->data['Blog']['detail_th'] = str_replace($temp_folder, $this->request->data['Blog']['image_dir'], $this->request->data['Blog']['detail_th']);
$this->request->data['Blog']['detail_en'] = str_replace($temp_folder, $this->request->data['Blog']['image_dir'], $this->request->data['Blog']['detail_en']);
// Upload Blog Photo
$this->Blog->create();
$photo = $this->request->data['Blog']['photo'];
$this->request->data['Blog']['photo'] = '';
if (!$this->Blog->save($this->request->data)) {
$this->Session->setFlash(__('ไม่สามารถเพิ่มข้อมูลได้'), 'flash-fail');
return $this->redirect(array('action' => 'index', 'admin' => true));
}
// Check Temp folder and Copy file to image folder
$this->is_copyTempFolder(AuthComponent::user('username'), $this->request->data['Blog']['image_dir']);
// Upload Photo Cover In This Foler Blog
if (!empty($photo['name'])) {
$lastId = $this->Blog->getLastInsertId();
$path = WWW_ROOT . 'uploads/blog/' . $this->request->data['Blog']['image_dir'] . '/';
$folder = new Folder($path);
// Check Folder path If Not to Create
if (is_null($folder->path)) {
//$folder->delete();
$folder->create(WWW_ROOT . DS . 'uploads' . DS . 'blog' . DS . $this->request->data['Blog']['image_dir']);
}
$status = $this->uploadImage($photo, $path, $lastId);
if (!$status['status']) {
$this->Session->setFlash($status['message'], 'flash-fail');
return;
}
$this->Blog->id = $lastId;
$this->Blog->saveField('photo', $status['file_name']);
}
$this->Session->setFlash(__('เพิ่มข้อมูลสำเร็จ'), 'flash-success');
return $this->redirect(array('action' => 'index', 'admin' => true));
}
}
// Open New Page
if ($preview == NULL) {
// Check Temp folder for delete first
$this->is_deleteTempFolder(AuthComponent::user('username') . '_temp');
}
$this->set('title_for_layout', __('เขียนโพสใหม่'));
}
示例5: make_an_offer
public function make_an_offer()
{
if ($this->request->is('post')) {
$this->layout = "ajax_layout";
$sms_data = $this->request->data;
$ad_title = $sms_data['ad_title'];
$offer_rs = $sms_data['offer_rs'];
$receiver_mobile = $sms_data['receiver_mobile'];
$sender_mobile = $sms_data['sender_mobile'];
$sender_name = $this->activeUser['User']['fb_name'];
$sender_email = $this->activeUser['User']['username'];
// save on cloudant
// get uuid
$guid = String::uuid();
// get todays datetime in seconds
$time_in_seconds = CakeTime::convert(time(), new DateTimeZone('Asia/Calcutta'));
// set array for cloudant DB
$msg_array['id'] = "msg_" . $time_in_seconds . '_' . $guid;
$msg_array['created_timestamp'] = $time_in_seconds;
$msg_array['doc_type'] = 'sms';
$msg_array['ad_id'] = $sms_data['ad_id'];
$msg_array['ad_fb_id'] = $sms_data['ad_fb_id'];
$msg_array['sender_fb_id'] = $this->activeUser['User']['fb_id'];
$msg_array['name'] = $sender_name;
$msg_array['mobile'] = $sender_mobile;
$msg_array['email'] = $sender_email;
// Set created timestamp
date_default_timezone_set('Asia/Calcutta');
$todays = new DateTime();
$msg_array['created'] = $todays->format('Y-m-d H:i:s');
// pr($msg_array);die();
$this->SetAdReply->setDataSource('cloudant_db');
if (!$this->SetAdReply->save($msg_array)) {
echo 0;
}
//send sms
if ($receiver_mobile != null) {
$sms = new Sms();
$sms->sendMakeAnOffer($ad_title, $sender_name, $sender_mobile, $sender_email, $offer_rs, $receiver_mobile);
//$msg_array['message'] = $sender_data['senderMsg'];
echo "1";
} else {
echo "0";
}
}
}
示例6: edit_post
public function edit_post($id = null)
{
$files_aaray = array();
// get item types
$item_types = $this->ItemType->find('list', array('order' => array('sort_order')));
$this->set('item_types', $item_types);
// get Role list
$roles = $this->AdPost->curlGet('axi_fxchng/role_2d7e8411c977679a8dade0f7c4b967c5');
$this->set('roles', $roles['role']);
$user_data = $this->activeUser;
$this->set('user_data', $user_data);
// get last inserted ad_id of current user
$ad_details = $this->AdPost->curlGet('axi_fxchng/' . $id);
$this->set('ad_details', $ad_details);
// // pr($ad_details);
// // check resume
// if (isset($ad_details['resume'])) {
// if($ad_details['resume'] != null) {
// $files_aaray['resume'] = $ad_details['resume'];
// }
// }
// // check photos
// if(isset($ad_details['primary_photo'])) {
// if($ad_details['primary_photo']['filename'] != null) {
// $files_aaray['primary_photo']['filename'] = $ad_details['primary_photo']['filename'];
// $files_aaray['primary_photo']['dir'] = $ad_details['primary_photo']['dir'];
// }
// if(sizeof($ad_details['photo']) > 0) {
// $outer_temp = array();
// foreach ($ad_details['photo'] as $avail_photo) {
// $tmp_photo = array();
// $tmp_photo['filename'] = $avail_photo['filename'];
// $tmp_photo['dir'] = $avail_photo['dir'];
// array_push($outer_temp, $tmp_photo);
// }
// $files_aaray['photo'] = $outer_temp;
// }
// }
// $this->set('saved_paths', $files_aaray);
if ($this->request->is('post')) {
// get uuid
$guid = String::uuid();
// get todays datetime in seconds
$time_in_seconds = CakeTime::convert(time(), new DateTimeZone('Asia/Calcutta'));
// set final id for array
$id = "ad_1435730552_55938278-9a78-4086-ba8d-378e52d40771";
$item_data = $this->data;
// final Array for cloudant
$final_aray = array();
$final_aray['id'] = $id;
// $final_aray['doc_type'] = 'ad';
$final_aray['fb_id'] = $this->activeUser['User']['fb_id'];
// $final_aray['created_timestamp'] = $time_in_seconds*1000;
$final_aray['i_want_to'] = $item_data['i_want_to'];
$final_aray['job_type'] = $item_data['job_type'];
$final_aray['condition'] = $item_data['condition'];
// $final_aray['item_type']['id'] = $item_data['ItemType']['id'];
$final_aray['item_type']['name'] = $item_data['ItemType']['name'];
// for resume
// if (!$item_data['ItemType']['resume_file']['size'] <= 0) {
// $filename = array();
// $filename['resume_file']['name'] = $item_data['ItemType']['resume_file']['name'];
// $filename['resume_file']['type'] = $item_data['ItemType']['resume_file']['type'];
// $filename['resume_file']['tmp_name'] = $item_data['ItemType']['resume_file']['tmp_name'];
// $filename['resume_file']['size'] = $item_data['ItemType']['resume_file']['size'];
// $filename['resume_file']['error'] = $item_data['ItemType']['resume_file']['error'];
// $filename['guid'] = $id;
// if(!$this->ItemPhoto->save($filename)) {
// $this->Session->setFlash('Sorry, an error occurred.', 'default', array('class' => 'alert alert-danger') , 'error');
// $this -> redirect(array('controller' => 'ad_posts', 'action' => 'index'));
// }
// else {
// $last_uploaded_resume = $this->ItemPhoto->findByGuid($id);
// $final_aray['resume'] = $last_uploaded_resume['ItemPhoto']['id']."/".$last_uploaded_resume['ItemPhoto']['resume_file'];
// }
// } // end of resume
// check photo uploaded or not
// if (!$item_data['ItemType']['image_files'][0]['size'] <= 0) {
// // save images in sql database
// $item_photo_details = array();
// // loop each uploaded images
// foreach($item_data['ItemType']['image_files'] as $value) {
// $filename = array();
// $filename['image_file']['name'] = $value['name'];
// $filename['image_file']['type'] = $value['type'];
// $filename['image_file']['tmp_name'] = $value['tmp_name'];
// $filename['image_file']['size'] = $value['size'];
// $filename['image_file']['error'] = $value['error'];
// $filename['guid'] = $id;
// array_push($item_photo_details, $filename);
// }
// if($this->ItemPhoto->saveMany($item_photo_details)) {
// // get current uploaded photos
// $last_uploaded_images = $this->ItemPhoto->find('all',array('conditions'=>array('guid' => $id), 'order'=>'created'));
// $count = 0;
// $primary_photo = array(); // for save primary photo
// $photos = array(); // for save other photos
// $tmp_photo = array();
// foreach ($last_uploaded_images as $value) {
// // for photos
//.........这里部分代码省略.........