• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multilanguage model

#1
Hi guys!
The question of multilanguage model. I have the entity Page, PageDescription and models
PHP Code:
class PageModel extends CI_Model {
 
   
    protected $tableEntity 
'pages';
 
   
    protected $returnType 
'Page\Entity\Page';
 
   
    public 
function findAll()
 
   {
 
       $this->db->select('*')->from($this->tableEntity);
 
       
        $query 
$this->db->get();
 
       
        return $query
->custom_result_object($this->returnType);
 
   }
 
      
    public 
function fillDescription(array $pages = array(), $language_id 0)
 
   {
 
       $this->load->model('page/pagedescriptionmodel');
 
       
        return $this
->pagedescriptionmodel->findAllDescriptions($pages$language_id);
 
   }


And entity
PHP Code:
class Page extends Entity {
 
   use DateTimeTrait;
 
   use TranslationTrait;
 
   /**
     * @var int
     */
 
   protected $page_id;

 
   /**
     * @var int
     */
 
   protected $category_id;

 
   /**
     * @var int
     */
 
   protected $layout_id;

 
   /**
     * @var int
     */
 
   protected $sort_order;

 
   /**
     * @var string
     */
 
   protected $page_url;

 
   /**
     * @var string
     */
 
   protected $image;
 
   
    
/**
     * @var array
     */
 
   protected $descriptions = array();

PHP Code:
class PageDescription extends Entity {
 
   use MetaDataTrait;
 
   /**
     * @var int
     */
 
   protected $page_id;
 
   /**
     * @var int
     */
 
   protected $language_id;

 
   /**
     * @var string
     */
 
   protected $shot_description;

 
   /**
     * @var string
     */
 
   protected $description;

 
   /**
     * @var string
     */
 
   protected $publish_content;

 
   /**
     * @var string
     */
 
   protected $author;

 
   /**
     * @var int
     */
 
   protected $active;

Users can search pages for different fields from databases. Only there is an idea to make another abstract class SearchModel with the method
PHP Code:
   public function findByCriteria(array $criteria = array())
 
   {
 
       $this->db->select($this->fields)->from($this->table);
 
       $this->db->join($this->tableDescription$this->table '.' $this->joinField ' = ' $this->tableDescription '.' $this->joinField'left');
 
       
foreach ($criteria as $fieldEntity)
        {
if(
method_exists('condition'.$fieldEntity->name)) {
call method from subclass
}
        }
 
       
        $this
->db->group_by($this->table '.' $this->joinField);
 
       
        $orderFields 
$this->validateAndGetFieldForOrder($this->getOrderFields());
 
       
        foreach 
($orderFields as $fieldName => $fieldDirection)
 
       {
 
           $this->db->order_by($fieldName$fieldDirection);
 
       }
 
       
        $this
->db->limit($this->getLimit(), $this->getStart());
 
       
        $query 
$this->db->get();

 
       if ($this->returnType)
 
       {
 
           return $query->custom_result_object($this->returnType);
 
       }
 
       else
        
{
 
           return $query->result();
 
       }
 
   
How else can this problem be solved? Sorry for my English
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.