本文整理汇总了PHP中Arr::filter_prefixed方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::filter_prefixed方法的具体用法?PHP Arr::filter_prefixed怎么用?PHP Arr::filter_prefixed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arr
的用法示例。
在下文中一共展示了Arr::filter_prefixed方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_infotab_edit
/**
* Edit product infotabs
*
* @param $product_id = Product ID
* @param $infotab_id = Infotab ID
* @param $hotspot_id = Hotspot ID
*
*/
public function action_infotab_edit($produt_id = false, $infotab_id = false, $hotspot_id = false)
{
// Check for product
if (!is_numeric($produt_id)) {
\Response::redirect('admin/product/list');
}
// Get news item to edit
if (!($product = Model_Product::find_one_by_id($produt_id))) {
\Response::redirect('admin/product/list');
}
// Check for infotab
if (!is_numeric($infotab_id)) {
\Response::redirect('admin/product/list');
}
// Get news item to edit
if (!($item = Model_Product_To_Infotabs::find_by_pk($infotab_id))) {
\Response::redirect('admin/product/list');
}
// Get hotspot is exist
if (is_numeric($hotspot_id)) {
if (!($hotspot = Model_Infotab_Image::find_by_pk($hotspot_id))) {
unset($hotspot);
}
}
if (\Input::post()) {
$val = Model_Product_To_Infotabs::validate('update', $item->type);
// Upload image and display errors if there are any
$image = $this->upload_infotab_image();
if (!$image['exists'] && \Config::get('infotab.image.required', false) && empty($item->images)) {
// No previous images and image is not selected and it is required
\Messages::error('<strong>There was an error while trying to upload infotab image</strong>');
\Messages::error('You have to select image');
} elseif ($image['errors']) {
\Messages::error('<strong>There was an error while trying to upload infotab image</strong>');
foreach ($image['errors'] as $error) {
\Messages::error($error);
}
}
if ($val->run() && $image['is_valid'] && !(!$image['exists'] && \Config::get('infotab.image.required', false) && empty($item->images))) {
/** IMAGES **/
// Get all alt texts to update if there is no image change
foreach (\Arr::filter_prefixed(\Input::post(), 'alt_text_') as $image_id => $alt_text) {
if (strpos($image_id, 'new_') === false) {
$item_images[$image_id] = array('id' => $image_id, 'data' => array('alt_text' => \Input::post('alt_text_' . $image_id, '')));
}
}
// Save images if new files are submitted
if (isset($this->_infotab_image_data)) {
foreach ($this->_infotab_image_data as $image_data) {
$cover_count = count($item->images);
if (strpos($image_data['field'], 'new_') === false) {
// Update existing image
if (str_replace('image_', '', $image_data['field']) != 0) {
$image_id = (int) str_replace('image_', '', $image_data['field']);
$cover_count--;
$item_images[$image_id] = array('id' => $image_id, 'data' => array('infotab_id' => $item->unique_id, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_' . $image_id, '')));
$this->delete_infotab_image(\Input::post('image_db_' . $image_id, ''));
}
} else {
// Save new image
$image_tmp = str_replace('image_new_', '', $image_data['field']);
$item_images[0] = array('id' => 0, 'data' => array('infotab_id' => $item->unique_id, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_new_' . $image_tmp, ''), 'cover' => $cover_count == 0 ? 1 : 0, 'sort' => $cover_count + 1));
}
}
}
Model_Infotab::bind_images($item_images);
/** END OF IMAGES **/
// Get POST values
$insert = \Input::post();
// Prep some values
$insert['description'] = trim($insert['description']);
$insert['active'] = !empty($insert['description']) ? 1 : 0;
$item->set($insert);
try {
$item->save();
\Messages::success('Infotab successfully updated.');
\Response::redirect(\Input::post('exit', false) ? \Uri::create('admin/product/infotab_list/' . $product->id) : \Uri::admin('current'));
} catch (\Database_Exception $e) {
// show validation errors
\Messages::error('<strong>There was an error while trying to update infotab</strong>');
// Uncomment lines below to show database errors
//$errors = $e->getMessage();
//\Messages::error($errors);
}
} else {
// Delete uploaded images if there is product saving error
if (isset($this->_infotab_image_data)) {
foreach ($this->_infotab_image_data as $image_data) {
$this->delete_infotab_image($image_data['saved_as']);
}
}
if ($val->error() != array()) {
//.........这里部分代码省略.........
示例2: headers
/**
* Fetch a item from the HTTP request headers
*
* @return array
*/
public static function headers($index = null, $default = null)
{
static $headers = null;
// do we need to fetch the headers?
if ($headers === null) {
// deal with fcgi or nginx installs
if (!function_exists('getallheaders')) {
$server = \Arr::filter_prefixed(static::server(), 'HTTP_', true);
foreach ($server as $key => $value) {
$key = join('-', array_map('ucfirst', explode('_', strtolower($key))));
$headers[$key] = $value;
}
$value = static::server('Content_Type', static::server('Content-Type')) and $headers['Content-Type'] = $value;
$value = static::server('Content_Length', static::server('Content-Length')) and $headers['Content-Length'] = $value;
} else {
$headers = getallheaders();
}
}
return empty($headers) ? $default : (func_num_args() === 0 ? $headers : \Arr::get($headers, $index, $default));
}
示例3: action_update
public function action_update($id = false)
{
if (!is_numeric($id)) {
throw new \HttpNotFoundException();
}
// Get accordion item to edit
if (!($item = Model_Accordion::find_one_by_id($id))) {
throw new \HttpNotFoundException();
}
// Accordion from home page?
if ($item->parent_id == 1) {
\Config::load('page::accordion_banner', 'details', true, true);
}
\View::set_global('title', 'Edit Accordion');
if (\Input::post()) {
$val = Model_Accordion::validate('update');
// Upload image and display errors if there are any
$image = $this->upload_image();
if (!$image['exists'] && \Config::get('details.image.required', false) && empty($item->images)) {
// No previous images and image is not selected and it is required
\Messages::error('<strong>There was an error while trying to upload accordion image</strong>');
\Messages::error('You have to select image');
} elseif ($image['errors']) {
\Messages::error('<strong>There was an error while trying to upload accordion image</strong>');
foreach ($image['errors'] as $error) {
\Messages::error($error);
}
}
if ($val->run() && $image['is_valid'] && !(!$image['exists'] && \Config::get('details.image.required', false) && empty($item->images))) {
/** IMAGES **/
// Get all alt texts to update if there is no image change
foreach (\Arr::filter_prefixed(\Input::post(), 'alt_text_') as $image_id => $alt_text) {
if (strpos($image_id, 'new_') === false) {
$item_images[$image_id] = array('id' => $image_id, 'data' => array('alt_text' => \Input::post('alt_text_' . $image_id, '')));
}
}
// Save images if new files are submitted
if (isset($this->_image_data)) {
foreach ($this->_image_data as $image_data) {
$cover_count = count($item->images);
if (strpos($image_data['field'], 'new_') === false) {
// Update existing image
if (str_replace('image_', '', $image_data['field']) != 0) {
$image_id = (int) str_replace('image_', '', $image_data['field']);
$cover_count--;
$item_images[$image_id] = array('id' => $image_id, 'data' => array('content_id' => $item->id, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_' . $image_id, '')));
$this->delete_image(\Input::post('image_db_' . $image_id, ''));
}
} else {
// Save new image
$image_tmp = str_replace('image_new_', '', $image_data['field']);
$item_images[0] = array('id' => 0, 'data' => array('content_id' => $item->id, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_new_' . $image_tmp, ''), 'cover' => $cover_count == 0 ? 1 : 0, 'sort' => $cover_count + 1));
}
}
}
Model_Accordion::bind_images($item_images);
/** END OF IMAGES **/
// Get POST values
$insert = \Input::post();
// Prepare some values
$insert['active_from'] = !empty($insert['active_from']) ? strtotime($insert['active_from']) : NULL;
$insert['active_to'] = !empty($insert['active_to']) ? strtotime($insert['active_to']) : NULL;
if ($insert['status'] != 2) {
unset($insert['active_from']);
unset($insert['active_to']);
}
$item->set($insert);
try {
$item->save();
\Messages::success('Accordion successfully updated.');
\Response::redirect(\Input::post('exit', false) ? \Uri::create('admin/page/accordion/list/' . $item->parent_id) : \Uri::admin('current'));
} catch (\Database_Exception $e) {
// show validation errors
\Messages::error('<strong>There was an error while trying to update accordion</strong>');
// Uncomment lines below to show database errors
//$errors = $e->getMessage();
//\Messages::error($errors);
}
} else {
// Delete uploaded images if there is page saving error
if (isset($this->_image_data)) {
foreach ($this->_image_data as $image_data) {
$this->delete_image($image_data['saved_as']);
}
}
if ($val->error() != array()) {
// show validation errors
\Messages::error('<strong>There was an error while trying to update accordion</strong>');
foreach ($val->error() as $e) {
\Messages::error($e->get_message());
}
}
}
}
$accordion = Model_Accordion::find_one_by_id($id);
$page = Model_Page::find_one_by_id($accordion->parent_id);
\Theme::instance()->set_partial('content', $this->view_dir . 'update')->set('page', $page)->set('accordion', $accordion);
}
示例4: action_update
//.........这里部分代码省略.........
}
$update = Model_Attribute::find_one_by_id($post['update_items'][$key]);
if ($update) {
$item_images = array();
$data = array('product_id' => $post['product_id'], 'attribute_group_id' => $post['attribute_group_id'], 'attributes' => $attribute, 'product_code' => $post['product_code'][$key], 'retail_price' => $post['retail_price'][$key], 'sale_price' => $post['sale_price'][$key], 'stock_quantity' => $post['stock_quantity'][$key], 'active' => isset($post['active']) && $post['active'][$key] ? $post['active'][$key] : $post['active_new'][$key]);
// Default radio
$data['default'] = 0;
if (isset($post['default']) && $post['default'] == $key) {
$this->reset_default($item->id);
$data['default'] = 1;
}
$update->set($data);
$update->save();
$attr_id = $update->id;
// Get combinations for multiple images
if (isset($post['apply_image']) && isset($post['action'])) {
if (in_array($attr_id, $post['action'])) {
$multiple_images['action'][$attr_id] = $attr_id;
}
}
if (isset($_FILES['image_new_' . $attr_id])) {
// Upload image and display errors if there are any
$image = $this->upload_image('image');
if ($image['errors'] && $image['exists']) {
\Messages::error('<strong>There was an error while trying to upload product attribute image</strong>');
foreach ($image['errors'] as $error) {
\Messages::error($error);
}
}
// if($image['is_valid'] && !(!$image['exists'] && \Config::get('details.image.required', false) && empty($item->images)))
if ($image['is_valid'] && !(!$image['exists'] && \Config::get('details.image.required', false))) {
/** IMAGES **/
// Get all alt texts to update if there is no image change
foreach (\Arr::filter_prefixed(\Input::post(), 'alt_text_') as $image_id => $alt_text) {
if (strpos($image_id, 'new_') === false) {
$item_images[$image_id] = array('id' => $image_id, 'data' => array('alt_text' => \Input::post('alt_text_' . $image_id, '')));
if (!empty($item_images)) {
Model_Attribute::bind_images($item_images);
}
}
}
// Save images if new files are submitted
if (isset($this->_image_data) && $image['exists'] !== false) {
foreach ($this->_image_data as $image_data) {
$cover_count = count($update->images);
if (strpos($image_data['field'], 'new_') === false) {
// Update existing image
if (str_replace('image_', '', $image_data['field']) != 0) {
$image_id = (int) str_replace('image_', '', $image_data['field']);
$cover_count--;
$item_images[$image_id] = array('id' => $image_id, 'data' => array('content_id' => $attr_id, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_' . $image_id, '')));
//$this->delete_image(\Input::post('image_db_' . $image_id, ''));
}
if (!empty($item_images)) {
Model_Attribute::bind_images($item_images);
}
} else {
// Save new image
$image_tmp = str_replace('image_new_', '', $image_data['field']);
$image_new = $item_images[0] = array('id' => 0, 'data' => array('content_id' => $attr_id, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_new_' . $image_tmp, ''), 'cover' => $cover_count == 0 ? 1 : 0, 'sort' => $cover_count + 1));
if (!empty($item_images)) {
Model_Attribute::bind_images($item_images);
}
// Multiple images
if (isset($post['apply_image']) && isset($post['action']) && false) {
foreach ($post['action'] as $action_value) {
示例5: test_filter_prefixed
/**
* Tests Arr::element()
*
* @test
*/
public function test_filter_prefixed()
{
$arr = array('foo' => 'baz', 'prefix_bar' => 'yay');
$output = Arr::filter_prefixed($arr);
$this->assertEquals(array('bar' => 'yay'), $output);
}
示例6: action_update
//.........这里部分代码省略.........
// We will insert first QTY in list. All other will be ignired
if (!isset($discounts[$user_group_id][$value])) {
$new_discounts[$user_group_id][$value]['user_group_id'] = $user_group_id;
$new_discounts[$user_group_id][$value]['product_group_id'] = $id;
$new_discounts[$user_group_id][$value]['qty'] = $value;
$new_discounts[$user_group_id][$value]['discount'] = $_POST['new_discount'][$user_group_id][$key];
}
}
if (!empty($new_discounts)) {
foreach ($new_discounts[$user_group_id] as $key => $value) {
// Insert discount
$discount = Model_Group_Discounts::forge($new_discounts[$user_group_id][$key]);
$discount->save();
}
}
}
//end
$val = Model_Group::validate('update');
// Upload image and display errors if there are any
$image = $this->upload_image();
if (!$image['exists'] && \Config::get('details.image.required', false) && empty($item->images)) {
// No previous images and image is not selected and it is required
\Messages::error('<strong>There was an error while trying to upload group image</strong>');
\Messages::error('You have to select image');
} elseif ($image['errors']) {
\Messages::error('<strong>There was an error while trying to upload group image</strong>');
foreach ($image['errors'] as $error) {
\Messages::error($error);
}
}
if ($val->run() && $image['is_valid'] && !(!$image['exists'] && \Config::get('details.image.required', false) && empty($item->images))) {
/** IMAGES **/
// Get all alt texts to update if there is no image change
foreach (\Arr::filter_prefixed(\Input::post(), 'alt_text_') as $image_id => $alt_text) {
if (strpos($image_id, 'new_') === false) {
$item_images[$image_id] = array('id' => $image_id, 'data' => array('alt_text' => \Input::post('alt_text_' . $image_id, '')));
}
}
// Save images if new files are submitted
if (isset($this->_image_data)) {
foreach ($this->_image_data as $image_data) {
$cover_count = count($item->images);
if (strpos($image_data['field'], 'new_') === false) {
// Update existing image
if (str_replace('image_', '', $image_data['field']) != 0) {
$image_id = (int) str_replace('image_', '', $image_data['field']);
$cover_count--;
$item_images[$image_id] = array('id' => $image_id, 'data' => array('content_id' => $item->id, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_' . $image_id, '')));
$this->delete_image(\Input::post('image_db_' . $image_id, ''));
}
} else {
// Save new image
$image_tmp = str_replace('image_new_', '', $image_data['field']);
$item_images[0] = array('id' => 0, 'data' => array('content_id' => $item->id, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_new_' . $image_tmp, ''), 'cover' => $cover_count == 0 ? 1 : 0, 'sort' => $cover_count + 1));
}
}
}
$item_images = isset($item_images) ? $item_images : array();
Model_Group::bind_images($item_images);
/** END OF IMAGES **/
// Get POST values
$insert = \Input::post();
$insert['type'] = 'pricing';
$item->set($insert);
try {
$item->save();
示例7: save_order
protected function save_order()
{
if (!$this->check_logged()) {
\Messages::error('You must be logged in if you want to continue with your order.');
\Response::redirect(\Uri::create('order/checkout/address'));
}
// Save order
$user = false;
$order = false;
$items = \Cart::items();
if (\Sentry::check()) {
$user = \Sentry::user();
}
if (\Input::post() && $items && $user) {
$group_id = $user['groups'][0]['id'];
$item_with_discount = array();
foreach ($items as $item) {
$id = $item->get('id');
$product_groups = \Product\Model_Product_To_Groups::find_by_product_id($item->get('id'));
foreach ($product_groups as $group) {
$all_discounts = \Product\Model_Group_Discounts::find_by(array('user_group_id' => $group_id, 'product_group_id' => $group->group_id), null, null, null);
foreach ($all_discounts as $discount) {
$discount = (int) $item_with_discount[$id]['discount'] + $discount->discount;
$sub_total = $item->totalPrice(true) - (int) $discount / $item->totalPrice(true) * 100;
$item_with_discount[$id] = array('product_group_id' => $group->product_id, 'user_group_id' => $group->group_id, 'discount' => $discount, 'sub_total' => $sub_total);
}
}
$item_with_discount['total_discount'] = (int) $item_with_discount['total_discount'] + (int) $item_with_discount[$id]['total_discount'];
$item_with_discount['total_price'] = (double) $item_with_discount['total_price'] + (double) $item_with_discount[$id]['sub_total'];
}
// check for a valid CSRF token
if (!\Security::check_token()) {
\Messages::error('CSRF attack or expired CSRF token.');
\Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost')));
}
try {
// Update or create order
if (is_numeric(\Session::get('order.id'))) {
$order = \Order\Model_Order::find_one_by_id(\Session::get('order.id'));
}
if (!$order) {
$order = \Order\Model_Order::forge();
}
$shipping_price = $order->shipping_price(null, null, true);
$metadata = $user['metadata'];
if ($billing = \Arr::filter_prefixed($metadata, 'shipping_')) {
foreach ($billing as $key => $value) {
$order->{$key} = $metadata[$key];
unset($metadata[$key]);
}
}
foreach ($metadata as $key => $value) {
$order->{$key} = $value;
}
$order->email = $user->get('email');
$order->user_id = $user->get('id');
$order->status = 'Pending';
$order->discount_amount = $item_with_discount['total_discount'];
//\Cart::getTotal('price');
$order->total_price = $item_with_discount['total_price'];
//\Cart::getTotal('price');
$order->finished = 1;
$order->guest = $metadata['guest'] ? 1 : 0;
$order->accepted = $metadata['master'] == 1 ? 1 : 0;
$order->credit_account = $metadata['credit_account'] == 1 ? 1 : 0;
$order->shipping_price = $shipping_price;
// Save order, add products to order products
if ($order->save()) {
foreach ($items as $item) {
$product_data = null;
if ($product = \Product\Model_Product::find_one_by_id($item->get('id'))) {
$product_data = \Product\Model_Product::product_data($product, $item->get('attributes'));
}
if ($product_data) {
$order_products = \Order\Model_Products::forge();
$order_products->order_id = $order->id;
$order_products->title = $product->title;
$order_products->code = $product_data['code'];
$order_products->price = $item->singlePrice(true);
$order_products->price_type = $product_data['price_type'];
$order_products->quantity = $item->get('quantity');
$order_products->product_id = $product->id;
$order_products->artwork_required = $product->artwork_required;
$order_products->artwork_free_over = $product->artwork_free_over;
$order_products->subtotal = $item_with_discount[$item->get('id')]['sub_total'];
//$item->totalPrice(true);
$order_products->attributes = json_encode(\Product\Model_Attribute::get_combination($item->get('attributes')));
if (!empty($product->categories)) {
$categories = array();
foreach ($product->categories as $category) {
$categories[] = $category->title;
}
if ($categories) {
$order_products->product_category = implode(',', $categories);
}
}
$order_products->save();
// Find artworks
if ($unique_id = $item->get('unique_id')) {
if ($artworks = \Order\Model_Artwork::find(array('where' => array('unique_id' => $unique_id, 'order_id' => $order->id)))) {
//.........这里部分代码省略.........
示例8: save_order
protected function save_order()
{
if (!$this->check_logged()) {
\Messages::error('You must be logged in if you want to continue with your order.');
\Response::redirect(\Uri::create('order/checkout/address'));
}
// Save order
$user = false;
$order = false;
$items = \Cart::items();
if (\Sentry::check()) {
$user = \Sentry::user();
}
if (\Input::post() && $items && $user) {
// check for a valid CSRF token
if (!\Security::check_token()) {
\Messages::error('CSRF attack or expired CSRF token.');
\Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost')));
}
try {
// Update or create order
if (is_numeric(\Session::get('order.id'))) {
$order = \Order\Model_Order::find_one_by_id(\Session::get('order.id'));
}
if (!$order) {
$order = \Order\Model_Order::forge();
}
$cart_total = 0;
foreach ($items as $item) {
$product_data = null;
if ($product = \Product\Model_Product::find_one_by_id($item->get('id'))) {
$product_data = \Product\Model_Product::product_data($product, $item->get('attributes'));
}
$total_price = $item->totalDiscountedPrice(true);
if (isset($product_data["price"]) && $product_data["price"] != 0) {
$total_price = $product_data["price"] * $item->get('quantity');
}
$cart_total += $total_price;
}
$method = \Input::post('delivery') == 'pickup' ? false : true;
$shipping_price = $order->shipping_price(null, null, true, $method);
$metadata = $user['metadata'];
$data = array('email' => $user->get('email'), 'user_id' => $user->get('id'), 'status' => 'Pending', 'total_price' => $cart_total, 'finished' => 1, 'guest' => $metadata['guest'] ? 1 : 0, 'accepted' => $metadata['master'] == 1 ? 1 : 0, 'credit_account' => $metadata['credit_account'] == 1 ? 1 : 0, 'shipping_method' => \Input::post('delivery'), 'shipping_price' => $shipping_price, 'gst_price' => ($cart_total + $shipping_price) * 0.1);
// $order->discount_amount = $item_with_discount['total_discount'];//\Cart::getTotal('price');
//\Cart::getDiscountedTotal('price');//\Cart::getTotal('price');
if ($billing = \Arr::filter_prefixed($metadata, 'shipping_')) {
foreach ($billing as $key => $value) {
$data[$key] = $metadata[$key];
unset($metadata[$key]);
}
}
foreach ($metadata as $key => $value) {
$data[$key] = $value;
}
$order->set($data);
// Save order, add products to order products
if ($order->save()) {
foreach ($items as $item) {
$product_data = null;
if ($product = \Product\Model_Product::find_one_by_id($item->get('id'))) {
$product_data = \Product\Model_Product::product_data($product, $item->get('attributes'));
}
$item_exists = \Order\Model_Products::find(array('where' => array('product_id' => $product->id, 'order_id' => $order->id)));
if ($product_data && !$item_exists) {
$order_products = \Order\Model_Products::forge(array('order_id' => $order->id, 'title' => $product->title, 'code' => $product_data['code'], 'price' => $product_data['price'], 'price_type' => $product_data['price_type'], 'quantity' => $item->get('quantity'), 'product_id' => $product->id, 'artwork_required' => $product->artwork_required, 'artwork_free_over' => $product->artwork_free_over, 'subtotal' => $product_data['price'] * $item->get('quantity'), 'attributes' => json_encode(\Product\Model_Attribute::get_combination($item->get('attributes'))), 'attributes_id' => $item->get('attributes')));
//$item->singleDiscountedPrice(true);//$item->singlePrice(true);
//$item->totalDiscountedPrice(true);//$item->totalPrice(true);
if (!empty($product->categories)) {
$categories = array();
foreach ($product->categories as $category) {
$categories[] = $category->title;
}
if ($categories) {
$order_products->product_category = implode(',', $categories);
}
}
// update stock quantity
\Product\Model_Attribute::update_stock_quantity($item->get('attributes'), $item->get('quantity'));
$order_products->save();
// Find artworks
if ($unique_id = $item->get('unique_id')) {
if ($artworks = \Order\Model_Artwork::find(array('where' => array('unique_id' => $unique_id, 'order_id' => $order->id)))) {
$ysi = \Yousendit\Base::forge();
// Artworks (update, delete)
foreach ($artworks as $artwork) {
// Remove deleted artwork
if ($artwork->deleted_at > 0) {
$ysi->delete_artwork($artwork->file_id);
$artwork->delete();
} else {
$artwork->set(array('order_product_id' => $order_products->id));
$artwork->save();
}
}
}
}
}
}
}
if ($order) {
//.........这里部分代码省略.........
示例9: action_update_files
public function action_update_files($id = false)
{
if (!is_numeric($id)) {
\Response::redirect('admin/application/list');
}
// Get news item to edit
if (!($item = Model_Application::find_one_by_id($id))) {
\Response::redirect('admin/application/list');
}
\View::set_global('title', 'Edit Application Files');
if (\Input::post()) {
if (\Input::post('file_upload', false)) {
// Upload files and display errors if there are any
$file = $this->upload_file();
if (!$file['exists'] && \Config::get('details.image.required', false) && empty($item->images)) {
// No previous images and image is not selected and it is required
\Messages::error('<strong>There was an error while trying to upload content file</strong>');
\Messages::error('You have to select image');
} elseif ($file['errors']) {
\Messages::error('<strong>There was an error while trying to upload content file</strong>');
foreach ($file['errors'] as $error) {
\Messages::error($error);
}
}
if ($file['is_valid'] && !(!$file['exists'] && \Config::get('details.file.required', false) && empty($item->files))) {
/** FILES **/
// Get all alt texts to update if there is no image change
foreach (\Arr::filter_prefixed(\Input::post(), 'title_') as $file_id => $title) {
if (strpos($file_id, 'new_') === false) {
$item_files[$file_id] = array('id' => $file_id, 'data' => array('title' => \Input::post('title_' . $file_id, '')));
}
}
// Save files if new ones are submitted
if (isset($this->_file_data)) {
foreach ($this->_file_data as $file_data) {
$cover_count = count($item->files);
if (strpos($file_data['field'], 'new_') === false) {
// Update existing file
if (str_replace('file_', '', $file_data['field']) != 0) {
$file_id = (int) str_replace('file_', '', $file_data['field']);
$cover_count--;
$item_files[$file_id] = array('id' => $file_id, 'data' => array('content_id' => $item->id, 'file' => $file_data['saved_as'], 'title' => \Input::post('title_' . $file_id, '')));
$this->delete_file(\Input::post('file_db_' . $file_id, ''));
}
} else {
// Save new file
$file_tmp = str_replace('file_new_', '', $file_data['field']);
$item_files[0] = array('id' => 0, 'data' => array('content_id' => $item->id, 'file' => $file_data['saved_as'], 'title' => \Input::post('title_new_' . $file_tmp, ''), 'cover' => $cover_count == 0 ? 1 : 0, 'sort' => $cover_count + 1));
}
}
}
Model_Application::bind_files($item_files);
\Messages::success('Application documents successfully updated.');
\Response::redirect(\Uri::admin('current'));
/** END OF FILES **/
} else {
// Delete uploaded files if there is application saving error
if (isset($this->_file_data)) {
foreach ($this->_file_data as $file_data) {
$this->delete_file($file_data['saved_as']);
}
}
\Messages::error('<strong>There was an error while trying to update application documents</strong>');
}
}
if (\Input::post('video_upload', false)) {
// Upload image and display errors if there are any
$image = $this->upload_image('video');
if ($image['errors']) {
\Messages::error('<strong>There was an error while trying to upload content image</strong>');
foreach ($image['errors'] as $error) {
\Messages::error($error);
}
}
if ($image['is_valid'] && !(\Config::get('details.video.required', false) && empty($item->videos))) {
/** VIDEOS **/
// Get all video urls to update if there is no image change
foreach (\Arr::filter_prefixed(\Input::post(), 'video_url_') as $video_id => $url) {
$not_updated[] = $video_id;
if (strpos($video_id, 'new_') === false) {
$video_url = \Input::post('video_url_' . $video_id, false);
if ($video_url) {
// Check video
$youtube = \App\Youtube::forge();
$video = $youtube->parse(\Input::post('video_url_' . $video_id, ''))->get();
if ($video) {
// Update existing videos
$item_videos[$video_id] = array('id' => $video_id, 'data' => array('content_id' => $item->id, 'url' => \Input::post('video_url_' . $video_id, ''), 'title' => \Input::post('video_title_' . $video_id, '')));
// Remove video ID as it is updated correctly
array_pop($not_updated);
// Delete image and use default one
if (\Input::post('video_delete_image_' . $video_id, false)) {
$item_videos[$video_id]['data']['thumbnail'] = '';
$this->delete_image(\Input::post('video_file_db_' . $video_id, ''), 'video');
}
} else {
\Messages::error('"' . \Input::post('video_url_' . $video_id, '') . '" is invalid video URL. Video not updated.');
}
} else {
\Messages::error('Video URL can\'t be empty. Video not updated.');
//.........这里部分代码省略.........