public function run() { $this->controller->pageTitle = 'Book a Workspace'; $now = date('Y-m-d', time()); $date = Yii::app()->request->getParam('date'); $date = $date == '' ? $now : $date; $proxy = new CHub(); $result = $proxy->getHubList(); if (Yii::app()->request->isAjaxRequest) { $id = Yii::app()->request->getParam('id'); $hub = Yii::app()->request->getParam('hub'); $date = Yii::app()->request->getParam('date'); if ($id) { $date = date('Ymd', strtotime($date)); $record = Reservations::model()->findAll('startTime =' . date('Ymd', strtotime($date)) . '100000' . ' and userId=' . Yii::app()->user->id . ' and type=1 and status=1'); $orderid = Order::model()->findAllByAttributes(array('status' => 1, 'userId' => Yii::app()->user->id, 'type' => 1)); if ($orderid) { foreach ($orderid as $list) { $order = OrderProduct::model()->find('endDate>=' . $date . ' and orderId=' . $list['id'] . ' and startDate<=' . $date); if ($order) { break; } } if ($order) { echo CJSON::encode(array('code' => 200, 'data' => array('num' => $order['totalTimes'] - $order['usedTimes'], 'count' => count($record)))); } else { echo CJSON::encode(array('code' => 200, 'data' => array('num' => 0))); } } else { $code = CodeUsed::model()->findAll('userId=' . Yii::app()->user->id); if ($code) { foreach ($code as $list) { $value = Code::model()->find('endDate>=' . $date . ' and id=' . $list['codeId'] . ' and startDate<=' . $date); if ($value) { break; } } if ($value) { echo CJSON::encode(array('code' => 200, 'data' => array('num' => 1, 'count' => count($record)))); } else { echo CJSON::encode(array('code' => 200, 'data' => array('num' => 0))); } } else { echo CJSON::encode(array('code' => 200, 'data' => array('num' => 0))); } } } else { $proxy = new CReservation(); $result = $proxy->getNumber($date); if ($result['code'] == 200) { $data = array('code' => 200, 'data' => $result); echo CJSON::encode($data); } } } else { $this->controller->render('workspacelist', array('data' => $result['data'], 'date' => $date)); } }
public function getNumber($date, $hubId = '') { $date = date('YmdHis', strtotime($date . ' 10:00:00')); $hub = new Hub(); $hublist = $hub->getHUb(); if ($hubId) { $result = Reservations::model()->count('status !=0 and type=1 and startTime=' . $date . ' and hubId=' . $hubId); } else { $result = array(); foreach ($hublist as $key) { $result[] = Reservations::model()->count('status !=0 and type=1 and startTime=' . $date . ' and hubId=' . $key['id']); } } if ($result) { $data = array('code' => 200, 'message' => 'SUCCESS', 'count' => $result); } else { $data = array('code' => 200, 'message' => 'SUCCESS', 'count' => 0); } return $data; }
public function mySelect($date, $userId, $roomId, $location) { $criteria = new CDbCriteria(); $criteria->addCondition(array('status=1', 'type=2', 'userId=' . $userId, 'conferenceroomId=' . $roomId, 'hubId=' . $location)); $criteria->addSearchCondition('startTime', $date); $result = Reservations::model()->findAll($criteria); if (!empty($result)) { $arr = array(); foreach ($result as $list) { $start = strtotime($list['startTime']); $end = strtotime($list['endTime']); $length = ($end - $start) / 3600; for ($i = 0; $i < $length * 2; $i++) { array_push($arr, (date('H', $start) - 9 + date('i', $start) / 60) * 2 + $i); } } return $arr; } else { return ''; } }
/** * This is method for delete reservation from list * @param string $id * @return array[] { * 'code':200, * 'message':'SUCCESS' * } */ public function cancelReservation($id) { $result = Reservations::model()->findByAttributes(array('id' => $id)); $result->status = '0'; if ($result->save()) { $data = array('code' => 200, 'message' => 'SUCCESS'); } return $data; }