コード例 #1
0
 public function renderDefault()
 {
     $this->template->categories_count = mapper::categories()->countAll();
     $this->template->manufacturers_count = mapper::manufacturers()->countAll();
     $this->template->pages_count = mapper::pages()->countNotRef();
     $this->template->products_count = mapper::products()->countAll();
     $this->template->pictures_count = mapper::pictures()->countAll();
     $this->template->orders_count = mapper::orders()->countAll();
     $this->template->orders_initial_count = mapper::orders()->countWithInitialStatus();
 }
コード例 #2
0
 public function onNewPictureSubmit(Form $form)
 {
     if (!$form->isValid()) {
         return;
     }
     $file = $form['file']->getValue();
     // save thumbnail
     try {
         $image = $file->getImage();
     } catch (Exception $e) {
         $form->addError(__('Uploaded file has to be an image.'));
         return;
     }
     if ($image->getWidth() > $image->getHeight()) {
         $image->resize(NULL, 60);
     } else {
         $image->resize(60, NULL);
     }
     $image->crop(intval(($image->getWidth() - 60) / 2), intval(($image->getHeight() - 60) / 2), 60, 60);
     $thumbnail_filename = sha1(microtime()) . '.png';
     $image->save(Environment::expand('%mediaDir%/' . $thumbnail_filename));
     unset($image);
     // save big picture
     $big_filename = String::webalize($form['rename']->getValue());
     $need_resave = TRUE;
     if (empty($big_filename)) {
         $big_filename = $file->getName();
     }
     if (($pos = strrpos($big_filename, '.')) !== FALSE) {
         $ext = substr($big_filename, $pos);
         $before_ext = substr($big_filename, 0, $pos);
         if (strtolower($ext) !== '.png') {
             $big_filename = $before_ext . '.png';
         } else {
             $need_resave = FALSE;
         }
     } else {
         $big_filename .= '.png';
     }
     if ($need_resave) {
         $image = $file->getImage();
         $image->save(Environment::expand('%mediaDir%/' . $big_filename));
     } else {
         $file->move(Environment::expand('%mediaDir%/' . $big_filename));
     }
     $image = $file->getImage();
     $image->resize(300, 300, Image::ENLARGE);
     $image->save(Environment::expand('%mediaDir%/' . $big_filename));
     // save to db
     if (!mapper::pictures()->insertOne($big_filename, $thumbnail_filename, $form['description']->getValue())) {
         $form->addError(__('Cannot save image data into the database, try again.'));
     } else {
         adminlog::log(__('Added picture "%s"'), $big_filename);
         $this->redirect('pictures');
         $this->terminate();
     }
 }