/** * Registers a user * * @param array $data * @return boolean */ public function register(array $data) { // Create a hash $data['password_hash'] = $this->getHash($data['password']); // Remove unnecessary keys $data = ArrayUtils::arrayWithout($data, array('captcha', 'passwordConfirm', 'password')); // Now insert the new record safely return $this->userMapper->persist($data); }
/** * Fetches as a list * * @return array */ public function fetchList() { return ArrayUtils::arrayList($this->categoryMapper->fetchList(), 'id', 'name'); }
/** * Updates a category * * @param array $input Raw input data * @return boolean Depending on success */ public function update(array $input) { $input = $this->prepareInput($input); $category =& $input['category']; $this->webPageManager->update($category['web_page_id'], $category['slug']); // If at least one menu widget it added if ($this->hasMenuWidget() && isset($input['menu'])) { $this->updateMenuItem($category['web_page_id'], $category['name'], $input['menu']); } // Track it $this->track('Category "%s" has been updated', $category['name']); return $this->categoryMapper->update(ArrayUtils::arrayWithout($category, array('slug', 'menu'))); }
/** * Prepare raw input data before sending to a mapper * * @param array $data * @return void */ private function prepareInput(array $input) { $input['timestamp_asked'] = strtotime($input['date_asked']); $input['timestamp_answered'] = strtotime($input['date_answered']); return ArrayUtils::arrayWithout($input, array('date_asked', 'date_answered')); }
/** * Makes an order * * @param array $input Raw input data * @return boolean */ public function make(array $input) { $defaults = array('approved' => '0', 'qty' => $this->basketManager->getTotalQuantity(), 'total_price' => $this->basketManager->getTotalPrice()); $data = array_merge($input, $defaults); $data['date'] = date('Y-m-d', time()); // First of all, insert, because we need to obtain a last id $this->orderInfoMapper->insert(ArrayUtils::arrayWithout($data, array('captcha'))); // Now obtain last id $id = $this->orderInfoMapper->getLastId(); $products = $this->basketManager->getProducts(); if ($this->addProducts($id, $products)) { // Order is saved. Now clear the basket $this->basketManager->clear(); $this->basketManager->save(); return true; } else { return false; } }
/** * Updates a post * * @param array $input Raw input data * @return boolean Depending on success */ public function update(array $input) { $form = $this->prepareInput($input); $post =& $form['data']['post']; // Allow to remove a cover, only it case it exists and checkbox was checked if (isset($post['remove_cover']) && !empty($post['cover'])) { // Remove a cover, but not a dir itself $this->imageManager->delete($post['id'], $post['cover']); $post['cover'] = ''; } else { // Do the check only in case cover doesn't need to be removed if (!empty($form['files'])) { // If we have a previous cover, then we gotta remove it if (!empty($post['cover'])) { // Remove previous one $this->imageManager->delete($post['id'], $post['cover']); } $file = $form['files']['file']; // Before we start uploading a file, we need to filter its base name $this->filterFileInput($file); $this->imageManager->upload($post['id'], $file); // Now override cover's value with file's base name we currently have from user's input $post['cover'] = $file[0]->getName(); } } // Update a record itself now $this->postMapper->update(ArrayUtils::arrayWithout($post, array('date', 'slug', 'remove_cover'))); // Update a slug $this->webPageManager->update($post['web_page_id'], $post['slug']); // And finally now just track it $this->track('Post "%s" has been updated', $post['name']); return true; }
/** * Updates an item * * @param array $input Raw input data * @return boolean */ public function update(array $input) { $this->track('The "%s" item has been updated', $input['name']); return $this->itemMapper->update(ArrayUtils::arrayWithout($input, array('max_depth'))); }
/** * Updates a form * * @param array $input Raw input data * @return boolean */ public function update(array $input) { $input = $this->prepareInput($input); $form = $input['form']; if ($this->formMapper->update(ArrayUtils::arrayWithout($form, array('slug', 'menu')))) { $this->webPageManager->update($form['web_page_id'], $form['slug']); if ($this->hasMenuWidget() && isset($input['menu'])) { $this->updateMenuItem($form['web_page_id'], $form['name'], $input['menu']); } $this->track('Mail form "%s" has been updated', $form['name']); return true; } else { return false; } }
/** * Updates a category * * @param array $input Raw input data * @return boolean */ public function update(array $input) { $input = $this->prepareInput($input); $category =& $input['data']['category']; // Allow to remove a cover, only it case it exists and checkbox was checked if (isset($category['remove_cover'])) { // Remove a cover, but not a dir itself $this->imageManager->delete($category['id']); $category['cover'] = ''; } else { if (!empty($input['files']['file'])) { $file =& $input['files']['file']; // If we have a previous cover's image, then we need to remove it if (!empty($category['cover'])) { if (!$this->imageManager->delete($category['id'], $category['cover'])) { // If failed, then exit this method immediately return false; } } // And now upload a new one $this->filterFileInput($file); $category['cover'] = $file[0]->getName(); $this->imageManager->upload($category['id'], $file); } } $this->webPageManager->update($category['web_page_id'], $category['slug']); if ($this->hasMenuWidget() && isset($input['menu'])) { $this->updateMenuItem($category['web_page_id'], $category['name'], $input['menu']); } $this->track('Category "%s" has been updated', $category['name']); return $this->categoryMapper->update(ArrayUtils::arrayWithout($category, array('menu', 'slug', 'remove_cover'))); }
/** * Updates a stoke * * @param array $input Raw input data * @return boolean */ public function update(array $input) { return $this->stokeMapper->update(ArrayUtils::arrayWithout($input, array('slug'))); }
/** * Updates a post * * @param array $input Raw input data * @return boolean */ public function update(array $input) { $input = $this->prepareInput($input); $this->webPageManager->update($input['web_page_id'], $input['slug']); $this->track('Post "%s" has been updated', $input['name']); return $this->postMapper->update(ArrayUtils::arrayWithout($input, array('date', 'slug'))); }
/** * Sends data from a user * * @param array $input Raw input data * @param boolean $enableModeration Whether a review should be moderated or not * @return boolean */ public function send(array $input, $enableModeration) { // Always current timestamp $input['timestamp'] = time(); // This value depends on configuration, where we handled moderation if ($enableModeration) { $input['published'] = '0'; } else { $input['published'] = '1'; } return $this->reviewsMapper->insert(ArrayUtils::arrayWithout($input, array('captcha'))); }
/** * Adds a category * * @param array $input Raw input data * @return boolean */ public function add(array $input) { $input = $this->prepareInput($input); $category =& $input['data']['category']; // Cover is always empty by default $category['cover'] = ''; // If we have a cover, then we need to upload it if (!empty($input['files']['file'])) { $file =& $input['files']['file']; // Now filter original file's name $this->filterFileInput($file); // Override empty cover's value now $category['cover'] = $file[0]->getName(); } $category['web_page_id'] = ''; if ($this->categoryMapper->insert(ArrayUtils::arrayWithout($category, array('slug', 'menu')))) { $id = $this->getLastId(); // If we have a cover, then we need to upload it if (!empty($input['files']['file'])) { $this->imageManager->upload($id, $input['files']['file']); } $this->track('Added category "%s"', $category['name']); if ($this->webPageManager->add($id, $category['slug'], 'Shop (Categories)', 'Shop:Category@indexAction', $this->categoryMapper)) { // Do the work in case menu widget was injected if ($this->hasMenuWidget()) { $this->addMenuItem($this->webPageManager->getLastId(), $category['name'], $input['data']); } } return true; } }
/** * Updates a product * * @param array $input Raw input data * @return boolean */ public function update(array $input) { $input = $this->prepareInput($input); // Product data $product =& $input['data']['product']; // Current product id we're dealing with $productId = $product['id']; // An array of new appended images from a user $appendedImages = $input['files']['file']; if (!empty($input['files'])) { // Array of changed images, representing an id => FileBag instance $changedImages = $this->getChangedImages($input['files']); // Do we have any changed image? if (!empty($changedImages)) { foreach ($changedImages as $imageId => $fileBag) { // First of all we need to remove old image if ($this->imageManager->delete($productId, $this->imageMapper->fetchFileNameById($imageId))) { $this->filterFileInput($fileBag); $this->imageManager->upload($productId, $fileBag); $this->imageMapper->updateFileNameById($imageId, $fileBag[0]->getName()); } } // PHP hasn't block scope, so we have to remove it manually unset($fileBag); } } // New user appended images if (!empty($appendedImages)) { // Upload all appended files firstly if ($this->imageManager->upload($productId, $appendedImages)) { // Then save them foreach ($appendedImages as $fileBag) { $this->imageMapper->insert($productId, $fileBag->getName(), 1, 1); } } } $photos =& $input['data']['photos']; // Do we have images to delete? if (isset($photos['toDelete'])) { // Grab photo ids we're gonna remove $ids = array_keys($photos['toDelete']); foreach ($ids as $imageId) { // Try to remove on file-system first if ($this->imageManager->delete($productId, $this->imageMapper->fetchFileNameById($imageId))) { // If successful, then remove from a storage as well $this->imageMapper->deleteById($imageId); } } } if (isset($photos['published'])) { // Update photos published state foreach ($photos['published'] as $id => $published) { $this->imageMapper->updatePublishedById($id, $published); } } if (isset($photos['order'])) { // Update photos order foreach ($photos['order'] as $id => $order) { $this->imageMapper->updateOrderById($id, $order); } } // Update a cover now if (isset($photos['cover'])) { $product['cover'] = $photos['cover']; } $this->track('Product "%s" has been updated', $product['name']); $this->webPageManager->update($product['web_page_id'], $product['slug']); return $this->productMapper->update(ArrayUtils::arrayWithout($product, array('slug'))); }
/** * Adds a contact * * @param array $input Raw input data * @return boolean */ public function add(array $input) { $this->track('Contact "%s" has been added', $input['name']); return $this->contactMapper->insert(ArrayUtils::arrayWithout($input, array('makeDefault'))); }
/** * Updates a page * * @param array $input Raw input data * @return boolean */ public function update(array $input) { $input = $this->prepareInput($input); $page =& $input['page']; $this->webPageManager->update($page['web_page_id'], $page['slug'], $page['controller']); if ($this->hasMenuWidget() && isset($input['menu'])) { $this->updateMenuItem($page['web_page_id'], $page['name'], $input['menu']); } $this->track('The page "%s" has been updated', $page['name']); return $this->pageMapper->update(ArrayUtils::arrayWithout($page, array('controller', 'makeDefault', 'slug', 'menu'))); }