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

Source for file FileMetaMapper.php

Documentation is available at FileMetaMapper.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 FileMeta 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_FileMeta $fileMeta{
  35.         $data array(
  36.             'fileType'          => $fileMeta->getFileType(),
  37.             'fileName'          => $fileMeta->getFileName(),
  38.             'filePath'          => $fileMeta->getFilePath(),
  39.             'fileSize'          => $fileMeta->getFileSize(),
  40.             'modificationDate'  => $fileMeta->getModificationDate(),
  41.             'creationDate'      => $fileMeta->getCreationDate(),
  42.             'keyWords'          => $fileMeta->getKeyWords(),
  43.             'lastUpdate'        => date('Y-m-d H:i:s')
  44.         );
  45.  
  46.         if (null === ($id $fileMeta->getId())) {
  47.             $this->getDbTable()->insert($data);
  48.         else {
  49.             $this->getDbTable()->update($dataarray('ID = ?' => $id));
  50.         }
  51.     }
  52.  
  53.     /**
  54.      * Finds an file meta in the persistant layer by its id an loads
  55.      * it in the given model object.
  56.      *
  57.      * @access public
  58.      * @param int $id 
  59.      * @param MediaSearch_Model_FileMeta $fileMeta 
  60.      */
  61.     public function find($idMediaSearch_Model_FileMeta $fileMeta{
  62.         $resultSet $this->getDbTable()->find($id);
  63.  
  64.         if (=== count($resultSet)) {
  65.             return;
  66.         }
  67.  
  68.         $row $resultSet->current();
  69.         $fileMeta->setId($row->ID);
  70.         $this->createModel($row$fileMeta);
  71.     }
  72.  
  73.     /**
  74.      * Sets up a given model object with the data in the row array.
  75.      *
  76.      * @todo setOptions benutzen.
  77.      *
  78.      * @access protected
  79.      * @param array $row 
  80.      * @param MediaSearch_Model_FileMeta $fileMeta 
  81.      */
  82.     protected function createModel($rowMediaSearch_Model_Abstract $model{
  83.         $model->setFileType($row->fileType)
  84.               ->setFileName($row->fileName)
  85.               ->setFilePath($row->filePath)
  86.               ->setFileSize($row->fileSize)
  87.               ->setModificationDate($row->modificationDate)
  88.               ->setCreationDate($row->creationDate)
  89.               ->setKeyWords($row->keyWords)
  90.               ->setLastUpdate($row->lastUpdate)
  91.               ->setMapper($this);
  92.     }
  93.  
  94.     /**
  95.      * Creates model objectes from multiple rows.
  96.      *
  97.      * @access protected
  98.      * @param array $resultSet 
  99.      * @return array 
  100.      */
  101.     protected function createModelFromRowSet(array $resultSet{
  102.         $entries array();
  103.  
  104.         foreach ($resultSet as $row{
  105.             $fileMeta new MediaSearch_Model_FileMeta();
  106.             $fileMeta->setId($row['ID']);
  107.             $this->createModel($row$fileMeta);
  108.             $entries[$fileMeta;
  109.         }
  110.  
  111.         return $entries;
  112.     }
  113.  
  114.     /**
  115.      * Finds data by id. You can optionaly provide type ids.
  116.      *
  117.      * @access public
  118.      * @param array $primaryKeys 
  119.      * @param array $types 
  120.      * @return array 
  121.      */
  122.     public function findByIdAndTypes(array $primaryKeysarray $types null{
  123.         $select new Zend_Db_Table_Select($this->getDbTable());
  124.  
  125.         foreach ($primaryKeys as $id{
  126.             $select->orWhere('ID = ?'$id);
  127.         }
  128.  
  129.         if (null !== $types{
  130.             foreach ($types as $type{
  131.                 $select->orWhere('fileType = ?'$type);
  132.             }
  133.         }
  134.  
  135.         $statement $select->query();
  136.         $resultSet $statement->fetchAll();
  137.  
  138.         if (=== count($resultSet)) {
  139.             return;
  140.         }
  141.  
  142.         return $this->createModelFromRowSet($resultSet);
  143.     }
  144. }

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