Пример #1
0
 /**
  * @return MediaCollection
  */
 public function getAdditionalMedia()
 {
     $collection = new MediaCollection();
     $collection->addFilter(new Ajde_Filter_Join('node_media', 'node_media.media', 'media.id'));
     $collection->addFilter(new Ajde_Filter_Join('node', 'node.id', 'node_media.node'));
     $collection->addFilter(new Ajde_Filter_Where('node_media.node', Ajde_Filter::FILTER_EQUALS, $this->getPK()));
     $collection->orderBy('node_media.sort');
     return $collection;
 }
Пример #2
0
 private function _unused()
 {
     $used = new MediaCollection();
     $unused = new MediaCollection();
     $unused->addFilter(new Ajde_Filter_Where('id', Ajde_Filter::FILTER_EQUALS, '-9999'));
     $db = Ajde_Db::getInstance()->getConnection();
     /** @var MediaModel $media */
     foreach ($used as $media) {
         $stmt = $db->query('SELECT id FROM node WHERE media = ' . $media->getPK());
         $stmt->execute();
         $node = $stmt->rowCount();
         $stmt = $db->query('SELECT id FROM node_media WHERE media = ' . $media->getPK());
         $stmt->execute();
         $nodeMedia = $stmt->rowCount();
         $meta = 0;
         $stmt = $db->query('SELECT * FROM node_meta INNER JOIN meta ON meta.id = node_meta.meta AND node_meta.`value` <> \'\' AND meta.type = \'media\' AND node_meta.`value` = ' . $media->getPK());
         $stmt->execute();
         $meta += $stmt->rowCount();
         $stmt = $db->query('SELECT * FROM setting_meta INNER JOIN meta ON meta.id = setting_meta.meta AND setting_meta.`value` <> \'\' AND meta.type = \'media\' AND setting_meta.`value` = ' . $media->getPK());
         $stmt->execute();
         $meta += $stmt->rowCount();
         if ($node == 0 && $nodeMedia == 0 && $meta == 0) {
             $unused->add($media);
         }
     }
     return $unused;
 }