/**
  * @param \Bjr\BjrLend\Domain\Model\Article $article
  * @param $period
  * @return array|null|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
  *
  */
 public function checkPeriodForArticle(\Bjr\BjrLend\Domain\Model\Article $article, $period)
 {
     $querySettings = $this->createQuery()->getQuerySettings();
     $querySettings->setStoragePageIds(array($article->getPid()));
     $this->setDefaultQuerySettings($querySettings);
     $query = $this->createQuery();
     $constraints = array();
     foreach ($period as $date) {
         $tempConstraints = array();
         $tempConstraints[] = $query->equals('article', $article->getUid());
         $tempConstraints[] = $query->lessThanOrEqual('issueStart', $date);
         $tempConstraints[] = $query->greaterThanOrEqual('issueEnd', $date);
         $constraints[] = $query->logicalAnd($tempConstraints);
     }
     if (count($constraints) > 0) {
         $query->matching($query->logicalOr($constraints));
         $result = $query->execute();
     } else {
         $result = NULL;
     }
     return $result;
 }
 /**
  * Save an image with FAL
  * @param \TYPO3\CMS\Core\Resource\File $fileObject
  * @param \Bjr\BjrLend\Domain\Model\Article $article
  * @param $pid
  * @return int last insert id
  *
  */
 public function saveImage(\TYPO3\CMS\Core\Resource\File $fileObject, \Bjr\BjrLend\Domain\Model\Article $article)
 {
     //$dateiname = $filename; // Dateinamen auslesen
     $tabellenName = 'tx_bjrlend_domain_model_article';
     $feldName = 'image';
     $data = array('uid_local' => $fileObject->getUid(), 'uid_foreign' => $article->getUid(), 'tablenames' => $tabellenName, 'fieldname' => $feldName, 'pid' => $article->getPid(), 'table_local' => 'sys_file', 'tstamp' => time(), 'crdate' => time(), 'cruser_id' => 100);
     $where = 'deleted ="0" AND hidden ="0" AND tablenames ="' . $tabellenName . '" AND uid_foreign=' . (int) $article->getUid() . ' AND table_local="sys_file"' . ' AND fieldname ="' . $feldName . '"';
     $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'sys_file_reference', $where);
     if (empty($row)) {
         $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_file_reference', $data, FALSE);
         $res = $GLOBALS['TYPO3_DB']->sql_insert_id();
     } else {
         $data = array('uid_local' => $fileObject->getUid(), 'tstamp' => time(), 'cruser_id' => 100);
         $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_file_reference', $where, $data, FALSE);
     }
     return $res;
 }
 /**
  * @param \Bjr\BjrLend\Domain\Model\Article $article
  * @return \Bjr\BjrLend\Domain\Model\Organization
  */
 public function findByArticle(\Bjr\BjrLend\Domain\Model\Article $article)
 {
     $query = $this->createQuery();
     $organization = $query->matching($query->equals('articleFolderPid', $article->getPid()))->execute()->getFirst();
     return $organization;
 }