Skip to content

Commit

Permalink
product images, done for now
Browse files Browse the repository at this point in the history
  • Loading branch information
nclundsten committed Apr 11, 2012
1 parent f09f3e3 commit aeb64cf
Show file tree
Hide file tree
Showing 24 changed files with 193 additions and 106 deletions.
8 changes: 5 additions & 3 deletions Module.php
Expand Up @@ -26,12 +26,14 @@ public function init(Manager $moduleManager)
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
//'Zend\Loader\ClassMapAutoloader' => array(
// __DIR__ . '/autoload_classmap.php',
//),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
'CatalogManager' => __DIR__ . '/src/CatalogManager',
'Catalog' => __DIR__ . '/src/Catalog',
),
),
);
Expand Down
70 changes: 1 addition & 69 deletions autoload_classmap.php
@@ -1,70 +1,2 @@
<?php
return array(

'Catalog\Controller\CatalogController' => __DIR__ . '/src/Catalog/Controller/CatalogController.php',
'CatalogManager\Controller\CatalogManagerController'
=> __DIR__ . '/src/CatalogManager/Controller/CatalogManagerController.php',
'Catalog\Controller\ErrorController' => __DIR__ . '/src/Catalog/Controller/ErrorController.php',
'Catalog\Module' => __DIR__ . '/Module.php',

/**
* Services
*/
'Catalog\Service\ServiceInterface' => __DIR__ . '/src/Catalog/Service/ServiceInterface.php',
'Catalog\Service\ServiceAbstract' => __DIR__ . '/src/Catalog/Service/ServiceAbstract.php',
'Catalog\Service\ProductService' => __DIR__ . '/src/Catalog/Service/ProductService.php',
'Catalog\Service\OptionService' => __DIR__ . '/src/Catalog/Service/OptionService.php',
'Catalog\Service\ChoiceService' => __DIR__ . '/src/Catalog/Service/ChoiceService.php',
'Catalog\Service\ProductUomService' => __DIR__ . '/src/Catalog/Service/ProductUomService.php',
'Catalog\Service\UomService' => __DIR__ . '/src/Catalog/Service/UomService.php',
'Catalog\Service\AvailabilityService' => __DIR__ . '/src/Catalog/Service/AvailabilityService.php',
'Catalog\Service\CompanyService' => __DIR__ . '/src/Catalog/Service/CompanyService.php',
'Catalog\Service\CategoryService' => __DIR__ . '/src/Catalog/Service/CategoryService.php',
'Catalog\Service\SpecService' => __DIR__ . '/src/Catalog/Service/SpecService.php',
'Catalog\Service\MediaServiceInterface' => __DIR__ . '/src/Catalog/Service/MediaServiceInterface.php',
'Catalog\Service\MediaServiceAbstract' => __DIR__ . '/src/Catalog/Service/MediaServiceAbstract.php',
'Catalog\Service\DocumentService' => __DIR__ . '/src/Catalog/Service/DocumentService.php',
'Catalog\Service\ImageService' => __DIR__ . '/src/Catalog/Service/ImageService.php',
'Catalog\Service\CatalogService' => __DIR__ . '/src/Catalog/Service/CatalogService.php',
'Catalog\Service\Installer' => __DIR__ . '/src/Catalog/Service/Installer.php',

'CatalogManager\Service\ModelLinkerService' => __DIR__ . '/src/CatalogManager/Service/ModelLinkerService.php',

/**
* Mappers
*/
'Catalog\Model\Mapper\ModelMapperInterface' => __DIR__ . '/src/Catalog/Model/Mapper/ModelMapperInterface.php',
'Catalog\Model\Mapper\DbMapperAbstract' => __DIR__ . '/src/Catalog/Model/Mapper/DbMapperAbstract.php',
'Catalog\Model\Mapper\ProductMapper' => __DIR__ . '/src/Catalog/Model/Mapper/ProductMapper.php',
'Catalog\Model\Mapper\OptionMapper' => __DIR__ . '/src/Catalog/Model/Mapper/OptionMapper.php',
'Catalog\Model\Mapper\ChoiceMapper' => __DIR__ . '/src/Catalog/Model/Mapper/ChoiceMapper.php',
'Catalog\Model\Mapper\ProductUomMapper' => __DIR__ . '/src/Catalog/Model/Mapper/ProductUomMapper.php',
'Catalog\Model\Mapper\UomMapper' => __DIR__ . '/src/Catalog/Model/Mapper/UomMapper.php',
'Catalog\Model\Mapper\AvailabilityMapper' => __DIR__ . '/src/Catalog/Model/Mapper/AvailabilityMapper.php',
'Catalog\Model\Mapper\CompanyMapper' => __DIR__ . '/src/Catalog/Model/Mapper/CompanyMapper.php',
'Catalog\Model\Mapper\CategoryMapper' => __DIR__ . '/src/Catalog/Model/Mapper/CategoryMapper.php',
'Catalog\Model\Mapper\SpecMapper' => __DIR__ . '/src/Catalog/Model/Mapper/SpecMapper.php',
'Catalog\Model\Mapper\MediaMapperAbstract' => __DIR__ . '/src/Catalog/Model/Mapper/MediaMapperAbstract.php',
'Catalog\Model\Mapper\DocumentMapper' => __DIR__ . '/src/Catalog/Model/Mapper/DocumentMapper.php',
'Catalog\Model\Mapper\MYSQL_CatalogMapper' => __DIR__ . '/src/Catalog/Model/Mapper/MYSQL_CatalogMapper.php',

/**
* Models
*/
'Catalog\Model\ModelInterface' => __DIR__ . '/src/Catalog/Model/ModelInterface.php',
'Catalog\Model\ModelAbstract' => __DIR__ . '/src/Catalog/Model/ModelAbstract.php',
'Catalog\Model\Product' => __DIR__ . '/src/Catalog/Model/Product.php',
'Catalog\Model\Option' => __DIR__ . '/src/Catalog/Model/Option.php',
'Catalog\Model\OptionSlider' => __DIR__ . '/src/Catalog/Model/OptionSlider.php',
'Catalog\Model\Choice' => __DIR__ . '/src/Catalog/Model/Choice.php',
'Catalog\Model\Category' => __DIR__ . '/src/Catalog/Model/Category.php',
'Catalog\Model\ProductUom' => __DIR__ . '/src/Catalog/Model/ProductUom.php',
'Catalog\Model\Uom' => __DIR__ . '/src/Catalog/Model/Uom.php',
'Catalog\Model\Availability' => __DIR__ . '/src/Catalog/Model/Availability.php',
'Catalog\Model\Company' => __DIR__ . '/src/Catalog/Model/Company.php',
'Catalog\Model\Spec' => __DIR__ . '/src/Catalog/Model/Spec.php',
'Catalog\Model\MediaAbstract' => __DIR__ . '/src/Catalog/Model/MediaAbstract.php',
'Catalog\Model\Document' => __DIR__ . '/src/Catalog/Model/Document.php',
'Catalog\Model\Image' => __DIR__ . '/src/Catalog/Model/Image.php',

);
return array();
7 changes: 7 additions & 0 deletions config/module.config.php
Expand Up @@ -221,6 +221,13 @@
),
),

'Catalog\Model\Mapper\ImageMapper' => array(
'parameters' => array(
'readAdapter' => 'catalog_read_db',
'writeAdapter' => 'catalog_write_db',
),
),

'Catalog\Model\Mapper\SpecMapper' => array(
'parameters' => array(
'readAdapter' => 'catalog_read_db',
Expand Down
4 changes: 2 additions & 2 deletions src/Catalog/Model/Mapper/AvailabilityMapper.php
Expand Up @@ -5,7 +5,7 @@
use Catalog\Model\Availability,
ArrayObject;

class AvailabilityMapper extends DbMapperAbstract
class AvailabilityMapper extends ModelMapperAbstract
{
protected $tableName = 'catalog_availability';

Expand All @@ -24,7 +24,7 @@ public function getByParentProductUomId($productUomId)
$rows = $db->fetchAll($sql);

$availabilities = array();
if(count($rows) > 0 ){
if (count($rows) > 0){
foreach($rows as $row){
$availabilities[] = $this->mapModel($row);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Catalog/Model/Mapper/CategoryMapper.php
Expand Up @@ -4,7 +4,7 @@
use Catalog\Model\Category,
ArrayObject;

class CategoryMapper extends DbMapperAbstract
class CategoryMapper extends ModelMapperAbstract
{
protected $tableName = 'catalog_category';

Expand Down
2 changes: 1 addition & 1 deletion src/Catalog/Model/Mapper/ChoiceMapper.php
Expand Up @@ -4,7 +4,7 @@
use Catalog\Model\Choice,
ArrayObject;

class ChoiceMapper extends DbMapperAbstract
class ChoiceMapper extends ModelMapperAbstract
{
protected $tableName = 'catalog_choice';

Expand Down
2 changes: 1 addition & 1 deletion src/Catalog/Model/Mapper/CompanyMapper.php
Expand Up @@ -5,7 +5,7 @@
use Catalog\Model\Company,
ArrayObject;

class CompanyMapper extends DbMapperAbstract
class CompanyMapper extends ModelMapperAbstract
{
protected $tableName = 'catalog_company';

Expand Down
59 changes: 59 additions & 0 deletions src/Catalog/Model/Mapper/ImageMapper.php
@@ -0,0 +1,59 @@
<?php
namespace Catalog\Model\Mapper;
use Catalog\Model\Image,
ArrayObject;
class ImageMapper extends MediaMapperAbstract
{
protected $linkerTableName = 'catalog_product_image_linker';

public function getModel()
{
return new Image;
}

public function getModelClass()
{
return 'media';
}

public function getImagesByProductId($productId)
{
$db = $this->getReadAdapter();
$sql = $db->select()
->from($this->getLinkerTableName())
->join(
$this->getTableName(),
$this->getLinkerTableName().'.media_id = '.$this->getTableName().'.media_id'
)
->where('product_id = ?', $productId);
$this->events()->trigger(__FUNCTION__, $this, array('query' => $sql));
$rows = $db->fetchAll($sql);

$specs = array();
if (count($rows) > 0){
foreach($rows as $row){
$specs[] = $this->mapModel($row);
}
}
return $specs;
}

public function linkParentProduct($productId, $imageId)
{
$db = $this->getReadAdapter();
$sql = $db->select()
->from($this->getLinkerTableName())
->where('product_id = ?', $productId)
->where('media_id = ?', $imageId);
$this->events()->trigger(__FUNCTION__, $this, array('query' => $sql));
$row = $db->fetchRow($sql);
if(false === $row){
$data = new ArrayObject(array(
'product_id' => $productId,
'media_id' => $imageId,
));
$db->insert($this->getLinkerTableName(), (array) $data);
}
}
}

2 changes: 1 addition & 1 deletion src/Catalog/Model/Mapper/MediaMapperAbstract.php
@@ -1,7 +1,7 @@
<?php
namespace Catalog\Model\Mapper;
use ArrayObject;
abstract class MediaMapperAbstract extends DbMapperAbstract
abstract class MediaMapperAbstract extends ModelMapperAbstract
{
protected $tableName = 'catalog_media';

Expand Down
@@ -1,7 +1,7 @@
<?php

namespace Catalog\Model\Mapper;
use ZfcBase\Mapper\DbMapperAbstract as ZfcDbMapperAbstract,
use ZfcBase\Mapper\DbMapperAbstract,
ArrayObject,
Exception;

Expand All @@ -10,7 +10,7 @@
*
* @uses ZfcDbMapperAbstract
*/
abstract class DbMapperAbstract extends ZfcDbMapperAbstract implements ModelMapperInterface
abstract class ModelMapperAbstract extends DbMapperAbstract implements ModelMapperInterface
{

/**
Expand Down Expand Up @@ -224,16 +224,6 @@ public function persist($model, $mode = 'insert')
return $model;
}

/**
* fromCamelCase
*
* takes a camelCase model property name and returns a underscore_separated database column name
*
* @param mixed $name
* @static
* @access public
* @return void
*/
public function fromCamelCase($name)
{
return trim(preg_replace_callback('/([A-Z])/', function($c){ return '_'.strtolower($c[1]); }, $name),'_');
Expand Down
7 changes: 0 additions & 7 deletions src/Catalog/Model/Mapper/ModelMapperInterface.php
Expand Up @@ -60,12 +60,5 @@ public function getModelsBySearchData($string);
*/
public function persist($model, $mode);

/**
* fromCamelCase
*
* used to change camelcase attributes and turn them into underscore separated table field names
*/
public function fromCamelCase($name);

public function getIdField();
}
2 changes: 1 addition & 1 deletion src/Catalog/Model/Mapper/OptionMapper.php
Expand Up @@ -4,7 +4,7 @@
use Catalog\Model\Option,
ArrayObject;

class OptionMapper extends DbMapperAbstract
class OptionMapper extends ModelMapperAbstract
{
protected $tableName = 'catalog_option';
protected $productLinkerTableName = 'catalog_product_option_linker';
Expand Down
2 changes: 1 addition & 1 deletion src/Catalog/Model/Mapper/ProductMapper.php
Expand Up @@ -5,7 +5,7 @@
use Catalog\Model\Product,
ArrayObject;

class ProductMapper extends DbMapperAbstract
class ProductMapper extends ModelMapperAbstract
{
protected $tableName = 'catalog_product';

Expand Down
2 changes: 1 addition & 1 deletion src/Catalog/Model/Mapper/ProductUomMapper.php
Expand Up @@ -5,7 +5,7 @@
use Catalog\Model\ProductUom,
ArrayObject;

class ProductUomMapper extends DbMapperAbstract
class ProductUomMapper extends ModelMapperAbstract
{
protected $tableName = 'catalog_product_uom';

Expand Down
2 changes: 1 addition & 1 deletion src/Catalog/Model/Mapper/SpecMapper.php
@@ -1,7 +1,7 @@
<?php
namespace Catalog\Model\Mapper;
use Catalog\Model\Spec;
class SpecMapper extends DbMapperAbstract
class SpecMapper extends ModelMapperAbstract
{
protected $tableName = 'catalog_product_spec';

Expand Down
2 changes: 1 addition & 1 deletion src/Catalog/Model/Mapper/UomMapper.php
Expand Up @@ -5,7 +5,7 @@
use Catalog\Model\Uom,
ArrayObject;

class UomMapper extends DbMapperAbstract
class UomMapper extends ModelMapperAbstract
{
protected $tableName = 'ansi_uom';

Expand Down
19 changes: 19 additions & 0 deletions src/Catalog/Model/Product.php
Expand Up @@ -13,6 +13,7 @@ class Product extends ModelAbstract
protected $parentChoices;
protected $specs;
protected $documents;
protected $images;

//item view
protected $manufacturer;
Expand Down Expand Up @@ -253,4 +254,22 @@ public function setDocuments($documents)
$this->documents = $documents;
return $this;
}

public function hasImages()
{
if($this->getImages()){
return true;
}
}

public function getImages()
{
return $this->images;
}

public function setImages($images)
{
$this->images = $images;
return $this;
}
}
1 change: 0 additions & 1 deletion src/Catalog/Service/CatalogService.php
Expand Up @@ -12,7 +12,6 @@ class CatalogService
protected $choiceService;
protected $categoryService;
protected $specService;

protected $imageService;
protected $documentService;

Expand Down
13 changes: 13 additions & 0 deletions src/Catalog/Service/ProductService.php
Expand Up @@ -9,6 +9,7 @@ class ProductService extends ServiceAbstract
protected $companyService;
protected $specService;
protected $documentService;
protected $imageService;

public function populateModel($product){
if($product){
Expand All @@ -18,6 +19,7 @@ public function populateModel($product){
$product->setCompanies($this->getCompanyService()->getAll());
$product->setSpecs($this->getSpecService()->getByProductId($productId));
$product->setDocuments($this->getDocumentService()->getDocumentsByProductId($productId));
$product->setImages($this->getImageService()->getImagesByProductId($productId));
return $product;
}
}
Expand Down Expand Up @@ -85,4 +87,15 @@ public function setDocumentService($documentService)
$this->documentService = $documentService;
return $this;
}

public function getImageService()
{
return $this->imageService;
}

public function setImageService($imageService)
{
$this->imageService = $imageService;
return $this;
}
}

0 comments on commit aeb64cf

Please sign in to comment.