protected function _getLanguageRow($parentData) { $s = new Kwf_Model_Select(); $s->whereEquals('domain', $parentData->id); $s->whereEquals('master', 1); return $this->_getModel()->getRow($s); }
protected function _getSelect($row) { $ret = new Kwf_Model_Select(); foreach ($this->_groupBy as $k => $field) { if (is_array($field)) { $values = $field; $field = $k; $valueFound = false; foreach ($values as $value) { if ($row->{$field} == $value) { $valueFound = true; $ret->whereEquals($field, $value); break; } } if (!$valueFound) { $ret->whereNotEquals($field, $values); } } else { if (is_null($row->{$field})) { $ret->whereNull($field); } else { $ret->whereEquals($field, $row->{$field}); } } } return $ret; }
private function _fetchRedirectUrl($type, $source, $host) { $s = new Kwf_Model_Select(); $s->whereEquals('type', $type); $source = rtrim($source, '/'); if ($type == 'domain' || $type == 'domainPath') { $sourceWithoutWww = preg_replace('#^www\\.#', '', $source); $sources = array($source, 'http://' . $source, $source . '/', 'http://' . $source . '/', $sourceWithoutWww, 'http://' . $sourceWithoutWww, $sourceWithoutWww . '/', 'http://' . $sourceWithoutWww . '/'); $s->whereEquals('source', $sources); } else { if (substr($source, 0, 6) == '/media') { $parts = explode('/', $source); if (isset($parts[6])) { $source = str_replace($parts[6], '%', $source); } $s->where(new Kwf_Model_Select_Expr_Like('source', $source)); } else { $sources = array($source, $source . '/'); $s->whereEquals('source', $sources); } } $s->whereEquals('active', true); if ($type == 'path') { if ($root = Kwf_Component_Data_Root::getInstance()) { $domainComponents = $root->getDomainComponents(array('ignoreVisible' => true)); if (count($domainComponents) > 1) { $path = $root->getComponent()->formatPath(array('host' => $host, 'path' => '')); if (!is_null($path)) { $path = trim($path, '/'); $component = $root->getComponent()->getPageByUrl($path, null); if ($component) { $s->whereEquals('domain_component_id', $component->getDomainComponent()->dbId); } else { return null; } } else { return null; } } } } $row = $this->getRow($s); $target = null; if ($row) { if ($row->target_type == 'extern') { $target = $row->target; } else { if ($row->target_type == 'intern' || $row->target_type == 'downloadTag') { $c = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($row->target); if ($c) { $target = $c->getAbsoluteUrl(); } } } } return $target; }
protected function _getRowById($id) { if (!$id) { return null; } $s = new Kwf_Model_Select(); $s->whereEquals($this->_model->getPrimaryKey(), $id); $s->whereEquals('component_id', $this->_getParam('componentId')); return $this->_model->getRow($s); }
public static function getSettings() { $ret = parent::getSettings(); $ret['generators']['content'] = array('class' => 'Kwf_Component_Generator_Static', 'component' => 'Kwc_Newsletter_Detail_Mail_Paragraphs_Component'); $select = new Kwf_Model_Select(); $select->whereEquals('unsubscribed', false); $select->whereEquals('activated', true); $select->order('id', 'ASC'); $ret['recipientSources'] = array('n' => array('model' => 'Kwc_Newsletter_Subscribe_Model', 'select' => $select)); $ret['trackViews'] = true; return $ret; }
public function importToQueue(Kwf_Model_Abstract $model, Kwf_Model_Select $select) { $newsletter = $this->getData()->row; if (in_array($newsletter->status, array('start', 'stop', 'finished', 'sending'))) { throw new Kwf_ClientException(trlKwf('Can only add users to a paused newsletter')); } $ret = array('rtrExcluded' => array()); // check if the necessary modelShortcut is set in 'mail' childComponent // this function checks if everything neccessary is set $this->getData()->getChildComponent('_mail')->getChildComponent('_redirect')->getComponent()->getRecipientModelShortcut(get_class($model)); if (!$model->hasColumnMappings('Kwc_Mail_Recipient_Mapping')) { throw new Kwf_Exception('Model "' . get_class($model) . '" has to implement column mapping "Kwc_Mail_Recipient_Mapping"'); } if ($model->hasColumnMappings('Kwc_Mail_Recipient_UnsubscribableMapping')) { $unsubscribeColumn = $model->getColumnMapping('Kwc_Mail_Recipient_UnsubscribableMapping', 'unsubscribed'); $select->whereEquals($unsubscribeColumn, 0); } if ($model->hasColumn('activated')) { $select->whereEquals('activated', 1); } $mapping = $model->getColumnMappings('Kwc_Mail_Recipient_Mapping'); $import = array(); $emails = array(); foreach ($model->export(Kwf_Model_Abstract::FORMAT_ARRAY, $select) as $e) { $searchArray = array(); foreach ($e as $k => $field) { if ($k == 'firstname' || $k == 'lastname' || $k == 'email') { $searchArray[] = $field; } } $searchText = implode(' ', $searchArray); $import[] = array('newsletter_id' => $newsletter->id, 'recipient_model' => get_class($model), 'recipient_id' => $e['id'], 'searchtext' => $searchText); $emails[] = $e[$mapping['email']]; } // check against rtr-ecg list if (count($emails) && $this->_getSetting('checkRtrList')) { $badKeys = Kwf_Util_RtrList::getBadKeys($emails); // remove the bad rtr entries from the list if ($badKeys) { foreach ($badKeys as $badKey) { $ret['rtrExcluded'][] = $emails[$badKey]; unset($import[$badKey]); } } } // add to model $queueModel = $this->getData()->parent->getComponent()->getChildModel()->getDependentModel('Queue'); $queueModel->import(Kwf_Model_Db::FORMAT_ARRAY, $import, array('ignore' => true)); return $ret; }
public function testWhere() { $select = new Kwf_Model_Select(); $select->whereEquals('parent_foo', 5); $count = $this->_modelChild->countRows($select); $this->assertEquals(1, $count); }
public function updatePages($cmp) { $s = new Kwf_Model_Select(); $s->whereEquals('component_id', $cmp->dbId); $rows = $this->getRows($s); $rowsByTargetPageId = array(); foreach ($rows as $r) { $rowsByTargetPageId[$r->target_page_id] = $r; } $childPagesComponentSelect = array('ignoreVisible' => true); $pos = 0; foreach ($cmp->getPage()->getChildPages($childPagesComponentSelect) as $childPage) { if (is_numeric($childPage->dbId)) { $id = $childPage->dbId; } else { $id = substr(md5($childPage->dbId), 0, 5); } $pos++; if (isset($rowsByTargetPageId[$childPage->dbId])) { $row = $rowsByTargetPageId[$childPage->dbId]; unset($rowsByTargetPageId[$childPage->dbId]); } else { $row = $this->createRow(); $row->target_page_id = $childPage->dbId; $row->visible = false; } $row->child_id = $id; $row->pos = $pos; $row->component_id = $cmp->dbId; $row->save(); } foreach ($rowsByTargetPageId as $row) { $row->delete(); } }
public function processInput(array $postData) { parent::processInput($postData); $this->_accessByMailRow = false; if (isset($postData['key'])) { $s = new Kwf_Model_Select(); $s->whereEquals('key', $postData['key']); $s->where(new Kwf_Model_Select_Expr_Higher('date', new Kwf_Date(time() - 24 * 60 * 60))); $this->_accessByMailRow = Kwf_Model_Abstract::getInstance('Kwf_Component_Plugin_AccessByMail_Model')->getRow($s); if (!$this->_accessByMailRow) { $this->_errors[] = array('message' => trlKwf("Invalid or expired Link. Please request a new one.")); } else { $session = new Kwf_Session_Namespace('kwc_' . $this->getData()->parent->componentId); $session->login = true; $session->key = $postData['key']; } } else { $session = new Kwf_Session_Namespace('kwc_' . $this->getData()->parent->componentId); if ($session->login) { $s = new Kwf_Model_Select(); $s->whereEquals('key', $session->key); $this->_accessByMailRow = Kwf_Model_Abstract::getInstance('Kwf_Component_Plugin_AccessByMail_Model')->getRow($s); } } }
protected function _getRecipient() { $rs = $this->_getMailComponent()->getRecipientSources(); $recipientId = $this->_getParam('recipientId'); if (!$recipientId) { $component = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getParam('componentId'), array('ignoreVisible' => true)); $source = reset($rs); $model = Kwf_Model_Abstract::getInstance($source['model']); $select = $model->select(); if ($model->hasColumn('newsletter_component_id')) { $select->whereEquals('newsletter_component_id', $component->parent->componentId); } if (isset($source['select'])) { $select->merge($source['select']); } $row = $model->getRow($select); if (!$row) { throw new Kwf_Exception_Client(trlKwf('Preview cannot be shown because it needs at least one recipient of this newsletter')); } $recipientId = $row->id; } $select = new Kwf_Model_Select(); $select->whereEquals('id', $recipientId); $subscribeModelKey = $this->_getParam('subscribeModelKey'); if (!$subscribeModelKey) { $subscribeModelKey = current(array_keys($rs)); } $model = $rs[$subscribeModelKey]['model']; $row = Kwf_Model_Abstract::getInstance($model)->getRow($select); return $row; }
public function getUserToLoginByParams($redirectBackUrl, array $params) { $userData = $this->_getUserDataByParams($redirectBackUrl, $params); $s = new Kwf_Model_Select(); $s->whereEquals('facebook_user_id', $userData->id); return $this->_model->getRow($s); }
public function setUp() { parent::setUp(); $select = new Kwf_Model_Select(); $select->whereEquals('active', 1); $this->_model = new Kwf_Model_Union(array('models' => array('a' => 'Kwf_Model_Union_MergeSelect_Model1', 'b' => array('model' => 'Kwf_Model_Union_MergeSelect_Model2', 'select' => $select)), 'columnMapping' => 'Kwf_Model_Union_MergeSelect_TestMapping')); }
protected function _subscriptionExists(Kwc_Newsletter_Subscribe_Row $row) { if ($row->id) { throw new Kwf_Exception("you can only insert unsaved rows"); } $s = new Kwf_Model_Select(); $s->whereEquals('email', $row->email); //what if the email field is not named email? $s->whereEquals('newsletter_component_id', $this->getSubscribeToNewsletterComponent()->dbId); $s->where(new Kwf_Model_Select_Expr_Or(array(new Kwf_Model_Select_Expr_Equal('unsubscribed', 1), new Kwf_Model_Select_Expr_Equal('activated', 1)))); if ($row->getModel()->countRows($s)) { //already subscribed, don't save return true; } return false; }
public function orderConfirmed(Kwc_Shop_Cart_Order $order) { if (!$order->voucher_code) { return; } $c = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($order->checkout_component_id); foreach ($c->getComponent()->getSumRows($order) as $sumRow) { if (isset($sumRow['type']) && $sumRow['type'] == 'voucher') { $s = new Kwf_Model_Select(); $s->whereEquals('code', $order->voucher_code); $row = Kwf_Model_Abstract::getInstance('Kwc_Shop_Cart_Plugins_Voucher_Vouchers')->getRow($s); $remainingAmount = $row->amount - $row->used_amount + $sumRow['amount']; $h = $row->createChildRow('history'); $h->amount = -$sumRow['amount']; $h->order_id = $order->id; $h->date = $order->date; $h->comment = trlKwf('Order') . ' ' . $order->order_number; $h->save(); //verbrauchten betrag auch noch bei der order speichern $order->voucher_amount = (double) $h->amount; $order->voucher_remaining_amount = (double) $remainingAmount; $order->save(); break; } } }
public function testExprCompareHigherInSelect() { $select = new Kwf_Model_Select(); $select->whereEquals('expr_foo_bar_higher', true); $count = $this->_modelChild->countRows($select); $this->assertEquals(2, $count); }
/** * returns a list of all visible favourite componentIds */ public static function getFavouriteComponentIds($favouritesModel) { $ret = array(); $userId = Kwf_Registry::get('userModel')->getAuthedUserId(); if ($userId) { $cacheIdUser = '******' . $userId; $ret = Kwf_Cache_Simple::fetch($cacheIdUser, $success); if (!$success) { // get all favourites related to user $select = new Kwf_Model_Select(); $select->whereEquals('user_id', $userId); $favouritesModel = Kwf_Model_Abstract::getInstance($favouritesModel); $favourites = $favouritesModel->getRows($select); $componentIds = array(); foreach ($favourites as $favourite) { $component = Kwf_Component_Data_Root::getInstance()->getComponentById($favourite->component_id); // check if component is visible and existent if ($component) { // if component is visible create list of users related to component $componentIds[] = $component->componentId; } } // cache relation of visible components to user Kwf_Cache_Simple::add($cacheIdUser, $componentIds); $ret = $componentIds; } } return $ret; }
public function jsonParseFilesAction() { $pattern = array('start' => array('** Exception **', '** Thrown **', '** Message **', '** ExceptionDetail **', '** REQUEST_URI **', '** HTTP_REFERER **', '** User **', '** Time **', '** _USERAGENT **', '** _GET **', '** _POST **', '** _SERVER **', '** _FILES **', '** _SESSION **'), 'end' => array('-- Exception --', '-- Thrown --', '-- Message --', '-- ExceptionDetail --', '-- REQUEST_URI --', '-- HTTP_REFERER --', '-- User --', '-- Time --', '-- _USERAGENT --', '-- _GET --', '-- _POST --', '-- _SERVER --', '-- _FILES --', '-- _SESSION --')); $files = glob('log/*/*/*'); if (empty($files)) { throw new Kwf_Exception_Client(trlKwf('No log files found.')); } $data = array(); foreach ($files as $filename) { $logMessage = array(); $fileInfo = pathinfo($filename); $folders = explode('/', $fileInfo['dirname']); $file = file_get_contents($filename); for ($i = 0; $i < count($pattern['start']); $i++) { preg_match_all('/(' . preg_quote($pattern['start'][$i]) . ')(.+?)(' . preg_quote($pattern['end'][$i]) . ')/si', $file, $matches); if (empty($matches[1])) { continue; } $logMessage[trim(str_replace('**', '', $matches[1][0]))] = trim($matches[2][0]); } $select = new Kwf_Model_Select(); $select->whereEquals('filename', $fileInfo['filename']); if ($this->_getModel()->countRows($select) > 0) { continue; } $data[] = array('type' => $folders[1], 'exception' => isset($logMessage['Exception']) ? $logMessage['Exception'] : '', 'thrown' => isset($logMessage['Thrown']) ? $logMessage['Thrown'] : '', 'message' => isset($logMessage['Message']) ? $logMessage['Message'] : '', 'exception_detail' => isset($logMessage['ExceptionDetail']) ? $logMessage['ExceptionDetail'] : '', 'request_uri' => isset($logMessage['REQUEST_URI']) ? $logMessage['REQUEST_URI'] : '', 'http_referer' => isset($logMessage['HTTP_REFERER']) ? $logMessage['HTTP_REFERER'] : '', 'user' => isset($logMessage['User']) ? $logMessage['User'] : '', 'useragent' => isset($logMessage['_USERAGENT']) ? $logMessage['_USERAGENT'] : '', 'get' => isset($logMessage['_GET']) ? $logMessage['_GET'] : '', 'post' => isset($logMessage['_POST']) ? $logMessage['_POST'] : '', 'server' => isset($logMessage['_SERVER']) ? $logMessage['_SERVER'] : '', 'files' => isset($logMessage['_FILES']) ? $logMessage['_FILES'] : '', 'session' => isset($logMessage['_SESSION']) ? $logMessage['_SESSION'] : '', 'filename' => $fileInfo['filename'], 'date' => $folders[2] . ' ' . $logMessage['Time']); } $this->_getModel()->import(Kwf_Model_Abstract::FORMAT_ARRAY, $data); $this->view->message = trlKwf('All files successfully parsed'); }
public function jsonGetFavouritesAction() { $rows = array(); $authedUser = Kwf_Registry::get('userModel')->getAuthedUser(); if ($authedUser) { $modelClass = Kwc_Abstract::getSetting($this->_getParam('class'), 'favouritesModel'); $model = Kwf_Model_Abstract::getInstance($modelClass); $select = new Kwf_Model_Select(); $select->whereEquals('user_id', $authedUser->id); $select->whereEquals('component_id', $this->_getParam('kwcFavouritesComponentIds')); foreach ($model->export(Kwf_Model_Abstract::FORMAT_ARRAY, $select, array('columns' => array('component_id'))) as $row) { $rows[] = $row['component_id']; } } $this->view->componentIds = $rows; }
public function __get($name) { if ($name == 'name' || $name == 'col_span' || $name == 'total_columns' || $name == 'columns') { if (!isset($this->_rows)) { $select = new Kwf_Model_Select(); $select->whereEquals('component_id', $this->component_id); $select->order('pos'); $this->_rows = $this->getModel()->getRows($select); } $columnTypes = Kwc_Abstract::getSetting($this->getModel()->getComponentClass(), 'columns'); $typeName = array_keys($columnTypes); $typeName = array_shift($typeName); if ($parentRow = $this->getParentRow('Component')) { $typeName = $parentRow->type; } $type = $columnTypes[$typeName]; if ($name == 'columns') { return array_sum($type['colSpans']); } if ($name == 'total_columns') { return count($type['colSpans']); } unset($columnTypes); $i = 0; $countInvisible = 0; foreach ($this->_rows as $row) { if (!$row->visible) { $countInvisible++; $i++; if ($this == $row) { if ($name == 'name') { return trlKwf('Invisible'); } else { if ($name == 'col_span') { return max($type['colSpans']); } } } else { continue; } } $number = $i - $countInvisible; while ($number >= count($type['colSpans'])) { $number -= count($type['colSpans']); } if ($this == $row) { if ($name == 'name') { return trlKwf('Column {0}, width {1}%', array($number + 1, floor($type['colSpans'][$number] / array_sum($type['colSpans']) * 100))); } else { if ($name == 'col_span') { return $type['colSpans'][$number]; } } } $i++; } } return parent::__get($name); }
public function getSelect() { $select = parent::getSelect(); $s = new Kwf_Model_Select(); $s->whereEquals('category_id', $this->getData()->parent->id); $select->where(new Kwf_Model_Select_Expr_Child_Contains('Categories', $s)); return $select; }
public function testOrder() { $s = new Kwf_Model_Select(); $s->whereEquals('id', 1); $s->order('foo'); $row = $this->_modelChild->getRow($s); $this->assertEquals($row->foo, 777); }
public function testParentExpression() { $s = new Kwf_Model_Select(); $s->whereEquals('id', 2); $s->expr('parent_bar'); $row = $this->_model->getRow($s); $this->assertEquals(5, $row->parent_bar); }
public function testDeleteRows() { $model = $this->_m; $model->getRow(1)->delete(); $s = new Kwf_Model_Select(); $s->whereEquals('id', 1); $model->deleteRows($s); $this->assertEquals(1, $model->countRows()); }
protected function _getSelect() { $ret = parent::_getSelect(); if ($this->_getParam('valuesqry') == 'true') { $ret = new Kwf_Model_Select(); $ret->whereEquals('id', explode('|', $this->_getParam('query'))); } return $ret; }
public function load($row) { if ($this->getFieldname() == 'author_id') { $select = new Kwf_Model_Select(); $select->whereEquals('id', $this->_getChainedRow($row)->author_id); return Kwf_Model_Abstract::getInstance('Kwc_Articles_Directory_AuthorsModel')->getRow($select)->name; } parent::load($row); }
public function testChildSumWithExpressionLazy() { $select = new Kwf_Model_Select(); $s = new Kwf_Model_Select(); $s->whereEquals('id', 1); $row = $this->_modelBar->getRow($s); $sum = $row->foo_value_sum; $this->assertEquals(6, $sum); }
protected function _getSelect() { $ret = parent::_getSelect(); if ($this->_getParam('positionId')) { $s = new Kwf_Model_Select(); $s->whereEquals('groupId', $this->_getParam('positionId')); $ret->where(new Kwf_Model_Select_Expr_Child_Contains('EmployeeFlightRoles', $s))->whereEquals('groupType', '1'); } return $ret; }
public function getSelect() { $class = $this->getData()->parent->parent->componentClass; $childReference = Kwc_Abstract::hasSetting($class, 'childReferenceName') ? Kwc_Abstract::getSetting($class, 'childReferenceName') : 'Categories'; $select = parent::getSelect(); $s = new Kwf_Model_Select(); $s->whereEquals('category_id', $this->getData()->parent->id); $select->where(new Kwf_Model_Select_Expr_Child_Contains($childReference, $s)); return $select; }
public function testChildContains() { $select = new Kwf_Model_Select(); $childSelect = new Kwf_Model_Select(); $childSelect->whereEquals('bar', 5); $s = new Kwf_Model_Select(); $s->where(new Kwf_Model_Select_Expr_Child_Contains('Reference1', $childSelect)); $foo = $this->_modelFoo->getRow($s); $this->assertEquals('5', $foo->foo); }
public function testChildContains2() { $model = Kwf_Model_Abstract::getInstance('Kwf_Model_Union_Dependent_Parent'); $childSelect = new Kwf_Model_Select(); $childSelect->whereEquals('foo', 'xx'); $select = new Kwf_Model_Select(); $select->where(new Kwf_Model_Select_Expr_Child_Contains('TestModel', $childSelect)); $this->assertEquals(2, count($model->getRows($select))); $this->assertEquals(2, $model->countRows($select)); }