protected function getParentRecordIds(dmProjectModule $module, dmProjectModule $parentModule) { /* * if parent is local relation for module, * we can prepare parent records */ if ($module->hasLocal($parentModule)) { $local = $module->getTable()->getRelationHolder()->getLocalByClass($parentModule->getModel())->getLocal(); $query = sprintf('SELECT r.id, r.%s FROM %s r WHERE EXISTS (SELECT page.id FROM dm_page page WHERE page.module = ? AND page.action = ? AND page.record_id = r.%s)', $local, $module->getTable()->getTableName(), $local); $_parentRecordIds = dmDb::pdo($query, array($parentModule->getKey(), 'show'))->fetchAll(PDO::FETCH_NUM); $parentRecordIds = array(); foreach ($_parentRecordIds as $_parentRecordId) { $parentRecordIds[$_parentRecordId[0]] = $_parentRecordId[1]; } } elseif ($module->hasAssociation($parentModule)) { $association = $module->getTable()->getRelationHolder()->getAssociationByClass($parentModule->getModel()); $query = sprintf('SELECT association.%s, association.%s FROM %s association WHERE EXISTS (SELECT page.id FROM dm_page page WHERE page.module = ? AND page.action = ? AND page.record_id = association.%s) GROUP BY association.%s', $association->getForeign(), $association->getLocal(), $association->getAssociationTable()->getTableName(), $association->getForeign(), $association->getLocal()); $_parentRecordIds = dmDb::pdo($query, array($parentModule->getKey(), 'show'))->fetchAll(PDO::FETCH_NUM); $parentRecordIds = array(); foreach ($_parentRecordIds as $value) { $parentRecordIds[$value[1]] = $value[0]; } } else { $parentRecordIds = false; } return $parentRecordIds; }
public function validatePattern(dmProjectModule $module, $field, $pattern, dmDoctrineRecord $record = null) { $record = null === $record ? $module->getTable()->findOne() : $record; try { $this->getReplacementsForPatterns($module, array($pattern), $record); } catch (Exception $e) { if (sfConfig::get('dm_debug')) { throw $e; } return false; } return true; }
protected function checkEachRecordHasShowPage(dmProjectModule $module, lime_test $t) { $moduleKey = $module->getKey(); $model = $module->getModel(); if ($ancestorModule = $module->getFarthestAncestor()) { $ancestorModel = $ancestorModule->getModel(); } else { $ancestorModel = null; } $errors = array(); /* * Verify that each record -that must have a page- has one */ foreach ($module->getTable()->findAll() as $record) { $page = $record->getDmPage(); $error = null; if (!$ancestorModel) { if (!$page) { $error = sprintf('%s %s has no page', $model, $record); } } else { if ($ancestorRecord = $record->getAncestorRecord($ancestorModel)) { if (!$page) { $error = sprintf('%s %s has no page', $model, $record); } } else { if ($page) { $error = sprintf('%s %s has a page, but no ancestor', $model, $record); } } } if ($error) { $t->diag($error); $errors[] = $error; continue; } if (!$page) { continue; } if ($page->record_id != $record->id) { $error = sprintf('%s page has bad record : %s', $page, $record); $t->diag($error); $errors[] = $error; } $parentPage = $page->getNode()->getParent(); if ($parentModule = $module->getNearestAncestorWithPage()) { if ($parentPage->module != $parentModule->getKey()) { $error = sprintf('parent page has bad module : %s', $parentPage->module); $t->diag($error); $errors[] = $error; } if ($parentPage->action != 'show') { $error = sprintf('parent page has bad action : %s', $parentPage->action); $t->diag($error); $errors[] = $error; } } else { if ($parentPage->module != $module->getKey()) { $error = sprintf('parent page has bad module : %s', $parentPage->module); $t->diag($error); $errors[] = $error; } if ($parentPage->action != 'list') { $error = sprintf('parent page has bad action : %s', $parentPage->action); $t->diag($error); $errors[] = $error; } } } return $errors; }