MediaSearch_Model
[ class tree: MediaSearch_Model ] [ index: MediaSearch_Model ] [ all elements ]

Source for file KeyWordMapper.php

Documentation is available at KeyWordMapper.php

  1. <?php
  2. /**
  3.  * MediaSearch
  4.  *
  5.  * LICENSE
  6.  *
  7.  * "THE BEER-WARE LICENSE" (Revision 42):
  8.  * "Sven Strittmatter" <ausserirdisch@sven-space.de> wrote this file.
  9.  * As long as you retain this notice you can do whatever you want with
  10.  * this stuff. If we meet some day, and you think this stuff is worth it,
  11.  * you can buy me a beer in return.
  12.  *
  13.  * $Author$
  14.  * $Revision$
  15.  *
  16.  * @category    MediaSearch
  17.  * @package     MediaSearch_Model
  18.  * @copyright   Copyright (c) 2009 Sven Strittmatter
  19.  */
  20.  
  21. /**
  22.  * Maps the KeyWord model object to the database table object.
  23.  *
  24.  * @category   MediaSearch
  25.  * @package    MediaSearch_Model
  26.  * @copyright  Copyright (c) 2009 Sven Strittmatter
  27.  */
  28.     /**
  29.      * Saves the given model object persistent.
  30.      *
  31.      * @access public
  32.      * @param MediaSearch_Model_FileMeta $fileMeta 
  33.      */
  34.    public function save(MediaSearch_Model_KeyWord $keyWord{
  35.         $data array(
  36.             'keyWord'     => $keyWord->getKeyWord(),
  37.             'FileMetaIds' => $keyWord->getFileMetaIds()
  38.         );
  39.  
  40.         if (null === ($id $keyWord->getId())) {
  41.             $this->getDbTable()->insert($data);
  42.         else {
  43.             $this->getDbTable()->update($dataarray('ID = ?' => $id));
  44.         }
  45.     }
  46.  
  47.     /**
  48.      * Finds an keyword in the persistant layer by its id an loads
  49.      * it in the given model object.
  50.      *
  51.      * @access public
  52.      * @param int $id 
  53.      * @param MediaSearch_Model_FileMeta $fileMeta 
  54.      */
  55.     public function find($idMediaSearch_Model_KeyWord $keyWord{
  56.         $resultSet $this->getDbTable()->find($id);
  57.  
  58.         if (== count($resultSet)) {
  59.             return;
  60.         }
  61.  
  62.         $row $resultSet->current();
  63.         $keyWord->setId($row->ID);
  64.         $this->createModel($row$keyWord);
  65.     }
  66.  
  67.     /**
  68.      * Sets up a given model object with the data in the row array.
  69.      *
  70.      * @todo setOptions benutzen.
  71.      *
  72.      * @access protected
  73.      * @param array $row 
  74.      * @param MediaSearch_Model_FileMeta $fileMeta 
  75.      */
  76.     protected function createModel($rowMediaSearch_Model_Abstract $model{
  77.         $model->setKeyWord($row->keyWord)
  78.               ->setFileMetaIds($row->FileMetaIds)
  79.               ->setMapper($this);
  80.     }
  81.  
  82.     /**
  83.      * Creates model objectes from multiple rows.
  84.      *
  85.      * @access protected
  86.      * @param array $resultSet 
  87.      * @return array 
  88.      */
  89.     protected function createModelFromRowSet(array $resultSet{
  90.         $entries array();
  91.  
  92.         foreach ($resultSet as $row{
  93.             $keyWord new MediaSearch_Model_KeyWord();
  94.             $keyWord->setId($row['ID']);
  95.             $this->createModel($row$keyWord);
  96.             $entries[$keyWord;
  97.         }
  98.  
  99.         return $entries;
  100.     }
  101.  
  102.     /**
  103.      * Finds key words by keywords given in the array.
  104.      *
  105.      * @access public
  106.      * @param array $keywords 
  107.      * @return array 
  108.      */
  109.     public function findByKeyWords(array $keywords{
  110.         $resultSet $this->getDbTable()->findByKeyWords($keywords);
  111.  
  112.         if (=== count($resultSet)) {
  113.             return;
  114.         }
  115.  
  116.         $keyWords array();
  117.  
  118.         foreach ($resultSet as $row{
  119.             $keyWords[new MediaSearch_Model_KeyWord(array(
  120.                 'keyWord' => $row['keyWord'],
  121.                 'fileMetaIds' => explode(','$row['FileMetaIds'])
  122.             ));
  123.         }
  124.  
  125.         return $keyWords;
  126.     }
  127. }

Documentation generated on Mon, 17 Aug 2009 14:53:25 +0200 by phpDocumentor 1.4.2