Welcome Guest, Not a member yet? Register   Sign In
Multilanguage model
#1

(This post was last modified: 08-07-2017, 05:14 AM by phpforever2017.)

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




Theme © iAndrew 2016 - Forum software by © MyBB