コード例 #1
0
ファイル: dmProjectLoremizer.php プロジェクト: theolymp/diem
 public function executeModuleRecursive(dmModule $module, dmTableLoremizer $loremizer)
 {
     $loremizer->execute($module->getTable());
     foreach ($module->getChildren() as $child) {
         $this->executeModuleRecursive($child, $loremizer);
     }
 }
コード例 #2
0
ファイル: dmUnitTestHelper.php プロジェクト: theolymp/diem
 public function clearModule(dmModule $module)
 {
     try {
         $module->getTable()->createQuery()->delete()->execute();
     } catch (Exception $e) {
         $t->diag(sprintf('Can not delete %s records : %s', $module, $e->getMessage()));
     }
     foreach ($module->getTable()->getRelationHolder()->getAssociations() as $alias => $association) {
         $association['refTable']->createQuery()->delete()->execute();
     }
 }
コード例 #3
0
ファイル: dmPageSynchronizer.php プロジェクト: rafix/diem
 protected function updateModuleShowPagesRecursive(dmModule $module)
 {
     $moduleKey = $module->getKey();
     if (!$module->hasPage()) {
         foreach ($module->getChildren() as $child) {
             $this->updateModuleShowPagesRecursive($child);
         }
         return;
     }
     /*
      * prepares pages to update
      */
     $_showPages = dmDb::pdo('SELECT p.id, p.module, p.record_id, p.lft, p.rgt FROM dm_page p WHERE p.module = ? AND p.action = ?', array($moduleKey, 'show'))->fetchAll(PDO::FETCH_ASSOC);
     $showPages = array();
     foreach ($_showPages as $_showPage) {
         $showPages[$_showPage['record_id']] = $_showPage;
     }
     if ($module->hasListPage()) {
         $parentModule = $module;
         /*
          * prepare records
          */
         // http://github.com/diem-project/diem/issues#issue/182
         if (count($module->getTable()->getOption('inheritanceMap'))) {
             $records = $module->getTable()->createQuery('r')->select('r.id')->fetchArray();
         } else {
             $records = dmDb::pdo('SELECT r.id FROM ' . $module->getTable()->getTableName() . ' r')->fetchAll(PDO::FETCH_ASSOC);
         }
         /*
          * prepare parent pages
          */
         $parentPageIds = dmDb::pdo('SELECT p.id FROM dm_page p WHERE p.module = ? AND p.action = ?', array($moduleKey, 'list'))->fetch(PDO::FETCH_NUM);
         $parentPageIds = $parentPageIds[0];
         if (!$parentPageIds) {
             throw new dmException(sprintf('%s needs a parent page, %s.%s, but it does not exists', $module, $moduleKey, 'list'));
         }
         $parentRecordIds = false;
     } else {
         if (!($parentModule = $module->getNearestAncestorWithPage())) {
             throw new dmException(sprintf('%s module is child of %s module, but %s module has no ancestor with page', $module, $parentModule, $module));
         }
         /*
          * prepare records
          */
         $select = 'r.id';
         if ($module->hasLocal($module->getParent())) {
             $select .= ', r.' . $module->getTable()->getRelationHolder()->getLocalByClass($module->getParent()->getModel())->getLocal();
         }
         // http://github.com/diem-project/diem/issues#issue/182
         if (count($module->getTable()->getOption('inheritanceMap'))) {
             $records = $module->getTable()->createQuery('r')->select($select)->fetchArray();
         } else {
             $records = dmDb::pdo('SELECT ' . $select . ' FROM ' . $module->getTable()->getTableName() . ' r')->fetchAll(PDO::FETCH_ASSOC);
         }
         /*
          * prepare parent pages
          */
         $_parentPageIds = dmDb::pdo('SELECT p.id, p.record_id FROM dm_page p WHERE p.module = ? AND p.action = ?', array($parentModule->getKey(), 'show'))->fetchAll(PDO::FETCH_NUM);
         $parentPageIds = array();
         foreach ($_parentPageIds as $value) {
             $parentPageIds[$value[1]] = $value[0];
         }
         $parentRecordIds = $this->getParentRecordIds($module, $parentModule);
     }
     foreach ($records as $record) {
         if (isset($showPages[$record['id']])) {
             $page = $showPages[$record['id']];
         } else {
             $page = array('id' => null, 'record_id' => $record['id'], 'module' => $moduleKey, 'action' => 'show');
         }
         try {
             $this->updatePageFromRecord($page, $record, $module, $parentModule, $parentPageIds, $parentRecordIds);
         } catch (dmPageMustNotExistException $e) {
             if ($page['id']) {
                 dmDb::table('DmPage')->find($page['id'])->getNode()->delete();
             }
         }
     }
     foreach ($module->getChildren() as $child) {
         $this->updateModuleShowPagesRecursive($child);
     }
 }
コード例 #4
0
 public function __construct(dmModule $module, sfEventDispatcher $dispatcher)
 {
     $this->module = $module;
     $this->dispatcher = $dispatcher;
     $this->table = $module->getTable();
 }
コード例 #5
0
ファイル: dmContentChart.php プロジェクト: theolymp/diem
 protected function getNbRecordsForModuleAndWeekDelta(dmModule $module, $weekDelta)
 {
     return $module->getTable()->createQuery('r')->where('r.created_at > ?', date('Y-m-d H:i:s', strtotime($weekDelta + 1 . ' week ago')))->andWhere('r.created_at <= ?', date('Y-m-d H:i:s', strtotime($weekDelta . ' week ago')))->count();
 }
コード例 #6
0
 protected function getSortReferersQuery(dmModule $refererModule)
 {
     return $refererModule->getTable()->createQuery('r')->whereIsActive(true, $refererModule->getModel())->orderBy('r.position asc');
 }