/** * Render element * * @param Zend_Form_Element $element * @return string */ public function aElement(Zend_Form_Element $element) { $viewClasses = array($element->getAttrib('class')); if ($element->isRequired()) { if (!$element->getAttrib('title')) { $element->setAttrib('title', 'Field is required'); } $viewClasses[] = 'aForm-field-required'; } if ($element->getValidators()) { $viewClasses[] = 'aForm-field-validate'; } if ($element->hasErrors()) { $viewClasses[] = 'aForm-field-invalid'; } elseif ($element->getValue() || !$element->isRequired()) { $viewClasses[] = 'aForm-field-valid'; } if ($element->getValidators()) { $viewClasses[] = 'aForm-field-validate'; } $element->setAttrib('class', implode(' ', $viewClasses)); $options = null; $separator = null; if ($element instanceof Zend_Form_Element_Multi) { $options = $element->getMultiOptions(); $separator = $element->getSeparator(); } return $this->view->{$element->helper}($element->getName(), $element->getValue(), $element->getAttribs(), $options, $separator); }
/** * @param mixed $value * @return booleans */ public function isValid($value) { $db = Zend_Db_Table::getDefaultAdapter(); $sql = 'SELECT m.id FROM meeting m LEFT JOIN event e ON (m.id_event = e.id) WHERE m.ghost = false AND (e.latest = true OR (e.latest IS NULL AND m.id_meeting_type = 6)) AND m.id_meeting_type IN (3,4,6) AND ( (' . $db->quoteInto('m.meeting_at >= ?', $this->_objectEventAt->getValue()) . ' AND ' . $db->quoteInto('m.meeting_at + (m.length * interval \'1 minute\') <= timestamp ? + interval \'' . $this->_objectLength->getValue() . ' minutes\'', $this->_objectEventAt->getValue()) . ') OR (' . $db->quoteInto('m.meeting_at <= ?', $this->_objectEventAt->getValue()) . ' AND ' . $db->quoteInto('m.meeting_at >= timestamp ?', $this->_objectEventAt->getValue()) . ') OR (' . $db->quoteInto('m.meeting_at <= ?', $this->_objectEventAt->getValue()) . ' AND ' . $db->quoteInto('m.meeting_at + (m.length * interval \'1 minute\') >= timestamp ? + interval \'' . $this->_objectLength->getValue() . ' minutes\'', $this->_objectEventAt->getValue()) . ') OR (' . $db->quoteInto('m.meeting_at < timestamp ? + interval \'' . $this->_objectLength->getValue() . ' minutes\'', $this->_objectEventAt->getValue()) . ' AND ' . $db->quoteInto('m.meeting_at + (m.length * interval \'1 minute\') >= timestamp ? + interval \'' . $this->_objectLength->getValue() . ' minutes\'', $this->_objectEventAt->getValue()) . ') ) AND ' . $db->quoteInto('m.id_user = ?', Zend_Auth::getInstance()->getIdentity()->id) . ' AND ' . $db->quoteInto('m.id_branch = ?', Zend_Auth::getInstance()->getIdentity()->id_branch); if ($this->_nextEvent !== false) { $sql .= ' AND ' . $db->quoteInto('m.id_event <> ?', $this->_nextEvent); } $rows = $db->query($sql); if ($rows->rowCount() > 0) { $this->_error(self::VISIT_EXISTS); return false; } else { return true; } }
/** * @param mixed $value * @return booleans */ public function isValid($value) { if (count($this->_object->getValue()) >= count($this->_object->getMultiOptions())) { return true; } else { $this->_error(self::ALL_FIELDS_NOT_CHECKED); return false; } }
/** * Overrides isValid() from Zend_Validate_Interface * * @param string $value * @access public * @return bool */ public function isValid($value) { if (NULL === $this->_element) { require_once 'Zend/Exception.php'; throw new Zend_Exception('You must add a Zend_Form_Element to the SameAs validator prior to calling the isValid() method'); } if ($value != $this->_element->getValue()) { $this->_error(self::NOT_THE_SAME); return FALSE; } return TRUE; }
public function getValue($name = '') { $value = parent::getValue(); if ($name) { $value = isset($value[$name]) ? $value[$name] : ''; } return $value; }
/** * Get value * * If element type is one of the button types, returns the label. * * @param \Zend_Form_Element $element * * @return string|null */ public function getValue($element) { if (!$element instanceof \Zend_Form_Element) { return null; } foreach ($this->_buttonTypes as $type) { if ($element instanceof $type) { if (stristr($type, 'submit')) { $element->content = $element->getLabel(); return $element->getValue(); } if (stristr($type, 'button')) { $element->content = $element->getLabel(); return $element->getValue(); } return $element->getLabel(); } } return $element->getValue(); }
public function getValue() { $valueFiltered = parent::getValue(); $tmp = array(); if (!empty($valueFiltered)) { foreach ($valueFiltered as $value) { $_from = preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $value['from']) ? $value['from'] : ''; $_to = preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $value['to']) || empty($value['to']) ? $value['to'] : $_from; if (!empty($_from)) { array_push($tmp, array('from' => $_from, 'to' => $_to)); } } } return $tmp; }
public function getValue($toString = true) { $value = parent::getValue(); if (is_array($value)) { $xml = new SimpleXMLElement('<elementData />'); foreach ($value as $k => $v) { $xml->{$k} = $v; } } else { $xml = simplexml_load_string($value); } if (is_object($xml)) { if ($toString) { return $xml->asXML(); } else { return $xml; } } else { return null; } }
public function testPassingConfigObjectToConstructorSetsObjectState() { $config = new Zend_Config($this->getOptions()); $element = new Zend_Form_Element($config); $this->assertEquals('changed', $element->getName()); $this->assertEquals('foo', $element->getValue()); $this->assertEquals('bar', $element->getLabel()); $this->assertEquals(50, $element->getOrder()); $this->assertFalse($element->isRequired()); $this->assertEquals('bar', $element->foo); $this->assertEquals('bat', $element->baz); }
/** * Remove cookie.jar if configs change and convert form password to password element * @param string $section * @param string $namespace * @param unknown_type $key * @param Zend_Form_Element $element * @param Zend_Form $form * @param Zend_Controller_Action $controller */ public function prepareConfigElement($section, $namespace, $key, Zend_Form_Element $element, Zend_Form $form, Zend_Controller_Action $controller) { // nothing to do if this isn't the right section if ($namespace != $this->getId()) { return; } // remove cookie.jar if somethings has value if (!$form->isErrors() && !is_null($element->getValue())) { $this->clearLastCheck(); } }
/** * Get value * * If element type is one of the button types, returns the label. * * @param Zend_Form_Element $element * @return string|null */ public function getValue($element) { if (!$element instanceof Zend_Form_Element) { return null; } $type = $element->getType(); if (in_array($type, $this->_buttonTypes)) { return $element->getLabel(); } return $element->getValue(); }
/** * Remove cookie.jar if configs change and convert form password to password element * @param string $section * @param string $namespace * @param unknown_type $key * @param Zend_Form_Element $element * @param Zend_Form $form * @param Zend_Controller_Action $controller */ public function prepareConfigElement($section, $namespace, $key, Zend_Form_Element $element, Zend_Form $form, Zend_Controller_Action $controller) { // nothing to do if this isn't the right section if ($namespace != $this->getId()) { return; } switch ($key) { // i have to convert it to a password element case 'plugins_megavideo_premium_password': $password = $form->createElement('password', 'plugins_megavideo_premium_password', array('label' => $element->getLabel(), 'description' => $element->getDescription(), 'renderPassword' => true)); $form->plugins_megavideo_premium_password = $password; break; } // remove cookie.jar if somethings has value if (!$form->isErrors() && !is_null($element->getValue()) && file_exists(APPLICATION_PATH . '/../data/megavideo/cookie.jar')) { if (@(!unlink(APPLICATION_PATH . '/../data/megavideo/cookie.jar'))) { X_Debug::e("Error removing cookie.jar"); } } }
/** * Get value * * If element type is one of the button types, returns the label. * * @param Zend_Form_Element $element * @return string|null */ public function getValue($element) { if (!$element instanceof Zend_Form_Element) { return null; } foreach ($this->_buttonTypes as $type) { if ($element instanceof $type) { return $element->getLabel(); } } return $element->getValue(); }
/** * Gets form element html * * @param Zend_Form_Element $element * @return string */ protected function getInputHTML($element) { $helper = $element->helper; $elBelongsTo = $element->getBelongsTo(); if (!empty($this->belongsTo)) { $name = $this->mergeBelongsTo($this->belongsTo, $element->getBelongsTo()); $name .= '[' . $element->getName() . ']'; } else { if (!empty($elBelongsTo)) { $name = $this->mergeBelongsTo($elBelongsTo, $element->getName()); } else { $name = $element->getName(); } } $value = $element->getValue(); //echo 'Name:'.$name.' | Class:'. get_class($element).' | Helper:'.$helper.'['.$value.']'.'<br/>'; return $element->getView()->{$helper}($name, $value, $element->getAttribs(), $element->options); }
public function decorateConfig($content, Zend_Form_Element $element, array $options) { $view = $this->getView(); $value = $view->escape($element->getValue()); return '<textarea name="' . $view->escape($element->getName()) . '"' . ' class="f-max-size" readonly="readonly"' . ' id="' . $view->escape($element->getId()) . '"' . ' rows="' . (substr_count($value, "\n") + 1) . '" cols="80" style="width: 100%;"' . '>' . $value . '</textarea>'; }
/** * Convert form password to password element * @param string $section * @param string $namespace * @param unknown_type $key * @param Zend_Form_Element $element * @param Zend_Form $form * @param Zend_Controller_Action $controller */ public function prepareConfigElement($section, $namespace, $key, Zend_Form_Element $element, Zend_Form $form, Zend_Controller_Action $controller) { // nothing to do if this isn't the right section if ($namespace != $this->getId()) { return; } switch ($key) { // i have to convert it to a password element case 'plugins_rapidshare_premium_password': $password = $form->createElement('password', 'plugins_rapidshare_premium_password', array('label' => $element->getLabel(), 'description' => $element->getDescription(), 'renderPassword' => true)); $form->plugins_rapidshare_premium_password = $password; break; } // remove cookie if somethings has value if (!$form->isErrors() && !is_null($element->getValue()) && ($key = 'plugins_rapidshare_premium_password')) { // clean cookies try { X_Debug::i("Cleaning up cookies in cache"); /* @var $cacheHelper X_VlcShares_Plugins_Helper_Cache */ $cacheHelper = X_VlcShares_Plugins::helpers()->helper('cache'); try { $cacheHelper->retrieveItem("rapidshare::cookie"); // set expire date to now! $cacheHelper->storeItem("rapidshare::cookie", '', 0); } catch (Exception $e) { // nothing to do } try { $cacheHelper->retrieveItem("rapidshare::lastreloginflag"); // set expire date to now! $cacheHelper->storeItem("realdebrid::lastreloginflag", '', 0); } catch (Exception $e) { // nothing to do } } catch (Exception $e) { X_Debug::w("Cache plugin disabled? O_o"); } } }