public function save($memberId) { $values = $this->getValues(); foreach ($values as $key => $value) { $profile = Doctrine::getTable('Profile')->retrieveByName($key); if (!$profile) { continue; } $memberProfile = Doctrine::getTable('MemberProfile')->retrieveByMemberIdAndProfileId($memberId, $profile->getId()); if (is_null($value['value'])) { if ($memberProfile) { if ($profile->isMultipleSelect()) { $memberProfile->clearChildren(); } $memberProfile->delete(); } continue; } if (!$memberProfile) { $memberProfile = new MemberProfile(); $memberProfile->setMemberId($memberId); $memberProfile->setProfileId($profile->getId()); } $memberProfile->setPublicFlag($memberProfile->getProfile()->getDefaultPublicFlag()); if (isset($value['public_flag'])) { $memberProfile->setPublicFlag($value['public_flag']); } $memberProfile->save(); if ($profile->isMultipleSelect()) { $ids = array(); $_values = array(); if ('date' === $profile->getFormType()) { $_values = array_map('intval', explode('-', $value['value'])); $options = $profile->getProfileOption(); foreach ($options as $option) { $ids[] = $option->getId(); } $memberProfile->setValue($value['value']); } else { $ids = $value['value']; } Doctrine::getTable('MemberProfile')->createChild($memberProfile, $memberId, $profile->getId(), $ids, $_values); } else { $memberProfile->setValue($value['value']); } $memberProfile->save(); } return true; }
public function save($memberId) { $values = $this->getValues(); foreach ($values as $key => $value) { $profile = Doctrine::getTable('Profile')->retrieveByName($key); if (!$profile) { continue; } $memberProfile = Doctrine::getTable('MemberProfile')->retrieveByMemberIdAndProfileId($memberId, $profile->getId()); if (!$memberProfile) { $memberProfile = new MemberProfile(); $memberProfile->setMemberId($memberId); $memberProfile->setProfileId($profile->getId()); } $memberProfile->setPublicFlag($memberProfile->getProfile()->getDefaultPublicFlag()); if (isset($value['public_flag'])) { $memberProfile->setPublicFlag($value['public_flag']); } $memberProfile->save(); if ($profile->isMultipleSelect()) { $children = $memberProfile->getNode()->getChildren(); if (count($children) < count($value['value'])) { $n = count($value['value']) - count($children); for ($i = 0; $i < $n; ++$i) { $childProfile = new MemberProfile(); $childProfile->setMemberId($memberId); $childProfile->setProfileId($profile->getId()); $childProfile->getNode()->insertAsLastChildOf($memberProfile); $childProfile->save(); } } $children = $memberProfile->getNode()->getChildren(); if ('date' === $profile->getFormType()) { foreach ($children as $child) { $child->setValue(null); $child->save(); } $_values = array_map('intval', explode('-', $value['value'])); $options = $profile->getProfileOption(); foreach ($_values as $i => $value) { $children[$i]->setValue($value); $children[$i]->save(); } } else { foreach ($children as $child) { $child->setProfileOptionId(null); $child->save(); } foreach ($value['value'] as $i => $v) { $children[$i]->setProfileOptionId($v); $children[$i]->save(); } } } else { $memberProfile->setValue($value['value']); } $children = $memberProfile->getNode()->getChildren(); foreach ($children as $child) { if ('' === $child->_get('value') && is_null($child->get('profile_option_id'))) { $child->getNode()->delete(); } } $memberProfile->save(); } return true; }
protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $this->conn = $databaseManager->getDatabase('doctrine')->getDoctrineConnection(); $sql = 'SELECT id FROM member WHERE is_active != 0'; $where = array(); if ( $options['min'] && $options['max'] && $options['min'] <= $options['max']) { $sql .= ' AND id BETWEEN ? AND ?'; $where = array(intval($options['min']),intval($options['max'])); } $memberIds = $this->conn->fetchColumn($sql, $where); // configを増やす if ($options['config']) { $configs = explode(',',$options['config']); foreach ($memberIds as $memberid) { $member = Doctrine::getTable('Member')->find($memberid); foreach ($configs as $config) { $member->setConfig($config, 'dummy'); $this->logSection('member_config', sprintf("%s - %s", $config, $memberid)); } $member->free(); } } // profileを増やす if ($options['profile']) { $profiles = explode(',',$options['profile']); $preProfiles = Doctrine::getTable('Profile')->createQuery() ->select('id') ->execute(array(), Doctrine::HYDRATE_NONE); foreach ($preProfiles as $key => $value) { $profileid = $value[0]; if (in_array($profileid, $profiles)) { foreach ($memberIds as $memberid) { $sql = 'SELECT id FROM member_profile WHERE member_id = ? AND profile_id = ?'; $where = array(intval($memberid), intval($profileid)); $mp = $this->conn->fetchOne($sql, $where); print "$mp"; if (!$mp) { opApplicationConfiguration::registerZend(); $memberProfile = new MemberProfile(); $memberProfile->setMemberId($memberid); $memberProfile->setProfileId($profileid); $memberProfile->setValue('dummy'); $memberProfile->save(); $memberProfile->free(); $this->logSection('member_profile', sprintf("%s - %s", $memberid, $profileid)); } } } } } }
public function createChild(Doctrine_Record $parent, $memberId, $profileId, $optionIds, $values = array()) { $parent->clearChildren(); foreach ($optionIds as $i => $optionId) { $childProfile = new MemberProfile(); $childProfile->setMemberId($memberId); $childProfile->setProfileId($profileId); $childProfile->setProfileOptionId($optionId); if (isset($values[$i])) { $childProfile->setValue($values[$i]); } $childProfile->getNode()->insertAsLastChildOf($parent); $childProfile->save(); } }
public function setMemberProfile($member, $name, $value) { $profile = Doctrine::getTable('Profile')->retrieveByName($name); if (!$profile) { return null; } $memberProfile = new MemberProfile(); $memberProfile->setMemberId($member->id); $memberProfile->setProfileId($profile->id); $memberProfile->setValue($value); $memberProfile->save(); }