/** * Get additional content data selected * * @param $result = Query result */ public static function post_find($result) { if ($result !== null) { if (is_array($result)) { foreach ($result as $item) { // It will first check if we already have result in temporary result, // and only execute query if we dont. That way we dont have duplicate queries // Get content images $item->get_images = static::lazy_load(function () use($item) { return Model_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'images'); // Get content files $item->get_files = static::lazy_load(function () use($item) { return Model_File::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'files'); // Get content videos $item->get_videos = static::lazy_load(function () use($item) { return Model_Video::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'videos'); // Get content children $item->get_children = static::lazy_load(function () use($item) { return Model_Casestudy::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'children'); // Get content accordions $item->get_accordions = static::lazy_load(function () use($item) { return Model_Accordion::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'accordions'); // Get content children $item->get_seo = static::lazy_load(function () use($item) { return Model_Seo::find_one_by_content_id($item->id); }, $item->id, 'seo', 'object'); // Get related products $item->get_related_products = static::lazy_load(function () use($item) { $related = Model_Application_To_Related::find(function ($query) use($item) { return $query->where('application_id', $item->id); }, 'related_id'); if (!empty($related)) { $related = '(' . implode(',', array_keys($related)) . ')'; return \Product\Model_Product::find(function ($query) use($related, $item) { $query->where('id', 'IN', \DB::expr($related)); $query->where('id', '<>', $item->id); $query->order_by('sort', 'asc'); return $query; }, 'id'); } return array(); }, $item->id, 'related_products'); // Get hotspot images $item->get_hotspot = static::lazy_load(function () use($item) { $return = new \stdClass(); $return->images = Model_Application_Image::find_by_application_id($item->id); return $return; }, $item->id, 'hotspot', 'object'); } } } // return the result return $result; }
public function action_create() { \View::set_global('title', 'Add New'); if (\Input::post()) { $val = Model_Team::validate('create'); // Upload image and display errors if there are any $image = $this->upload_image(); if (!$image['exists'] && \Config::get('details.image.required', false) && empty($item->image)) { // No previous images and image is not selected and it is required \Messages::error('<strong>There was an error while trying to upload member image</strong>'); \Messages::error('You have to select image'); } elseif ($image['errors']) { \Messages::error('<strong>There was an error while trying to upload member image</strong>'); foreach ($image['errors'] as $error) { \Messages::error($error); } } if ($val->run() && $image['is_valid'] && !(!$image['exists'] && \Config::get('details.image.required', false))) { // Get POST values $insert = \Input::post(); // Prepare some values $insert['published_at'] = !empty($insert['published_at']) ? strtotime($insert['published_at']) : \Date::forge()->get_timestamp(); $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 = Model_Team::forge($insert); try { $item->save(); // Validate and insert team slug into SEO database table $val_seo = Model_Seo::validate('create_seo'); $insert_seo = array('content_id' => $item->id, 'slug' => \Inflector::friendly_title($item->name, '-', true)); while (!$val_seo->run($insert_seo)) { $insert_seo['slug'] = \Str::increment($insert_seo['slug'], 1, '-'); } $item_seo = Model_Seo::forge($insert_seo); $item_seo->save(); // END OF: SEO // Insert team images if ($this->_image_data) { $item_image = array(array('id' => 0, 'data' => array('content_id' => $item->id, 'image' => $this->_image_data[0]['saved_as'], 'alt_text' => \Input::post('alt_text', ''), 'cover' => 1, 'sort' => 1))); Model_Team::bind_images($item_image); } \Messages::success('Member successfully created.'); \Response::redirect(\Input::post('update', false) ? \Uri::create('admin/team/update/' . $item->id) : \Uri::admin('current')); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to create member</strong>'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); } } else { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to create member</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } // Delete uploaded image if there is team saving error if (isset($this->_image_data)) { $this->delete_image($this->_image_data[0]['saved_as']); } } \Theme::instance()->set_partial('content', $this->view_dir . 'create'); }
/** * Get additional content data selected * * @param $result = Query result */ public static function post_find($result) { if ($result !== null) { if (is_array($result)) { foreach ($result as $item) { // It will first check if we already have result in temporary result, // and only execute query if we dont. That way we dont have duplicate queries // Get content images $item->get_images = static::lazy_load(function () use($item) { return Model_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'images'); // Get content files $item->get_files = static::lazy_load(function () use($item) { return Model_File::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'files'); // Get content videos $item->get_videos = static::lazy_load(function () use($item) { return Model_Video::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'videos'); // Get content children $item->get_children = static::lazy_load(function () use($item) { return Model_Team::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'children'); // Get content accordions $item->get_accordions = static::lazy_load(function () use($item) { return Model_Accordion::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'accordions'); // Get content children $item->get_seo = static::lazy_load(function () use($item) { return Model_Seo::find_one_by_content_id($item->id); }, $item->id, 'seo', 'object'); } } } // return the result return $result; }
/** * Update application SEO options * * @param $id = Application ID */ public function action_update_seo($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 Meta Content'); if (\Input::post()) { $val = Model_Seo::validate('update', $item->id); // Get POST values $insert = \Input::post(); if ($val->run($insert)) { // Update SEO database table $item_seo = Model_Seo::find_one_by_content_id($item->id); $item_seo->set($insert); try { $item_seo->save(); \Messages::success('Meta content successfully updated.'); \Response::redirect(\Uri::admin('current')); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to update meta content</strong>'); // Uncomment lines below to show database errors //$errors = $e->getMessage(); //\Messages::error($errors); } } else { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to update meta content</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } } \Theme::instance()->set_partial('content', $this->view_dir . 'update_seo')->set('application', Model_Application::find_one_by_id($id)); }