Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Autoría | Ultima modificación | Ver Log |

<?php
declare(strict_types=1);

namespace LeadersLinked\Mapper;

use LeadersLinked\Mapper\Common\MapperCommon;
use Laminas\Db\Adapter\AdapterInterface;
use LeadersLinked\Model\MyCoachCategory;
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
use LeadersLinked\Model\MyCoachCategoryJobDescription;


class MyCoachCategoryJobDescriptionMapper extends MapperCommon
{
    const _TABLE = 'tbl_my_coach_category_jobs_description';

    /**
     *
     * @var MyCoachCategoryJobDescriptionMapper
     */
    private static $_instance;
    
    /**
     *
     * @param AdapterInterface $adapter
     */
    private function __construct($adapter)
    {
        parent::__construct($adapter);
    }
    
    /**
     *
     * @param AdapterInterface $adapter
     * @return MyCoachCategoryJobDescriptionMapper
     */
    public static function getInstance($adapter)
    {
        if(self::$_instance == null) {
            self::$_instance = new MyCoachCategoryJobDescriptionMapper($adapter);
        }
        return self::$_instance;
    }
    
    /**
     * 
     * @param array $job_description_ids
     * @return MyCoachCategoryJobDescription[]
     */
    public function fetchAllByJobDescriptionIds($job_description_ids)
    {
        $select = $this->sql->select(self::_TABLE);
        $select->where->in('job_description_id', $job_description_ids);
        
        //echo $select->getSqlString($this->adapter->platform);
        
        $prototype = new MyCoachCategoryJobDescription();
        return $this->executeFetchAllObject($select, $prototype);
    }
    
    /**
     * 
     * @param int $category_id
     * @param int $job_description_id
     * @return MyCoachCategoryJobDescription
     */
    public function fetchOneByCategoryIdAndJobDescriptionId($category_id, $job_description_id)
    {
        
        $select = $this->sql->select(self::_TABLE);
        $select->where->equalTo('category_id', $category_id);
        $select->where->equalTo('job_description_id', $job_description_id);
        
        //echo $select->getSqlString($this->adapter->platform);
        
        $prototype = new MyCoachCategoryJobDescription();
        return $this->executeFetchOneObject($select, $prototype);
    }
    
    /**
     *
     * @param int $company_id
     * @param array $job_description_ids
     * @return MyCoachCategoryJobDescription[]
     */
    public function fetchAllByCompanyIdAndJobDescriptionIds($company_id, $job_description_ids)
    {
        
        $select = $this->sql->select(self::_TABLE);
        $select->where->equalTo('company_id', $company_id);
        $select->where->in('job_description_id', $job_description_ids);
        
        
        $prototype = new MyCoachCategoryJobDescription();
        return $this->executeFetchAllObject($select, $prototype);
    }
    
    
    /**
     *
     * @param
     * @return MyCoachCategoryJobDescription[]
     */
    public function fetchAllByJobDescriptionId($job_description_id)
    {
        
        $select = $this->sql->select(self::_TABLE);
        $select->where->equalTo('job_description_id', $job_description_id);
        
        
        $prototype = new MyCoachCategoryJobDescription();
        return $this->executeFetchAllObject($select, $prototype);
    }
    
    
    
    
    /**
     *
     * @param 
     * @return MyCoachCategoryJobDescription[]
     */
    public function fetchAllByCategoryId($category_id)
    {
        
        $select = $this->sql->select(self::_TABLE);
        $select->where->equalTo('category_id', $category_id);

        
        $prototype = new MyCoachCategoryJobDescription();
        return $this->executeFetchAllObject($select, $prototype);
    }
    
    /**
     *
     * @param int $category_id
     * @return boolean
     */
    public function deleteAllByCategoryId($category_id)
    {
        $delete = $this->sql->delete(self::_TABLE);
        $delete->where->equalTo('category_id', $category_id);
        
        return $this->executeDelete($delete);
    }
    
    /**
     *
     * @param int $category_id
     * @param int $job_description_id
     * @return boolean
     */
    public function  deleteOneByCategoryIdAndUserId($category_id, $job_description_id)
    {
        $delete = $this->sql->delete(self::_TABLE);
        $delete->where->equalTo('category_id', $category_id);
        $delete->where->equalTo('job_description_id', $job_description_id);
        
        return $this->executeDelete($delete);
    }
    
    
    /**
     *
     * @param int $id
     * @return boolean
     */
    public function  delete($id)
    {
        
        $delete = $this->sql->delete(self::_TABLE);
        $delete->where->equalTo('id', $id);
        
        return $this->executeDelete($delete);
    }
    
    /**
     *
     * @param MyCoachCategory $record
     * @return boolean
     */
    public function insert($record) {
        $hydrator = new ObjectPropertyHydrator();
        $values = $hydrator->extract($record);
        $values = $this->removeEmpty($values);
        
        $insert = $this->sql->insert(self::_TABLE);
        $insert->values($values);
        $result = $this->executeInsert($insert);
        if($result) {
            $record->id = $this->lastInsertId;
        }
        
       return $result;
    }
    
    
    
    /**
     *
     * @param MyCoachCategory $record
     * @return boolean
     */
    public function update($record) 
    {
        $hydrator = new ObjectPropertyHydrator();
        $values = $hydrator->extract($record);
        $values = $this->removeEmpty($values);
        
        $update = $this->sql->update(self::_TABLE);
        $update->set($values);
        $update->where->equalTo('id', $record->id);
        
        
        return $this->executeUpdate($update);
    }
}