remove notnorm gen model

This commit is contained in:
Manuel Raynaud
2013-01-15 10:39:16 +01:00
parent 7e124c51e2
commit 8279cc37b4
72 changed files with 0 additions and 1235 deletions

View File

@@ -1,50 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Accessory extends Base
{
protected $product_id;
protected $accessory;
protected $position;
protected $properties = array(
"product_id",
"accessory",
"position"
);
public function getProductId()
{
return $this->product_id;
}
public function setProductId($product_id)
{
$this->product_id = $product_id;
}
public function getAccessory()
{
return $this->accessory;
}
public function setAccessory($accessory)
{
$this->accessory = $accessory;
}
public function getPosition()
{
return $this->position;
}
public function setPosition($position)
{
$this->position = $position;
}
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Address extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Admin extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class AdminGroup extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class AdminLog extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Area extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Attribute extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class AttributeAv extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class AttributeAvDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class AttributeCategory extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class AttributeCombination extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class AttributeDesc extends Base
{
}

View File

@@ -1,477 +0,0 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Model\Base;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
* Abstract class. All model classes inherit from this class
*
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
abstract class Base
{
/**
* Primary key
* @var int
*/
protected $id;
/**
*
* @var \NotORM
*/
protected $db;
/**
*
* @var Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
*
* Short name of the current class instance
*
* @var string
*/
protected $className;
/**
*
* @var string
*/
protected $table;
/**
*
* @var string date when the record had been updated
*/
protected $updated_at;
/**
*
* @var string date when the record had been saved
*/
protected $created_at;
/**
*
* base properties for all models
*
* @var array
*/
private $baseProperties = array(
"created_at",
"updated_at"
);
/**
*
* @param \NotORM $NotORM
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
*/
public function __construct(\NotORM $NotORM, ContainerInterface $container)
{
$this->db = $NotORM;
$this->className = $this->getShortClassName();
$this->table = $this->underscore($this->className);
$this->container = $container;
}
/**
*
* return the date and time when the record had been updated.
*
* @return \DateTime
*/
public function getUpdatedAt()
{
if ($this->updated_at) {
return new \DateTime($this->updated_at);
} else {
return null;
}
}
/**
*
* return the raw date time when the record had been updated
*
* @return string
*/
public function getRawUpadtedAt()
{
return $this->updated_at;
}
/**
*
* string date time when the record had been updated
*
* @param string $updated_at
*/
public function setUpdatedAt($updated_at)
{
$this->updated_at = $updated_at;
}
/**
*
* return the date and time when the record had been created.
*
* @return \DateTime
*/
public function getCreatedAt()
{
if ($this->created_at) {
return new \DateTime($this->created_at);
} else {
return null;
}
}
/**
*
* return the raw date time when the record had been created
*
* @return string
*/
public function getRawCreatedAt()
{
return $this->created_at;
}
/**
*
* string date time when the record had been updated
*
* @param string $created_at
*/
public function setCreatedAt($created_at)
{
$this->created_at = $created_at;
}
/**
*
* return the base properties like created_at, updated_at
*
* @return array
*/
private function getBaseProperties()
{
return $this->baseProperties;
}
/**
*
* return the public properties of the current model.
*
* @return array
*/
public function getProperties()
{
return $this->properties;
}
/**
*
* return the id of the current record
*
* @return type
*/
public function getId()
{
return $this->id;
}
/**
*
* fix the id if needed
*
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
*
* @return string Name of the current Table
*/
public function getTable()
{
return $this->table;
}
/**
*
* @return \NotORM
*/
public function getConnection()
{
return $this->db;
}
/**
*
* @return Symfony\Component\DependencyInjection\ContainerInterface
*/
public function getContainer()
{
return $this->container;
}
/**
*
* return the short name (without namespace) of the current instance class name.
*
* @return string
*/
public function getClassName()
{
return $this->className;
}
/**
* Persist data in current table
*
* Same method for saving or updating a record
*
*/
public function save()
{
if ($this->isNew()) {
$this->updated_at = $this->created_at = date('Y-m-d H:i:s');
} else {
$this->updated_at = date("Y-m-d H:i:s");
}
$values = $this->prepare();
$table = $this->getTable();
$this->getConnection()->$table()->insert_update(
array("id", $this->getId()),
$values,
$values
);
}
/**
*
* Find record by primary key
*
* @param int $pk
* @return Object
*/
public function find($pk)
{
$table = $this->getTable();
$result = $this->getConnection()->$table()->where("id", $pk);
return $this->parseOneQuery($result);
}
/**
*
* Find record for a specific column
*
* @param mixed $column column name
* @param mixed $search value searching
* @return array
* @throws \InvalidArgumentException column name cannot be empty
*/
public function findBy($column, $search)
{
if (empty($column)) {
throw new \InvalidArgumentException("Column name cannot be emtpy");
}
$table = $this->getTable();
$result = $this->getConnection()->$table()->where($column, $search);
return $this->parseQuery($result);
}
/**
*
* Find the first record for a specific column
*
* @param mixed $column column name
* @param mixed $search value searching
* @return Object
* @throws \InvalidArgumentException column name cannot be empty
*/
public function findOneBy($column, $search)
{
if (empty($column)) {
throw new \InvalidArgumentException("Column name cannot be emtpy");
}
$table = $this->getTable();
$result = $this->getConnection()->$table()->where($column, $search)->limit(1);
return $this->parseOneQuery($result);
}
/**
*
* delete the current record
*
* @return int
* @throws \RuntimeException
*/
public function delete()
{
if ($this->isNew()) {
throw new \RuntimeException("Cannot delete row. id is empty");
}
$table = $this->getTable();
return $this->getConnection()->$table()
->where("id", $this->getId())
->delete();
}
/**
*
* @param \NotORM_Result $results
* @return array
*/
private function parseQuery(\NotORM_Result $results)
{
$return = array();
$properties = array_merge($this->getBaseProperties(), $this->getProperties());
// @TODO : change hard code assignation
array_push($properties, "id");
foreach ($results as $result) {
//$class = new static($this->getConnection());
$class = $this->getContainer()->get("model.".$this->getClassName());
foreach ($properties as $property) {
call_user_func(array($class, "set".ucfirst(self::camelize($property))), $result[$property]);
}
array_push($return, $class);
}
return $return;
}
private function parseOneQuery(\NotORM_Result $results)
{
$return = $this->parseQuery($results);
return count($return) ? $return[0] : null ;
}
/**
*
* prepare an array for persisting data
*
* @return Array
*/
private function prepare()
{
$properties = array_merge($this->getBaseProperties(), $this->getProperties());
$values = array();
foreach ($properties as $property) {
$values[$property] = $this->$property;
}
return $values;
}
/**
*
* check if the current record is new or not.
*
* @return boolean
*/
public function isNew()
{
return $this->getId() ? false:true;
}
/**
*
* @return string name of the current table
*/
protected function getShortClassName()
{
$info = new \ReflectionObject($this);
return $info->getShortName();
}
/**
*
* extract from symfony 1.4
*
* change camelized wirnd into underscore word.
*
* ex : AttributeCategory => attribute_category
*
* @param string $camel_cased_word
* @return string
*/
protected function underscore($camel_cased_word)
{
$tmp = $camel_cased_word;
$tmp = str_replace('::', '/', $tmp);
$tmp = self::pregtr($tmp, array('/([A-Z]+)([A-Z][a-z])/' => '\\1_\\2',
'/([a-z\d])([A-Z])/' => '\\1_\\2'));
return strtolower($tmp);
}
/**
* Returns a camelized string from a lower case and underscored string by replaceing slash with
* double-colon and upper-casing each letter preceded by an underscore.
*
* @param string $lower_case_and_underscored_word String to camelize.
*
* @return string Camelized string.
*/
public static function camelize($lower_case_and_underscored_word)
{
$tmp = $lower_case_and_underscored_word;
$tmp = self::pregtr($tmp, array('#/(.?)#e' => "'::'.strtoupper('\\1')",'/(^|_|-)+(.)/e' => "strtoupper('\\2')"));
return $tmp;
}
public static function pregtr($search, $replacePairs)
{
return preg_replace(array_keys($replacePairs), array_values($replacePairs), $search);
}
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Category extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class CategoryDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Combination extends Base
{
}

View File

@@ -1,87 +0,0 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Config extends Base
{
protected $name;
protected $value;
protected $secure;
protected $hidden;
protected $properties = array(
"name",
"value",
"secure",
"hidden"
);
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
public function getValue()
{
return $this->value;
}
public function setValue($value)
{
$this->value = $value;
}
public function getSecure()
{
return $this->secure;
}
public function setSecure($secure)
{
$this->secure = $secure;
}
public function getHidden()
{
return $this->hidden;
}
public function setHidden($hidden)
{
$this->hidden = $hidden;
}
public function read($search, $default)
{
$result = $this->findOneBy("name",$search);
return $result ? $result->getValue() : $default;
}
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class ConfigDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Content extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class ContentAssoc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class ContentDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class ContentFolder extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Country extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class CountryDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Coupon extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class CouponOrder extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class CouponRule extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Currency extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Customer extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class CustomerTitle extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class CustomerTitleDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Delivzone extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Document extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class DocumentDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Feature extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class FeatureAv extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class FeatureAvDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class FeatureCategory extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class FeatureDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class FeatureProd extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Folder extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class FolderDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Group extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class GroupDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class GroupModule extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class GroupResource extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Image extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class ImageDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Lang extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Message extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class MessageDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Module extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class ModuleDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Order extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class OrderAddress extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class OrderFeature extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class OrderProduct extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class OrderStatus extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class OrderStatusDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Product extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class ProductCategory extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class ProductDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Resource extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class ResourceDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Rewriting extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Stock extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class Tax extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class TaxDesc extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class TaxQuery extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class TaxRule extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class TaxRuleCountry extends Base
{
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Base;
class TaxRuleDesc extends Base
{
}