本文整理汇总了PHP中Box::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Box::model方法的具体用法?PHP Box::model怎么用?PHP Box::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box
的用法示例。
在下文中一共展示了Box::model方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dateTarget
/**
* Get the date target
*/
static function dateTarget($dateId)
{
$Item = Box::model()->with('UserBoxes')->find(array('select' => 'SUM(quantity * box_price) as total', 'condition' => 'delivery_date_id = ' . $dateId . ''));
return $Item ? $Item->total : 0;
}
示例2: foreach
<td class="value"><strong><?php
echo SnapFormat::currency(BoxItem::dateTarget($SelectedDeliveryDate->id));
?>
</strong></td>
<td></td>
</tr>
<tr>
<td class="total" colspan="3">
Box Retail:
</td>
<?php
$totalRetal = 0;
foreach ($DeliveryDateBoxes as $DeliveryDateBoxMerged) {
$dateBoxIds = explode(',', $DeliveryDateBoxMerged->box_ids);
foreach ($dateBoxIds as $dateBoxId) {
$DateBox = Box::model()->findByPk($dateBoxId);
$retail = $value = $DateBox->retailPrice;
$totalRetal += $retail;
?>
<td class="value <?php
echo $retail > $DateBox->box_price ? 'red' : '';
?>
"><?php
echo SnapFormat::currency($retail);
?>
</td>
<?php
}
?>
<?php
}
示例3: repeatCurrentOrder
/**
* @param type $DDs Array of DeliveryDate objects
*/
public function repeatCurrentOrder($DDs)
{
$SPs = isset($this->_SupplierProduct[$this->delivery_date_id]) ? $this->_SupplierProduct[$this->delivery_date_id] : array();
$UBs = isset($this->_UserBox[$this->delivery_date_id]) ? $this->_UserBox[$this->delivery_date_id] : array();
$allOk = true;
foreach ($DDs as $DD) {
//Clear the current order
unset($this->_SupplierProduct[$DD->id]);
unset($this->_UserBox[$DD->id]);
//Repopulate the order
foreach ($SPs as $id => $qty) {
$Product = SupplierProduct::model()->findByPk($id);
$availTo = strtotime($Product->customer_available_to);
$availFrom = strtotime($Product->customer_available_from);
$curDate = strtotime($DD->date);
if ($curDate < $availTo && $curDate > $availFrom) {
$this->_SupplierProduct[$DD->id][$id] = $qty;
} else {
$allOk = false;
}
}
foreach ($UBs as $id => $qty) {
//Find the equivalent box type for the current date
$CopyBox = Box::model()->findByAttributes(array('box_id' => $id));
$NewBox = Box::model()->findByAttributes(array('size_id' => $CopyBox->size_id, 'delivery_date_id' => $DD->id));
if ($NewBox) {
$this->_UserBox[$DD->id][$NewBox->box_id] = $qty;
} else {
Yii::app()->user->setFlash('warning', 'A box has been removed from your future orders.');
}
}
}
$this->_user->setState('boxocart.SupplierProduct', $this->_SupplierProduct);
$this->_user->setState('boxocart.UserBox', $this->_UserBox);
return $allOk;
}
示例4: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model = Box::model()->findByPk((int) $id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例5: actionGenerateOrderList
/**
* Generate a packing list spreadsheet for a given date_id
*/
public function actionGenerateOrderList($date)
{
$tablePrefix = SnapUtil::config('boxomatic/tablePrefix');
$sql = '
SELECT
SUM(item_quantity) as total,
SUM(item_quantity * item_value) as total_price,
item_value,
GROUP_CONCAT(DISTINCT t.box_id ORDER BY t.box_id DESC) AS box_ids,
GROUP_CONCAT(DISTINCT `box_item_id` ORDER BY `BoxItems`.box_id DESC) as box_item_ids,
`BoxItems`.`box_item_id`,
`BoxItems`.`item_name`,
`BoxItems`.`item_unit`,
`Supplier`.`name`
FROM `' . $tablePrefix . 'boxes` `t`
LEFT OUTER JOIN `' . $tablePrefix . 'user_boxes` `UserBoxes`
ON (`UserBoxes`.`box_id`=`t`.`box_id`)
LEFT OUTER JOIN `' . $tablePrefix . 'box_items` `BoxItems`
ON (`BoxItems`.`box_id`=`t`.`box_id`)
LEFT OUTER JOIN `' . $tablePrefix . 'suppliers` `Supplier`
ON (`BoxItems`.`supplier_id`=`Supplier`.`id`)
WHERE (
delivery_date_id=' . $date . '
AND user_box_id is not null
AND
(
UserBoxes.status=' . UserBox::STATUS_APPROVED . ' OR
UserBoxes.status=' . UserBox::STATUS_DELIVERED . '
)
)
GROUP BY name,item_name
ORDER BY name;
';
$connection = Yii::app()->db;
$command = $connection->createCommand($sql);
$dataReader = $command->query();
$items = $dataReader->readAll();
if (empty($items)) {
echo 'No customer orders!';
exit;
}
$phpExcelPath = Yii::getPathOfAlias('boxomatic.external.PHPExcel');
$DateBoxes = Box::model()->with('BoxSize')->findAll(array('condition' => 'delivery_date_id = ' . $date, 'order' => 'box_size_name DESC'));
//disable Yii's Autoload because it messes with PHPExcel's autoloader
spl_autoload_unregister(array('YiiBase', 'autoload'));
include $phpExcelPath . DIRECTORY_SEPARATOR . 'PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Supplier');
$objPHPExcel->getActiveSheet()->SetCellValue('B1', 'Item');
$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Total Quantity');
$objPHPExcel->getActiveSheet()->SetCellValue('D1', 'Unit');
$objPHPExcel->getActiveSheet()->SetCellValue('E1', 'Unit Price');
$objPHPExcel->getActiveSheet()->SetCellValue('F1', 'Total Price');
$alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$boxIds = explode(',', $items[0]['box_ids']);
$pos = 6;
spl_autoload_register(array('YiiBase', 'autoload'));
foreach ($DateBoxes as $n => $Box) {
$custCount = $Box->customerCount;
$objPHPExcel->getActiveSheet()->SetCellValue($alpha[$pos] . '1', $Box->BoxSize->box_size_name . ' (' . $custCount . ')');
$objPHPExcel->getActiveSheet()->getColumnDimension($alpha[$pos])->setAutoSize(true);
$pos++;
}
$objPHPExcel->getActiveSheet()->getStyle("A1:" . $alpha[$pos] . '1')->applyFromArray(array("font" => array("bold" => true)));
$row = 2;
foreach ($items as $item) {
$objPHPExcel->getActiveSheet()->SetCellValue('A' . $row, $item['name']);
$objPHPExcel->getActiveSheet()->SetCellValue('B' . $row, $item['item_name']);
$objPHPExcel->getActiveSheet()->SetCellValue('C' . $row, $item['total']);
$objPHPExcel->getActiveSheet()->SetCellValue('D' . $row, $item['item_unit']);
$objPHPExcel->getActiveSheet()->SetCellValue('E' . $row, $item['item_value']);
$objPHPExcel->getActiveSheet()->SetCellValue('F' . $row, $item['total_price']);
$boxIds = explode(',', $item['box_ids']);
$boxItemIds = explode(',', $item['box_item_ids']);
$pos = 6;
foreach ($DateBoxes as $Box) {
$BoxItem = null;
$biPos = false;
$biPos = array_search($Box->box_id, $boxIds);
if ($biPos !== false) {
$BoxItem = BoxItem::model()->findByAttributes(array('box_id' => $Box->box_id, 'box_item_id' => $boxItemIds[$biPos]));
}
$quantity = $BoxItem && !empty($BoxItem->item_quantity) ? $BoxItem->item_quantity : '0';
$objPHPExcel->getActiveSheet()->SetCellValue($alpha[$pos] . $row, $quantity);
$pos++;
}
$row++;
}
$objPHPExcel->getActiveSheet()->getColumnDimension("A")->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension("B")->setAutoSize(true);
//.........这里部分代码省略.........
示例6: actionOrder
/**
* Manages all models.
*/
public function actionOrder($show = 4)
{
$model = new UserBox();
$Customer = Customer::model()->findByPk(Yii::app()->user->user_id);
$deadlineDays = SnapUtil::config('boxomatic/orderDeadlineDays');
if (isset($_GET['all'])) {
$DeliveryDates = DeliveryDate::model()->findAll();
} else {
$DeliveryDates = DeliveryDate::model()->with('Boxes')->findAll(array('condition' => 'date_sub(date, interval -1 week) > NOW()', 'limit' => $show + 1));
}
$BoxSizes = BoxSize::model()->findAll(array('order' => 'box_size_name DESC'));
if (isset($_POST['btn_recurring'])) {
$monthsAdvance = (int) $_POST['months_advance'];
$startingFrom = $_POST['starting_from'];
$every = $_POST['every'];
$locationId = $_POST['Customer']['delivery_location_key'];
$custLocationId = new CDbExpression('NULL');
if (strpos($locationId, '-')) {
//has a customer location
$parts = explode('-', $locationId);
$locationId = $parts[1];
$custLocationId = $parts[0];
}
$Location = Location::model()->findByPk($locationId);
foreach ($_POST['Recurring'] as $key => $quantity) {
$boxSizeId = str_replace('bs_', '', $key);
$Boxes = Box::model()->with('DeliveryDate')->findAll("\n\t\t\t\t\tdate >= '{$startingFrom}' AND\n\t\t\t\t\tdate <= date_add('{$startingFrom}', interval {$monthsAdvance} month) AND\n\t\t\t\t\tdate_sub(date, interval {$deadlineDays} day) > NOW() AND\n\t\t\t\t\tsize_id={$boxSizeId}");
$n = 0;
foreach ($Boxes as $Box) {
$CustBoxes = UserBox::model()->findAllByAttributes(array('user_id' => $Customer->user_id, 'box_id' => $Box->box_id));
foreach ($CustBoxes as $CustBox) {
$CustBox->delete();
}
$n++;
if ($n % 2 == 0 && $every == 'fortnight') {
continue;
}
//Create extra customer box rows
for ($i = 0; $i < $quantity; $i++) {
$CustBox = new UserBox();
$CustBox->user_id = $Customer->user_id;
$CustBox->box_id = $Box->box_id;
$CustBox->quantity = 1;
$CustBox->delivery_cost = $Location->location_delivery_value;
$CustBox->save();
$CustDeliveryDate = Order::model()->findByAttributes(array('user_id' => $Customer->user_id, 'delivery_date_id' => $CustBox->Box->delivery_date_id));
if (!$CustDeliveryDate) {
$CustDeliveryDate = new Order();
$CustDeliveryDate->user_id = $Customer->user_id;
$CustDeliveryDate->delivery_date_id = $CustBox->Box->delivery_date_id;
}
$CustDeliveryDate->location_id = $locationId;
$CustDeliveryDate->customer_location_id = $custLocationId;
$CustDeliveryDate->save();
}
}
}
}
if (isset($_POST['btn_clear_orders'])) {
//Get all boxes beyond the deadline date
$Boxes = Box::model()->with('DeliveryDate')->findAll("\n\t\t\t\tdate_sub(date, interval {$deadlineDays} day) > NOW()");
foreach ($Boxes as $Box) {
$CustBox = UserBox::model()->findByAttributes(array('user_id' => $Customer->user_id, 'box_id' => $Box->box_id));
//Only create a records if an entry doesn't already exist
if ($CustBox) {
$CustBox->delete();
}
}
}
if (isset($_POST['Orders'])) {
foreach ($_POST['Orders'] as $boxId => $quantity) {
$Box = Box::model()->findByPk($boxId);
$CustBoxes = UserBox::model()->with('Box')->findAll(array('condition' => 'user_id=:customerId AND size_id=:sizeId AND delivery_date_id=:deliveryDateId', 'params' => array(':customerId' => $Customer->user_id, ':sizeId' => $Box->size_id, ':deliveryDateId' => $Box->delivery_date_id)));
$curQuantity = count($CustBoxes);
$diff = $quantity - $curQuantity;
if ($diff > 0) {
//Create extra customer box rows
for ($i = 0; $i < $diff; $i++) {
$CustBox = new UserBox();
$CustBox->user_id = $Customer->user_id;
$CustBox->box_id = $boxId;
$CustBox->quantity = 1;
$CustBox->delivery_cost = $Customer->Location->location_delivery_value;
$CustBox->save();
}
}
if ($diff < 0) {
//Remove any boxes the customer no longer wants;
$diff = abs($diff);
for ($i = 0; $i < $diff; $i++) {
$CustBoxes[$i]->delete();
}
}
}
}
if (isset($_POST['CustDeliveryDates'])) {
foreach ($_POST['CustDeliveryDates'] as $key => $locationId) {
//.........这里部分代码省略.........
示例7: actionOrder
/**
* Manages all models.
*/
public function actionOrder($date = null, $cat = null, $show = 5, $location = null)
{
if (!$cat) {
$cat = SnapUtil::config('boxomatic/supplier_product_feature_category');
}
$customerId = Yii::app()->user->user_id;
$Customer = Customer::model()->findByPk($customerId);
$deadlineDays = SnapUtil::config('boxomatic/orderDeadlineDays');
if (!$date) {
$date = DeliveryDate::getCurrentDeliveryDateId();
}
$updatedExtras = array();
$updatedOrders = array();
$Category = Category::model()->findByPk($cat);
$DeliveryDate = DeliveryDate::model()->findByPk($date);
$AllDeliveryDates = false;
$pastDeadline = false;
$CustDeliveryDate = false;
if ($Customer) {
$CustDeliveryDate = Order::model()->findByAttributes(array('delivery_date_id' => $date, 'user_id' => $customerId));
if (!$CustDeliveryDate) {
$CustDeliveryDate = new Order();
$CustDeliveryDate->delivery_date_id = $date;
$CustDeliveryDate->user_id = $customerId;
$CustDeliveryDate->location_id = $Customer->location_id;
$CustDeliveryDate->save();
}
$AllDeliveryDates = DeliveryDate::model()->with('Locations')->findAll("Locations.location_id = " . $CustDeliveryDate->location_id);
$deadline = strtotime('+' . $deadlineDays . ' days');
$pastDeadline = strtotime($DeliveryDate->date) < $deadline;
if ($pastDeadline) {
Yii::app()->user->setFlash('warning', 'Order deadline has passed, order cannot be changed.');
}
}
if (!$Customer && (isset($_POST['supplier_purchases']) || isset($_POST['boxes']))) {
Yii::app()->user->setFlash('error', 'You must register to make an order.');
$this->redirect(array('site/register'));
}
if ($location) {
$locationId = $location;
$custLocationId = new CDbExpression('NULL');
if (strpos($locationId, '-')) {
//has a customer location
$parts = explode('-', $locationId);
$locationId = $parts[1];
$custLocationId = $parts[0];
}
//$Location=Location::model()->findByPk($locationId);
$CustDeliveryDate->location_id = $locationId;
$CustDeliveryDate->customer_location_id = $custLocationId;
$CustDeliveryDate->save();
$CustDeliveryDate->refresh();
}
if (isset($_POST['btn_recurring'])) {
$monthsAdvance = (int) $_POST['months_advance'];
$startingFrom = $_POST['starting_from'];
$every = $_POST['every'];
$locationId = $_POST['Order']['delivery_location_key'];
$custLocationId = new CDbExpression('NULL');
if (strpos($locationId, '-')) {
//has a customer location
$parts = explode('-', $locationId);
$locationId = $parts[1];
$custLocationId = $parts[0];
}
$dayOfWeek = date('N', strtotime($CustDeliveryDate->DeliveryDate->date)) + 1;
if ($dayOfWeek == 8) {
$dayOfWeek = 1;
}
$orderedExtras = OrderItem::findCustomerExtras($customerId, $date);
$orderedBoxes = UserBox::model()->with('Box')->findAllByAttributes(array('user_id' => $Customer->user_id), 'delivery_date_id=' . $date);
$DeliveryDates = DeliveryDate::model()->findAll("\n\t\t\t\t\tdate >= '{$startingFrom}' AND\n\t\t\t\t\tdate <= DATE_ADD('{$startingFrom}', interval {$monthsAdvance} MONTH) AND\n\t\t\t\t\tdate_sub(date, interval {$deadlineDays} day) > NOW() AND\n\t\t\t\t\tDAYOFWEEK(date) = '" . $dayOfWeek . "'");
$n = 0;
foreach ($DeliveryDates as $DD) {
$CustDD = Order::model()->findByAttributes(array('delivery_date_id' => $DD->id, 'user_id' => $customerId));
if (!$CustDD) {
$CustDD = new Order();
$CustDD->delivery_date_id = $DD->id;
$CustDD->user_id = $customerId;
$CustDD->location_id = $CustDeliveryDate->location_id;
$CustDD->save();
}
//Delete any extras already ordered
$TBDExtras = OrderItem::findCustomerExtras($customerId, $DD->id);
foreach ($TBDExtras as $TBDExtra) {
$TBDExtra->delete();
}
//Delete any extras already ordered
$TBDBoxes = UserBox::model()->with('Box')->findAllByAttributes(array('user_id' => $Customer->user_id), 'delivery_date_id=' . $CustDD->delivery_date_id);
foreach ($TBDBoxes as $TBDBox) {
$TBDBox->delete();
}
$n++;
if ($n % 2 == 0 && $every == 'fortnight') {
continue;
}
//Copy current days order
//.........这里部分代码省略.........