Example #1
0
 /**
  * 将提交的过滤条件应用到table的过滤器上
  */
 protected function _applyFilter()
 {
     $fc = $this->_getFilterConfig();
     foreach ($_GET as $key => $val) {
         $rawKey = $key;
         if (!isset($fc[$key]) && (substr($key, -8) == 'MoreThan' || substr($key, -8) == 'LessThan')) {
             $key = substr($key, 0, -8);
         }
         if (!isset($fc[$key])) {
             continue;
         }
         $filter = $fc[$key];
         //是否允许空字符串作为条件,默认情况下不允许
         if (!isset($filter['allowEmptyString']) || !$filter['allowEmptyString']) {
             $field = $this->_table->getField($key);
             if (!preg_match('/(?:char|text|enum)/i', $field['Type']) && $val === '') {
                 continue;
             }
         }
         //检查值是否在忽略列表中
         if (isset($filter['ignore']) && !is_array($val)) {
             if (!is_array($filter['ignore'])) {
                 $filter['ignore'] = array($filter['ignore']);
             }
             if (in_array($val, $filter['ignore'])) {
                 continue;
             }
         }
         $cond = $this->_table->getCondition();
         if ($filter['type'] == 'between') {
             $betweenType = substr($rawKey, -8);
             if ($betweenType == 'MoreThan') {
                 if (isset($filter['leftOpen']) && $filter['leftOpen']) {
                     $operator = '>';
                 } else {
                     $operator = '>=';
                 }
             } else {
                 if (isset($filter['rightOpen']) && $filter['rightOpen']) {
                     $operator = '<';
                 } else {
                     $operator = '<=';
                 }
             }
             $cond->add($key, $val, $operator);
         } else {
             if (empty($filter['operator'])) {
                 $filter['operator'] = '=';
             }
             $cond->add($key, $val, $filter['operator']);
         }
         $this->_view->assign($rawKey, $val);
     }
 }
 /**
  * Set a property on a given object to a given value.
  *
  * Checks if the setter or the property are public are made before
  * calling this method.
  *
  * @param object $object   Object to set property on
  * @param object $accessor ReflectionMethod or ReflectionProperty
  * @param mixed  $value    Value of property
  *
  * @return void
  */
 protected function setProperty($object, $accessor, $value)
 {
     if ($accessor instanceof \ReflectionProperty) {
         $object->{$accessor->getName()} = $value;
     } else {
         if ($accessor instanceof ReflectionContainer) {
             $object->{$accessor->getName()}($accessor->getField(), $value);
         } else {
             $object->{$accessor->getName()}($value);
         }
     }
 }
Example #3
0
 /**
  * Method to create html for field custom text
  * @return string custom text or ''
  */
 public function getCustomText()
 {
     $field = $this->field->getField();
     //input
     $html = '';
     if (isset($field->customtext) && $field->customtext != '') {
         JPluginHelper::importPlugin('content');
         $customtext = JHtml::_('content.prepare', $field->customtext);
         $html .= '<div class="visCustomText ">' . $customtext . '</div>';
     }
     //Trigger onVisformsAfterCustomtextPrepare event to allow changes on field properties before control html is created
     JPluginHelper::importPlugin('visforms');
     $dispatcher = JDispatcher::getInstance();
     //make custom adjustments to the custom text html
     $dispatcher->trigger('onVisformsAfterCustomtextPrepare', array('com_visforms.field', &$html, $this->layout));
     return $html;
 }
 /**
  *Method to get all members for this context.
  * @return array|false of ids for members in current context, otherwise false.
  * @param  string      $contextCode
  */
 function getContextUsers($contextCode)
 {
     if ($this->_objDBContext->isInContext()) {
         if ($contextCode == '') {
             $this->_contextCode = $this->_objDBContext->getContextCode();
         } else {
             $this->_contextCode = $contextCode;
         }
         $path = array($this->_contextCode, $this->_contextGroup);
         $groupId = $this->_objGroupAdmin->getLeafId($path);
         // Get userIds of members
         $groupUsers = $this->_objGroupAdmin->getGroupUsers($groupId);
         $userIds = $this->_objGroupAdmin->getField($groupUsers, 'id');
         return $userIds;
     } else {
         return FALSE;
     }
 }
 /**
  * Method to create a child node for the tree recursively
  * @access Private
  * @param array $nodesArr : The list of nodes for a course
  * @param string $parentId : The Id of the parent Node
  * @param string $title : The Title of the node
  * @param string $sharedNodesArr : The array of shared nodes
  * @return string $basenode : A tree node 
  */
 function getChildNodes($nodeArr, $parentId, $title, $sharedNodesArr = NULL)
 {
     //setup the link
     $link = $this->URI(array('nodeid' => $parentId, 'action' => 'content'), $this->module);
     //create an indicator to see where you are on the tree
     if ($this->getParam('nodeid') == $parentId) {
         $icon = 'arrow.gif';
     } else {
         $icon = NULL;
     }
     //create a new tree node
     if ($title == '') {
         $title = '-[missing title]-';
     }
     $basenode = new treenode(array('text' => stripslashes($title), 'link' => $link, 'icon' => $icon, 'expandedIcon' => NULL));
     //add the shared nodes to the tree
     if (is_array($sharedNodesArr)) {
         foreach ($sharedNodesArr as $line) {
             if ($parentId == $line['nodeid']) {
                 //print $line['nodeid'];
                 $this->objDBContentNodes->resetTable();
                 $sharedRootNodeId = $this->objDBContentNodes->getField('tbl_context_parentnodes_id', $line['shared_nodeid']);
                 $tmpList = $this->objDBContentNodes->getAll("WHERE tbl_context_parentnodes_id='" . $sharedRootNodeId . "' ");
                 $basenode->addItem($this->getChildNodes($tmpList, $line['shared_nodeid'], $this->shortenString($this->objDBContentNodes->getField('title', $line['shared_nodeid']))));
             }
         }
     }
     //search for more children
     foreach ($nodeArr as $line) {
         if ($line['parent_Node'] == $parentId) {
             $text = $this->objDBContentNodes->getMenuText($line['id']);
             if ($text == '') {
                 $text = $line['title'];
             }
             $basenode->addItem($this->getChildNodes($nodeArr, $line['id'], $this->shortenString($text), $sharedNodesArr));
         }
     }
     return $basenode;
 }
Example #6
0
 /**
  * Method to validate the form data. 
  *  This override handle the inputs of files types, (Joomla issue when they
  * are required)
  *
  * @access	public
  * @param	object	$form	The form to validate against.
  * @param	array	$data	The data to validate.
  * @param	string	$group	The name of the field group to validate.
  *
  * @return	mixed	Array of filtered data if valid, false otherwise.
  */
 public function validate($form, $data, $group = null)
 {
     //Get the posted files if this model is concerned by files submission
     // JOOMLA FIX : if missing fields in $_POST -> issue in partial update when required
     $currentData = $this->getItem();
     foreach ($currentData as $fieldName => $value) {
         $field = $form->getField($fieldName, $group, $value);
         //Skip the ID data (and other fields not in the form)
         if (!$field) {
             continue;
         }
         //Missing in $_POST and required
         if (!in_array($fieldName, array_keys($data)) && $field->required) {
             //Insert the current object value. (UPDATE)
             $data[$fieldName] = $currentData->{$fieldName};
         }
     }
     //JOOMLA FIX : Reformate some field types not handled properly
     foreach ($form->getFieldset($group) as $field) {
         $value = null;
         if (isset($data[$field->fieldname])) {
             $value = $data[$field->fieldname];
         }
         switch ($field->type) {
             //JOOMLA FIX : Reformate the date/time format comming from the post
             case 'ckcalendar':
                 //cimport('helpers.dates');
                 if ($value && (string) $field->format && !RtiprintHelperDates::isNull((string) $value)) {
                     $time = RtiprintHelperDates::getSqlDate($value, array($field->format));
                     if ($time === null) {
                         JError::raiseWarning(1203, JText::sprintf('RTIPRINT_VALIDATOR_WRONG_DATETIME_FORMAT_FOR_PLEASE_RETRY', $field->label));
                         $valid = false;
                     } else {
                         $data[$field->fieldname] = RtiprintHelperDates::toSql($time);
                     }
                 }
                 break;
                 //JOOMLA FIX : Apply a null value if the field is in the form
             //JOOMLA FIX : Apply a null value if the field is in the form
             case 'ckcheckbox':
                 if (!$value) {
                     $data[$field->fieldname] = 0;
                 }
                 break;
         }
     }
     // JOOMLA FIX : always missing file names in $_POST -> issue when required
     //Get the posted files if this model is concerned by files submission
     if (count($this->fileFields)) {
         $fileInput = new JInput($_FILES);
         $files = $fileInput->get('jform', null, 'array');
         if (count($files['name'])) {
             foreach ($files['name'] as $fieldName => $value) {
                 //For required files, temporary insert the value comming from $_FILES
                 if (!empty($value)) {
                     $field = $form->getField($fieldName, $group);
                     if ($field->required) {
                         $data[$fieldName] = $value;
                     }
                 }
             }
         }
     }
     //Exec the native PHP validation (rules)
     $result = parent::validate($form, $data, $group);
     //check the result before to go further
     if ($result === false) {
         return false;
     }
     //ID key follower (in some case, ex : save2copy task)
     if (isset($data['id'])) {
         $result['id'] = $data['id'];
     }
     return $result;
 }
Example #7
0
 /**
  * Get records similiar to one record
  *
  * @param object $record The file_marc object for the current record
  * @param int    $max    The maximum records to return; Default is 5
  *
  * @throws object        PEAR Error
  * @return array         An array of query results
  * @access public
  */
 public function getMoreLikeThis($record, $max = 5)
 {
     // Create array of query parts:
     $parts = array();
     // Add Dewey class to query
     if ($deweyField = $record->getField('082')) {
         if ($deweyFieldData = $deweyField->getSubfield('a')) {
             $deweyClass = $deweyFieldData->getData();
             // Skip "English Fiction" Dewey class -- this won't give us useful
             // matches because there's too much of it and it's too broad.
             if (substr($deweyClass, 0, 3) != '823') {
                 $parts[] = 'srw.dd any "' . $deweyClass . '"';
             }
         }
     }
     // Add author to query
     if ($deweyField = $record->getField('100')) {
         if ($deweyFieldData = $deweyField->getSubfield('a')) {
             $parts[] = 'srw.au all "' . $deweyFieldData->getData() . '"';
         }
     }
     // Add subjects to query
     $subjTags = array('650', '651', '655');
     foreach ($subjTags as $currentTag) {
         if ($subjFieldList = $record->getFields($currentTag)) {
             foreach ($subjFieldList as $subjField) {
                 if ($subjField = $subjField->getSubfield('a')) {
                     $parts[] = 'srw.su all "' . trim($subjField->getData()) . '"';
                 }
             }
         }
     }
     // Add title to query
     if ($titleField = $record->getField('245')) {
         if ($titleFieldData = $titleField->getSubfield('a')) {
             $title = trim($titleFieldData->getData());
             if ($titleFieldData = $titleField->getSubfield('b')) {
                 $title .= ' ' . trim($titleFieldData->getData());
             }
             $parts[] = 'srw.ti any "' . str_replace('"', '', $title) . '"';
         }
     }
     // Not current record ID
     $idField = $record->getField('001');
     $id = trim($idField->getData());
     $query = '(' . implode(' or ', $parts) . ") not srw.no all \"{$id}\"";
     // Query String Parameters
     $options = array('operation' => 'searchRetrieve', 'query' => $query, 'maximumRecords' => $max, 'startRecord' => 1, 'wskey' => $this->_wskey, 'recordSchema' => 'marcxml');
     if ($this->debug) {
         echo '<pre>More Like This Query: ';
         print_r($query);
         echo "</pre>\n";
     }
     $result = $this->call('GET', $options);
     if (PEAR::isError($result)) {
         PEAR::raiseError($result);
     }
     return $result;
 }