public function findAll($params = array()) { $polls = parent::findAll($params); if(!$polls) return false; foreach ($polls as $key => $value) { $s = $this->connection->find("SELECT * FROM polls_responses WHERE polls_id = ".$polls[$key]['id']." "); $polls[$key]['responses'] = $s; } return $polls; }
/** * Recover a corrupted tree * * The mode parameter is used to specify the source of info that is valid/correct. The opposite source of data * will be populated based upon that source of info. E.g. if the MPTT fields are corrupt or empty, with the $mode * 'parent' the values of the parent_id field will be used to populate the left and right fields. * * @since 1.2 * @TODO Could be written to be faster, *maybe*. Ideally using a subquery and putting all the logic burden on the DB. * @param AppModel $model * @param string $mode parent or tree * @return boolean True on success, false on failure * @access public */ function recover(&$model, $mode = 'parent') { extract($this->settings[$model->name]); $model->recursive = -1; if ($mode == 'parent') { $count = 1; foreach ($model->findAll($scope, array($model->primaryKey)) as $Array) { $model->{$model->primaryKey} = $Array[$model->name][$model->primaryKey]; $lft = $count++; $rght = $count++; $model->save(array($left => $lft, $right => $rght)); } foreach ($model->findAll($scope, array($model->primaryKey, $parent)) as $Array) { $model->create(); $model->id = $Array[$model->name][$model->primaryKey]; $this->_set_parent($model, $Array[$model->name][$parent], true); } } else { foreach ($model->findAll($scope, array($model->primaryKey, $parent)) as $Array) { $path = $this->get_path($model, $Array[$model->name][$model->primaryKey]); if ($path == null || count($path) < 2) { $parent_id = null; } else { $parent_id = $path[count($path) - 2][$model->name][$model->primaryKey]; } // Sidestep beforeSave $model->updateAll(array($parent => $parent_id), array($model->primaryKey => $Array[$model->name][$model->primaryKey])); } } }