/** * Print X products in tip * @return void * @param string flag (column) which has to be set to TRUE * @param integer number of products */ public function block_flag($flag, $num) { // Creating instance of model and fetching data $products = new Product_Model(); $data = $products->get_flag($flag, $num); // View $template = new View('block_flag'); $template->data = $data; $template->render(TRUE); }
public function editValidate($data = array()) { $getProduct = $this->getId('', $data['name']); //check product exists if ($getProduct) { if (!empty($data['id'])) { // Case : Edit User if ($getProduct['id'] != $data['id']) { self::$error['name'] = 'ProductName already exists !Please enter a different ProductName!'; } } else { // Case : Add User self::$error['name'] = 'ProductName already exists !Please enter a different ProductName!'; } } $dataValidate = array('name' => $data['name'], 'price' => $data['price']); $this->validate->dataValidate($dataValidate); //Merge 2 error array self::$error = array_merge($this->validate->getError(), self::$error); if (!$this->validate->fileValidate()) { self::$error['file'] = "File must have ( gif , jpeg , jpg , png ) type"; } if (isset(self::$error['name']) || isset(self::$error['price']) || isset(self::$error['file'])) { if (!empty(self::$error['name']) || !empty(self::$error['price']) || !empty(self::$error['file'])) { return false; } } return true; }
public function add() { $argumentarray = Router::$arguments; //$id = $argumentarray[0]; $products = new Product_Model(); $id = $products->getNextID(); if (isset($_POST['save'])) { $post = new Validation(array_merge($_POST, $_FILES)); $post->pre_filter('trim', 'productName', 'productSize', 'productDescription', 'productImage'); $post->add_rules('productName', 'required'); $post->add_rules('productDescription', 'required'); if (!$post->validate()) { $errors = $post->errors('form_errors'); foreach ($errors as $error) { echo '<p class="error">' . $error . '</p>'; } } else { //$id = $argumentarray[0]; $products = new Product_Model(); $product = ORM::factory('product'); $product->name = $post->productName; $product->size = $post->productSize; $product->description = $post->productDescription; $product->image = $post->productImage; if (!empty($_FILES['image']['name'])) { // uses Kohana upload helper $_FILES = Validation::factory($_FILES)->add_rules('image', 'upload::valid', 'upload::type[gif,jpg,jpeg,png]', 'upload::size[2M]'); if ($_FILES->validate()) { // Temporary file name $filename = upload::save('image', basename($_FILES['image']['tmp_name'])); $file = basename($_FILES['image']['name']); // Resize, sharpen, and save the image Image::factory($filename)->save(DOCROOT . '../../env/product_images/' . $file); // Remove the temporary file unlink($filename); $product->image = $file; } else { $errors = $_FILES->errors('form_user'); } } $product->save(); url::redirect('/products/edit/' . $product->id); } } $this->_renderView(); }
public function index() { $db = new Database(); // clean up old orders that are a week or older and are 'Pending' $dat = time(); $lastweek = $dat - 604800; $result = $db->query('DELETE FROM orders WHERE date_modified < ' . $lastweek . ' AND statusID = 1'); // In Kohana, all views are loaded and treated as objects. $this->template->content = new View('homepage'); $this->template->metaDescription = $this->description; $this->template->metaKeywords = $this->keywords; $this->template->metaTitle = $this->title; // getOccasions and getOccasion($id) is a method defined in Occasion_Model $occasions = new Occasion_Model(); $this->template->content->occasionresults = $occasions->getOccasions(); // getProducts is a method defined in Product_Model $products = new Product_Model(); $this->template->content->productresults = $products->getHomepageProducts(); // getLatestTestimonial is a method defined in Testimonial_Model $testimonial = new Testimonial_Model(); $this->template->content->testimonialresult = $testimonial->getLatestTestimonial(); // get the most recently created hearts of each product type $result = $db->query('SELECT orders.id, orders.can_share, orders_baskets.id, orders_baskets.product_id, orders_baskets.designpath, orders_baskets.msg_text1, orders_baskets.msg_text2, fc.name FROM orders INNER JOIN orders_baskets ON orders.id = orders_baskets.order_id LEFT JOIN foil_colors fc ON fc.id = orders_baskets.foil_id WHERE orders.can_share = 1 AND orders_baskets.designpath != "" AND orders_baskets.img_approved = 1 AND orders.statusID IN (2,4,5) AND orders.site_id = ' . My_Template_Controller::getCurrentSite()->id . ' ORDER BY order_date DESC LIMIT 4'); $recentForward = array(); $recentBack = array(); $i = 0; foreach ($result as $recent) { if ($i < 10) { $recentForward[$i] = $recent; } else { $recentBack[$i - 10] = $recent; } $i++; } $this->template->content->recentHearts = $recentForward; $this->template->content->recentHeartsBack = $recentBack; //$result = $db->query('SELECT orders.id, orders.can_share, orders_baskets.id, orders_baskets.product_id, orders_baskets.designpath FROM orders INNER JOIN orders_baskets ON orders.id = orders_baskets.order_id WHERE orders.can_share = 1 AND orders_baskets.designpath != "" AND orders_baskets.img_approved = 1 AND orders.statusID IN (2,4,5) ORDER BY order_date ASC LIMIT 10'); // You can assign anything variable to a view by using standard OOP // methods. In my welcome view, the $title variable will be assigned // the value I give it here. $this->template->title = $this->title; $result = $db->query("SELECT * FROM slides WHERE site_id = '" . My_Template_Controller::getCurrentSite()->id . "'"); $this->template->content->slides = $result; }
public function index() { // In Kohana, all views are loaded and treated as objects. $this->template->content = new View('testimonials'); $this->template->metaDescription = $this->description; $this->template->metaKeywords = $this->keywords; $this->template->metaTitle = $this->title; // You can assign anything variable to a view by using standard OOP // methods. In my welcome view, the $title variable will be assigned // the value I give it here. $this->template->title = $this->title; $db = new Database(); $resultall = $db->query('SELECT t.* ' . 'FROM testimonials t ' . 'INNER JOIN sites_testimonials st ON t.id = st.testimonial_id ' . 'WHERE st.site_id = ' . self::getCurrentSite()->id . ' ORDER BY t.id DESC'); $this->template->content->testimonialresults = $resultall; // getProducts is a method defined in Product_Model $products = new Product_Model(); $this->template->content->productresults = $products->getProductsForSite(TRUE); // getOccasions and getOccasion($id) is a method defined in Occasion_Model $occasions = new Occasion_Model(); $this->template->content->occasionresults = $occasions->getOccasions(); $this->template->content->message = ""; }
public function show() { // In Kohana, all views are loaded and treated as objects. $this->template->content = new View('occasions'); $occasionarray = Router::$arguments; $occasionname = $occasionarray[0]; // getOccasions and getOccasion($id) is a method defined in Occasion_Model $occasions = new Occasion_Model(); $this->template->content->occasionresults = $occasions->getOccasions(); $occasion = $occasions->getOccasionByName($occasionname); $this->template->content->occasion = $occasion; $this->template->metaDescription = $occasion->meta_description; $this->template->metaKeywords = $occasion->meta_keywords; $this->template->metaTitle = $occasion->meta_title; // You can assign anything variable to a view by using standard OOP // methods. In my welcome view, the $title variable will be assigned // the value I give it here. $this->template->title = $occasion->meta_title; // getProducts is a method defined in Product_Model $products = new Product_Model(); $this->template->content->productresults = $products->getProductsForSite(TRUE); }
public function getModel() { $Model = new Product_Model(); return $Model->findItem(array('Id = ' . $this->Model)); }
/** * The function returns current product Models. * * @access public * @return array The product Models. */ public function getModels() { $Model = new Product_Model(); return $Model->findList(array('ProductId = ' . $this->Id), 'Position asc'); }
// Automatically calculates the editor base path based on the _samples directory. // This is usefull only for these samples. A real application should use something like this: // oFCKeditor.BasePath = '/fckeditor/' ; // '/fckeditor/' is the default value. var sBasePath = '<?php echo url::base(); ?> /media/js/fckeditor/'; } </script> <?php //$id = $this->uri->segment(3); $argumentarray = Router::$arguments; $products = new Product_Model(); $production_times = new Production_Time_Model(); $product_colors = new Product_Color_Model(); $product_flavors = new Product_Flavor_Model(); $product_costs = new Product_Cost_Model(); if (isset($argumentarray[0])) { $id = $argumentarray[0]; $product = $products->getProductByID($id); } else { $id = $products->getNextID(); $product = ORM::factory('product'); } $i = 0; $j = 0; $times = $production_times->getProductionTimes(); $productcolors = $product_colors->getColorsForProduct($id);